Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
note_hash_tree_check_trace.cpp
Go to the documentation of this file.
2
3#include <cassert>
4#include <memory>
5#include <stack>
6#include <unordered_map>
7
16
17namespace bb::avm2::tracegen {
18
22{
23 using C = Column;
24
25 uint32_t row = 0;
27 bool write = event.append_data.has_value();
28
29 FF note_hash = event.note_hash;
30 FF siloed_note_hash = event.note_hash;
31 FF unique_note_hash = event.note_hash;
32
33 bool should_silo = false;
34 AztecAddress address = 0;
35 FF nonce = 0;
36
37 bool should_unique = false;
38 uint64_t note_hash_counter = 0;
39 FF next_root = 0;
40 FF first_nullifier = 0;
41
42 if (write) {
43 simulation::NoteHashAppendData append_data = event.append_data.value();
44 should_silo = append_data.siloing_data.has_value();
45 should_unique = append_data.uniqueness_data.has_value();
46 if (should_silo) {
47 siloed_note_hash = append_data.siloing_data->siloed_note_hash;
48 address = append_data.siloing_data->address;
49 }
50 if (should_unique) {
51 unique_note_hash = append_data.uniqueness_data->unique_note_hash;
52 nonce = append_data.uniqueness_data->nonce;
53 first_nullifier = append_data.uniqueness_data->first_nullifier;
54 }
55 note_hash_counter = append_data.note_hash_counter;
56 next_root = append_data.next_snapshot.root;
57 }
58
59 FF prev_leaf_value = event.existing_leaf_value;
60 bool exists = prev_leaf_value == unique_note_hash;
61 FF prev_leaf_value_unique_note_hash_diff_inv = exists ? 0 : (prev_leaf_value - unique_note_hash).invert();
62
63 trace.set(row,
64 { { { C::note_hash_tree_check_sel, 1 },
65 { C::note_hash_tree_check_write, write },
66 { C::note_hash_tree_check_exists, exists },
67 { C::note_hash_tree_check_note_hash, note_hash },
68 { C::note_hash_tree_check_leaf_index, event.leaf_index },
69 { C::note_hash_tree_check_prev_root, event.prev_snapshot.root },
70 { C::note_hash_tree_check_should_silo, should_silo },
71 { C::note_hash_tree_check_address, address },
72 { C::note_hash_tree_check_should_unique, should_unique },
73 { C::note_hash_tree_check_note_hash_index, note_hash_counter },
74 { C::note_hash_tree_check_discard, discard },
75 { C::note_hash_tree_check_next_root, next_root },
76 { C::note_hash_tree_check_siloed_note_hash, siloed_note_hash },
77 { C::note_hash_tree_check_siloing_separator, GENERATOR_INDEX__SILOED_NOTE_HASH },
78 { C::note_hash_tree_check_unique_note_hash, unique_note_hash },
79 { C::note_hash_tree_check_first_nullifier_pi_index,
81 { C::note_hash_tree_check_first_nullifier, first_nullifier },
82 { C::note_hash_tree_check_nonce, nonce },
83 { C::note_hash_tree_check_nonce_separator, GENERATOR_INDEX__NOTE_HASH_NONCE },
84 { C::note_hash_tree_check_unique_note_hash_separator, GENERATOR_INDEX__UNIQUE_NOTE_HASH },
85 { C::note_hash_tree_check_prev_leaf_value, prev_leaf_value },
86 { C::note_hash_tree_check_prev_leaf_value_unique_note_hash_diff_inv,
87 prev_leaf_value_unique_note_hash_diff_inv },
88 { C::note_hash_tree_check_next_leaf_value, write ? unique_note_hash : 0 },
89 { C::note_hash_tree_check_note_hash_tree_height, NOTE_HASH_TREE_HEIGHT },
90 { C::note_hash_tree_check_should_write_to_public_inputs, write && (!discard) },
91 { C::note_hash_tree_check_public_inputs_index,
93 row++;
94 });
95}
96
100 .add<lookup_note_hash_tree_check_read_first_nullifier_settings, InteractionType::LookupGeneric>()
102 .add<lookup_note_hash_tree_check_unique_note_hash_poseidon2_settings, InteractionType::LookupGeneric>()
106
107} // namespace bb::avm2::tracegen
#define AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX
#define GENERATOR_INDEX__NOTE_HASH_NONCE
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX
#define GENERATOR_INDEX__SILOED_NOTE_HASH
#define GENERATOR_INDEX__UNIQUE_NOTE_HASH
#define NOTE_HASH_TREE_HEIGHT
InteractionDefinition & add(auto &&... args)
void process(const simulation::EventEmitterInterface< simulation::NoteHashTreeCheckEvent >::Container &events, TraceContainer &trace)
TestTraceContainer trace
void process_with_discard(const std::vector< std::variant< EventType, simulation::CheckPointEventType > > &events, ProcessEventFn &&process_event)
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_nonce_computation_poseidon2_settings_ > lookup_note_hash_tree_check_nonce_computation_poseidon2_settings
lookup_settings< lookup_note_hash_tree_check_silo_poseidon2_settings_ > lookup_note_hash_tree_check_silo_poseidon2_settings
AvmFlavorSettings::FF FF
Definition field.hpp:10
void write(B &buf, field2< base_field, Params > const &value)
simulation::PublicDataTreeReadWriteEvent event
std::optional< NoteHashUniquenessData > uniqueness_data
std::optional< NoteHashSiloingData > siloing_data