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;
42using testing::NiceMock;
49TEST(NullifierExistsConstrainingTest, PositiveTest)
51 TestTraceContainer
trace({ { { C::execution_sel, 1 },
52 { C::execution_sel_execute_nullifier_exists, 1 },
53 { C::execution_register_0_,
FF(0x123456) },
54 { C::execution_register_1_, 1 },
55 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
56 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
57 { C::execution_mem_tag_reg_1_,
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_, 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::U1) },
72 { C::execution_sel_opcode_error, 0 },
74 check_relation<nullifier_exists>(trace);
77TEST(NullifierExistsConstrainingTest, NegativeInvalidOutputTag)
79 TestTraceContainer
trace({ { { C::execution_sel, 1 },
80 { C::execution_sel_execute_nullifier_exists, 1 },
81 { C::execution_register_0_,
FF(0x123456) },
82 { C::execution_register_1_, 0 },
83 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
84 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
85 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U8) },
86 { C::execution_sel_opcode_error, 0 },
90 "NULLIFIER_EXISTS_U1_OUTPUT_TAG");
93TEST(NullifierExistsConstrainingTest, NegativeNullifierExistsSuccess)
95 TestTraceContainer
trace({ {
96 { C::execution_sel_execute_nullifier_exists, 1 },
97 { C::execution_sel_opcode_error, 1 },
101 "INFALLIBLE_OPCODES_SUCCESS");
104TEST(NullifierExistsConstrainingTest, Interactions)
110 DeduplicatingEventEmitter<FieldGreaterThanEvent>
event_emitter;
113 EventEmitter<NullifierTreeCheckEvent> nullifier_tree_check_event_emitter;
114 NullifierTreeCheck nullifier_tree_check(
poseidon2, merkle_check,
field_gt, nullifier_tree_check_event_emitter);
117 FF siloed_nullifier = 42;
122 AppendOnlyTreeSnapshot nullifier_tree_snapshot = AppendOnlyTreeSnapshot{
124 .next_available_leaf_index = 128,
128 nullifier_tree_check.assert_read(
131 TestTraceContainer
trace({ {
132 { C::execution_sel_execute_nullifier_exists, 1 },
133 { C::execution_register_0_, siloed_nullifier },
134 { C::execution_register_1_, 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::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 EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#define AVM_EXEC_OP_ID_NULLIFIER_EXISTS
FieldGreaterThan field_gt
static constexpr size_t SR_INFALLIBLE_OPCODES_SUCCESS
static constexpr size_t SR_NULLIFIER_EXISTS_U1_OUTPUT_TAG
Native Poseidon2 hash function implementation.
EventEmitter< DataCopyEvent > event_emitter
NullifierTreeLeafPreimage 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
::bb::crypto::merkle_tree::NullifierLeafValue NullifierLeafValue
std::variant< NullifierTreeReadWriteEvent, CheckPointEventType > NullifierTreeCheckEvent
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
NiceMock< MockExecution > execution