1#include <gtest/gtest.h>
27using tracegen::ExecutionTraceBuilder;
28using tracegen::IndexedTreeCheckTraceBuilder;
29using tracegen::TestTraceContainer;
31using simulation::DeduplicatingEventEmitter;
32using simulation::EventEmitter;
33using simulation::FieldGreaterThan;
34using simulation::FieldGreaterThanEvent;
35using simulation::IndexedTreeCheck;
37using simulation::IndexedTreeLeafData;
38using simulation::MockMerkleCheck;
39using simulation::MockPoseidon2;
40using simulation::MockRangeCheck;
44using testing::NiceMock;
51TEST(NullifierExistsConstrainingTest, PositiveTest)
53 TestTraceContainer
trace({ { { C::execution_sel, 1 },
54 { C::execution_sel_execute_nullifier_exists, 1 },
55 { C::execution_register_0_,
FF(0x123456) },
56 { C::execution_register_1_, 1 },
57 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
58 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
59 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U1) },
62 { C::execution_sel_opcode_error, 0 },
64 check_relation<nullifier_exists>(trace);
67TEST(NullifierExistsConstrainingTest, PositiveNullifierNotExists)
69 TestTraceContainer
trace({ { { C::execution_sel, 1 },
70 { C::execution_sel_execute_nullifier_exists, 1 },
71 { C::execution_register_0_,
FF(0x123456) },
72 { C::execution_register_1_, 0 },
73 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
74 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
75 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U1) },
78 { C::execution_sel_opcode_error, 0 },
80 check_relation<nullifier_exists>(trace);
83TEST(NullifierExistsConstrainingTest, NegativeInvalidOutputTag)
85 TestTraceContainer
trace({ { { C::execution_sel, 1 },
86 { C::execution_sel_execute_nullifier_exists, 1 },
87 { C::execution_register_0_,
FF(0x123456) },
88 { C::execution_register_1_, 0 },
89 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
90 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
91 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U8) },
94 { C::execution_sel_opcode_error, 0 },
98 "NULLIFIER_EXISTS_U1_OUTPUT_TAG");
101TEST(NullifierExistsConstrainingTest, NegativeNullifierExistsSuccess)
103 TestTraceContainer
trace({ {
104 { C::execution_sel_execute_nullifier_exists, 1 },
105 { C::execution_sel_opcode_error, 1 },
109 "INFALLIBLE_OPCODES_SUCCESS");
112TEST(NullifierExistsConstrainingTest, Interactions)
118 DeduplicatingEventEmitter<FieldGreaterThanEvent>
event_emitter;
126 FF siloed_nullifier = 42;
130 .
value = siloed_nullifier,
135 AppendOnlyTreeSnapshot nullifier_tree_snapshot = AppendOnlyTreeSnapshot{
137 .next_available_leaf_index = 128,
149 nullifier_tree_snapshot);
151 TestTraceContainer
trace({ {
152 { C::execution_sel_execute_nullifier_exists, 1 },
153 { C::execution_register_0_, siloed_nullifier },
154 { C::execution_register_1_, 1 },
155 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
156 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U1) },
157 { C::execution_prev_nullifier_tree_root, nullifier_tree_snapshot.root },
160 { C::execution_sel_opcode_error, 0 },
164 IndexedTreeCheckTraceBuilder indexed_tree_check_trace_builder;
167 check_relation<nullifier_exists>(trace);
169 check_interaction<ExecutionTraceBuilder, lookup_nullifier_exists_nullifier_exists_check_settings>(trace);
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#define AVM_EXEC_OP_ID_NULLIFIER_EXISTS
#define NULLIFIER_TREE_HEIGHT
#define DOM_SEP__NULLIFIER_MERKLE
FieldGreaterThan field_gt
IndexedTreeCheck indexed_tree_check
EventEmitter< simulation::IndexedTreeCheckEvent > indexed_tree_check_event_emitter
static constexpr size_t SR_INFALLIBLE_OPCODES_SUCCESS
static constexpr size_t SR_NULLIFIER_EXISTS_U1_OUTPUT_TAG
void assert_read(const FF &value, std::optional< IndexedTreeSiloingParameters > siloing_params, bool exists, const IndexedTreeLeafData &low_leaf_preimage, uint64_t low_leaf_index, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &snapshot) override
Performs a membership/non-membership read check on an indexed tree.
Native Poseidon2 hash function implementation.
EventEmitter< DataCopyEvent > event_emitter
IndexedTreeLeafData low_leaf
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > NullifierTreeLeafPreimage
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > poseidon2
std::variant< IndexedTreeReadWriteEvent, CheckPointEventType > IndexedTreeCheckEvent
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
NiceMock< MockExecution > execution