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

#include <mega_circuit_builder.hpp>

Inheritance diagram for bb::MegaCircuitBuilder_< FF >:
bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks > bb::CircuitBuilderBase< ExecutionTrace_::FF >

Public Types

using ExecutionTrace = MegaExecutionTraceBlocks
 
- Public Types inherited from bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >
enum  MEMORY_SELECTORS
 
enum  NNF_SELECTORS
 
using ExecutionTrace = MegaExecutionTraceBlocks
 
using FF = typename ExecutionTrace::FF
 
using RomRamLogic = RomRamLogic_< ExecutionTrace >
 
using scaled_witness = std::pair< uint32_t, FF >
 
using add_simple = std::tuple< scaled_witness, scaled_witness, FF >
 
- Public Types inherited from bb::CircuitBuilderBase< ExecutionTrace_::FF >
using FF = ExecutionTrace_::FF
 
using EmbeddedCurve = curve::Grumpkin
 

Public Member Functions

ecc_op_tuple queue_ecc_add_accum (const g1::affine_element &point)
 Add simple point addition operation to the op queue and add corresponding gates.
 
ecc_op_tuple queue_ecc_mul_accum (const g1::affine_element &point, const FF &scalar, bool in_finalize=false)
 Add point mul-then-accumulate operation to the op queue and add corresponding gates.
 
ecc_op_tuple queue_ecc_eq (bool in_finalize=true)
 Add point equality operation to the op queue based on the value of the internal accumulator and add corresponding gates.
 
ecc_op_tuple queue_ecc_no_op ()
 Logic for a no-op operation.
 
void queue_ecc_random_op ()
 Mechanism for populating two rows with randomness. This "operation" doesn't return a tuple representing the indices of the ecc op values because it should never be used in subsequent logic.
 
void queue_ecc_hiding_op (const curve::BN254::BaseField &Px, const curve::BN254::BaseField &Py)
 Add a hiding op with random (possibly non-curve) Px, Py values to the op queue and circuit.
 
 MegaCircuitBuilder_ (const size_t size_hint=0, std::shared_ptr< ECCOpQueue > op_queue_in=std::make_shared< ECCOpQueue >(), bool is_write_vk_mode=false)
 
 MegaCircuitBuilder_ (std::shared_ptr< ECCOpQueue > op_queue_in)
 
 MegaCircuitBuilder_ (std::shared_ptr< ECCOpQueue > op_queue_in, const std::vector< FF > &witness_values, const std::vector< uint32_t > &public_inputs, const bool is_write_vk_mode)
 Constructor from data generated from ACIR.
 
uint32_t get_ecc_op_idx (const EccOpCode &op_code)
 Convert op code to the witness index for the corresponding op index in the builder.
 
void finalize_circuit (const bool ensure_nonzero)
 
void add_ultra_and_mega_gates_to_ensure_all_polys_are_non_zero ()
 Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomial. This only adds gates for the Goblin polynomials. Most polynomials are handled via the Ultra method, which should be done by a separate call to the Ultra builder's non zero polynomial gates method.
 
void add_mega_gates_to_ensure_all_polys_are_non_zero ()
 Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomial. This only adds gates for the Goblin polynomials. Most polynomials are handled via the Ultra method, which should be done by a separate call to the Ultra builder's non zero polynomial gates method.
 
size_t get_num_constant_gates () const override
 
void add_public_calldata (const uint32_t &in)
 Add a witness variable to the public calldata.
 
void add_public_secondary_calldata (const uint32_t &in)
 Add a witness variable to secondary_calldata.
 
void add_public_return_data (const uint32_t &in)
 Add a witness variable to the public return_data.
 
uint32_t read_bus_vector (BusId bus_idx, const uint32_t &read_idx_witness_idx)
 Read from a databus column.
 
uint32_t read_calldata (const uint32_t &read_idx_witness_idx)
 Read from calldata and create a corresponding databus read gate.
 
uint32_t read_secondary_calldata (const uint32_t &read_idx_witness_idx)
 Read from secondary_calldata and create a corresponding databus read gate.
 
