Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ProgramBlock Class Reference

#include <program_block.hpp>

Public Member Functions

 ProgramBlock ()=default
 
void process_instruction (FuzzInstruction instruction)
 process the instruction
 
void finalize_with_return (uint8_t return_size, MemoryTagWrapper return_value_tag, uint16_t return_value_offset_index)
 finalize the program block with a return instruction Tries to find memory address with the given return_value_tag, if there are no such address (zero variables of such tag are stored), it sets the return address to 0. Sets the terminator type to RETURN.
 
void finalize_with_jump (ProgramBlock *target_block, bool copy_memory_manager=true)
 finalize the block with a jump Sets the terminator type to JUMP, adds the target block to the successors and the current block to the predecessors.
 
void finalize_with_jump_if (ProgramBlock *target_then_block, ProgramBlock *target_else_block, uint16_t condition_offset, bool copy_memory_manager=true)
 finalize the block with a jump if Sets the terminator type to JUMP_IF, adds the target blocks to the successors and the current block to the predecessors. Sets the condition offset index.
 
void insert_internal_call (ProgramBlock *target_block)
 insert INTERNALCALL instruction with 0 offset
 
std::optional< uint16_t > get_terminating_condition_value ()
 
std::vector< bb::avm2::simulation::Instructionget_instructions ()
 
bool is_memory_address_set (uint16_t address)
 
void patch_internal_calls ()
 in insert_internal_call we insert INTERNALCALL instruction with 0 offset, because we don't know the resulting block offsets this method patches the INTERNALCALL instructions with the actual offset
 

Public Attributes

std::vector< ProgramBlock * > successors
 
std::vector< ProgramBlock * > predecessors
 
ProgramBlockcaller = nullptr
 the block that called this block by INTERNALCALL This field is copied to predecessors on every CFG instructions
 
TerminatorType terminator_type = TerminatorType::NONE
 
int offset = -1
 

Private Member Functions

void preprocess_memory_addresses (AddressRef address, uint32_t actual_address)
 preprocess the memory addresses Sets M[0] = base_offset for Relative/IndirectRelative modes Sets M[pointer_address] = pointer_value for Indirect/IndirectRelative modes
 
void preprocess_memory_addresses (ResultAddressRef address, uint32_t actual_address)
 
void process_add_8_instruction (ADD_8_Instruction instruction)
 
void process_sub_8_instruction (SUB_8_Instruction instruction)
 
void process_mul_8_instruction (MUL_8_Instruction instruction)
 
void process_div_8_instruction (DIV_8_Instruction instruction)
 
void process_eq_8_instruction (EQ_8_Instruction instruction)
 
void process_lt_8_instruction (LT_8_Instruction instruction)
 
void process_lte_8_instruction (LTE_8_Instruction instruction)
 
void process_and_8_instruction (AND_8_Instruction instruction)
 
void process_or_8_instruction (OR_8_Instruction instruction)
 
void process_xor_8_instruction (XOR_8_Instruction instruction)
 
void process_shl_8_instruction (SHL_8_Instruction instruction)
 
void process_shr_8_instruction (SHR_8_Instruction instruction)
 
void process_set_8_instruction (SET_8_Instruction instruction)
 
void process_set_16_instruction (SET_16_Instruction instruction)
 
void process_set_32_instruction (SET_32_Instruction instruction)
 
void process_set_64_instruction (SET_64_Instruction instruction)
 
void process_set_128_instruction (SET_128_Instruction instruction)
 
void process_set_ff_instruction (SET_FF_Instruction instruction)
 
void process_mov_8_instruction (MOV_8_Instruction instruction)
 
void process_mov_16_instruction (MOV_16_Instruction instruction)
 
void process_not_8_instruction (NOT_8_Instruction instruction)
 
void process_fdiv_8_instruction (FDIV_8_Instruction instruction)
 
void process_add_16_instruction (ADD_16_Instruction instruction)
 
void process_sub_16_instruction (SUB_16_Instruction instruction)
 
void process_mul_16_instruction (MUL_16_Instruction instruction)
 
void process_div_16_instruction (DIV_16_Instruction instruction)
 
void process_fdiv_16_instruction (FDIV_16_Instruction instruction)
 
void process_eq_16_instruction (EQ_16_Instruction instruction)
 
void process_lt_16_instruction (LT_16_Instruction instruction)
 
void process_lte_16_instruction (LTE_16_Instruction instruction)
 
void process_and_16_instruction (AND_16_Instruction instruction)
 
void process_or_16_instruction (OR_16_Instruction instruction)
 
void process_xor_16_instruction (XOR_16_Instruction instruction)
 
void process_not_16_instruction (NOT_16_Instruction instruction)
 
void process_shl_16_instruction (SHL_16_Instruction instruction)
 
void process_shr_16_instruction (SHR_16_Instruction instruction)
 
void process_cast_8_instruction (CAST_8_Instruction instruction)
 
void process_cast_16_instruction (CAST_16_Instruction instruction)
 
void process_sstore_instruction (SSTORE_Instruction instruction)
 
void process_sload_instruction (SLOAD_Instruction instruction)
 
void process_getenvvar_instruction (GETENVVAR_Instruction instruction)
 
void process_emitnulifier_instruction (EMITNULLIFIER_Instruction instruction)
 
void process_nullifierexists_instruction (NULLIFIEREXISTS_Instruction instruction)
 
void process_emitnotehash_instruction (EMITNOTEHASH_Instruction instruction)
 
void process_notehashexists_instruction (NOTEHASHEXISTS_Instruction instruction)
 
void process_calldatacopy_instruction (CALLDATACOPY_Instruction instruction)
 

Private Attributes

MemoryManager memory_manager
 
std::vector< bb::avm2::simulation::Instructioninstructions
 
uint16_t condition_offset_index = 0
 the offset index of the condition variable (for JUMP_IF)
 
std::map< size_t, ProgramBlock * > internal_call_instruction_indicies_to_patch
 

Detailed Description

Definition at line 37 of file program_block.hpp.

Constructor & Destructor Documentation

◆ ProgramBlock()

ProgramBlock::ProgramBlock ( )
default

Member Function Documentation

◆ finalize_with_jump()

void ProgramBlock::finalize_with_jump ( ProgramBlock target_block,
bool  copy_memory_manager = true 
)

finalize the block with a jump Sets the terminator type to JUMP, adds the target block to the successors and the current block to the predecessors.

Definition at line 1049 of file program_block.cpp.

◆ finalize_with_jump_if()

void ProgramBlock::finalize_with_jump_if ( ProgramBlock target_then_block,
ProgramBlock target_else_block,
uint16_t  condition_offset,
bool  copy_memory_manager = true 
)

finalize the block with a jump if Sets the terminator type to JUMP_IF, adds the target blocks to the successors and the current block to the predecessors. Sets the condition offset index.

Definition at line 1060 of file program_block.cpp.

◆ finalize_with_return()

void ProgramBlock::finalize_with_return ( uint8_t  return_size,
MemoryTagWrapper  return_value_tag,
uint16_t  return_value_offset_index 
)

finalize the program block with a return instruction Tries to find memory address with the given return_value_tag, if there are no such address (zero variables of such tag are stored), it sets the return address to 0. Sets the terminator type to RETURN.

Note
if the block has caller, it inserts INTERNALRETURN only

Definition at line 1013 of file program_block.cpp.

◆ get_instructions()

std::vector< bb::avm2::simulation::Instruction > ProgramBlock::get_instructions ( )

Definition at line 1184 of file program_block.cpp.

◆ get_terminating_condition_value()

std::optional< uint16_t > ProgramBlock::get_terminating_condition_value ( )

Definition at line 1105 of file program_block.cpp.

◆ insert_internal_call()

void ProgramBlock::insert_internal_call ( ProgramBlock target_block)

insert INTERNALCALL instruction with 0 offset

Definition at line 1079 of file program_block.cpp.

◆ is_memory_address_set()

bool ProgramBlock::is_memory_address_set ( uint16_t  address)

Definition at line 1114 of file program_block.cpp.

◆ patch_internal_calls()

void ProgramBlock::patch_internal_calls ( )

in insert_internal_call we insert INTERNALCALL instruction with 0 offset, because we don't know the resulting block offsets this method patches the INTERNALCALL instructions with the actual offset

Definition at line 1090 of file program_block.cpp.

◆ preprocess_memory_addresses() [1/2]

void ProgramBlock::preprocess_memory_addresses ( AddressRef  address,
uint32_t  actual_address 
)
private

preprocess the memory addresses Sets M[0] = base_offset for Relative/IndirectRelative modes Sets M[pointer_address] = pointer_value for Indirect/IndirectRelative modes

Definition at line 11 of file program_block.cpp.

◆ preprocess_memory_addresses() [2/2]

void ProgramBlock::preprocess_memory_addresses ( ResultAddressRef  address,
uint32_t  actual_address 
)
private

Definition at line 46 of file program_block.cpp.

◆ process_add_16_instruction()

void ProgramBlock::process_add_16_instruction ( ADD_16_Instruction  instruction)
private

Definition at line 472 of file program_block.cpp.

◆ process_add_8_instruction()

void ProgramBlock::process_add_8_instruction ( ADD_8_Instruction  instruction)
private

Definition at line 56 of file program_block.cpp.

◆ process_and_16_instruction()

void ProgramBlock::process_and_16_instruction ( AND_16_Instruction  instruction)
private

Definition at line 640 of file program_block.cpp.

◆ process_and_8_instruction()

