15using simulation::PublicDataTreeReadWriteEvent;
19struct EventWithDiscard {
20 simulation::PublicDataTreeReadWriteEvent
event;
27 TraceContainer&
trace)
36 for (
size_t i = 0; i < events_with_metadata.size(); i++) {
37 bool end = i == events_with_metadata.size() - 1;
38 const auto&
event = events_with_metadata[i].event;
39 const bool discard = events_with_metadata[i].discard;
41 bool exists =
event.low_leaf_preimage.leaf.slot ==
event.leaf_slot;
42 FF slot_low_leaf_slot_diff_inv =
exists ? 0 : (
event.leaf_slot -
event.low_leaf_preimage.leaf.slot).invert();
44 bool next_slot_is_nonzero =
false;
47 next_slot_is_nonzero =
event.low_leaf_preimage.nextKey != 0;
48 next_slot_inv = next_slot_is_nonzero ?
event.low_leaf_preimage.nextKey.invert() : 0;
51 bool write =
event.write_data.has_value();
54 bool should_write_to_public_inputs =
55 nondiscarded_write && first_write_per_slot.at(
event.leaf_slot) ==
event.execution_id;
56 FF final_value = nondiscarded_write ? last_value_per_slot.at(
event.leaf_slot) : 0;
58 FF intermediate_root = 0;
60 FF updated_low_leaf_hash = 0;
62 AppendOnlyTreeSnapshot next_snapshot =
event.prev_snapshot;
65 next_snapshot =
event.write_data->next_snapshot;
66 intermediate_root =
event.write_data->intermediate_root;
67 updated_low_leaf =
event.write_data->updated_low_leaf_preimage;
68 updated_low_leaf_hash =
event.write_data->updated_low_leaf_hash;
69 new_leaf_hash =
event.write_data->new_leaf_hash;
71 uint32_t clk =
event.execution_id;
72 uint32_t clk_diff = end ? 0 : events_with_metadata[i + 1].event.execution_id - clk;
74 uint32_t public_data_writes_length = write_idx -
76 static_cast<uint32_t
>(should_write_to_public_inputs);
80 { C::public_data_check_sel, 1 },
81 { C::public_data_check_not_end, !end },
82 { C::public_data_check_end, end },
83 { C::public_data_check_value,
event.value },
84 { C::public_data_check_slot,
event.slot },
85 { C::public_data_check_root,
event.prev_snapshot.root },
86 { C::public_data_check_address,
event.contract_address },
87 { C::public_data_check_write_root, next_snapshot.root },
88 { C::public_data_check_tree_size_before_write,
event.prev_snapshot.nextAvailableLeafIndex },
89 { C::public_data_check_tree_size_after_write, next_snapshot.nextAvailableLeafIndex },
90 { C::public_data_check_write,
write },
91 { C::public_data_check_clk, clk },
92 { C::public_data_check_discard,
discard },
93 { C::public_data_check_low_leaf_slot,
event.low_leaf_preimage.leaf.slot },
94 { C::public_data_check_low_leaf_value,
event.low_leaf_preimage.leaf.value },
95 { C::public_data_check_low_leaf_next_index,
event.low_leaf_preimage.nextIndex },
96 { C::public_data_check_low_leaf_next_slot,
event.low_leaf_preimage.nextKey },
97 { C::public_data_check_updated_low_leaf_value, updated_low_leaf.leaf.value },
98 { C::public_data_check_updated_low_leaf_next_index, updated_low_leaf.nextIndex },
99 { C::public_data_check_updated_low_leaf_next_slot, updated_low_leaf.nextKey },
100 { C::public_data_check_low_leaf_index,
event.low_leaf_index },
101 { C::public_data_check_clk_diff, clk_diff },
102 { C::public_data_check_constant_32, 32 },
103 { C::public_data_check_leaf_slot,
event.leaf_slot },
105 { C::public_data_check_leaf_not_exists, !
exists },
106 { C::public_data_check_leaf_slot_low_leaf_slot_diff_inv, slot_low_leaf_slot_diff_inv },
107 { C::public_data_check_next_slot_is_nonzero, next_slot_is_nonzero },
108 { C::public_data_check_next_slot_inv, next_slot_inv },
109 { C::public_data_check_low_leaf_hash,
event.low_leaf_hash },
110 { C::public_data_check_intermediate_root, intermediate_root },
112 { C::public_data_check_updated_low_leaf_hash, updated_low_leaf_hash },
113 { C::public_data_check_should_insert, should_insert },
114 { C::public_data_check_new_leaf_hash, new_leaf_hash },
115 { C::public_data_check_write_idx, write_idx },
116 { C::public_data_check_nondiscaded_write, nondiscarded_write },
117 { C::public_data_check_should_write_to_public_inputs, should_write_to_public_inputs },
118 { C::public_data_check_final_value, final_value },
119 { C::public_data_check_public_data_writes_length, public_data_writes_length },
120 { C::public_data_check_length_pi_idx,
124 if (should_write_to_public_inputs) {
133 TraceContainer&
trace)
142 for (
size_t i = 0; i < nondiscarded_writes.size(); i++) {
143 bool end = i == nondiscarded_writes.size() - 1;
144 const auto&
event = nondiscarded_writes[i];
146 uint32_t clk =
event.execution_id;
148 bool leaf_slot_increase =
false;
149 bool check_clock =
false;
150 uint32_t clk_diff = 0;
153 const auto& next_event = nondiscarded_writes[i + 1];
155 if (
event.leaf_slot == next_event.leaf_slot) {
156 assert(
event.execution_id < next_event.execution_id);
157 clk_diff = next_event.execution_id -
event.execution_id;
161 leaf_slot_increase =
true;
165 bool should_write_to_public_inputs = first_write_per_slot.at(
event.leaf_slot) ==
event.execution_id;
166 FF final_value = last_value_per_slot.at(
event.leaf_slot);
170 { C::public_data_squash_sel, 1 },
171 { C::public_data_squash_leaf_slot,
event.leaf_slot },
172 { C::public_data_squash_value,
event.value },
173 { C::public_data_squash_clk, clk },
174 { C::public_data_squash_write_to_public_inputs, should_write_to_public_inputs },
175 { C::public_data_squash_leaf_slot_increase, leaf_slot_increase },
176 { C::public_data_squash_check_clock, check_clock },
177 { C::public_data_squash_clk_diff, clk_diff },
178 { C::public_data_squash_constant_32, 32 },
179 { C::public_data_squash_final_value, final_value },
196 events_with_metadata.reserve(events.size());
200 if (!first_write_per_slot.contains(event.leaf_slot)) {
201 first_write_per_slot[event.leaf_slot] = event.execution_id;
203 last_value_per_slot[
event.leaf_slot] =
event.value;
209 events_with_metadata.end(),
210 [](
const EventWithDiscard&
a,
const EventWithDiscard&
b) {
211 return a.event.execution_id < b.event.execution_id;
214 process_public_data_tree_check_trace(events_with_metadata, first_write_per_slot, last_value_per_slot,
trace);
217 nondiscarded_writes.reserve(events_with_metadata.size());
219 for (
const auto& event_with_metadata : events_with_metadata) {
220 if (event_with_metadata.event.write_data.has_value() && !event_with_metadata.discard) {
221 nondiscarded_writes.push_back(event_with_metadata.event);
227 nondiscarded_writes.end(),
228 [](
const PublicDataTreeReadWriteEvent&
a,
const PublicDataTreeReadWriteEvent&
b) {
229 if (a.leaf_slot == b.leaf_slot) {
230 return a.execution_id < b.execution_id;
235 process_squashing_trace(nondiscarded_writes, first_write_per_slot, last_value_per_slot,
trace);
239 InteractionDefinition()
242 .add<lookup_public_data_check_low_leaf_slot_validation_settings, InteractionType::LookupGeneric>()
244 .add<lookup_public_data_check_low_leaf_poseidon2_0_settings, InteractionType::LookupGeneric>()
246 .add<lookup_public_data_check_updated_low_leaf_poseidon2_0_settings, InteractionType::LookupGeneric>()
248 .add<lookup_public_data_check_low_leaf_merkle_check_settings, InteractionType::LookupGeneric>()
250 .add<lookup_public_data_check_new_leaf_poseidon2_1_settings, InteractionType::LookupGeneric>()
252 .add<perm_public_data_check_squashing_settings, InteractionType::Permutation>()
254 InteractionType::LookupIntoIndexedByClk>()
260 InteractionType::LookupIntoIndexedByClk>();
#define GENERATOR_INDEX__PUBLIC_LEAF_INDEX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_DATA_WRITES_ROW_IDX
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_DATA_WRITES_ROW_IDX
#define PUBLIC_DATA_TREE_HEIGHT
std::vector< Event > Container
InteractionDefinition & add(auto &&... args)
static const InteractionDefinition interactions
void process(const simulation::EventEmitterInterface< simulation::PublicDataTreeCheckEvent >::Container &events, TraceContainer &trace)
void set(Column col, uint32_t row, const FF &value)
IndexedLeaf< PublicDataLeafValue > PublicDataTreeLeafPreimage
void process_with_discard(const std::vector< std::variant< EventType, simulation::CheckPointEventType > > &events, ProcessEventFn &&process_event)
lookup_settings< lookup_public_data_check_low_leaf_next_slot_validation_settings_ > lookup_public_data_check_low_leaf_next_slot_validation_settings
lookup_settings< lookup_public_data_check_new_leaf_merkle_check_settings_ > lookup_public_data_check_new_leaf_merkle_check_settings
lookup_settings< lookup_public_data_check_updated_low_leaf_poseidon2_1_settings_ > lookup_public_data_check_updated_low_leaf_poseidon2_1_settings
lookup_settings< lookup_public_data_check_silo_poseidon2_settings_ > lookup_public_data_check_silo_poseidon2_settings
lookup_settings< lookup_public_data_check_write_writes_length_to_public_inputs_settings_ > lookup_public_data_check_write_writes_length_to_public_inputs_settings
lookup_settings< lookup_public_data_check_new_leaf_poseidon2_0_settings_ > lookup_public_data_check_new_leaf_poseidon2_0_settings
lookup_settings< lookup_public_data_check_write_public_data_to_public_inputs_settings_ > lookup_public_data_check_write_public_data_to_public_inputs_settings
lookup_settings< lookup_public_data_check_low_leaf_poseidon2_1_settings_ > lookup_public_data_check_low_leaf_poseidon2_1_settings
void write(B &buf, field2< base_field, Params > const &value)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
simulation::PublicDataTreeReadWriteEvent event
static IndexedLeaf< PublicDataLeafValue > empty()