Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::RomRamLogic_< ExecutionTrace > Class Template Reference

ROM/RAM logic handler for UltraCircuitBuilder. More...

#include <rom_ram_logic.hpp>

Public Types

using FF = typename ExecutionTrace::FF
 
using CircuitBuilder = UltraCircuitBuilder_< ExecutionTrace >
 

Public Member Functions

 RomRamLogic_ ()=default
 
size_t create_ROM_array (const size_t array_size)
 Create a new read-only memory region.
 
void set_ROM_element (CircuitBuilder *builder, const size_t rom_id, const size_t index_value, const uint32_t value_witness)
 Initialize a rom cell to equal value_witness
 
void set_ROM_element_pair (CircuitBuilder *builder, const size_t rom_id, const size_t index_value, const std::array< uint32_t, 2 > &value_witnesses)
 Initialize a ROM array element with a pair of witness values.
 
uint32_t read_ROM_array (CircuitBuilder *builder, const size_t rom_id, const uint32_t index_witness)
 Read a single element from ROM.
 
std::array< uint32_t, 2 > read_ROM_array_pair (CircuitBuilder *builder, const size_t rom_id, const uint32_t index_witness)
 Read a pair of elements from ROM.
 
void create_ROM_gate (CircuitBuilder *builder, RomRecord &record)
 Gate that'reads' from a ROM table, i.e., the table index is a witness not precomputed.
 
void create_sorted_ROM_gate (CircuitBuilder *builder, RomRecord &record)
 Gate that performs consistency checks to validate that a claimed ROM read value is correct.
 
void process_ROM_array (CircuitBuilder *builder, const size_t rom_id)
 Compute additional gates required to validate ROM reads. Called when generating the proving key.
 
void process_ROM_arrays (CircuitBuilder *builder)
 Process all of the ROM arrays.
 
size_t create_RAM_array (const size_t array_size)
 Create a new updatable memory region.
 
void init_RAM_element (CircuitBuilder *builder, const size_t ram_id, const size_t index_value, const uint32_t value_witness)
 Initialize a RAM cell to equal value_witness
 
uint32_t read_RAM_array (CircuitBuilder *builder, const size_t ram_id, const uint32_t index_witness)
 
void write_RAM_array (CircuitBuilder *builder, const size_t ram_id, const uint32_t index_witness, const uint32_t value_witness)
 
void create_RAM_gate (CircuitBuilder *builder, RamRecord &record)
 Gate that performs a read/write operation into a RAM table, i.e. table index is a witness not precomputed.
 
void create_sorted_RAM_gate (CircuitBuilder *builder, RamRecord &record)
 Gate that performs consistency checks to validate that a claimed RAM read/write value is correct.
 
void create_final_sorted_RAM_gate (CircuitBuilder *builder, RamRecord &record, const size_t ram_array_size)
 Performs consistency checks to validate that a claimed RAM read/write value is correct. Used for the final gate in a list of sorted RAM records.
 
void process_RAM_array (CircuitBuilder *builder, const size_t ram_id)
 Compute additional gates required to validate RAM read/writes. Called when generating the proving key.
 
void process_RAM_arrays (CircuitBuilder *builder)
 
bool operator== (const RomRamLogic_ &other) const noexcept
 

Public Attributes

std::vector< RamTranscriptram_arrays
 Each entry in ram_arrays represents an independent RAM table. RamTranscript tracks the current table state, as well as the 'records' produced by each read and write operation. Used in compute_proving_key to generate consistency check gates required to validate the RAM read/write history.
 
std::vector< RomTranscriptrom_arrays
 Each entry in ram_arrays represents an independent ROM table. RomTranscript tracks the current table state, as well as the 'records' produced by each read operation. Used in compute_proving_key to generate consistency check gates required to validate the ROM read history.
 

Detailed Description

template<typename ExecutionTrace>
class bb::RomRamLogic_< ExecutionTrace >

ROM/RAM logic handler for UltraCircuitBuilder.

Definition at line 107 of file rom_ram_logic.hpp.

Member Typedef Documentation

◆ CircuitBuilder

template<typename ExecutionTrace >
using bb::RomRamLogic_< ExecutionTrace >::CircuitBuilder = UltraCircuitBuilder_<ExecutionTrace>

Definition at line 110 of file rom_ram_logic.hpp.

◆ FF

template<typename ExecutionTrace >
using bb::RomRamLogic_< ExecutionTrace >::FF = typename ExecutionTrace::FF