void ProgramBlock::process_and_8_instruction ( AND_8_Instruction  instruction)
private

Definition at line 199 of file program_block.cpp.

◆ process_calldatacopy_instruction()

void ProgramBlock::process_calldatacopy_instruction ( CALLDATACOPY_Instruction  instruction)
private

Definition at line 976 of file program_block.cpp.

◆ process_cast_16_instruction()

void ProgramBlock::process_cast_16_instruction ( CAST_16_Instruction  instruction)
private

Definition at line 782 of file program_block.cpp.

◆ process_cast_8_instruction()

void ProgramBlock::process_cast_8_instruction ( CAST_8_Instruction  instruction)
private

Definition at line 763 of file program_block.cpp.

◆ process_div_16_instruction()

void ProgramBlock::process_div_16_instruction ( DIV_16_Instruction  instruction)
private

Definition at line 535 of file program_block.cpp.

◆ process_div_8_instruction()

void ProgramBlock::process_div_8_instruction ( DIV_8_Instruction  instruction)
private

Definition at line 118 of file program_block.cpp.

◆ process_emitnotehash_instruction()

void ProgramBlock::process_emitnotehash_instruction ( EMITNOTEHASH_Instruction  instruction)
private

Definition at line 910 of file program_block.cpp.

◆ process_emitnulifier_instruction()

void ProgramBlock::process_emitnulifier_instruction ( EMITNULLIFIER_Instruction  instruction)
private

Definition at line 870 of file program_block.cpp.

◆ process_eq_16_instruction()

void ProgramBlock::process_eq_16_instruction ( EQ_16_Instruction  instruction)
private

Definition at line 577 of file program_block.cpp.

◆ process_eq_8_instruction()

void ProgramBlock::process_eq_8_instruction ( EQ_8_Instruction  instruction)
private

Definition at line 138 of file program_block.cpp.

◆ process_fdiv_16_instruction()

void ProgramBlock::process_fdiv_16_instruction ( FDIV_16_Instruction  instruction)
private

Definition at line 556 of file program_block.cpp.

◆ process_fdiv_8_instruction()

void ProgramBlock::process_fdiv_8_instruction ( FDIV_8_Instruction  instruction)
private

Definition at line 433 of file program_block.cpp.

◆ process_getenvvar_instruction()

void ProgramBlock::process_getenvvar_instruction ( GETENVVAR_Instruction  instruction)
private

Definition at line 849 of file program_block.cpp.

◆ process_instruction()

void ProgramBlock::process_instruction ( FuzzInstruction  instruction)

process the instruction

Parameters
instructionthe instruction to process Updates stored_variables if the instruction writes to memory Updates instructions with the instruction If arguments of the instruction are not in stored_variables, the instruction is skipped

Definition at line 1119 of file program_block.cpp.

◆ process_lt_16_instruction()

void ProgramBlock::process_lt_16_instruction ( LT_16_Instruction  instruction)
private

Definition at line 598 of file program_block.cpp.

◆ process_lt_8_instruction()

void ProgramBlock::process_lt_8_instruction ( LT_8_Instruction  instruction)
private

Definition at line 158 of file program_block.cpp.

◆ process_lte_16_instruction()

void ProgramBlock::process_lte_16_instruction ( LTE_16_Instruction  instruction)
private

Definition at line 619 of file program_block.cpp.

◆ process_lte_8_instruction()

void ProgramBlock::process_lte_8_instruction ( LTE_8_Instruction  instruction)
private

Definition at line 179 of file program_block.cpp.

◆ process_mov_16_instruction()

void ProgramBlock::process_mov_16_instruction ( MOV_16_Instruction  instruction)
private

Definition at line 415 of file program_block.cpp.

◆ process_mov_8_instruction()

void ProgramBlock::process_mov_8_instruction ( MOV_8_Instruction  instruction)
private

Definition at line 398 of file program_block.cpp.

◆ process_mul_16_instruction()

void ProgramBlock::process_mul_16_instruction ( MUL_16_Instruction  instruction)
private

Definition at line 514 of file program_block.cpp.

◆ process_mul_8_instruction()

void ProgramBlock::process_mul_8_instruction ( MUL_8_Instruction  instruction)
private

Definition at line 98 of file program_block.cpp.

◆ process_not_16_instruction()

void ProgramBlock::process_not_16_instruction ( NOT_16_Instruction  instruction)
private

Definition at line 703 of file program_block.cpp.

◆ process_not_8_instruction()

void ProgramBlock::process_not_8_instruction ( NOT_8_Instruction  instruction)
private

Definition at line 454 of file program_block.cpp.

◆ process_notehashexists_instruction()

void ProgramBlock::process_notehashexists_instruction ( NOTEHASHEXISTS_Instruction  instruction)
private

Definition at line 931 of file program_block.cpp.

◆ process_nullifierexists_instruction()

