Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::avm2::simulation::TxBytecodeManager Class Reference

#include <bytecode_manager.hpp>

Inheritance diagram for bb::avm2::simulation::TxBytecodeManager:
bb::avm2::simulation::TxBytecodeManagerInterface

Public Member Functions

 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 BytecodeRetrievalEvent. Corresponds to traces: bc_retrieval.pil bc_hashing.pil bc_decomposition.pil.
 
std::shared_ptr< std::vector< uint8_t > > get_bytecode_data (const BytecodeId &bytecode_id) override
 
Instruction read_instruction (const BytecodeId &bytecode_id, PC pc) override
 Reads and deserializes the instruction given by the pair [ bytecode_id, pc ]. Corresponds to instr_fetching.pil.
 
Instruction read_instruction (const BytecodeId &bytecode_id, std::shared_ptr< std::vector< uint8_t > > bytecode_ptr, PC pc) override
 Reads and deserializes the instruction given by the pair [ bytecode_id, pc ] and emits an InstructionFetchingEvent. Corresponds to the subtrace instr_fetching.pil.
 
- Public Member Functions inherited from bb::avm2::simulation::TxBytecodeManagerInterface
virtual ~TxBytecodeManagerInterface ()=default
 

Private Attributes

ContractDBInterfacecontract_db
 
HighLevelMerkleDBInterfacemerkle_db
 
BytecodeHashingInterfacebytecode_hasher
 
RangeCheckInterfacerange_check
 
ContractInstanceManagerInterfacecontract_instance_manager
 
RetrievedBytecodesTreeCheckInterfaceretrieved_bytecodes_tree_check
 
EventEmitterInterface< BytecodeRetrievalEvent > & retrieval_events
 
EventEmitterInterface< BytecodeDecompositionEvent > & decomposition_events
 
EventEmitterInterface< InstructionFetchingEvent > & fetching_events
 
unordered_flat_map< BytecodeId, std::shared_ptr< std::vector< uint8_t > > > bytecodes
 

Detailed Description

Definition at line 26 of file bytecode_manager.hpp.

Constructor & Destructor Documentation

◆ TxBytecodeManager()

bb::avm2::simulation::TxBytecodeManager::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 
)
inline

Definition at line 28 of file bytecode_manager.hpp.

Member Function Documentation

◆ get_bytecode()

BytecodeId bb::avm2::simulation::TxBytecodeManager::get_bytecode ( const AztecAddress address)
overridevirtual

Retrieves and validates bytecode from the TxBytecodeManager's ContractDBInterface and emits a BytecodeRetrievalEvent. Corresponds to traces: bc_retrieval.pil bc_hashing.pil bc_decomposition.pil.

If we have not yet processed the gathered bytecode instance, we emit a BytecodeHashingEvent and BytecodeDecompositionEvent. The decomposition trace stores the bytecode from the BytecodeDecompositionEvent as individual bytes to be referred to by instruction fetching. It enforces the bytecode size and representation as packed fields, which are used by the hashing trace to enforce the correctness of the bytecode id (=commitment).

Exceptions
BytecodeRetrievalErrorif
  • the contract at the given address is not deployed
  • we have reached the limit of the number of bytecodes to retrieve for this tx
Unexpectedexception if
  • the contract class for the retrieved instance does not exist
  • the bytecode commitment for the retrieved instance does not exist
  • the bytecode commitment does not match the calculated hash (inside assert_public_bytecode_commitment()) Note: the deployer contract guarantees that if we have a deployed instance, its contract class and hence its bytecode commitment must exist. If the contract is not deployed, this is caught by the above BytecodeRetrievalError.
Parameters
addressThe address of the contract instance to retrieve bytecode for.
Returns
The id (=commitment) of the bytecode.

Implements bb::avm2::simulation::TxBytecodeManagerInterface.

Definition at line 42 of file bytecode_manager.cpp.

◆ get_bytecode_data()

std::shared_ptr< std::vector< uint8_t > > bb::avm2::simulation::TxBytecodeManager::get_bytecode_data ( const BytecodeId bytecode_id)
overridevirtual

◆ read_instruction() [1/2]

Instruction bb::avm2::simulation::TxBytecodeManager::read_instruction ( const BytecodeId bytecode_id,
PC  pc 
)
overridevirtual

Reads and deserializes the instruction given by the pair [ bytecode_id, pc ]. Corresponds to instr_fetching.pil.

