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 <memory>
4#include <optional>
5
9
10namespace bb::avm2::simulation {
11
12// Manages the bytecode operations of all calls in a transaction.
13// In particular, it will not duplicate hashing and decomposition.
15 public:
16 virtual ~TxBytecodeManagerInterface() = default;
17
18 // Retrieves the bytecode and
19 // (1) sets up the address-class id connection,
20 // (2) hashes it if needed.
21 virtual BytecodeId get_bytecode(const AztecAddress& address) = 0;
23 // Retrieves an instruction and decomposes it if needed.
24 virtual Instruction read_instruction(const BytecodeId& bytecode_id, uint32_t pc) = 0;
25 virtual Instruction read_instruction(const BytecodeId& bytecode_id,
26 std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
27 uint32_t pc) = 0;
28};
29
30// Manages the bytecode of a single nested call. Therefore always the same bytecode.
31// Mostly a wrapper around a TxBytecodeManager.
33 public:
34 virtual ~BytecodeManagerInterface() = default;
35
36 virtual Instruction read_instruction(uint32_t pc) = 0;
37
38 // Returns the id of the current bytecode. Tries to fetch it if not already done.
39 // Throws BytecodeNotFoundError if contract does not exist.
41
42 // Returns the id of the current bytecode if it has been retrieved, std::nullopt otherwise.
43 // Won't try to retrieve the bytecode.
45};
46
47struct BytecodeRetrievalError : public std::runtime_error {
48 BytecodeRetrievalError(const std::string& message)
49 : std::runtime_error(message)
50 {}
51};
52
53struct InstructionFetchingError : public std::runtime_error {
54 InstructionFetchingError(const std::string& message)
55 : std::runtime_error(message)
56 {}
57};
58
59} // namespace bb::avm2::simulation
virtual Instruction read_instruction(uint32_t pc)=0
virtual std::optional< BytecodeId > get_retrieved_bytecode_id()=0
virtual Instruction read_instruction(const BytecodeId &bytecode_id, std::shared_ptr< std::vector< uint8_t > > bytecode_ptr, uint32_t pc)=0
virtual Instruction read_instruction(const BytecodeId &bytecode_id, uint32_t pc)=0
virtual BytecodeId get_bytecode(const AztecAddress &address)=0
virtual std::shared_ptr< std::vector< uint8_t > > get_bytecode_data(const BytecodeId &bytecode_id)=0
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
BytecodeRetrievalError(const std::string &message)