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.
23 // Retrieves an instruction and decomposes it if needed.
24 // This version of read_instruction might retrieve the bytecode (and generate an event) if not already done.
25 virtual Instruction read_instruction(const BytecodeId& bytecode_id, uint32_t pc) = 0;
26 // This version of read_instruction does not retrieve the bytecode.
27 virtual Instruction read_instruction(const BytecodeId& bytecode_id,
28 std::shared_ptr<std::vector<uint8_t>> bytecode_ptr,
29 uint32_t pc) = 0;
30};
31
32// Manages the bytecode of a single nested call. Therefore always the same bytecode.
33// Mostly a wrapper around a TxBytecodeManager.
35 public:
36 virtual ~BytecodeManagerInterface() = default;
37
38 virtual Instruction read_instruction(uint32_t pc) = 0;
39
40 // Returns the id of the current bytecode. Tries to fetch it if not already done.
41 // Throws BytecodeNotFoundError if contract does not exist.
43
44 // Returns the id of the current bytecode if it has been retrieved, std::nullopt otherwise.
45 // Won't try to retrieve the bytecode.
47};
48
49struct BytecodeRetrievalError : public std::runtime_error {
50 BytecodeRetrievalError(const std::string& message)
51 : std::runtime_error(message)
52 {}
53};
54
55struct InstructionFetchingError : public std::runtime_error {
56 InstructionFetchingError(const std::string& message)
57 : std::runtime_error(message)
58 {}
59};
60
61} // 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)