Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
emit_unencrypted_log.cpp
Go to the documentation of this file.
2
3#include <cassert>
4#include <cstdint>
5#include <stdexcept>
6
7namespace bb::avm2::simulation {
8
12 MemoryAddress log_address,
13 uint32_t log_size)
14{
15 uint64_t end_log_address = static_cast<uint64_t>(log_address) + static_cast<uint64_t>(log_size) - 1;
16 bool error_memory_out_of_bounds = greater_than.gt(end_log_address, AVM_HIGHEST_MEM_ADDRESS);
17
18 SideEffectStates side_effect_states = context.get_side_effect_states();
19 uint32_t prev_emitted_log_fields = side_effect_states.numUnencryptedLogFields;
20
21 uint32_t total_log_fields_size = PUBLIC_LOG_HEADER_LENGTH + log_size;
22
23 uint32_t expected_next_emitted_log_fields = prev_emitted_log_fields + total_log_fields_size;
24
25 bool error_too_many_log_fields = greater_than.gt(expected_next_emitted_log_fields, FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH);
26
27 bool error_is_static = context.get_is_static();
28
29 // Will be computed in the loop below
30 bool error_tag_mismatch = false;
31
33 values.reserve(log_size);
34 if (!error_memory_out_of_bounds) {
35 for (uint32_t i = 0; i < log_size; ++i) {
36 MemoryValue value = memory.get(log_address + i);
37 if (value.get_tag() != ValueTag::FF) {
38 error_tag_mismatch = true;
39 }
40 values.push_back(value);
41 }
42 }
43
44 bool error = error_memory_out_of_bounds || error_too_many_log_fields || error_tag_mismatch || error_is_static;
45
46 if (!error) {
47 side_effect_states.numUnencryptedLogFields = expected_next_emitted_log_fields;
48 }
49 context.set_side_effect_states(side_effect_states);
50
53 .contract_address = contract_address,
54 .space_id = memory.get_space_id(),
55 .log_address = log_address,
56 .log_size = log_size,
57 .prev_num_unencrypted_log_fields = prev_emitted_log_fields,
58 .next_num_unencrypted_log_fields = side_effect_states.numUnencryptedLogFields,
59 .is_static = error_is_static,
60 .values = values,
61 .error_memory_out_of_bounds = error_memory_out_of_bounds,
62 .error_too_many_log_fields = error_too_many_log_fields,
63 .error_tag_mismatch = error_tag_mismatch,
64 });
65
66 if (error_memory_out_of_bounds) {
67 throw EmitUnencryptedLogException("Memory out of bounds");
68 }
69 if (error_too_many_log_fields) {
70 throw EmitUnencryptedLogException("Too many logs");
71 }
72 if (error_tag_mismatch) {
73 throw EmitUnencryptedLogException("Tag mismatch");
74 }
75 if (error_is_static) {
76 throw EmitUnencryptedLogException("Static context");
77 }
78}
79
84
89
94
95} // namespace bb::avm2::simulation
#define FLAT_PUBLIC_LOGS_PAYLOAD_LENGTH
#define PUBLIC_LOG_HEADER_LENGTH
#define AVM_HIGHEST_MEM_ADDRESS
ExecutionIdManagerInterface & execution_id_manager
EventEmitterInterface< EmitUnencryptedLogEvent > & events
void emit_unencrypted_log(MemoryInterface &memory, ContextInterface &context, AztecAddress contract_address, MemoryAddress log_offset, uint32_t log_size) override
virtual void emit(Event &&event)=0
virtual uint32_t get_execution_id() const =0
virtual bool gt(const FF &a, const FF &b)=0
uint32_t MemoryAddress
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13