Overloaded helper fn which looks up the bytecode data by bytecode_id and delegates to read_instruction(bytecode_id, bytecode_ptr, pc) below.

Exceptions
InstructionFetchingErrorif any parse error is detected (see below).
Parameters
bytecode_idThe bytecode identifier (public bytecode commitment).
pcThe program counter.
Returns
The deserialized instruction.

Implements bb::avm2::simulation::TxBytecodeManagerInterface.

Definition at line 163 of file bytecode_manager.cpp.

◆ read_instruction() [2/2]

Instruction bb::avm2::simulation::TxBytecodeManager::read_instruction ( const BytecodeId bytecode_id,
std::shared_ptr< std::vector< uint8_t > >  bytecode_ptr,
PC  pc 
)
overridevirtual

Reads and deserializes the instruction given by the pair [ bytecode_id, pc ] and emits an InstructionFetchingEvent. Corresponds to the subtrace instr_fetching.pil.

Attempts to deserialize the instruction at pc in the provided bytecode bytecode_ptr and check its tag operand (if any). If any parsing error occurs (see below), the event is still emitted with the error.

Exceptions
InstructionFetchingErrorif any parse error is detected:
  • PC_OUT_OF_RANGE: thrown by deserialize_instruction() if pc >= bytecode.size().
  • OPCODE_OUT_OF_RANGE: thrown by deserialize_instruction() if the opcode byte does not correspond to a valid wire opcode.
  • INSTRUCTION_OUT_OF_RANGE: thrown by deserialize_instruction() if instruction_size > bytes_to_read from the bytecode.
  • TAG_OUT_OF_RANGE: if the instruction has a tag operand which does not correspond to a valid memory tag i.e. when the operand value > MemoryTag::MAX, as determined by check_tag().

Note that only one parsing error can occur for each event with hierarchy in the order above. This disjointedness is enforced in the circuit. See deserialize_instruction() and instr_fetching.pil for more detailed error information.

Parameters
bytecode_idThe bytecode identifier (public bytecode commitment).
bytecode_ptrShared pointer to the raw bytecode bytes.
pcThe program counter.
Returns
The deserialized instruction.

Implements bb::avm2::simulation::TxBytecodeManagerInterface.

Definition at line 192 of file bytecode_manager.cpp.

Member Data Documentation

◆ bytecode_hasher

BytecodeHashingInterface& bb::avm2::simulation::TxBytecodeManager::bytecode_hasher
private

Definition at line 58 of file bytecode_manager.hpp.

◆ bytecodes

unordered_flat_map<BytecodeId, std::shared_ptr<std::vector<uint8_t> > > bb::avm2::simulation::TxBytecodeManager::bytecodes
private

Definition at line 66 of file bytecode_manager.hpp.

◆ contract_db

ContractDBInterface& bb::avm2::simulation::TxBytecodeManager::contract_db
private

Definition at line 56 of file bytecode_manager.hpp.

◆ contract_instance_manager

ContractInstanceManagerInterface& bb::avm2::simulation::TxBytecodeManager::contract_instance_manager
private

Definition at line 60 of file bytecode_manager.hpp.

◆ decomposition_events

EventEmitterInterface<BytecodeDecompositionEvent>& bb::avm2::simulation::TxBytecodeManager::decomposition_events
private

Definition at line 63 of file bytecode_manager.hpp.

◆ fetching_events

EventEmitterInterface<InstructionFetchingEvent>& bb::avm2::simulation::TxBytecodeManager::fetching_events
private

Definition at line 64 of file bytecode_manager.hpp.

◆ merkle_db

HighLevelMerkleDBInterface& bb::avm2::simulation::TxBytecodeManager::merkle_db
private

Definition at line 57 of file bytecode_manager.hpp.

◆ range_check

RangeCheckInterface& bb::avm2::simulation::TxBytecodeManager::range_check
private

Definition at line 59 of file bytecode_manager.hpp.

◆ retrieval_events

EventEmitterInterface<BytecodeRetrievalEvent>& bb::avm2::simulation::TxBytecodeManager::retrieval_events
private

Definition at line 62 of file bytecode_manager.hpp.

◆ retrieved_bytecodes_tree_check

RetrievedBytecodesTreeCheckInterface& bb::avm2::simulation::TxBytecodeManager::retrieved_bytecodes_tree_check
private

Definition at line 61 of file bytecode_manager.hpp.


The documentation for this class was generated from the following files: