Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
memory.cpp
Go to the documentation of this file.
2
3#include <cstdint>
4
8
9namespace bb::avm2::simulation {
10
11namespace {
12
13// Default value for uninitialized memory: FF(0) with tag FF.
14const auto DEFAULT_MEM_VALUE = MemoryValue::from_tag(MemoryTag::FF, 0);
15
16} // namespace
17
25{
26 // Improvement: reconsider tag validation strategy.
29 debug("Memory write: ", index, " <- ", value.to_string());
30 events.emit({ .execution_clk = execution_id_manager.get_execution_id(),
32 .addr = index,
33 .value = value,
34 .space_id = space_id });
35}
36
45{
46 auto it = memory.find(index);
47 const auto& vt = it != memory.end() ? it->second : DEFAULT_MEM_VALUE;
48 events.emit({ .execution_clk = execution_id_manager.get_execution_id(),
50 .addr = index,
51 .value = vt,
52 .space_id = space_id });
53
54 debug("Memory read: ", index, " -> ", vt.to_string());
55 return vt;
56}
57
65{
66 auto it = memory.find(index);
67 return it != memory.end() ? it->second : DEFAULT_MEM_VALUE;
68}
69
80{
81 if (value.get_tag() == MemoryTag::FF) {
82 return;
83 }
84
85 uint128_t value_as_uint128 = static_cast<uint128_t>(value.as_ff());
88}
89
90} // namespace bb::avm2::simulation
static TaggedValue from_tag(ValueTag tag, FF value)
std::string to_string() const
virtual uint32_t get_execution_id() const =0
ExecutionIdGetterInterface & execution_id_manager
Definition memory.hpp:40
const MemoryValue & unconstrained_get(MemoryAddress index) const
Reads a value from memory without emitting an event.
Definition memory.cpp:64
void validate_tag(const MemoryValue &value) const
Validates that a value fits within its tag's bit-width via a range check.
Definition memory.cpp:79
EventEmitterInterface< MemoryEvent > & events
Definition memory.hpp:42
const MemoryValue & get(MemoryAddress index) const override
Reads a tagged value from memory at the given address.
Definition memory.cpp:44
void set(MemoryAddress index, MemoryValue value) override
Writes a tagged value to memory at the given address.
Definition memory.cpp:24
#define debug(...)
Definition log.hpp:99
AVM range check gadget for witness generation.
uint8_t get_tag_bits(ValueTag tag)
uint32_t MemoryAddress
unsigned __int128 uint128_t
Definition serialize.hpp:45