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#include <memory>
5
9
10namespace bb::avm2::simulation {
11
13{
14 // TODO: validate address?
15 // TODO: reconsider tag validation.
17 memory[index] = value;
18 debug("Memory write: ", index, " <- ", value.to_string());
19 events.emit({ .execution_clk = execution_id_manager.get_execution_id(),
20 .mode = MemoryMode::WRITE,
21 .addr = index,
22 .value = value,
23 .space_id = space_id });
24}
25
27{
28 // TODO: validate address?
29 static const auto default_value = MemoryValue::from<FF>(0);
30
31 auto it = memory.find(index);
32 const auto& vt = it != memory.end() ? it->second : default_value;
33 events.emit({ .execution_clk = execution_id_manager.get_execution_id(),
34 .mode = MemoryMode::READ,
35 .addr = index,
36 .value = vt,
37 .space_id = space_id });
38
39 debug("Memory read: ", index, " -> ", vt.to_string());
40 return vt;
41}
42
43// Sadly this is circuit leaking. In simulation we know the tag-value is consistent.
44// But the circuit does need to force a range check.
46{
47 if (value.get_tag() == MemoryTag::FF) {
48 return;
49 }
50
51 uint128_t value_as_uint128 = static_cast<uint128_t>(value.as_ff());
54}
55
56} // namespace bb::avm2::simulation
std::string to_string() const
virtual uint32_t get_execution_id() const =0
ExecutionIdGetterInterface & execution_id_manager
Definition memory.hpp:51
void validate_tag(const MemoryValue &value) const
Definition memory.cpp:45
EventEmitterInterface< MemoryEvent > & events
Definition memory.hpp:53
const MemoryValue & get(MemoryAddress index) const override
Definition memory.cpp:26
void set(MemoryAddress index, MemoryValue value) override
Definition memory.cpp:12
void debug(Args... args)
Definition log.hpp:59
uint8_t get_tag_bits(ValueTag tag)
uint32_t MemoryAddress
unsigned __int128 uint128_t
Definition serialize.hpp:44