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

#include <data_copy.hpp>

Inheritance diagram for bb::avm2::simulation::DataCopy:
bb::avm2::simulation::DataCopyInterface

Public Member Functions

 DataCopy (ExecutionIdGetterInterface &execution_id_manager, GreaterThanInterface &gt, EventEmitterInterface< DataCopyEvent > &event_emitter)
 
void cd_copy (ContextInterface &context, uint32_t copy_size, uint32_t offset, MemoryAddress dst_addr) override
 Writes calldata into dst_addr. There is slight difference in how enqueued and nested contexts are handled, this is mostly encapsulated in context.get_calldata()
 
void rd_copy (ContextInterface &context, uint32_t copy_size, uint32_t offset, MemoryAddress dst_addr) override
 Copies returndata from the last executed context to the dst_addr.
 
- Public Member Functions inherited from bb::avm2::simulation::DataCopyInterface
virtual ~DataCopyInterface ()=default
 

Private Member Functions

uint64_t min (uint64_t a, uint64_t b)
 

Private Attributes

ExecutionIdGetterInterfaceexecution_id_manager
 
GreaterThanInterfacegt
 
EventEmitterInterface< DataCopyEvent > & events
 

Detailed Description

Definition at line 15 of file data_copy.hpp.

Constructor & Destructor Documentation

◆ DataCopy()

bb::avm2::simulation::DataCopy::DataCopy ( ExecutionIdGetterInterface execution_id_manager,
GreaterThanInterface gt,
EventEmitterInterface< DataCopyEvent > &  event_emitter 
)
inline

Definition at line 17 of file data_copy.hpp.

Member Function Documentation

◆ cd_copy()

void bb::avm2::simulation::DataCopy::cd_copy ( ContextInterface context,
uint32_t  copy_size,
uint32_t  offset,
MemoryAddress  dst_addr 
)
overridevirtual

Writes calldata into dst_addr. There is slight difference in how enqueued and nested contexts are handled, this is mostly encapsulated in context.get_calldata()

Notes on DataCopy: The simulation for DataCopy has a lot of subtle complexity due to the requirements of the circuit constraints. The main complexity comes from the need to have the following 32-bit range checks (1) Computing read_index_upper_bound via min, which is used to determine the final index in the cd/rd to read up to. (2) Clamping reads at the memory boundary when src_addr + read_index_upper_bound exceeds AVM_MEMORY_SIZE. (3) Checking that writes are within bounds of the memory (only dst out of range is an error). (4) Checking whether the offset exceeds the clamped read index upper bound to determine the actual number of elements from calldata/returndata to read (i.e. from [offset, clamped]).

Parameters
copy_sizeThe size of calldata to copy (u32).
offsetThe offset in calldata to start copying from (u32).
dst_addrThe address in memory to write the calldata to.
Exceptions
DataCopyExceptionif the write memory access is out of bounds.

Implements bb::avm2::simulation::DataCopyInterface.

Definition at line 101 of file data_copy.cpp.

◆ min()

uint64_t bb::avm2::simulation::DataCopy::min ( uint64_t  a,
uint64_t  b 
)
private

Definition at line 71 of file data_copy.cpp.

◆ rd_copy()

void bb::avm2::simulation::DataCopy::rd_copy ( ContextInterface context,
uint32_t  copy_size,
uint32_t  offset,
MemoryAddress  dst_addr 
)
overridevirtual

Copies returndata from the last executed context to the dst_addr.

Parameters
copy_sizeThe size of returndata to copy (u32).
offsetThe offset in returndata to start copying from (u32).
dst_addrThe address in memory to write the returndata to.
Exceptions
DataCopyExceptionif the write memory access is out of bounds.

Implements bb::avm2::simulation::DataCopyInterface.

Definition at line 155 of file data_copy.cpp.

Member Data Documentation

◆ events

EventEmitterInterface<DataCopyEvent>& bb::avm2::simulation::DataCopy::events
private

Definition at line 33 of file data_copy.hpp.

◆ execution_id_manager

ExecutionIdGetterInterface& bb::avm2::simulation::DataCopy::execution_id_manager
private

Definition at line 31 of file data_copy.hpp.

◆ gt

GreaterThanInterface& bb::avm2::simulation::DataCopy::gt
private

Definition at line 32 of file data_copy.hpp.


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