Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bytecode_manager.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <optional>
6#include <span>
7#include <sys/types.h>
8#include <utility>
9#include <vector>
10
23
24namespace bb::avm2::simulation {
25
27 public:
47
50 Instruction read_instruction(const BytecodeId& bytecode_id, PC pc) override;
51 Instruction read_instruction(const BytecodeId& bytecode_id,
52 std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
53 PC pc) override;
54
55 private:
65
67};
68
69// This implementation of BytecodeManagerInterface caches the bytecode id and bytecode pointer after the first
70// retrieval. Calls to read_instruction will not ask the TxBytecodeManager to retrieve the bytecode again.
72 public:
77
79 {
80 // We only assert in debug mode because this is in the hot path of the execution.
81 BB_ASSERT_DEBUG(bytecode_id.has_value(), "Bytecode not retrieved before call to read_instruction");
82 auto id = get_bytecode_id();
84 }
85
94
96
97 private:
102};
103
104} // namespace bb::avm2::simulation
#define BB_ASSERT_DEBUG(expression,...)
Definition assert.hpp:55
TxBytecodeManagerInterface & tx_bytecode_manager
BytecodeManager(AztecAddress address, TxBytecodeManagerInterface &tx_bytecode_manager)
std::optional< BytecodeId > bytecode_id
std::optional< BytecodeId > get_retrieved_bytecode_id() override
std::shared_ptr< std::vector< uint8_t > > bytecode_ptr
Instruction read_instruction(PC pc) override
Core shared component for contract instance retrieval and validation.
HighLevelMerkleDBInterface & merkle_db
Instruction read_instruction(const BytecodeId &bytecode_id, PC pc) override
EventEmitterInterface< BytecodeDecompositionEvent > & decomposition_events
RetrievedBytecodesTreeCheckInterface & retrieved_bytecodes_tree_check
EventEmitterInterface< BytecodeRetrievalEvent > & retrieval_events
EventEmitterInterface< InstructionFetchingEvent > & fetching_events
unordered_flat_map< BytecodeId, std::shared_ptr< std::vector< uint8_t > > > bytecodes
std::shared_ptr< std::vector< uint8_t > > get_bytecode_data(const BytecodeId &bytecode_id) override
BytecodeHashingInterface & bytecode_hasher
ContractInstanceManagerInterface & contract_instance_manager
TxBytecodeManager(ContractDBInterface &contract_db, HighLevelMerkleDBInterface &merkle_db, BytecodeHashingInterface &bytecode_hasher, RangeCheckInterface &range_check, ContractInstanceManagerInterface &contract_instance_manager, RetrievedBytecodesTreeCheckInterface &retrieved_bytecodes_tree_check, EventEmitterInterface< BytecodeRetrievalEvent > &retrieval_events, EventEmitterInterface< BytecodeDecompositionEvent > &decomposition_events, EventEmitterInterface< InstructionFetchingEvent > &fetching_events)
BytecodeId get_bytecode(const AztecAddress &address) override
Retrieves and validates bytecode from the TxBytecodeManager's ContractDBInterface and emits a Bytecod...
virtual BytecodeId get_bytecode(const AztecAddress &address)=0
virtual Instruction read_instruction(const BytecodeId &bytecode_id, PC pc)=0
virtual std::shared_ptr< std::vector< uint8_t > > get_bytecode_data(const BytecodeId &bytecode_id)=0
AVM range check gadget for witness generation.
uint32_t PC
::ankerl::unordered_dense::map< Key, T > unordered_flat_map
Definition map.hpp:15
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13