1#include <gtest/gtest.h>
26using tracegen::ExecutionTraceBuilder;
27using tracegen::NullifierTreeCheckTraceBuilder;
28using tracegen::TestTraceContainer;
30using simulation::DeduplicatingEventEmitter;
31using simulation::EventEmitter;
32using simulation::FieldGreaterThan;
33using simulation::FieldGreaterThanEvent;
34using simulation::MockMerkleCheck;
35using simulation::MockPoseidon2;
36using simulation::MockRangeCheck;
37using simulation::NullifierTreeCheck;
40using testing::NiceMock;
46TEST(NullifierExistsConstrainingTest, PositiveTest)
48 TestTraceContainer
trace({ { { C::execution_sel, 1 },
49 { C::execution_sel_execute_nullifier_exists, 1 },
50 { C::execution_register_0_,
FF(0x123456) },
51 { C::execution_register_1_,
FF(0xdeadbeef) },
52 { C::execution_register_2_, 1 },
53 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
54 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
55 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
56 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
57 { C::execution_sel_opcode_error, 0 },
59 check_relation<nullifier_exists>(
trace);
62TEST(NullifierExistsConstrainingTest, PositiveNullifierNotExists)
64 TestTraceContainer
trace({ { { C::execution_sel, 1 },
65 { C::execution_sel_execute_nullifier_exists, 1 },
66 { C::execution_register_0_,
FF(0x123456) },
67 { C::execution_register_1_,
FF(0xdeadbeef) },
68 { C::execution_register_2_, 0 },
69 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
70 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
71 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
72 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
73 { C::execution_sel_opcode_error, 0 },
75 check_relation<nullifier_exists>(
trace);
78TEST(NullifierExistsConstrainingTest, NegativeInvalidOutputTag)
80 TestTraceContainer
trace({ { { C::execution_sel, 1 },
81 { C::execution_sel_execute_nullifier_exists, 1 },
82 { C::execution_register_0_,
FF(0x123456) },
83 { C::execution_register_1_,
FF(0xdeadbeef) },
84 { C::execution_register_2_, 0 },
85 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
86 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
87 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
88 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
89 { C::execution_sel_opcode_error, 0 },
93 "NULLIFIER_EXISTS_U1_OUTPUT_TAG");
96TEST(NullifierExistsConstrainingTest, NegativeNullifierExistsSuccess)
98 TestTraceContainer
trace({ {
99 { C::execution_sel_execute_nullifier_exists, 1 },
100 { C::execution_sel_opcode_error, 1 },
104 "NULLIFIER_EXISTS_SUCCESS");
107TEST(NullifierExistsConstrainingTest, Interactions)
110 NiceMock<MockMerkleCheck> merkle_check;
113 DeduplicatingEventEmitter<FieldGreaterThanEvent>
event_emitter;
116 EventEmitter<NullifierTreeCheckEvent> nullifier_tree_check_event_emitter;
117 NullifierTreeCheck nullifier_tree_check(
poseidon2, merkle_check,
field_gt, nullifier_tree_check_event_emitter);
122 AppendOnlyTreeSnapshot nullifier_tree_snapshot = AppendOnlyTreeSnapshot{
124 .nextAvailableLeafIndex = 128,
127 nullifier_tree_check.assert_read(
nullifier, address,
true, {}, 0, {}, nullifier_tree_snapshot);
129 TestTraceContainer
trace({ {
130 { C::execution_sel_execute_nullifier_exists, 1 },
132 { C::execution_register_1_, address },
133 { C::execution_register_2_, 1 },
134 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
135 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
136 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
137 { C::execution_prev_nullifier_tree_root, nullifier_tree_snapshot.root },
138 { C::execution_sel_opcode_error, 0 },
142 NullifierTreeCheckTraceBuilder nullifier_tree_check_trace_builder;
143 nullifier_tree_check_trace_builder.process(nullifier_tree_check_event_emitter.dump_events(),
trace);
145 check_relation<nullifier_exists>(
trace);
147 check_interaction<ExecutionTraceBuilder, lookup_nullifier_exists_nullifier_exists_check_settings>(
trace);
#define AVM_EXEC_OP_ID_NULLIFIER_EXISTS
static constexpr size_t SR_NULLIFIER_EXISTS_U1_OUTPUT_TAG
static constexpr size_t SR_NULLIFIER_EXISTS_SUCCESS
EventEmitter< DataCopyEvent > event_emitter
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > poseidon2
std::variant< NullifierTreeReadWriteEvent, CheckPointEventType > NullifierTreeCheckEvent
FieldGreaterThan field_gt