1#include <gtest/gtest.h>
26using tracegen::ExecutionTraceBuilder;
27using tracegen::IndexedTreeCheckTraceBuilder;
28using tracegen::TestTraceContainer;
30using simulation::DeduplicatingEventEmitter;
31using simulation::EventEmitter;
32using simulation::FieldGreaterThan;
33using simulation::FieldGreaterThanEvent;
34using simulation::IndexedTreeCheck;
36using simulation::IndexedTreeLeafData;
37using simulation::MockMerkleCheck;
38using simulation::MockPoseidon2;
39using simulation::MockRangeCheck;
43using testing::NiceMock;
50TEST(NullifierExistsConstrainingTest, PositiveTest)
52 TestTraceContainer
trace({ { { C::execution_sel, 1 },
53 { C::execution_sel_execute_nullifier_exists, 1 },
54 { C::execution_register_0_,
FF(0x123456) },
55 { C::execution_register_1_, 1 },
56 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
57 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
58 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U1) },
60 { C::execution_sel_opcode_error, 0 },
62 check_relation<nullifier_exists>(trace);
65TEST(NullifierExistsConstrainingTest, PositiveNullifierNotExists)
67 TestTraceContainer
trace({ { { C::execution_sel, 1 },
68 { C::execution_sel_execute_nullifier_exists, 1 },
69 { C::execution_register_0_,
FF(0x123456) },
70 { C::execution_register_1_, 0 },
71 { C::execution_prev_nullifier_tree_root,
FF(0xabc) },
72 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
73 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U1) },
75 { C::execution_sel_opcode_error, 0 },
77 check_relation<nullifier_exists>(trace);
80TEST(NullifierExistsConstrainingTest, NegativeInvalidOutputTag)
82 TestTraceContainer
trace({ { { C::execution_sel, 1 },
83 { C::execution_sel_execute_nullifier_exists, 1 },
84 { C::execution_register_0_,
FF(0x123456) },
85 { C::execution_register_1_, 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::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)
114 DeduplicatingEventEmitter<FieldGreaterThanEvent>
event_emitter;
121 FF siloed_nullifier = 42;
125 .
value = siloed_nullifier,
130 AppendOnlyTreeSnapshot nullifier_tree_snapshot = AppendOnlyTreeSnapshot{
132 .next_available_leaf_index = 128,
144 nullifier_tree_snapshot);
146 TestTraceContainer
trace({ {
147 { C::execution_sel_execute_nullifier_exists, 1 },
148 { C::execution_register_0_, siloed_nullifier },
149 { C::execution_register_1_, 1 },
150 { C::execution_mem_tag_reg_0_,
static_cast<uint8_t
>(
MemoryTag::FF) },
151 { C::execution_mem_tag_reg_1_,
static_cast<uint8_t
>(
MemoryTag::U1) },
152 { C::execution_prev_nullifier_tree_root, nullifier_tree_snapshot.root },
154 { C::execution_sel_opcode_error, 0 },
158 IndexedTreeCheckTraceBuilder indexed_tree_check_trace_builder;
161 check_relation<nullifier_exists>(trace);
163 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
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