Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
note_hash_tree_check.cpp
Go to the documentation of this file.
4
5namespace bb::avm2::simulation {
6
7bool NoteHashTreeCheck::note_hash_exists(const FF& unique_note_hash,
8 const FF& leaf_value,
9 uint64_t leaf_index,
10 std::span<const FF> sibling_path,
11 const AppendOnlyTreeSnapshot& snapshot)
12{
13 merkle_check.assert_membership(leaf_value, leaf_index, sibling_path, snapshot.root);
15 .existing_leaf_value = leaf_value,
16 .leaf_index = leaf_index,
17 .prev_snapshot = snapshot });
18 return unique_note_hash == leaf_value;
19}
20
25
26FF NoteHashTreeCheck::make_nonce(uint64_t note_hash_counter) const
27{
28 return poseidon2.hash({ GENERATOR_INDEX__NOTE_HASH_NONCE, first_nullifier, note_hash_counter });
29}
30
31FF NoteHashTreeCheck::make_unique(const FF& siloed_note_hash, const FF& nonce) const
32{
33 return poseidon2.hash({ GENERATOR_INDEX__UNIQUE_NOTE_HASH, nonce, siloed_note_hash });
34}
35
38 uint64_t note_hash_counter,
39 std::span<const FF> sibling_path,
40 const AppendOnlyTreeSnapshot& prev_snapshot)
41{
43 note_hash, contract_address, /*should_make_unique=*/true, note_hash_counter, sibling_path, prev_snapshot);
44}
45
47 uint64_t note_hash_counter,
48 std::span<const FF> sibling_path,
49 const AppendOnlyTreeSnapshot& prev_snapshot)
50{
51 return append_note_hash_internal(siloed_note_hash,
52 /* contract_address */ std::nullopt,
53 /* should_make_unique */ true,
54 note_hash_counter,
55 sibling_path,
56 prev_snapshot);
57}
58
60 uint64_t note_hash_counter,
61 std::span<const FF> sibling_path,
62 const AppendOnlyTreeSnapshot& prev_snapshot)
63{
64 return append_note_hash_internal(unique_note_hash,
65 /* contract_address */ std::nullopt,
66 /* should_make_unique */ false,
67 note_hash_counter,
68 sibling_path,
69 prev_snapshot);
70}
71
74 bool should_make_unique,
75 uint64_t note_hash_counter,
76 std::span<const FF> sibling_path,
77 const AppendOnlyTreeSnapshot& prev_snapshot)
78{
79 FF original_note_hash = note_hash;
80
82 if (contract_address.has_value()) {
83 note_hash = make_siloed(*contract_address, note_hash);
84 siloing_data = NoteHashSiloingData{ .siloed_note_hash = note_hash, .address = *contract_address };
85 }
87 if (should_make_unique) {
88 FF nonce = make_nonce(note_hash_counter);
89 note_hash = make_unique(note_hash, nonce);
90 uniqueness_data =
91 NoteHashUniquenessData{ .nonce = nonce, .unique_note_hash = note_hash, .first_nullifier = first_nullifier };
92 }
93
94 FF next_root =
95 merkle_check.write(0, note_hash, prev_snapshot.nextAvailableLeafIndex, sibling_path, prev_snapshot.root);
97 .root = next_root,
98 .nextAvailableLeafIndex = prev_snapshot.nextAvailableLeafIndex + 1,
99 };
100 events.emit(NoteHashTreeReadWriteEvent{ .note_hash = original_note_hash,
101 .existing_leaf_value = 0,
102 .leaf_index = prev_snapshot.nextAvailableLeafIndex,
103 .prev_snapshot = prev_snapshot,
104 .append_data = NoteHashAppendData{
105 .siloing_data = siloing_data,
106 .uniqueness_data = uniqueness_data,
107 .note_hash_counter = note_hash_counter,
108 .next_snapshot = next_snapshot,
109 } });
110 return next_snapshot;
111}
112
117
122
127
128} // namespace bb::avm2::simulation
#define GENERATOR_INDEX__NOTE_HASH_NONCE
#define GENERATOR_INDEX__SILOED_NOTE_HASH
#define GENERATOR_INDEX__UNIQUE_NOTE_HASH
virtual void emit(Event &&event)=0
AppendOnlyTreeSnapshot append_siloed_note_hash(const FF &siloed_note_hash, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot) override
EventEmitterInterface< NoteHashTreeCheckEvent > & events
AppendOnlyTreeSnapshot append_note_hash(const FF &note_hash, AztecAddress contract_address, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot) override
FF make_nonce(uint64_t note_hash_counter) const
FF make_unique(const FF &siloed_note_hash, const FF &nonce) const
FF make_siloed(AztecAddress contract_address, const FF &note_hash) const
AppendOnlyTreeSnapshot append_note_hash_internal(FF note_hash, std::optional< AztecAddress > contract_address, bool should_make_unique, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot)
bool note_hash_exists(const FF &unique_note_hash, const FF &leaf_value, uint64_t leaf_index, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &snapshot) override
AppendOnlyTreeSnapshot append_unique_note_hash(const FF &unique_note_hash, uint64_t note_hash_counter, std::span< const FF > sibling_path, const AppendOnlyTreeSnapshot &prev_snapshot) override
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::optional< NoteHashSiloingData > siloing_data