Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
emit_unencrypted_log_trace.cpp
Go to the documentation of this file.
2
3#include <cstddef>
4#include <cstdint>
5
17
18namespace bb::avm2::tracegen {
19
20using C = Column;
21
25{
26 uint32_t row = 1;
28 // error = error_too_large | error_out_of_bounds | error_too_many_logs | error_tag_mismatch | is_static
29 // we split the above computation in 2 to reduce the degree of the full relation
30 bool error_too_many_logs_wrong_tag_is_static =
31 event.error_too_many_log_fields || event.error_tag_mismatch || event.is_static;
32 bool error = event.error_memory_out_of_bounds || error_too_many_logs_wrong_tag_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_unencrypted_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(
73 row,
74 { {
75 { C::emit_unencrypted_log_sel, 1 },
76 { C::emit_unencrypted_log_execution_clk, event.execution_clk },
77 { C::emit_unencrypted_log_space_id, event.space_id },
78 { C::emit_unencrypted_log_log_address, log_address },
79 { C::emit_unencrypted_log_log_size, event.log_size },
80 { C::emit_unencrypted_log_contract_address, event.contract_address },
81 { C::emit_unencrypted_log_prev_num_unencrypted_log_fields, event.prev_num_unencrypted_log_fields },
82 { C::emit_unencrypted_log_next_num_unencrypted_log_fields, event.next_num_unencrypted_log_fields },
83 { C::emit_unencrypted_log_is_static, event.is_static },
84 { C::emit_unencrypted_log_error, error },
85 { C::emit_unencrypted_log_discard, discard },
86 { C::emit_unencrypted_log_start, i == 0 },
87 { C::emit_unencrypted_log_end, i == event.log_size + PUBLIC_LOG_HEADER_LENGTH - 1 },
88 { C::emit_unencrypted_log_remaining_rows, remaining_rows },
89 { C::emit_unencrypted_log_remaining_rows_inv, remaining_rows }, // Will be inverted in batch later
90 { C::emit_unencrypted_log_error_out_of_bounds, event.error_memory_out_of_bounds },
91 { C::emit_unencrypted_log_max_mem_addr, AVM_HIGHEST_MEM_ADDRESS },
92 { C::emit_unencrypted_log_end_log_address, log_address + event.log_size - 1 },
93 { C::emit_unencrypted_log_error_too_many_log_fields, event.error_too_many_log_fields },
94 { C::emit_unencrypted_log_expected_next_log_fields, expected_next_log_fields },
95 { C::emit_unencrypted_log_public_logs_payload_length, FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH },
96 { C::emit_unencrypted_log_error_tag_mismatch, event.error_tag_mismatch },
97 { C::emit_unencrypted_log_seen_wrong_tag, seen_wrong_tag },
98 { C::emit_unencrypted_log_error_too_many_logs_wrong_tag_is_static,
99 error_too_many_logs_wrong_tag_is_static },
100 { C::emit_unencrypted_log_sel_should_write_to_public_inputs, !error && !discard },
101 { C::emit_unencrypted_log_is_write_contract_address, is_contract_address_row },
102 { C::emit_unencrypted_log_is_write_memory_value, is_value_row },
103 { C::emit_unencrypted_log_sel_should_read_memory,
104 is_value_row && !event.error_memory_out_of_bounds },
105 { C::emit_unencrypted_log_value, value },
106 { C::emit_unencrypted_log_tag, static_cast<uint8_t>(tag) },
107 { C::emit_unencrypted_log_correct_tag, correct_tag },
108 { C::emit_unencrypted_log_tag_inv, static_cast<uint8_t>(tag) }, // Will be inverted in batch later
109 { C::emit_unencrypted_log_public_inputs_index,
111 event.prev_num_unencrypted_log_fields + i },
112 { C::emit_unencrypted_log_public_inputs_value, public_inputs_value },
113 } });
114
115 row++;
116 if (is_value_row) {
117 log_address++;
118 }
119 }
120 });
121
122 // Batch invert the columns.
123 trace.invert_columns({ { C::emit_unencrypted_log_remaining_rows_inv, C::emit_unencrypted_log_tag_inv } });
124}
125
129 Column::gt_sel)
130 .add<lookup_emit_unencrypted_log_check_memory_out_of_bounds_settings, InteractionType::LookupGeneric>(
131 Column::gt_sel)
134
135} // namespace bb::avm2::tracegen
#define FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH
#define FLAT_PUBLIC_LOGS_HEADER_LENGTH
#define PUBLIC_LOG_HEADER_LENGTH
#define AVM_HIGHEST_MEM_ADDRESS
#define AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX
void process(const simulation::EventEmitterInterface< simulation::EmitUnencryptedLogEvent >::Container &events, TraceContainer &trace)
InteractionDefinition & add(auto &&... args)
TestTraceContainer trace
void process_with_discard(const std::vector< std::variant< EventType, simulation::CheckPointEventType > > &events, ProcessEventFn &&process_event)
lookup_settings< lookup_emit_unencrypted_log_check_log_fields_count_settings_ > lookup_emit_unencrypted_log_check_log_fields_count_settings
lookup_settings< lookup_emit_unencrypted_log_write_data_to_public_inputs_settings_ > lookup_emit_unencrypted_log_write_data_to_public_inputs_settings
AvmFlavorSettings::FF FF
Definition field.hpp:10
simulation::PublicDataTreeReadWriteEvent event