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 <cstdint>
4
11
12namespace bb::avm2::tracegen {
13
30 TraceContainer& trace)
31{
32 using C = Column;
33
34 uint32_t row = 0;
36 bool write = event.append_data.has_value();
37
38 FF note_hash = event.note_hash;
39 FF siloed_note_hash = event.note_hash;
40 FF unique_note_hash = event.note_hash;
41
42 bool should_silo = false;
44 FF nonce = 0;
45
46 bool should_unique = false;
47 uint64_t note_hash_counter = 0;
48 FF next_root = 0;
50
51 if (write) {
52 simulation::NoteHashAppendData append_data = event.append_data.value();
53 should_silo = append_data.siloing_data.has_value();
54 should_unique = append_data.uniqueness_data.has_value();
55 if (should_silo) {
56 siloed_note_hash = append_data.siloing_data->siloed_note_hash;
57 address = append_data.siloing_data->address;
58 }
59 if (should_unique) {
60 unique_note_hash = append_data.uniqueness_data->unique_note_hash;
61 nonce = append_data.uniqueness_data->nonce;
62 first_nullifier = append_data.uniqueness_data->first_nullifier;
63 }
64 note_hash_counter = append_data.note_hash_counter;
65 next_root = append_data.next_snapshot.root;
66 }
67
68 FF prev_leaf_value = event.existing_leaf_value;
69 bool exists = prev_leaf_value == unique_note_hash;
70 FF prev_leaf_value_unique_note_hash_diff = prev_leaf_value - unique_note_hash;
71
72 trace.set(row,
73 { { { C::note_hash_tree_check_sel, 1 },
74 { C::note_hash_tree_check_const_three, 3 },
75 { C::note_hash_tree_check_write, write },
76 { C::note_hash_tree_check_exists, exists },
77 { C::note_hash_tree_check_note_hash, note_hash },
78 { C::note_hash_tree_check_leaf_index, event.leaf_index },
79 { C::note_hash_tree_check_prev_root, event.prev_snapshot.root },
80 { C::note_hash_tree_check_sel_silo, should_silo },
81 { C::note_hash_tree_check_address, address },
82 { C::note_hash_tree_check_sel_unique, should_unique },
83 { C::note_hash_tree_check_note_hash_index, note_hash_counter },
84 { C::note_hash_tree_check_discard, discard },
85 { C::note_hash_tree_check_next_root, next_root },
86 { C::note_hash_tree_check_siloed_note_hash, siloed_note_hash },
87 { C::note_hash_tree_check_siloing_separator, DOM_SEP__SILOED_NOTE_HASH },
88 { C::note_hash_tree_check_unique_note_hash, unique_note_hash },
89 { C::note_hash_tree_check_first_nullifier_pi_index,
91 { C::note_hash_tree_check_first_nullifier, first_nullifier },
92 { C::note_hash_tree_check_nonce, nonce },
93 { C::note_hash_tree_check_nonce_separator, DOM_SEP__NOTE_HASH_NONCE },
94 { C::note_hash_tree_check_unique_note_hash_separator, DOM_SEP__UNIQUE_NOTE_HASH },
95 { C::note_hash_tree_check_prev_leaf_value, prev_leaf_value },
96 { C::note_hash_tree_check_prev_leaf_value_unique_note_hash_diff_inv,
97 prev_leaf_value_unique_note_hash_diff }, // Will be inverted in batch later
98 { C::note_hash_tree_check_next_leaf_value, write ? unique_note_hash : 0 },
99 { C::note_hash_tree_check_note_hash_tree_height, NOTE_HASH_TREE_HEIGHT },
100 { C::note_hash_tree_check_sel_write_to_public_inputs, write && (!discard) },
101 { C::note_hash_tree_check_public_inputs_index,
103 row++;
104 });
105
106 // Batch invert the columns.
107 trace.invert_columns({ { C::note_hash_tree_check_prev_leaf_value_unique_note_hash_diff_inv } });
108}
109
113 .add<lookup_note_hash_tree_check_read_first_nullifier_settings, InteractionType::LookupIntoIndexedByRow>()
115 .add<lookup_note_hash_tree_check_unique_note_hash_poseidon2_settings, InteractionType::LookupSequential>()
119
120} // namespace bb::avm2::tracegen
#define DOM_SEP__SILOED_NOTE_HASH
#define AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX
#define DOM_SEP__UNIQUE_NOTE_HASH
#define DOM_SEP__NOTE_HASH_NONCE
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX
#define NOTE_HASH_TREE_HEIGHT
InteractionDefinition & add(auto &&... args)
void process(const simulation::EventEmitterInterface< simulation::NoteHashTreeCheckEvent >::Container &events, TraceContainer &trace)
Process the note hash tree check events and populate the relevant columns in the trace.
TestTraceContainer trace
void process_with_discard(const std::vector< std::variant< EventType, simulation::CheckPointEventType > > &events, ProcessEventFn &&process_event)
Processes events from a stream, attaching a discard flag to indicate reverted checkpoints.
lookup_settings< lookup_note_hash_tree_check_merkle_check_settings_ > lookup_note_hash_tree_check_merkle_check_settings
AvmFlavorSettings::FF FF
Definition field.hpp:10
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
void write(B &buf, field2< base_field, Params > const &value)
simulation::PublicDataTreeReadWriteEvent event
Settings to be passed ot GenericLookupRelationImpl.
std::optional< NoteHashUniquenessData > uniqueness_data
std::optional< NoteHashSiloingData > siloing_data