Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
indexed_tree_check_trace.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4
9
10namespace bb::avm2::tracegen {
11
28 TraceContainer& trace)
29{
30 using C = Column;
31
32 uint32_t row = 0;
33 process_with_discard(events, [&](const simulation::IndexedTreeReadWriteEvent& event, bool raw_discard) {
34 FF value = event.value;
35 FF siloed_value = event.value;
36 FF address = 0;
37 FF siloing_separator = 0;
38
39 if (event.siloing_data.has_value()) {
40 siloed_value = event.siloing_data->siloed_value;
41 address = event.siloing_data->parameters.address;
42 siloing_separator = event.siloing_data->parameters.siloing_separator;
43 }
44
45 bool exists = event.low_leaf_data.value == siloed_value;
46 FF value_low_leaf_value_diff = siloed_value - event.low_leaf_data.value;
47
48 bool next_value_is_nonzero = false;
49 FF next_value = 0;
50 if (!exists) {
51 next_value_is_nonzero = event.low_leaf_data.next_value != 0;
52 next_value = event.low_leaf_data.next_value;
53 }
54
55 uint64_t updated_low_leaf_next_index = 0;
56 FF updated_low_leaf_next_key = 0;
57 FF updated_low_leaf_hash = 0;
58 FF new_leaf_hash = 0;
59 FF intermediate_root = 0;
60
61 bool append = event.append_data.has_value();
62 if (append) {
63 updated_low_leaf_next_key = siloed_value;
64 updated_low_leaf_next_index = event.prev_snapshot.next_available_leaf_index;
65 updated_low_leaf_hash = event.append_data->updated_low_leaf_hash;
66 new_leaf_hash = event.append_data->new_leaf_hash;
67 intermediate_root = event.append_data->intermediate_root;
68 }
69
70 // Some events do not require writing to public inputs. We always discard those. Lookups by gadgets that don't
71 // pass public inputs index should not look up discard.
72 bool discard = (!event.public_inputs_index.has_value()) || raw_discard;
73 bool sel_write_to_public_inputs = event.append_data.has_value() && (!discard);
74
75 trace.set(row,
76 { {
77 { C::indexed_tree_check_sel, 1 },
78 { C::indexed_tree_check_const_three, 3 },
79 { C::indexed_tree_check_write, event.write ? 1 : 0 },
80 { C::indexed_tree_check_value, value },
81 { C::indexed_tree_check_root, event.prev_snapshot.root },
82 { C::indexed_tree_check_exists, exists ? 1 : 0 },
83 { C::indexed_tree_check_not_exists, exists ? 0 : 1 },
84 { C::indexed_tree_check_write_root, event.next_snapshot.root },
85 { C::indexed_tree_check_tree_size_before_write, event.prev_snapshot.next_available_leaf_index },
86 { C::indexed_tree_check_tree_size_after_write, event.next_snapshot.next_available_leaf_index },
87 { C::indexed_tree_check_discard, discard ? 1 : 0 },
88 { C::indexed_tree_check_public_inputs_index, event.public_inputs_index.value_or(0) },
89 { C::indexed_tree_check_sel_silo, event.siloing_data.has_value() ? 1 : 0 },
90 { C::indexed_tree_check_address, address },
91 { C::indexed_tree_check_low_leaf_value, event.low_leaf_data.value },
92 { C::indexed_tree_check_low_leaf_next_index, event.low_leaf_data.next_index },
93 { C::indexed_tree_check_low_leaf_next_value, event.low_leaf_data.next_value },
94 { C::indexed_tree_check_updated_low_leaf_next_index, updated_low_leaf_next_index },
95 { C::indexed_tree_check_updated_low_leaf_next_value, updated_low_leaf_next_key },
96 { C::indexed_tree_check_low_leaf_index, event.low_leaf_index },
97 { C::indexed_tree_check_siloed_value, siloed_value },
98 { C::indexed_tree_check_siloing_separator, siloing_separator },
99 { C::indexed_tree_check_sel_insert, append ? 1 : 0 },
100 { C::indexed_tree_check_low_leaf_hash, event.low_leaf_hash },
101 { C::indexed_tree_check_intermediate_root, intermediate_root },
102 { C::indexed_tree_check_updated_low_leaf_hash, updated_low_leaf_hash },
103 { C::indexed_tree_check_tree_height, event.tree_height },
104 { C::indexed_tree_check_value_low_leaf_value_diff_inv,
105 value_low_leaf_value_diff }, // Will be inverted in batch later
106 { C::indexed_tree_check_next_value_is_nonzero, next_value_is_nonzero ? 1 : 0 },
107 { C::indexed_tree_check_next_value_inv, next_value }, // Will be inverted in batch later
108 { C::indexed_tree_check_new_leaf_hash, new_leaf_hash },
109 { C::indexed_tree_check_sel_write_to_public_inputs, sel_write_to_public_inputs ? 1 : 0 },
110 } });
111 row++;
112 });
113
114 // Batch invert the columns.
115 trace.invert_columns(
116 { { C::indexed_tree_check_value_low_leaf_value_diff_inv, C::indexed_tree_check_next_value_inv } });
117}
118
122 .add<lookup_indexed_tree_check_low_leaf_poseidon2_settings, InteractionType::LookupSequential>()
124 .add<lookup_indexed_tree_check_low_leaf_merkle_check_settings, InteractionType::LookupSequential>()
126 InteractionType::LookupGeneric>() // ff_gt deduplicates
128 InteractionType::LookupGeneric>() // ff_gt deduplicates
130 .add<lookup_indexed_tree_check_new_leaf_merkle_check_settings, InteractionType::LookupSequential>()
133
134} // namespace bb::avm2::tracegen
void process(const simulation::EventEmitterInterface< simulation::IndexedTreeCheckEvent >::Container &events, TraceContainer &trace)
Process generic indexed tree check events and populate the relevant columns in the trace.
InteractionDefinition & add(auto &&... args)
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_indexed_tree_check_silo_poseidon2_settings_ > lookup_indexed_tree_check_silo_poseidon2_settings
AvmFlavorSettings::FF FF
Definition field.hpp:10
lookup_settings< lookup_indexed_tree_check_low_leaf_value_validation_settings_ > lookup_indexed_tree_check_low_leaf_value_validation_settings
lookup_settings< lookup_indexed_tree_check_write_value_to_public_inputs_settings_ > lookup_indexed_tree_check_write_value_to_public_inputs_settings
lookup_settings< lookup_indexed_tree_check_updated_low_leaf_poseidon2_settings_ > lookup_indexed_tree_check_updated_low_leaf_poseidon2_settings
lookup_settings< lookup_indexed_tree_check_new_leaf_poseidon2_settings_ > lookup_indexed_tree_check_new_leaf_poseidon2_settings
simulation::PublicDataTreeReadWriteEvent event
Settings to be passed ot GenericLookupRelationImpl.