Definition at line 109 of file rom_ram_logic.hpp.

Constructor & Destructor Documentation

◆ RomRamLogic_()

template<typename ExecutionTrace >
bb::RomRamLogic_< ExecutionTrace >::RomRamLogic_ ( )
default

Member Function Documentation

◆ create_final_sorted_RAM_gate()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::create_final_sorted_RAM_gate ( CircuitBuilder builder,
RamRecord record,
const size_t  ram_array_size 
)

Performs consistency checks to validate that a claimed RAM read/write value is correct. Used for the final gate in a list of sorted RAM records.

Parameters
builder
recordStores details of this read operation. Mutated by this fn!

Definition at line 389 of file rom_ram_logic.cpp.

◆ create_RAM_array()

template<typename ExecutionTrace >
size_t bb::RomRamLogic_< ExecutionTrace >::create_RAM_array ( const size_t  array_size)

Create a new updatable memory region.

Creates a transcript object, where the inside memory state array is filled with "uninitialized memory" and empty memory record array. Puts this object into the vector of ROM arrays.

Parameters
array_sizeThe size of region in elements
Returns
size_t The index of the element

Definition at line 259 of file rom_ram_logic.cpp.

◆ create_RAM_gate()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::create_RAM_gate ( CircuitBuilder builder,
RamRecord record 
)

Gate that performs a read/write operation into a RAM table, i.e. table index is a witness not precomputed.

Parameters
builder
recordStores details of this read operation. Mutated by this fn!

Definition at line 357 of file rom_ram_logic.cpp.

◆ create_ROM_array()

template<typename ExecutionTrace >
size_t bb::RomRamLogic_< ExecutionTrace >::create_ROM_array ( const size_t  array_size)

Create a new read-only memory region.

Creates a transcript object, where the inside memory state array is filled with "uninitialized memory" and empty memory record array. Puts this object into the vector of ROM arrays.

Parameters
array_sizeThe size of region in elements
Returns
size_t The index of the element

Definition at line 8 of file rom_ram_logic.cpp.

◆ create_ROM_gate()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::create_ROM_gate ( CircuitBuilder builder,
RomRecord record 
)

Gate that'reads' from a ROM table, i.e., the table index is a witness not precomputed.

Parameters
builder
recordStores details of this read operation. Mutated by this fn!

Definition at line 137 of file rom_ram_logic.cpp.

◆ create_sorted_RAM_gate()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::create_sorted_RAM_gate ( CircuitBuilder builder,
RamRecord record 
)

Gate that performs consistency checks to validate that a claimed RAM read/write value is correct.

sorted RAM gates are generated sequentially, each RAM record is sorted first by index then by timestamp

Parameters
builder
recordStores details of this read operation. Mutated by this fn!

Definition at line 376 of file rom_ram_logic.cpp.

◆ create_sorted_ROM_gate()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::create_sorted_ROM_gate ( CircuitBuilder builder,
RomRecord record 
)

Gate that performs consistency checks to validate that a claimed ROM read value is correct.

sorted ROM gates are generated sequentially, each ROM record is sorted by index

Parameters
builder
recordStores details of this read operation. Mutated by this fn!

Definition at line 151 of file rom_ram_logic.cpp.

◆ init_RAM_element()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::init_RAM_element ( CircuitBuilder builder,
const size_t  ram_id,
const size_t  index_value,
const uint32_t  value_witness 
)

Initialize a RAM cell to equal value_witness

Parameters
builder
ram_idThe index of the RAM array, which cell we are initializing
index_valueThe index of the cell within the array (an actual index, not a witness index)
value_witnessThe index of the witness with the value that should be in the

Definition at line 270 of file rom_ram_logic.cpp.

◆ operator==()

template<typename ExecutionTrace >
bool bb::RomRamLogic_< ExecutionTrace >::operator== ( const RomRamLogic_< ExecutionTrace > &  other) const
inlinenoexcept

Definition at line 278 of file rom_ram_logic.hpp.

◆ process_RAM_array()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::process_RAM_array ( CircuitBuilder builder,
const size_t  ram_id 
)

Compute additional gates required to validate RAM read/writes. Called when generating the proving key.

Parameters
ram_idThe id of the RAM table
gate_offset_from_public_inputsRequired to track the gate position of where we're adding extra gates

Definition at line 426 of file rom_ram_logic.cpp.

◆ process_RAM_arrays()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::process_RAM_arrays ( CircuitBuilder builder)