uint32_t read_return_data (const uint32_t &read_idx_witness_idx)
 Read from return_data and create a corresponding databus read gate.
 
void append_to_bus_vector (const BusId bus_idx, const uint32_t &witness_idx)
 
const BusVectorget_calldata () const
 
const BusVectorget_secondary_calldata () const
 
const BusVectorget_return_data () const
 
std::string hash () const
 Compute a hash of the circuit.
 
- Public Member Functions inherited from bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >
void populate_public_inputs_block ()
 Copy the public input idx data into the public inputs trace block.
 
void process_non_native_field_multiplications ()
 Iterates over the cached_non_native_field_multiplication objects, removes duplicates, and instantiates the corresponding constraints.
 
 UltraCircuitBuilder_ (const size_t size_hint=0, bool is_write_vk_mode=false)
 
 UltraCircuitBuilder_ (const size_t size_hint, const std::vector< FF > &witness_values, const std::vector< uint32_t > &public_inputs, const bool is_write_vk_mode)
 Constructor from data generated from ACIR.
 
 UltraCircuitBuilder_ (const UltraCircuitBuilder_ &other)=default
 
 UltraCircuitBuilder_ (UltraCircuitBuilder_ &&other)=default
 
UltraCircuitBuilder_operator= (const UltraCircuitBuilder_ &other)=default
 
UltraCircuitBuilder_operator= (UltraCircuitBuilder_ &&other)=default
 
 ~UltraCircuitBuilder_ () override=default
 
void check_selector_length_consistency ()
 Debug helper method for ensuring all selectors have the same size.
 
void finalize_circuit (const bool ensure_nonzero)
 
void add_gates_to_ensure_all_polys_are_non_zero ()
 Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomial.
 
void create_add_gate (const add_triple_< FF > &in)
 Create an addition gate, where in.a * in.a_scaling + in.b * in.b_scaling + in.c * in.c_scaling + in.const_scaling = 0.
 
void create_big_mul_add_gate (const mul_quad_< FF > &in, const bool use_next_gate_w_4=false)
 Create a big multiplication-addition gate, where in.a * in.b * in.mul_scaling + in.a * in.a_scaling + in.b * in.b_scaling + in.c * in.c_scaling + in.d * in.d_scaling + in.const_scaling = 0. If include_next_gate_w_4 is enabled, then this sum also adds the value of the 4-th witness at the next index.
 
void create_big_add_gate (const add_quad_< FF > &in, const bool use_next_gate_w_4=false)
 Create a big addition gate, where in.a * in.a_scaling + in.b * in.b_scaling + in.c * in.c_scaling + in.d * in.d_scaling + in.const_scaling = 0. If include_next_gate_w_4 is enabled, then the sum also adds the value of the 4-th witness at the next index.
 
void create_bool_gate (const uint32_t a)
 Generate an arithmetic gate equivalent to x^2 - x = 0, which forces x to be 0 or 1.
 
void create_arithmetic_gate (const arithmetic_triple_< FF > &in)
 A plonk gate with disabled (set to zero) fourth wire. q_m * a * b + q_1 * a + q_2 * b + q_3.
 
void create_ecc_add_gate (const ecc_add_gate_< FF > &in)
 Create an elliptic curve addition gate.
 
void create_ecc_dbl_gate (const ecc_dbl_gate_< FF > &in)
 Create an elliptic curve doubling gate.
 
void fix_witness (const uint32_t witness_index, const FF &witness_value)
 Add a gate equating a particular witness to a constant, fixing its value.
 
void create_new_range_constraint (const uint32_t variable_index, const uint64_t target_range, std::string const msg="create_new_range_constraint")
 Constrain a variable to a range.
 
void create_range_constraint (const uint32_t variable_index, const size_t num_bits, std::string const &msg)
 
uint32_t put_constant_variable (const FF &variable)
 
size_t get_num_constant_gates () const override
 
size_t get_num_finalized_gates () const override
 Get the number of gates in a finalized circuit.
 
