Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
emit_public_log_trace.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4
14
15namespace bb::avm2::tracegen {
16
17using C = Column;
18
27{
28 uint32_t row = 1;
30 // error = error_out_of_bounds | error_too_many_log_fields | error_tag_mismatch | is_static
31 bool error = event.error_memory_out_of_bounds || event.error_too_many_log_fields || event.error_tag_mismatch ||
32 event.is_static;
33
34 FF log_address = FF(event.log_address);
35 bool seen_wrong_tag = false;
36
37 for (uint32_t i = 0; i < event.log_size + PUBLIC_LOG_HEADER_LENGTH; ++i) {
38 bool is_log_length_row = i == 0;
39 bool is_contract_address_row = i == 1;
40 bool is_value_row = i > 1;
41 uint32_t remaining_rows = PUBLIC_LOG_HEADER_LENGTH + event.log_size - 1 - i;
42
43 FF value = 0;
45
46 if (is_value_row) {
47 uint32_t value_index = i - PUBLIC_LOG_HEADER_LENGTH;
48 if (value_index < event.values.size()) {
49 value = event.values[value_index].as_ff();
50 tag = event.values[value_index].get_tag();
51 }
52 }
53
54 bool correct_tag = tag == ValueTag::FF;
55 if (!correct_tag) {
56 seen_wrong_tag = true;
57 }
58
59 uint32_t expected_next_log_fields =
60 event.prev_num_public_log_fields + PUBLIC_LOG_HEADER_LENGTH + event.log_size;
61
62 FF public_inputs_value = 0;
63
64 if (is_log_length_row) {
65 public_inputs_value = event.log_size;
66 } else if (is_contract_address_row) {
67 public_inputs_value = event.contract_address;
68 } else if (is_value_row) {
69 public_inputs_value = value;
70 }
71
72 trace.set(row,
73 { {
74 { C::emit_public_log_sel, 1 },
75 { C::emit_public_log_execution_clk, event.execution_clk },
76 { C::emit_public_log_space_id, event.space_id },
77 { C::emit_public_log_log_address, log_address },
78 { C::emit_public_log_log_size, event.log_size },
79 { C::emit_public_log_contract_address, event.contract_address },
80 { C::emit_public_log_prev_num_public_log_fields, event.prev_num_public_log_fields },
81 { C::emit_public_log_next_num_public_log_fields, event.next_num_public_log_fields },
82 { C::emit_public_log_is_static, event.is_static },
83 { C::emit_public_log_error, error },
84 { C::emit_public_log_discard, discard },
85 { C::emit_public_log_start, i == 0 },
86 { C::emit_public_log_end, i == event.log_size + PUBLIC_LOG_HEADER_LENGTH - 1 },
87 { C::emit_public_log_remaining_rows, remaining_rows },
88 { C::emit_public_log_remaining_rows_inv, remaining_rows }, // Will be inverted in batch later
89 { C::emit_public_log_error_out_of_bounds, event.error_memory_out_of_bounds },
90 { C::emit_public_log_max_mem_size, static_cast<uint64_t>(AVM_MEMORY_SIZE) },
91 { C::emit_public_log_end_log_address_upper_bound, log_address + event.log_size },
92 { C::emit_public_log_error_too_many_log_fields, event.error_too_many_log_fields },
93 { C::emit_public_log_expected_next_log_fields, expected_next_log_fields },
94 { C::emit_public_log_max_public_logs_payload_length, FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH },
95 { C::emit_public_log_error_tag_mismatch, event.error_tag_mismatch },
96 { C::emit_public_log_seen_wrong_tag, seen_wrong_tag },
97 { C::emit_public_log_sel_write_to_public_inputs, !error && !discard },
98 { C::emit_public_log_is_write_contract_address, is_contract_address_row },
99 { C::emit_public_log_is_write_memory_value, is_value_row },
100 { C::emit_public_log_sel_read_memory, is_value_row && !event.error_memory_out_of_bounds },
101 { C::emit_public_log_value, value },
102 { C::emit_public_log_tag, static_cast<uint8_t>(tag) },
103 { C::emit_public_log_correct_tag, correct_tag },
104 { C::emit_public_log_tag_inv, static_cast<uint8_t>(tag) }, // Will be inverted in batch later
105 { C::emit_public_log_public_inputs_index,
107 FLAT_PUBLIC_LOGS_HEADER_LENGTH + event.prev_num_public_log_fields + i },
108 { C::emit_public_log_public_inputs_value, public_inputs_value },
109 } });
110
111 row++;
112 if (is_value_row) {
113 log_address++;
114 }
115 }
116 });
117
118 // Batch invert the columns.
119 trace.invert_columns({ { C::emit_public_log_remaining_rows_inv, C::emit_public_log_tag_inv } });
120}
121
125 .add<lookup_emit_public_log_check_memory_out_of_bounds_settings, InteractionType::LookupGeneric>(Column::gt_sel)
127
128} // namespace bb::avm2::tracegen
#define FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH
#define FLAT_PUBLIC_LOGS_HEADER_LENGTH
#define PUBLIC_LOG_HEADER_LENGTH
#define AVM_MEMORY_SIZE
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX
void process(const simulation::EventEmitterInterface< simulation::EmitPublicLogEvent >::Container &events, TraceContainer &trace)
Process emit-public-log events into trace rows.
static const InteractionDefinition interactions
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.
AvmFlavorSettings::FF FF
Definition field.hpp:10
lookup_settings< lookup_emit_public_log_write_data_to_public_inputs_settings_ > lookup_emit_public_log_write_data_to_public_inputs_settings
lookup_settings< lookup_emit_public_log_check_log_fields_count_settings_ > lookup_emit_public_log_check_log_fields_count_settings
simulation::PublicDataTreeReadWriteEvent event