1#include <gmock/gmock.h>
2#include <gtest/gtest.h>
35using ::testing::NiceMock;
37using simulation::EventEmitter;
38using simulation::MerkleCheck;
39using simulation::MerkleCheckEvent;
40using simulation::MockExecutionIdManager;
41using simulation::MockGreaterThan;
42using simulation::NoopEventEmitter;
43using simulation::NoteHashTreeCheck;
44using simulation::Poseidon2;
45using simulation::Poseidon2HashEvent;
46using simulation::Poseidon2PermutationEvent;
47using simulation::Poseidon2PermutationMemoryEvent;
50using tracegen::MerkleCheckTraceBuilder;
51using tracegen::NoteHashTreeCheckTraceBuilder;
52using tracegen::Poseidon2TraceBuilder;
53using tracegen::PrecomputedTraceBuilder;
54using tracegen::PublicInputsTraceBuilder;
55using tracegen::TestTraceContainer;
62TEST(NoteHashTreeCheckConstrainingTests, PositiveExists)
67 NiceMock<MockGreaterThan>
mock_gt;
68 NiceMock<MockExecutionIdManager> mock_exec_id_manager;
72 EventEmitter<MerkleCheckEvent> merkle_event_emitter;
75 EventEmitter<simulation::NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
76 NoteHashTreeCheck note_hash_tree_check_simulator(0,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
78 TestTraceContainer
trace({ { { C::precomputed_first_row, 1 } } });
79 MerkleCheckTraceBuilder merkle_check_builder;
80 NoteHashTreeCheckTraceBuilder note_hash_tree_check_builder;
84 uint64_t leaf_index = 30;
85 std::vector<FF> sibling_path;
88 sibling_path.emplace_back(i);
92 EXPECT_TRUE(note_hash_tree_check_simulator.note_hash_exists(
97 AppendOnlyTreeSnapshot{ .root = root, .next_available_leaf_index = 128 }));
99 note_hash_tree_check_builder.process(note_hash_tree_check_event_emitter.dump_events(), trace);
100 merkle_check_builder.process(merkle_event_emitter.dump_events(), trace);
102 check_relation<note_hash_tree_check>(trace);
112TEST(NoteHashTreeCheckConstrainingTests, PositiveNotExists)
118 NiceMock<MockExecutionIdManager> mock_exec_id_manager;
119 NiceMock<MockGreaterThan>
mock_gt;
122 EventEmitter<MerkleCheckEvent> merkle_event_emitter;
125 EventEmitter<simulation::NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
126 NoteHashTreeCheck note_hash_tree_check_simulator(0,
poseidon2, merkle_check, note_hash_tree_check_event_emitter);
128 TestTraceContainer
trace({ { { C::precomputed_first_row, 1 } } });
129 MerkleCheckTraceBuilder merkle_check_builder;
130 NoteHashTreeCheckTraceBuilder note_hash_tree_check_builder;
132 FF requested_note_hash = 42;
133 FF actual_leaf_value = 43;
135 uint64_t leaf_index = 30;
136 std::vector<FF> sibling_path;
139 sibling_path.emplace_back(i);
143 EXPECT_FALSE(note_hash_tree_check_simulator.note_hash_exists(
148 AppendOnlyTreeSnapshot{ .root = root, .next_available_leaf_index = 128 }));
150 note_hash_tree_check_builder.process(note_hash_tree_check_event_emitter.dump_events(), trace);
151 merkle_check_builder.process(merkle_event_emitter.dump_events(), trace);
153 check_relation<note_hash_tree_check>(trace);
163TEST(NoteHashTreeCheckConstrainingTests, PositiveWrite)
165 auto test_public_inputs = testing::PublicInputsBuilder().rand_previous_non_revertible_accumulated_data(1).build();
169 NiceMock<MockGreaterThan>
mock_gt;
170 NiceMock<MockExecutionIdManager> mock_exec_id_manager;
174 EventEmitter<MerkleCheckEvent> merkle_event_emitter;
177 EventEmitter<simulation::NoteHashTreeCheckEvent> note_hash_tree_check_event_emitter;
178 NoteHashTreeCheck note_hash_tree_check_simulator(
179 test_public_inputs.previous_non_revertible_accumulated_data.nullifiers[0],
182 note_hash_tree_check_event_emitter);
184 TestTraceContainer
trace({ { { C::precomputed_first_row, 1 } } });
186 FF raw_note_hash = 42;
188 std::vector<FF> sibling_path;
191 sibling_path.emplace_back(i);
195 .next_available_leaf_index = 128 };
197 note_hash_tree_check_simulator.append_note_hash(raw_note_hash,
AztecAddress(7), 10, sibling_path, prev_snapshot);
199 NoteHashTreeCheckTraceBuilder note_hash_tree_check_builder;
200 note_hash_tree_check_builder.process(note_hash_tree_check_event_emitter.dump_events(), trace);
203 MerkleCheckTraceBuilder merkle_check_builder;
204 merkle_check_builder.process(merkle_event_emitter.dump_events(), trace);
214 check_relation<note_hash_tree_check>(trace);
224TEST(NoteHashTreeCheckConstrainingTests, NegativeSiloingOnRead)
226 TestTraceContainer
trace({ {
227 { C::note_hash_tree_check_sel, 1 },
228 { C::note_hash_tree_check_write, 0 },
229 { C::note_hash_tree_check_sel_silo, 1 },
230 { C::note_hash_tree_check_note_hash, 27 },
235 "DISABLE_SILOING_ON_READ");
238TEST(NoteHashTreeCheckConstrainingTests, NegativePassthroughSiloing)
240 TestTraceContainer
trace({ {
241 { C::note_hash_tree_check_sel, 1 },
242 { C::note_hash_tree_check_write, 0 },
243 { C::note_hash_tree_check_sel_silo, 0 },
244 { C::note_hash_tree_check_note_hash, 27 },
245 { C::note_hash_tree_check_siloed_note_hash, 27 },
250 trace.
set(C::note_hash_tree_check_siloed_note_hash, 0, 28);
253 "PASSTHROUGH_SILOING");
256TEST(NoteHashTreeCheckConstrainingTests, NegativeUniquenessOnRead)
258 TestTraceContainer
trace({ {
259 { C::note_hash_tree_check_sel, 1 },
260 { C::note_hash_tree_check_write, 0 },
261 { C::note_hash_tree_check_sel_unique, 1 },
262 { C::note_hash_tree_check_note_hash, 27 },
267 "DISABLE_UNIQUENESS_ON_READ");
270TEST(NoteHashTreeCheckConstrainingTests, NegativePassthroughUniqueness)
272 TestTraceContainer
trace({ {
273 { C::note_hash_tree_check_sel, 1 },
274 { C::note_hash_tree_check_write, 0 },
275 { C::note_hash_tree_check_sel_unique, 0 },
276 { C::note_hash_tree_check_note_hash, 27 },
277 { C::note_hash_tree_check_siloed_note_hash, 27 },
278 { C::note_hash_tree_check_unique_note_hash, 27 },
283 trace.
set(C::note_hash_tree_check_unique_note_hash, 0, 28);
287 "PASSTHROUGH_UNIQUENESS");
#define EXPECT_THROW_WITH_MESSAGE(code, expectedMessageRegex)
#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_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)
void process_phase_table(TraceContainer &trace)
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(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