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;
47TEST(NullifierExistsConstrainingTest, PositiveTest)
49 TestTraceContainer
trace({ { { C::execution_sel, 1 },
50 { C::execution_sel_execute_nullifier_exists, 1 },
51 { C::execution_register_0_,
FF(0x123456) },
52 { C::execution_register_1_,
FF(0xdeadbeef) },
53 { C::execution_register_2_, 1 },
54 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
55 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
56 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
57 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
58 { C::execution_sel_opcode_error, 0 },
60 check_relation<nullifier_exists>(trace);
63TEST(NullifierExistsConstrainingTest, PositiveNullifierNotExists)
65 TestTraceContainer
trace({ { { C::execution_sel, 1 },
66 { C::execution_sel_execute_nullifier_exists, 1 },
67 { C::execution_register_0_,
FF(0x123456) },
68 { C::execution_register_1_,
FF(0xdeadbeef) },
69 { C::execution_register_2_, 0 },
70 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
71 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
72 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
73 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
74 { C::execution_sel_opcode_error, 0 },
76 check_relation<nullifier_exists>(trace);
79TEST(NullifierExistsConstrainingTest, NegativeInvalidOutputTag)
81 TestTraceContainer
trace({ { { C::execution_sel, 1 },
82 { C::execution_sel_execute_nullifier_exists, 1 },
83 { C::execution_register_0_,
FF(0x123456) },
84 { C::execution_register_1_,
FF(0xdeadbeef) },
85 { C::execution_register_2_, 0 },
86 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
87 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
88 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
89 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U8) },
90 { C::execution_sel_opcode_error, 0 },
94 "NULLIFIER_EXISTS_U1_OUTPUT_TAG");
97TEST(NullifierExistsConstrainingTest, NegativeNullifierExistsSuccess)
99 TestTraceContainer
trace({ {
100 { C::execution_sel_execute_nullifier_exists, 1 },
101 { C::execution_sel_opcode_error, 1 },
105 "INFALLIBLE_OPCODES_SUCCESS");
108TEST(NullifierExistsConstrainingTest, Interactions)
111 NiceMock<MockMerkleCheck> merkle_check;
114 DeduplicatingEventEmitter<FieldGreaterThanEvent>
event_emitter;
117 EventEmitter<NullifierTreeCheckEvent> nullifier_tree_check_event_emitter;
118 NullifierTreeCheck nullifier_tree_check(
poseidon2, merkle_check,
field_gt, nullifier_tree_check_event_emitter);
123 AppendOnlyTreeSnapshot nullifier_tree_snapshot = AppendOnlyTreeSnapshot{
125 .next_available_leaf_index = 128,
128 nullifier_tree_check.assert_read(
nullifier,
address,
true, {}, 0, {}, nullifier_tree_snapshot);
130 TestTraceContainer
trace({ {
131 { C::execution_sel_execute_nullifier_exists, 1 },
133 { C::execution_register_1_,
address },
134 { C::execution_register_2_, 1 },
135 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
136 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::FF) },
137 { C::execution_mem_tag_reg_2_,
static_cast<uint8_t
>(
MemoryTag::U1) },
138 { C::execution_prev_nullifier_tree_root, nullifier_tree_snapshot.root },
139 { C::execution_sel_opcode_error, 0 },
143 NullifierTreeCheckTraceBuilder nullifier_tree_check_trace_builder;
144 nullifier_tree_check_trace_builder.process(nullifier_tree_check_event_emitter.dump_events(),
trace);
146 check_relation<nullifier_exists>(trace);
148 check_interaction<ExecutionTraceBuilder, lookup_nullifier_exists_nullifier_exists_check_settings>(trace);
FieldGreaterThan field_gt
#define AVM_EXEC_OP_ID_NULLIFIER_EXISTS
static constexpr size_t SR_INFALLIBLE_OPCODES_SUCCESS
static constexpr size_t SR_NULLIFIER_EXISTS_U1_OUTPUT_TAG
EventEmitter< DataCopyEvent > event_emitter
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessage)
TEST(TxExecutionConstrainingTest, WriteTreeValue)
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > poseidon2
std::variant< NullifierTreeReadWriteEvent, CheckPointEventType > NullifierTreeCheckEvent
NiceMock< MockExecution > execution