1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
36using ::testing::NiceMock;
38using simulation::EventEmitter;
39using simulation::MerkleCheck;
40using simulation::MerkleCheckEvent;
41using simulation::MockExecutionIdManager;
42using simulation::MockGreaterThan;
43using simulation::NoopEventEmitter;
44using simulation::NoteHashTreeCheck;
45using simulation::Poseidon2;
46using simulation::Poseidon2HashEvent;
47using simulation::Poseidon2PermutationEvent;
48using simulation::Poseidon2PermutationMemoryEvent;
51using tracegen::MerkleCheckTraceBuilder;
52using tracegen::NoteHashTreeCheckTraceBuilder;
53using tracegen::Poseidon2TraceBuilder;
54using tracegen::PrecomputedTraceBuilder;
55using tracegen::PublicInputsTraceBuilder;
56using tracegen::TestTraceContainer;
63TEST(NoteHashTreeCheckConstrainingTests, PositiveExists)
68 NiceMock<MockGreaterThan>
mock_gt;
69 NiceMock<MockExecutionIdManager> mock_exec_id_manager;
73 EventEmitter<MerkleCheckEvent> merkle_event_emitter;
76 EventEmitter<simulation::NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
77 NoteHashTreeCheck note_hash_tree_check_simulator(0,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
79 TestTraceContainer
trace({ { { C::precomputed_first_row, 1 } } });
80 MerkleCheckTraceBuilder merkle_check_builder;
81 NoteHashTreeCheckTraceBuilder note_hash_tree_check_builder;
85 uint64_t leaf_index = 30;
86 std::vector<FF> sibling_path;
89 sibling_path.emplace_back(i);
93 EXPECT_TRUE(note_hash_tree_check_simulator.note_hash_exists(
98 AppendOnlyTreeSnapshot{ .root = root, .next_available_leaf_index = 128 }));
100 note_hash_tree_check_builder.process(note_hash_tree_check_event_emitter.dump_events(), trace);
101 merkle_check_builder.process(merkle_event_emitter.dump_events(), trace);
103 check_relation<note_hash_tree_check>(trace);
113TEST(NoteHashTreeCheckConstrainingTests, PositiveNotExists)
119 NiceMock<MockExecutionIdManager> mock_exec_id_manager;
120 NiceMock<MockGreaterThan>
mock_gt;
123 EventEmitter<MerkleCheckEvent> merkle_event_emitter;
126 EventEmitter<simulation::NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
127 NoteHashTreeCheck note_hash_tree_check_simulator(0,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
129 TestTraceContainer
trace({ { { C::precomputed_first_row, 1 } } });
130 MerkleCheckTraceBuilder merkle_check_builder;
131 NoteHashTreeCheckTraceBuilder note_hash_tree_check_builder;
133 FF requested_note_hash = 42;
134 FF actual_leaf_value = 43;
136 uint64_t leaf_index = 30;
137 std::vector<FF> sibling_path;
140 sibling_path.emplace_back(i);
144 EXPECT_FALSE(note_hash_tree_check_simulator.note_hash_exists(
149 AppendOnlyTreeSnapshot{ .root = root, .next_available_leaf_index = 128 }));
151 note_hash_tree_check_builder.process(note_hash_tree_check_event_emitter.dump_events(), trace);
152 merkle_check_builder.process(merkle_event_emitter.dump_events(), trace);
154 check_relation<note_hash_tree_check>(trace);
164TEST(NoteHashTreeCheckConstrainingTests, PositiveWrite)
166 auto test_public_inputs = testing::PublicInputsBuilder().rand_previous_non_revertible_accumulated_data(1).build();
170 NiceMock<MockGreaterThan>
mock_gt;
171 NiceMock<MockExecutionIdManager> mock_exec_id_manager;
175 EventEmitter<MerkleCheckEvent> merkle_event_emitter;
178 EventEmitter<simulation::NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
179 NoteHashTreeCheck note_hash_tree_check_simulator(
180 test_public_inputs.previous_non_revertible_accumulated_data.nullifiers[0],
183 note_hash_tree_check_event_emitter);
185 TestTraceContainer
trace({ { { C::precomputed_first_row, 1 } } });
187 FF raw_note_hash = 42;
189 std::vector<FF> sibling_path;
192 sibling_path.emplace_back(i);
195 AppendOnlyTreeSnapshot prev_snapshot{ .root =
197 .next_available_leaf_index = 128 };
199 note_hash_tree_check_simulator.append_note_hash(raw_note_hash,
AztecAddress(7), 10, sibling_path, prev_snapshot);
201 NoteHashTreeCheckTraceBuilder note_hash_tree_check_builder;
202 note_hash_tree_check_builder.process(note_hash_tree_check_event_emitter.dump_events(), trace);
205 MerkleCheckTraceBuilder merkle_check_builder;
206 merkle_check_builder.process(merkle_event_emitter.dump_events(), trace);
216 check_relation<note_hash_tree_check>(trace);
226TEST(NoteHashTreeCheckConstrainingTests, NegativeSiloingOnRead)
228 TestTraceContainer
trace({ {
229 { C::note_hash_tree_check_sel, 1 },
230 { C::note_hash_tree_check_write, 0 },
231 { C::note_hash_tree_check_sel_silo, 1 },
232 { C::note_hash_tree_check_note_hash, 27 },
237 "DISABLE_SILOING_ON_READ");
240TEST(NoteHashTreeCheckConstrainingTests, NegativePassthroughSiloing)
242 TestTraceContainer
trace({ {
243 { C::note_hash_tree_check_sel, 1 },
244 { C::note_hash_tree_check_write, 0 },
245 { C::note_hash_tree_check_sel_silo, 0 },
246 { C::note_hash_tree_check_note_hash, 27 },
247 { C::note_hash_tree_check_siloed_note_hash, 27 },
252 trace.
set(C::note_hash_tree_check_siloed_note_hash, 0, 28);
255 "PASSTHROUGH_SILOING");
258TEST(NoteHashTreeCheckConstrainingTests, NegativeUniquenessOnRead)
260 TestTraceContainer
trace({ {
261 { C::note_hash_tree_check_sel, 1 },
262 { C::note_hash_tree_check_write, 0 },
263 { C::note_hash_tree_check_sel_unique, 1 },
264 { C::note_hash_tree_check_note_hash, 27 },
269 "DISABLE_UNIQUENESS_ON_READ");
272TEST(NoteHashTreeCheckConstrainingTests, NegativePassthroughUniqueness)
274 TestTraceContainer
trace({ {
275 { C::note_hash_tree_check_sel, 1 },
276 { C::note_hash_tree_check_write, 0 },
277 { C::note_hash_tree_check_sel_unique, 0 },
278 { C::note_hash_tree_check_note_hash, 27 },
279 { C::note_hash_tree_check_siloed_note_hash, 27 },
280 { C::note_hash_tree_check_unique_note_hash, 27 },
285 trace.
set(C::note_hash_tree_check_unique_note_hash, 0, 28);
289 "PASSTHROUGH_UNIQUENESS");
292TEST(NoteHashTreeCheckConstrainingTests, NegativeWrongMerkleHashSeparator)
294 TestTraceContainer
trace({ {
295 { C::note_hash_tree_check_sel, 1 },
306 "MERKLE_HASH_SEPARATOR_CONSTANT");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#define DOM_SEP__MERKLE_HASH
#define DOM_SEP__NULLIFIER_MERKLE
#define NOTE_HASH_TREE_HEIGHT
#define AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH
StrictMock< MockGreaterThan > mock_gt
EventEmitter< Poseidon2PermutationMemoryEvent > perm_mem_event_emitter
EventEmitter< Poseidon2PermutationEvent > perm_event_emitter
EventEmitter< Poseidon2HashEvent > hash_event_emitter
Poseidon2TraceBuilder poseidon2_builder
static constexpr size_t SR_DISABLE_SILOING_ON_READ
static constexpr size_t SR_PASSTHROUGH_SILOING
static constexpr size_t SR_PASSTHROUGH_UNIQUENESS
static constexpr size_t SR_MERKLE_HASH_SEPARATOR_CONSTANT
static constexpr size_t SR_DISABLE_UNIQUENESS_ON_READ
void process_hash(const simulation::EventEmitterInterface< simulation::Poseidon2HashEvent >::Container &hash_events, TraceContainer &trace)
Processes the hash events for the Poseidon2 hash function. It populates the columns for the poseidon2...
void process_misc(TraceContainer &trace, const uint32_t num_rows=PRECOMPUTED_TRACE_SIZE)
Populate miscellaneous precomputed columns: first_row selector and idx (row index).
void process_phase_table(TraceContainer &trace)
Populate the transaction phase specification table.
void set(Column col, uint32_t row, const FF &value)
PrecomputedTraceBuilder precomputed_builder
void check_interaction(tracegen::TestTraceContainer &trace)
TEST(AvmFixedVKTests, FixedVKCommitments)
Test that the fixed VK commitments agree with the ones computed from precomputed columns.
crypto::Poseidon2< crypto::Poseidon2Bn254ScalarFieldParams > poseidon2
FF unconstrained_root_from_path(uint64_t domain_separator, const FF &leaf_value, const uint64_t leaf_index, std::span< const FF > path)
lookup_settings< lookup_note_hash_tree_check_merkle_check_settings_ > lookup_note_hash_tree_check_merkle_check_settings
lookup_settings< lookup_note_hash_tree_check_read_first_nullifier_settings_ > lookup_note_hash_tree_check_read_first_nullifier_settings
lookup_settings< lookup_note_hash_tree_check_nonce_computation_poseidon2_settings_ > lookup_note_hash_tree_check_nonce_computation_poseidon2_settings
lookup_settings< lookup_note_hash_tree_check_unique_note_hash_poseidon2_settings_ > lookup_note_hash_tree_check_unique_note_hash_poseidon2_settings
lookup_settings< lookup_note_hash_tree_check_silo_poseidon2_settings_ > lookup_note_hash_tree_check_silo_poseidon2_settings
tracegen::PublicInputsTraceBuilder public_inputs_builder