void ProgramBlock::process_nullifierexists_instruction ( NULLIFIEREXISTS_Instruction  instruction)
private

Definition at line 883 of file program_block.cpp.

◆ process_or_16_instruction()

void ProgramBlock::process_or_16_instruction ( OR_16_Instruction  instruction)
private

Definition at line 661 of file program_block.cpp.

◆ process_or_8_instruction()

void ProgramBlock::process_or_8_instruction ( OR_8_Instruction  instruction)
private

Definition at line 220 of file program_block.cpp.

◆ process_set_128_instruction()

void ProgramBlock::process_set_128_instruction ( SET_128_Instruction  instruction)
private

Definition at line 366 of file program_block.cpp.

◆ process_set_16_instruction()

void ProgramBlock::process_set_16_instruction ( SET_16_Instruction  instruction)
private

Definition at line 321 of file program_block.cpp.

◆ process_set_32_instruction()

void ProgramBlock::process_set_32_instruction ( SET_32_Instruction  instruction)
private

Definition at line 336 of file program_block.cpp.

◆ process_set_64_instruction()

void ProgramBlock::process_set_64_instruction ( SET_64_Instruction  instruction)
private

Definition at line 351 of file program_block.cpp.

◆ process_set_8_instruction()

void ProgramBlock::process_set_8_instruction ( SET_8_Instruction  instruction)
private

Definition at line 306 of file program_block.cpp.

◆ process_set_ff_instruction()

void ProgramBlock::process_set_ff_instruction ( SET_FF_Instruction  instruction)
private

Definition at line 383 of file program_block.cpp.

◆ process_shl_16_instruction()

void ProgramBlock::process_shl_16_instruction ( SHL_16_Instruction  instruction)
private

Definition at line 721 of file program_block.cpp.

◆ process_shl_8_instruction()

void ProgramBlock::process_shl_8_instruction ( SHL_8_Instruction  instruction)
private

Definition at line 262 of file program_block.cpp.

◆ process_shr_16_instruction()

void ProgramBlock::process_shr_16_instruction ( SHR_16_Instruction  instruction)
private

Definition at line 742 of file program_block.cpp.

◆ process_shr_8_instruction()

void ProgramBlock::process_shr_8_instruction ( SHR_8_Instruction  instruction)
private

Definition at line 284 of file program_block.cpp.

◆ process_sload_instruction()

void ProgramBlock::process_sload_instruction ( SLOAD_Instruction  instruction)
private

Definition at line 822 of file program_block.cpp.

◆ process_sstore_instruction()

void ProgramBlock::process_sstore_instruction ( SSTORE_Instruction  instruction)
private

Definition at line 801 of file program_block.cpp.

◆ process_sub_16_instruction()

void ProgramBlock::process_sub_16_instruction ( SUB_16_Instruction  instruction)
private

Definition at line 493 of file program_block.cpp.

◆ process_sub_8_instruction()

void ProgramBlock::process_sub_8_instruction ( SUB_8_Instruction  instruction)
private

Definition at line 77 of file program_block.cpp.

◆ process_xor_16_instruction()

void ProgramBlock::process_xor_16_instruction ( XOR_16_Instruction  instruction)
private

Definition at line 682 of file program_block.cpp.

◆ process_xor_8_instruction()

void ProgramBlock::process_xor_8_instruction ( XOR_8_Instruction  instruction)
private

Definition at line 241 of file program_block.cpp.

Member Data Documentation

◆ caller

ProgramBlock* ProgramBlock::caller = nullptr

the block that called this block by INTERNALCALL This field is copied to predecessors on every CFG instructions

Definition at line 109 of file program_block.hpp.

◆ condition_offset_index

uint16_t ProgramBlock::condition_offset_index = 0
private

the offset index of the condition variable (for JUMP_IF)

Definition at line 43 of file program_block.hpp.

◆ instructions

std::vector<bb::avm2::simulation::Instruction> ProgramBlock::instructions
private

Definition at line 40 of file program_block.hpp.

◆ internal_call_instruction_indicies_to_patch

std::map<size_t, ProgramBlock*> ProgramBlock::internal_call_instruction_indicies_to_patch
private

Definition at line 48 of file program_block.hpp.

◆ memory_manager

MemoryManager ProgramBlock::memory_manager
private

Definition at line 39 of file program_block.hpp.

◆ offset

int ProgramBlock::offset = -1

Definition at line 111 of file program_block.hpp.

◆ predecessors

std::vector<ProgramBlock*> ProgramBlock::predecessors

Definition at line 105 of file program_block.hpp.

◆ successors

std::vector<ProgramBlock*> ProgramBlock::successors

Definition at line 104 of file program_block.hpp.

◆ terminator_type

TerminatorType ProgramBlock::terminator_type = TerminatorType::NONE

Definition at line 110 of file program_block.hpp.


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