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 bool error_too_large = greater_than.gt(log_size, PUBLIC_LOG_SIZE_IN_FIELDS);
16
17 uint64_t end_log_address = static_cast<uint64_t>(log_address) + static_cast<uint64_t>(log_size) - 1;
18 bool error_memory_out_of_bounds = greater_than.gt(end_log_address, AVM_HIGHEST_MEM_ADDRESS);
19
20 SideEffectStates side_effect_states = context.get_side_effect_states();
21 uint32_t log_index = side_effect_states.numUnencryptedLogs;
22
23 bool error_too_many_logs = log_index == MAX_PUBLIC_LOGS_PER_TX;
24
25 bool error_is_static = context.get_is_static();
26
27 // Will be computed in the loop below
28 bool error_tag_mismatch = false;
29
31 values.reserve(PUBLIC_LOG_SIZE_IN_FIELDS);
32
33 uint32_t num_memory_reads = 0;
34 if (!error_memory_out_of_bounds) {
35 num_memory_reads = std::min<uint32_t>(log_size, PUBLIC_LOG_SIZE_IN_FIELDS);
36 }
37
38 for (uint32_t i = 0; i < num_memory_reads; ++i) {
39 MemoryValue value = memory.get(log_address + i);
40 if (value.get_tag() != ValueTag::FF) {
41 error_tag_mismatch = true;
42 }
43 values.push_back(value);
44 }
45
46 bool error =
47 error_too_large || error_memory_out_of_bounds || error_too_many_logs || error_tag_mismatch || error_is_static;
48
49 if (!error) {
50 side_effect_states.numUnencryptedLogs = log_index + 1;
51 }
52 context.set_side_effect_states(side_effect_states);
53
57 .space_id = memory.get_space_id(),
58 .log_address = log_address,
59 .log_size = log_size,
60 .prev_num_unencrypted_logs = log_index,
61 .next_num_unencrypted_logs = side_effect_states.numUnencryptedLogs,
62 .is_static = error_is_static,
63 .values = values,
64 .error_too_large = error_too_large,
65 .error_memory_out_of_bounds = error_memory_out_of_bounds,
66 .error_too_many_logs = error_too_many_logs,
67 .error_tag_mismatch = error_tag_mismatch,
68 });
69
70 if (error_too_large) {
71 throw EmitUnencryptedLogException("Log size too large");
72 }
73 if (error_memory_out_of_bounds) {
74 throw EmitUnencryptedLogException("Memory out of bounds");
75 }
76 if (error_too_many_logs) {
77 throw EmitUnencryptedLogException("Too many logs");
78 }
79 if (error_tag_mismatch) {
80 throw EmitUnencryptedLogException("Tag mismatch");
81 }
82 if (error_is_static) {
83 throw EmitUnencryptedLogException("Static context");
84 }
85}
86
91
96
101
102} // namespace bb::avm2::simulation
#define MAX_PUBLIC_LOGS_PER_TX
#define AVM_HIGHEST_MEM_ADDRESS
#define PUBLIC_LOG_SIZE_IN_FIELDS
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