size_t get_num_finalized_gates_inefficient (bool ensure_nonzero=true) const
 Get the number of gates in the finalized version of the circuit.
 
size_t get_tables_size () const
 Get combined size of all tables used in circuit.
 
size_t get_finalized_total_circuit_size () const
 Get the actual finalized size of a circuit. Assumes the circuit is finalized already.
 
void assert_equal_constant (const uint32_t a_idx, const FF &b, std::string const &msg="assert equal constant")
 
plookup::BasicTableget_table (const plookup::BasicTableId id)
 Get the basic table with provided ID from the set of tables for the present circuit; create it if it doesnt yet exist.
 
plookup::MultiTableget_multitable (const plookup::MultiTableId id)
 
const std::deque< plookup::BasicTable > & get_lookup_tables () const
 
std::deque< plookup::BasicTable > & get_lookup_tables ()
 
size_t get_num_lookup_tables () const
 
plookup::ReadData< uint32_t > create_gates_from_plookup_accumulators (const plookup::MultiTableId &id, const plookup::ReadData< FF > &read_values, const uint32_t key_a_index, std::optional< uint32_t > key_b_index=std::nullopt)
 Create gates from pre-computed accumulator values which simultaneously establish individual basic-table lookups and the reconstruction of the desired result from those components.
 
std::vector< uint32_t > decompose_into_default_range (const uint32_t variable_index, const uint64_t num_bits, const uint64_t target_range_bitnum=DEFAULT_PLOOKUP_RANGE_BITNUM, std::string const &msg="decompose_into_default_range")
 
void create_unconstrained_gate (auto &block, const uint32_t &idx_1, const uint32_t &idx_2, const uint32_t &idx_3, const uint32_t &idx_4)
 Create a gate with no constraints but with possibly non-trivial wire values.
 
void create_unconstrained_gates (const std::vector< uint32_t > &variable_index)
 
void create_sort_constraint (const std::vector< uint32_t > &variable_index)
 
void create_sort_constraint_with_edges (const std::vector< uint32_t > &variable_index, const FF &, const FF &)
 
void assign_tag (const uint32_t variable_index, const uint32_t tag)
 
void set_tau_at_index (const uint32_t tag_index, const uint32_t tau_index)
 Set the tau(tag_index) = tau_index.
 
void set_tau_transposition (const uint32_t tag_index_1, const uint32_t tag_index_2)
 Add a transposition to tau.
 
uint32_t get_new_tag ()
 
RangeList create_range_list (const uint64_t target_range)
 
void process_range_list (RangeList &list)
 
void process_range_lists ()
 
void apply_memory_selectors (const MEMORY_SELECTORS type)
 Enable the memory gate of particular type.
 
void apply_nnf_selectors (const NNF_SELECTORS type)
 Enable the nnf gate of particular type.
 
void range_constrain_two_limbs (const uint32_t lo_idx, const uint32_t hi_idx, const size_t lo_limb_bits=DEFAULT_NON_NATIVE_FIELD_LIMB_BITS, const size_t hi_limb_bits=DEFAULT_NON_NATIVE_FIELD_LIMB_BITS, std::string const &msg="range_constrain_two_limbs")
 
std::array< uint32_t, 2 > evaluate_non_native_field_multiplication (const non_native_multiplication_witnesses< FF > &input)
 Create gates for a full non-native field multiplication identity a * b = q * p + r.
 
std::array< uint32_t, 2 > queue_partial_non_native_field_multiplication (const non_native_partial_multiplication_witnesses< FF > &input)
 Queue the addition of gates constraining the limb-multiplication part of a non native field mul.
 
std::array< uint32_t, 5 > evaluate_non_native_field_subtraction (add_simple limb0, add_simple limb1, add_simple limb2, add_simple limb3, std::tuple< uint32_t, uint32_t, FF > limbp)
 Construct gates for non-native field subtraction.
 
std::array< uint32_t, 5 > evaluate_non_native_field_addition (add_simple limb0, add_simple limb1, add_simple limb2, add_simple limb3, std::tuple< uint32_t, uint32_t, FF > limbp)
 Construct gates for non-native field addition.
 