Definition at line 557 of file rom_ram_logic.cpp.

◆ process_ROM_array()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::process_ROM_array ( CircuitBuilder builder,
const size_t  rom_id 
)

Compute additional gates required to validate ROM reads. Called when generating the proving key.

Parameters
builder
rom_idThe id of the ROM table
gate_offset_from_public_inputsRequired to track the gate position of where we're adding extra gates

Definition at line 166 of file rom_ram_logic.cpp.

◆ process_ROM_arrays()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::process_ROM_arrays ( CircuitBuilder builder)

Process all of the ROM arrays.

Definition at line 252 of file rom_ram_logic.cpp.

◆ read_RAM_array()

template<typename ExecutionTrace >
uint32_t bb::RomRamLogic_< ExecutionTrace >::read_RAM_array ( CircuitBuilder builder,
const size_t  ram_id,
const uint32_t  index_witness 
)

Definition at line 296 of file rom_ram_logic.cpp.

◆ read_ROM_array()

template<typename ExecutionTrace >
uint32_t bb::RomRamLogic_< ExecutionTrace >::read_ROM_array ( CircuitBuilder builder,
const size_t  rom_id,
const uint32_t  index_witness 
)

Read a single element from ROM.

Parameters
builder
rom_idThe index of the array to read from
index_witnessThe witness with the index inside the array
Returns
uint32_t Cell value witness index

Definition at line 78 of file rom_ram_logic.cpp.

◆ read_ROM_array_pair()

template<typename ExecutionTrace >
std::array< uint32_t, 2 > bb::RomRamLogic_< ExecutionTrace >::read_ROM_array_pair ( CircuitBuilder builder,
const size_t  rom_id,
const uint32_t  index_witness 
)

Read a pair of elements from ROM.

Parameters
rom_idThe id of the ROM array
index_witnessThe witness containing the index in the array
Returns
std::array<uint32_t, 2> A pair of indexes of witness variables of cell values

Definition at line 105 of file rom_ram_logic.cpp.

◆ set_ROM_element()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::set_ROM_element ( CircuitBuilder builder,
const size_t  rom_id,
const size_t  index_value,
const uint32_t  value_witness 
)

Initialize a rom cell to equal value_witness

Parameters
builder
rom_idThe index of the ROM array, which cell we are initializing
index_valueThe index of the cell within the array (an actual index, not a witness index)
value_witnessThe index of the witness with the value that should be in the

Initialize a ROM cell to equal value_witness index_value is a RAW VALUE that describes the cell index. It is NOT a witness When intializing ROM arrays, it is important that the index of the cell is known when compiling the circuit. This ensures that, for a given circuit, we know with 100% certainty that EVERY rom cell is initialized

Definition at line 25 of file rom_ram_logic.cpp.

◆ set_ROM_element_pair()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::set_ROM_element_pair ( CircuitBuilder builder,
const size_t  rom_id,
const size_t  index_value,
const std::array< uint32_t, 2 > &  value_witnesses 
)

Initialize a ROM array element with a pair of witness values.

Parameters
builder
rom_idROM array id
index_valueIndex in the array
value_witnessesThe witnesses to put in the slot

Definition at line 52 of file rom_ram_logic.cpp.

◆ write_RAM_array()

template<typename ExecutionTrace >
void bb::RomRamLogic_< ExecutionTrace >::write_RAM_array ( CircuitBuilder builder,
const size_t  ram_id,
const uint32_t  index_witness,
const uint32_t  value_witness 
)

Definition at line 327 of file rom_ram_logic.cpp.

Member Data Documentation

◆ ram_arrays

template<typename ExecutionTrace >
std::vector<RamTranscript> bb::RomRamLogic_< ExecutionTrace >::ram_arrays

Each entry in ram_arrays represents an independent RAM table. RamTranscript tracks the current table state, as well as the 'records' produced by each read and write operation. Used in compute_proving_key to generate consistency check gates required to validate the RAM read/write history.

Definition at line 120 of file rom_ram_logic.hpp.

◆ rom_arrays

template<typename ExecutionTrace >
std::vector<RomTranscript> bb::RomRamLogic_< ExecutionTrace >::rom_arrays

Each entry in ram_arrays represents an independent ROM table. RomTranscript tracks the current table state, as well as the 'records' produced by each read operation. Used in compute_proving_key to generate consistency check gates required to validate the ROM read history.

Definition at line 127 of file rom_ram_logic.hpp.


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