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
26struct BytecodeNotFoundError : public std::runtime_error {
27 BytecodeNotFoundError(const std::string& message)
28 : std::runtime_error(message)
29 {}
30};
31
32struct InstructionFetchingError : public std::runtime_error {
33 InstructionFetchingError(const std::string& message)
34 : std::runtime_error(message)
35 {}
36};
37
38// Manages the bytecode operations of all calls in a transaction.
39// In particular, it will not duplicate hashing and decomposition.
41 public:
42 virtual ~TxBytecodeManagerInterface() = default;
43
44 // Retrieves the bytecode and
45 // (1) sets up the address-class id connection,
46 // (2) hashes it if needed.
47 virtual BytecodeId get_bytecode(const AztecAddress& address) = 0;
48 // Retrieves an instruction and decomposes it if needed.
49 virtual Instruction read_instruction(BytecodeId bytecode_id, uint32_t pc) = 0;
50};
51
53 public:
71
72 BytecodeId get_bytecode(const AztecAddress& address) override;
73 Instruction read_instruction(BytecodeId bytecode_id, uint32_t pc) override;
74
75 private:
85};
86
87// Manages the bytecode of a single nested call.
88// Mostly a wrapper around a TxBytecodeManager.
90 public:
91 virtual ~BytecodeManagerInterface() = default;
92
93 virtual Instruction read_instruction(uint32_t pc) = 0;
94
95 // Returns the id of the current bytecode. Tries to fetch it if not already done.
96 // Throws BytecodeNotFoundError if contract does not exist.
98
99 // Returns the id of the current bytecode, or nullopt if contract does not exist.
100 // Does not throw (for use in during context serialization before execution is expecting errors)
102};
103
141
142} // namespace bb::avm2::simulation
TxBytecodeManagerInterface & tx_bytecode_manager
Instruction read_instruction(uint32_t pc) override
BytecodeManager(AztecAddress address, TxBytecodeManagerInterface &tx_bytecode_manager)
std::optional< BytecodeId > bytecode_id
std::optional< BytecodeId > try_get_bytecode_id() override
virtual Instruction read_instruction(uint32_t pc)=0
virtual std::optional< BytecodeId > try_get_bytecode_id()=0
Core shared component for contract instance retrieval and validation.
HighLevelMerkleDBInterface & merkle_db
EventEmitterInterface< BytecodeDecompositionEvent > & decomposition_events
EventEmitterInterface< BytecodeRetrievalEvent > & retrieval_events
EventEmitterInterface< InstructionFetchingEvent > & fetching_events
unordered_flat_map< BytecodeId, std::shared_ptr< std::vector< uint8_t > > > bytecodes
TxBytecodeManager(ContractDBInterface &contract_db, HighLevelMerkleDBInterface &merkle_db, BytecodeHashingInterface &bytecode_hasher, RangeCheckInterface &range_check, ContractInstanceManagerInterface &contract_instance_manager, EventEmitterInterface< BytecodeRetrievalEvent > &retrieval_events, EventEmitterInterface< BytecodeDecompositionEvent > &decomposition_events, EventEmitterInterface< InstructionFetchingEvent > &fetching_events)
BytecodeHashingInterface & bytecode_hasher
ContractInstanceManagerInterface & contract_instance_manager
Instruction read_instruction(BytecodeId bytecode_id, uint32_t pc) override
BytecodeId get_bytecode(const AztecAddress &address) override
virtual Instruction read_instruction(BytecodeId bytecode_id, uint32_t pc)=0
virtual BytecodeId get_bytecode(const AztecAddress &address)=0
::ankerl::unordered_dense::map< Key, T > unordered_flat_map
Definition map.hpp:15
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
BytecodeNotFoundError(const std::string &message)