size_t create_ROM_array (const size_t array_size)
 Create a new read-only memory region (a.k.a. ROM table)
 
void set_ROM_element (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 (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 (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 (const size_t rom_id, const uint32_t index_witness)
 Read a pair of elements from ROM.
 
size_t create_RAM_array (const size_t array_size)
 Create a new updatable memory region.
 
void init_RAM_element (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 (const size_t ram_id, const uint32_t index_witness)
 
void write_RAM_array (const size_t ram_id, const uint32_t index_witness, const uint32_t value_witness)
 
void create_poseidon2_external_gate (const poseidon2_external_gate_< FF > &in)
 Poseidon2 external round gate, activates the q_poseidon2_external selector and relation.
 
void create_poseidon2_internal_gate (const poseidon2_internal_gate_< FF > &in)
 Poseidon2 internal round gate, activates the q_poseidon2_internal selector and relation.
 
const std::vector< uint32_t > & get_used_witnesses () const
 
const std::unordered_set< uint32_t > & get_finalize_witnesses () const
 
void update_used_witnesses (uint32_t var_idx)
 Add a witness index to the boomerang exclusion list.
 
void update_used_witnesses (const std::vector< uint32_t > &used_indices)
 Add a list of witness indices to the boomerang exclusion list.
 
void update_finalize_witnesses (uint32_t var_idx)
 Add a witness index to the finalize exclusion list.
 
void update_finalize_witnesses (const std::vector< uint32_t > &finalize_indices)
 Add a list of witness indices to the finalize exclusion list.
 
msgpack::sbuffer export_circuit () override
 
- Public Member Functions inherited from bb::CircuitBuilderBase< ExecutionTrace_::FF >
 CircuitBuilderBase (size_t size_hint=0, bool is_write_vk_mode=false)
 
 CircuitBuilderBase (const CircuitBuilderBase &other)=default
 
 CircuitBuilderBase (CircuitBuilderBase &&other) noexcept=default
 
CircuitBuilderBaseoperator= (const CircuitBuilderBase &other)=default
 
CircuitBuilderBaseoperator= (CircuitBuilderBase &&other) noexcept=default
 
virtual ~CircuitBuilderBase ()=default
 
bool operator== (const CircuitBuilderBase &other) const=default
 
virtual size_t get_num_variables () const
 
size_t num_gates () const
 
void increment_num_gates (size_t count=1)
 
const std::unordered_map< uint32_t, uint32_t > & tau () const
 
uint32_t zero_idx () const
 
const std::vector< FF > & get_variables () const
 
FF get_variable (const uint32_t index) const
 Get the value of the variable v_{index}.
 
void set_variable (const uint32_t index, const FF &value)
 Set the value of the variable pointed to by a witness index.
 
const std::vector< uint32_t > & public_inputs () const
 
void finalize_public_inputs ()
 Set the _public_inputs_finalized to true to prevent any new public inputs from being added.
 
void initialize_public_inputs (const std::vector< uint32_t > &public_inputs)
 Directly initialize the public inputs vector.
 
virtual uint32_t add_variable (const FF &in)
 Add a variable to variables.
 
uint32_t add_variable (const OT &in)=delete
 
virtual uint32_t add_public_variable (const FF &in)
 Add a public variable to variables.
 
uint32_t add_public_variable (const OT &in)=delete
 
virtual uint32_t set_public_input (uint32_t witness_index)
 Make a witness variable public.
 
virtual void assert_equal (uint32_t a_idx, uint32_t b_idx, std::string const &msg="assert_equal")
 
size_t get_circuit_subgroup_size (size_t num_gates) const
 
size_t num_public_inputs () const
 
virtual void set_variable_name (uint32_t index, const std::string &name)
 Assign a name to a variable (equivalence class)
 
bool failed () const
 
const std::string & err () const
 
void failure (std::string msg)
 
bool is_write_vk_mode () const
 

Public Attributes

std::shared_ptr< ECCOpQueueop_queue
 
uint32_t null_op_idx
 
uint32_t add_accum_op_idx
 
uint32_t mul_accum_op_idx
 
uint32_t equality_op_idx
 
- Public Attributes inherited from bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >
ExecutionTrace blocks
 
std::unordered_map< FF, uint32_t > constant_variable_indices
 
RomRamLogic rom_ram_logic
 
std::vector< uint32_t > memory_read_records
 
std::vector< uint32_t > memory_write_records
 
std::map< uint64_t, RangeList > range_lists
 
std::vector< cached_partial_non_native_field_multiplication > cached_partial_non_native_field_multiplications
 
bool circuit_finalized
 
std::vector< fripa_proof
 
- Public Attributes inherited from bb::CircuitBuilderBase< ExecutionTrace_::FF >
std::vector< uint32_t > real_variable_index
 Map from witness index to real variable index.
 
std::vector< uint32_t > real_variable_tags
 real_variable_tags is the tagging mechanism for the the multiset-equality check.
 
uint32_t current_tag
 
PairingPointsTagging pairing_points_tagging
 PairingPoints tagging tool, used to ensure that all pairing points created in this circuit are aggregated together. This is not related to circuit logic.
 

Static Public Attributes

static constexpr size_t DEFAULT_NON_NATIVE_FIELD_LIMB_BITS
 
- Static Public Attributes inherited from bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >
static constexpr size_t NUM_WIRES
 
static constexpr std::string_view NAME_STRING
 
static constexpr size_t DEFAULT_PLOOKUP_RANGE_BITNUM
 
static constexpr size_t DEFAULT_PLOOKUP_RANGE_STEP_SIZE
 
static constexpr size_t DEFAULT_PLOOKUP_RANGE_SIZE
 
static constexpr size_t DEFAULT_NON_NATIVE_FIELD_LIMB_BITS
 

Private Member Functions

ecc_op_tuple populate_ecc_op_wires (const UltraOp &ultra_op, bool in_finalize=false)
 Add goblin ecc op gates for a single operation.
 
void set_goblin_ecc_op_code_constant_variables ()
 
void create_databus_read_gate (const databus_lookup_gate_< FF > &in, BusId bus_idx)
 Create a databus lookup/read gate.
 
void apply_databus_selectors (BusId bus_idx)
 

Private Attributes

DataBus databus
 

Additional Inherited Members

- Protected Member Functions inherited from bb::CircuitBuilderBase< ExecutionTrace_::FF >
void set_zero_idx (uint32_t value)
 
uint32_t get_first_variable_in_class (uint32_t index) const
 Get the index of the first variable in class.
 
void assert_valid_variables (const std::vector< uint32_t > &variable_indices)
 Check whether each variable index points to a witness value in the variables array.
 
- Protected Attributes inherited from bb::CircuitBuilderBase< ExecutionTrace_::FF >
std::unordered_map< uint32_t, uint32_t > _tau
 The permutation on variable tags, as a constituent of the generalized permutation argument.
 
std::unordered_map< uint32_t, std::string > variable_names
 

Detailed Description

template<typename FF>
class bb::MegaCircuitBuilder_< FF >

Definition at line 19 of file mega_circuit_builder.hpp.

Member Typedef Documentation

◆ ExecutionTrace

template<typename FF >
using bb::MegaCircuitBuilder_< FF >::ExecutionTrace = MegaExecutionTraceBlocks

Definition at line 24 of file mega_circuit_builder.hpp.

Constructor & Destructor Documentation

◆ MegaCircuitBuilder_() [1/3]

template<typename FF >
bb::MegaCircuitBuilder_< FF >::MegaCircuitBuilder_ ( const size_t  size_hint = 0,
std::shared_ptr< ECCOpQueue op_queue_in = std::make_shared<ECCOpQueue>(),
bool  is_write_vk_mode = false 
)
inline

Definition at line 53 of file mega_circuit_builder.hpp.

◆ MegaCircuitBuilder_() [2/3]

template<typename FF >
bb::MegaCircuitBuilder_< FF >::MegaCircuitBuilder_ ( std::shared_ptr< ECCOpQueue op_queue_in)
inline

Definition at line 68 of file mega_circuit_builder.hpp.

◆ MegaCircuitBuilder_() [3/3]

template<typename FF >
bb::MegaCircuitBuilder_< FF >::MegaCircuitBuilder_ ( std::shared_ptr< ECCOpQueue op_queue_in,
const std::vector< FF > &  witness_values,
const std::vector< uint32_t > &  public_inputs,
const bool  is_write_vk_mode 
)
inline

Constructor from data generated from ACIR.

Parameters
op_queue_inOp queue to which goblinized group ops will be added
witness_valueswitnesses values known to acir
public_inputsindices of public inputs in witness array
is_write_vk_modetrue if the builder is used to generate the vk of a circuit
Note
witness_values is the vector of witness values known at the time of acir generation. It is filled with witness values which are interleaved with zeros when witnesses are optimized away.
The length of the witness vector is in general less than total number of variables/witnesses that might be present for a circuit generated from acir, since many gates will depend on the details of the bberg implementation (or more generally on the backend used to process acir).

Definition at line 88 of file mega_circuit_builder.hpp.

Member Function Documentation

◆ add_mega_gates_to_ensure_all_polys_are_non_zero()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::add_mega_gates_to_ensure_all_polys_are_non_zero ( )

Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomial. This only adds gates for the Goblin polynomials. Most polynomials are handled via the Ultra method, which should be done by a separate call to the Ultra builder's non zero polynomial gates method.

Parameters
inStructure containing variables and witness selectors

Definition at line 41 of file mega_circuit_builder.cpp.

◆ add_public_calldata()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::add_public_calldata ( const uint32_t &  in)
inline

Add a witness variable to the public calldata.

Definition at line 139 of file mega_circuit_builder.hpp.

◆ add_public_return_data()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::add_public_return_data ( const uint32_t &  in)
inline

Add a witness variable to the public return_data.

Definition at line 155 of file mega_circuit_builder.hpp.

◆ add_public_secondary_calldata()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::add_public_secondary_calldata ( const uint32_t &  in)
inline

Add a witness variable to secondary_calldata.

In practice this is used in aztec by the kernel circuit to recieve output from a function circuit

Definition at line 146 of file mega_circuit_builder.hpp.

◆ add_ultra_and_mega_gates_to_ensure_all_polys_are_non_zero()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::add_ultra_and_mega_gates_to_ensure_all_polys_are_non_zero ( )

Ensure all polynomials have at least one non-zero coefficient to avoid commiting to the zero-polynomial. This only adds gates for the Goblin polynomials. Most polynomials are handled via the Ultra method, which should be done by a separate call to the Ultra builder's non zero polynomial gates method.

Parameters
inStructure containing variables and witness selectors

Definition at line 82 of file mega_circuit_builder.cpp.

◆ append_to_bus_vector()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::append_to_bus_vector ( const BusId  bus_idx,
const uint32_t &  witness_idx 
)
inline

Definition at line 192 of file mega_circuit_builder.hpp.

◆ apply_databus_selectors()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::apply_databus_selectors ( BusId  bus_idx)
private

Definition at line 299 of file mega_circuit_builder.cpp.

◆ create_databus_read_gate()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::create_databus_read_gate ( const databus_lookup_gate_< FF > &  in,
BusId  bus_idx 
)
private

Create a databus lookup/read gate.

Template Parameters
FF
Parameters
databus_lookup_gate_witness indices corresponding to: read index, result value

Definition at line 289 of file mega_circuit_builder.cpp.

◆ finalize_circuit()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::finalize_circuit ( const bool  ensure_nonzero)

Definition at line 19 of file mega_circuit_builder.cpp.

◆ get_calldata()

template<typename FF >
const BusVector & bb::MegaCircuitBuilder_< FF >::get_calldata ( ) const
inline

Definition at line 197 of file mega_circuit_builder.hpp.

◆ get_ecc_op_idx()

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::get_ecc_op_idx ( const EccOpCode op_code)
inline

Convert op code to the witness index for the corresponding op index in the builder.

Parameters
op_code
Returns
uint32_t

Definition at line 110 of file mega_circuit_builder.hpp.

◆ get_num_constant_gates()

template<typename FF >
size_t bb::MegaCircuitBuilder_< FF >::get_num_constant_gates ( ) const
inlineoverridevirtual

◆ get_return_data()

template<typename FF >
const BusVector & bb::MegaCircuitBuilder_< FF >::get_return_data ( ) const
inline

Definition at line 199 of file mega_circuit_builder.hpp.

◆ get_secondary_calldata()

template<typename FF >
const BusVector & bb::MegaCircuitBuilder_< FF >::get_secondary_calldata ( ) const
inline

Definition at line 198 of file mega_circuit_builder.hpp.

◆ hash()

template<typename FF >
std::string bb::MegaCircuitBuilder_< FF >::hash ( ) const
inline

Compute a hash of the circuit.

Hashes all wires and selectors from each block. Note that this encompases all gate data, copy constraints, and public inputs (via pub inputs block). Useful for debugging purposes to identify where two circuits diverge.

Definition at line 207 of file mega_circuit_builder.hpp.

◆ populate_ecc_op_wires()

template<typename FF >
ecc_op_tuple bb::MegaCircuitBuilder_< FF >::populate_ecc_op_wires ( const UltraOp ultra_op,
bool  in_finalize = false 
)
private

Add goblin ecc op gates for a single operation.

Parameters
ultra_opOperation data expressed in the ultra format
in_finalizeIt's used in boomerang catcher to mark that all variables from some connected component were created after finalize method was called
Note
All selectors are set to 0 since the ecc op selector is derived later based on the block size/location.

Definition at line 169 of file mega_circuit_builder.cpp.

◆ queue_ecc_add_accum()

template<typename FF >
ecc_op_tuple bb::MegaCircuitBuilder_< FF >::queue_ecc_add_accum ( const g1::affine_element point)

Add simple point addition operation to the op queue and add corresponding gates.

Parameters
pointPoint to be added into the accumulator

Definition at line 94 of file mega_circuit_builder.cpp.

◆ queue_ecc_eq()

template<typename FF >
ecc_op_tuple bb::MegaCircuitBuilder_< FF >::queue_ecc_eq ( bool  in_finalize = true)

Add point equality operation to the op queue based on the value of the internal accumulator and add corresponding gates.

Parameters
in_finalizeIt's used in boomerang catcher to mark that all variables from some connected component were created after finalize method was called
Returns
ecc_op_tuple encoding the point to which equality has been asserted

Definition at line 134 of file mega_circuit_builder.cpp.

◆ queue_ecc_hiding_op()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::queue_ecc_hiding_op ( const curve::BN254::BaseField Px,
const curve::BN254::BaseField Py 
)

Add a hiding op with random (possibly non-curve) Px, Py values to the op queue and circuit.

This op provides statistical hiding (~508 bits) for the accumulated_result in Translator/ECCVM. The Px, Py values are random field elements that may not be on the curve. The op uses opcode 3 (eq+reset) for Translator compatibility. In ECCVM, this op is prepended to land at row 1 (lagrange_second == 1), since row 0 is identically zero (for shifts).

Parameters
PxRandom field element for x-coordinate
PyRandom field element for y-coordinate

Definition at line 237 of file mega_circuit_builder.cpp.

◆ queue_ecc_mul_accum()

template<typename FF >
ecc_op_tuple bb::MegaCircuitBuilder_< FF >::queue_ecc_mul_accum ( const g1::affine_element point,
const FF scalar,
bool  in_finalize = false 
)

Add point mul-then-accumulate operation to the op queue and add corresponding gates.

Template Parameters
FF
Parameters
point
scalarThe scalar by which point is multiplied prior to being accumulated
in_finalizeIt's used in boomerang catcher to mark that all variables from some connected component were created after finalize method was called
Returns
ecc_op_tuple encoding the point and scalar inputs to the mul accum

Definition at line 115 of file mega_circuit_builder.cpp.

◆ queue_ecc_no_op()

template<typename FF >
ecc_op_tuple bb::MegaCircuitBuilder_< FF >::queue_ecc_no_op ( )

Logic for a no-op operation.

Returns
ecc_op_tuple with all its fields set to zero

Definition at line 150 of file mega_circuit_builder.cpp.

◆ queue_ecc_random_op()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::queue_ecc_random_op ( )

Mechanism for populating two rows with randomness. This "operation" doesn't return a tuple representing the indices of the ecc op values because it should never be used in subsequent logic.

Note
All selectors are set to 0 since the ecc op selector is derived later based on the block size/location. The method does not return a tuple of variable indices as those should not be used in subsequent steps for random ops.

Definition at line 216 of file mega_circuit_builder.cpp.

◆ read_bus_vector()

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::read_bus_vector ( BusId  bus_idx,
const uint32_t &  read_idx_witness_idx 
)

Read from a databus column.

Creates a databus lookup gate based on the input index and read result

Template Parameters
FF
Parameters
read_idx_witness_idxVariable index of the read index
Returns
uint32_t Variable index of the result of the read

Definition at line 263 of file mega_circuit_builder.cpp.

◆ read_calldata()

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::read_calldata ( const uint32_t &  read_idx_witness_idx)
inline

Read from calldata and create a corresponding databus read gate.

Parameters
read_idx_witness_idxWitness index for the calldata read index
Returns
uint32_t Witness index for the result of the read

Definition at line 165 of file mega_circuit_builder.hpp.

◆ read_return_data()

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::read_return_data ( const uint32_t &  read_idx_witness_idx)
inline

Read from return_data and create a corresponding databus read gate.

Parameters
read_idx_witness_idxWitness index for the return_data read index
Returns
uint32_t Witness index for the result of the read

Definition at line 187 of file mega_circuit_builder.hpp.

◆ read_secondary_calldata()

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::read_secondary_calldata ( const uint32_t &  read_idx_witness_idx)
inline

Read from secondary_calldata and create a corresponding databus read gate.

Parameters
read_idx_witness_idxWitness index for the secondary_calldata read index
Returns
uint32_t Witness index for the result of the read

Definition at line 176 of file mega_circuit_builder.hpp.

◆ set_goblin_ecc_op_code_constant_variables()

template<typename FF >
void bb::MegaCircuitBuilder_< FF >::set_goblin_ecc_op_code_constant_variables ( )
private

Definition at line 246 of file mega_circuit_builder.cpp.

Member Data Documentation

◆ add_accum_op_idx

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::add_accum_op_idx

Definition at line 34 of file mega_circuit_builder.hpp.

◆ databus

template<typename FF >
DataBus bb::MegaCircuitBuilder_< FF >::databus
private

Definition at line 21 of file mega_circuit_builder.hpp.

◆ DEFAULT_NON_NATIVE_FIELD_LIMB_BITS

template<typename FF >
constexpr size_t bb::MegaCircuitBuilder_< FF >::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS
staticconstexpr
Initial value:
=
UltraCircuitBuilder_<MegaExecutionTraceBlocks>::DEFAULT_NON_NATIVE_FIELD_LIMB_BITS

Definition at line 26 of file mega_circuit_builder.hpp.

◆ equality_op_idx

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::equality_op_idx

Definition at line 36 of file mega_circuit_builder.hpp.

◆ mul_accum_op_idx

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::mul_accum_op_idx

Definition at line 35 of file mega_circuit_builder.hpp.

◆ null_op_idx

template<typename FF >
uint32_t bb::MegaCircuitBuilder_< FF >::null_op_idx

Definition at line 33 of file mega_circuit_builder.hpp.

◆ op_queue

template<typename FF >
std::shared_ptr<ECCOpQueue> bb::MegaCircuitBuilder_< FF >::op_queue

Definition at line 30 of file mega_circuit_builder.hpp.


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