Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::CircuitBuilderBase< FF_ > Class Template Referenceabstract

#include <circuit_builder_base.hpp>

Public Types

using FF = FF_
 
using EmbeddedCurve = curve::Grumpkin
 

Public Member Functions

 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_finalized_gates () const
 
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
 
virtual size_t get_num_constant_gates () const =0
 
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.
 
template<typename OT >
uint32_t add_variable (const OT &in)=delete
 
virtual uint32_t add_public_variable (const FF &in)
 Add a public variable to variables.
 
template<typename OT >
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)
 
virtual msgpack::sbuffer export_circuit ()
 Export the existing circuit as msgpack compatible buffer.
 
bool failed () const
 
const std::string & err () const
 
void failure (std::string msg)
 
bool is_write_vk_mode () const
 

Public Attributes

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 = DUMMY_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.
 

Protected Member Functions

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

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
 

Private Member Functions

void update_real_variable_indices (uint32_t index, uint32_t new_real_index)
 Update all variables from index in equivalence class to have real variable new_real_index.
 

Private Attributes

std::vector< FFvariables
 
std::vector< uint32_t > _public_inputs
 
bool _public_inputs_finalized = false
 
std::vector< uint32_t > next_var_index
 
std::vector< uint32_t > prev_var_index
 
uint32_t _zero_idx = 0
 
size_t _num_gates = 0
 
bool _failed = false
 
std::string _err
 
bool _is_write_vk_mode = false
 

Static Private Attributes

static constexpr uint32_t REAL_VARIABLE = UINT32_MAX - 1
 
static constexpr uint32_t FIRST_VARIABLE_IN_CLASS = UINT32_MAX - 2
 

Detailed Description

template<typename FF_>
class bb::CircuitBuilderBase< FF_ >

Definition at line 24 of file circuit_builder_base.hpp.

Member Typedef Documentation

◆ EmbeddedCurve

template<typename FF_ >
using bb::CircuitBuilderBase< FF_ >::EmbeddedCurve = curve::Grumpkin

Definition at line 27 of file circuit_builder_base.hpp.

◆ FF

template<typename FF_ >
using bb::CircuitBuilderBase< FF_ >::FF = FF_

Definition at line 26 of file circuit_builder_base.hpp.

Constructor & Destructor Documentation

◆ CircuitBuilderBase() [1/3]

template<typename FF_ >
bb::CircuitBuilderBase< FF_ >::CircuitBuilderBase ( size_t  size_hint = 0,
bool  is_write_vk_mode = false 
)

Definition at line 14 of file circuit_builder_base_impl.hpp.

◆ CircuitBuilderBase() [2/3]

template<typename FF_ >
bb::CircuitBuilderBase< FF_ >::CircuitBuilderBase ( const CircuitBuilderBase< FF_ > &  other)
default

◆ CircuitBuilderBase() [3/3]

template<typename FF_ >
bb::CircuitBuilderBase< FF_ >::CircuitBuilderBase ( CircuitBuilderBase< FF_ > &&  other)
defaultnoexcept

◆ ~CircuitBuilderBase()

template<typename FF_ >
virtual bb::CircuitBuilderBase< FF_ >::~CircuitBuilderBase ( )
virtualdefault

Member Function Documentation

◆ add_public_variable() [1/2]

template<typename FF_ >
uint32_t bb::CircuitBuilderBase< FF_ >::add_public_variable ( const FF in)
virtual

Add a public variable to variables.

The only difference between this and add_variable is that here it is also added to the public_inputs vector

Parameters
inThe value of the variable
Returns
The index of the new variable in the variables vector

Definition at line 92 of file circuit_builder_base_impl.hpp.

◆ add_public_variable() [2/2]

template<typename FF_ >
template<typename OT >
uint32_t bb::CircuitBuilderBase< FF_ >::add_public_variable ( const OT &  in)
delete

◆ add_variable() [1/2]

template<typename FF_ >
uint32_t bb::CircuitBuilderBase< FF_ >::add_variable ( const FF in)
virtual

Add a variable to variables.

Parameters
inThe value of the variable
Returns
The index of the new variable in the variables vector

Definition at line 53 of file circuit_builder_base_impl.hpp.

◆ add_variable() [2/2]

template<typename FF_ >
template<typename OT >
uint32_t bb::CircuitBuilderBase< FF_ >::add_variable ( const OT &  in)
delete

◆ assert_equal()

template<typename FF >
void bb::CircuitBuilderBase< FF >::assert_equal ( uint32_t  a_idx,
uint32_t  b_idx,
std::string const &  msg = "assert_equal" 
)
virtual

Join variable class b to variable class a.

Parameters
a_variable_idxIndex of a variable in class a.
b_variable_idxIndex of a variable in class b.
msgClass tag.

Definition at line 125 of file circuit_builder_base_impl.hpp.

◆ assert_valid_variables()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::assert_valid_variables ( const std::vector< uint32_t > &  variable_indices)
protected

Check whether each variable index points to a witness value in the variables array.

Any variable whose index does not point to witness value is deemed invalid. This implicitly checks whether a variable index is equal to IS_CONSTANT; assuming that we will never have uint32::MAX number of variables

Parameters
variable_indicesThe indices to validate

Definition at line 159 of file circuit_builder_base_impl.hpp.

◆ err()

template<typename FF_ >
const std::string & bb::CircuitBuilderBase< FF_ >::err ( ) const

Definition at line 173 of file circuit_builder_base_impl.hpp.

◆ export_circuit()

template<typename FF_ >
msgpack::sbuffer bb::CircuitBuilderBase< FF_ >::export_circuit ( )
virtual

Export the existing circuit as msgpack compatible buffer.

Returns
msgpack compatible buffer

Reimplemented in bb::UltraCircuitBuilder_< ExecutionTrace_ >, and bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >.

Definition at line 86 of file circuit_builder_base_impl.hpp.

◆ failed()

template<typename FF_ >
bool bb::CircuitBuilderBase< FF_ >::failed ( ) const

Definition at line 168 of file circuit_builder_base_impl.hpp.

◆ failure()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::failure ( std::string  msg)

Definition at line 178 of file circuit_builder_base_impl.hpp.

◆ finalize_public_inputs()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::finalize_public_inputs ( )
inline

Set the _public_inputs_finalized to true to prevent any new public inputs from being added.

This is used, for example, for special internal public inputs (like pairing inputs) which we want to ensure are placed at the end of the public inputs vector

Definition at line 183 of file circuit_builder_base.hpp.

◆ get_circuit_subgroup_size()

template<typename FF_ >
size_t bb::CircuitBuilderBase< FF_ >::get_circuit_subgroup_size ( size_t  num_gates) const

Definition at line 77 of file circuit_builder_base_impl.hpp.

◆ get_first_variable_in_class()

template<typename FF_ >
uint32_t bb::CircuitBuilderBase< FF_ >::get_first_variable_in_class ( uint32_t  index) const
protected

Get the index of the first variable in class.

Parameters
indexThe index of the variable you want to look up
Returns
The index of the first variable in the same class as the submitted index

Definition at line 35 of file circuit_builder_base_impl.hpp.

◆ get_num_constant_gates()

template<typename FF_ >
virtual size_t bb::CircuitBuilderBase< FF_ >::get_num_constant_gates ( ) const
pure virtual

◆ get_num_finalized_gates()

template<typename FF_ >
size_t bb::CircuitBuilderBase< FF_ >::get_num_finalized_gates ( ) const
virtual

◆ get_num_variables()

template<typename FF_ >
size_t bb::CircuitBuilderBase< FF_ >::get_num_variables ( ) const
virtual

Definition at line 30 of file circuit_builder_base_impl.hpp.

◆ get_variable()

template<typename FF_ >
FF bb::CircuitBuilderBase< FF_ >::get_variable ( const uint32_t  index) const
inline

Get the value of the variable v_{index}.

Parameters
indexThe index of the variable
Returns
The value of the variable

Definition at line 151 of file circuit_builder_base.hpp.

◆ get_variables()

template<typename FF_ >
const std::vector< FF > & bb::CircuitBuilderBase< FF_ >::get_variables ( ) const
inline

Definition at line 144 of file circuit_builder_base.hpp.

◆ increment_num_gates()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::increment_num_gates ( size_t  count = 1)
inline

Definition at line 134 of file circuit_builder_base.hpp.

◆ initialize_public_inputs()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::initialize_public_inputs ( const std::vector< uint32_t > &  public_inputs)
inline

Directly initialize the public inputs vector.

Used e.g. in the case of a circuit generated from ACIR where some public input indices are known at the time of circuit construction

Parameters
public_inputsThe public inputs vector to initialize with

Definition at line 191 of file circuit_builder_base.hpp.

◆ is_write_vk_mode()

template<typename FF_ >
bool bb::CircuitBuilderBase< FF_ >::is_write_vk_mode ( ) const
inline

Definition at line 269 of file circuit_builder_base.hpp.

◆ num_gates()

template<typename FF_ >
size_t bb::CircuitBuilderBase< FF_ >::num_gates ( ) const
inline

Definition at line 131 of file circuit_builder_base.hpp.

◆ num_public_inputs()

template<typename FF_ >
size_t bb::CircuitBuilderBase< FF_ >::num_public_inputs ( ) const
inline

Definition at line 227 of file circuit_builder_base.hpp.

◆ operator=() [1/2]

template<typename FF_ >
CircuitBuilderBase & bb::CircuitBuilderBase< FF_ >::operator= ( CircuitBuilderBase< FF_ > &&  other)
defaultnoexcept

◆ operator=() [2/2]

template<typename FF_ >
CircuitBuilderBase & bb::CircuitBuilderBase< FF_ >::operator= ( const CircuitBuilderBase< FF_ > &  other)
default

◆ operator==()

template<typename FF_ >
bool bb::CircuitBuilderBase< FF_ >::operator== ( const CircuitBuilderBase< FF_ > &  other) const
default

◆ public_inputs()

template<typename FF_ >
const std::vector< uint32_t > & bb::CircuitBuilderBase< FF_ >::public_inputs ( ) const
inline

Definition at line 176 of file circuit_builder_base.hpp.

◆ set_public_input()

template<typename FF_ >
uint32_t bb::CircuitBuilderBase< FF_ >::set_public_input ( uint32_t  witness_index)
virtual

Make a witness variable public.

Parameters
witness_indexThe index of the witness
Returns
The index of the witness in the public inputs vector

Definition at line 100 of file circuit_builder_base_impl.hpp.

◆ set_variable()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::set_variable ( const uint32_t  index,
const FF value 
)
inline

Set the value of the variable pointed to by a witness index.

The witness value pointed to by a witness index is determined by the mapping of the input witness index to the corresponding "real variable index" which may agree with the input index or it may point to a different location within the variables array due to copy contraints that have been imposed, e.g. by assert_equal

Note
This has the same effect on the resulting circuit as assert_equal(add_variable(value), index) but has the benefit of not adding an additional variable to the circuit unnecessarily
Parameters
indexThe witness index
valueThe value to set

Definition at line 168 of file circuit_builder_base.hpp.

◆ set_variable_name()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::set_variable_name ( uint32_t  index,
const std::string &  name 
)
virtual

Assign a name to a variable (equivalence class)

Should be one name per equivalence class

Parameters
indexIndex of the variable you want to name
nameName of the variable

Definition at line 65 of file circuit_builder_base_impl.hpp.

◆ set_zero_idx()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::set_zero_idx ( uint32_t  value)
inlineprotected

Definition at line 63 of file circuit_builder_base.hpp.

◆ tau()

template<typename FF_ >
const std::unordered_map< uint32_t, uint32_t > & bb::CircuitBuilderBase< FF_ >::tau ( ) const
inline

Definition at line 137 of file circuit_builder_base.hpp.

◆ update_real_variable_indices()

template<typename FF_ >
void bb::CircuitBuilderBase< FF_ >::update_real_variable_indices ( uint32_t  index,
uint32_t  new_real_index 
)
private

Update all variables from index in equivalence class to have real variable new_real_index.

Parameters
indexThe index of a variable in the class we're updating
new_real_indexThe index of the real variable to update to

Definition at line 44 of file circuit_builder_base_impl.hpp.

◆ zero_idx()

template<typename FF_ >
uint32_t bb::CircuitBuilderBase< FF_ >::zero_idx ( ) const
inline

Definition at line 140 of file circuit_builder_base.hpp.

Member Data Documentation

◆ _err

template<typename FF_ >
std::string bb::CircuitBuilderBase< FF_ >::_err
private

Definition at line 235 of file circuit_builder_base.hpp.

◆ _failed

template<typename FF_ >
bool bb::CircuitBuilderBase< FF_ >::_failed = false
private

Definition at line 234 of file circuit_builder_base.hpp.

◆ _is_write_vk_mode

template<typename FF_ >
bool bb::CircuitBuilderBase< FF_ >::_is_write_vk_mode = false
private

Definition at line 238 of file circuit_builder_base.hpp.

◆ _num_gates

template<typename FF_ >
size_t bb::CircuitBuilderBase< FF_ >::_num_gates = 0
private

Definition at line 53 of file circuit_builder_base.hpp.

◆ _public_inputs

template<typename FF_ >
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::_public_inputs
private

Definition at line 33 of file circuit_builder_base.hpp.

◆ _public_inputs_finalized

template<typename FF_ >
bool bb::CircuitBuilderBase< FF_ >::_public_inputs_finalized = false
private

Definition at line 35 of file circuit_builder_base.hpp.

◆ _tau

template<typename FF_ >
std::unordered_map<uint32_t, uint32_t> bb::CircuitBuilderBase< FF_ >::_tau
protected

The permutation on variable tags, as a constituent of the generalized permutation argument.

See S6 of https://github.com/AztecProtocol/plonk-with-lookups-private/blob/new-stuff/GenPermuations.pdf See also relations/PERMUTATION_ARGUMENT_README.md

Note
The Generalized Permutation argument combines the usual permutation argument with several multiset-equality checks. It does this by modifying the sigma and ID polynomials at certain points with "tags".
In the internal representation, the key/values of _tau are real variable indicies.

Definition at line 89 of file circuit_builder_base.hpp.

◆ _zero_idx

template<typename FF_ >
uint32_t bb::CircuitBuilderBase< FF_ >::_zero_idx = 0
private

Definition at line 51 of file circuit_builder_base.hpp.

◆ current_tag

template<typename FF_ >
uint32_t bb::CircuitBuilderBase< FF_ >::current_tag = DUMMY_TAG

Definition at line 115 of file circuit_builder_base.hpp.

◆ FIRST_VARIABLE_IN_CLASS

template<typename FF_ >
constexpr uint32_t bb::CircuitBuilderBase< FF_ >::FIRST_VARIABLE_IN_CLASS = UINT32_MAX - 2
staticconstexprprivate

Definition at line 48 of file circuit_builder_base.hpp.

◆ next_var_index

template<typename FF_ >
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::next_var_index
private

Definition at line 41 of file circuit_builder_base.hpp.

◆ pairing_points_tagging

template<typename FF_ >
PairingPointsTagging bb::CircuitBuilderBase< FF_ >::pairing_points_tagging
mutable

PairingPoints tagging tool, used to ensure that all pairing points created in this circuit are aggregated together. This is not related to circuit logic.

Definition at line 267 of file circuit_builder_base.hpp.

◆ prev_var_index

template<typename FF_ >
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::prev_var_index
private

Definition at line 45 of file circuit_builder_base.hpp.

◆ REAL_VARIABLE

template<typename FF_ >
constexpr uint32_t bb::CircuitBuilderBase< FF_ >::REAL_VARIABLE = UINT32_MAX - 1
staticconstexprprivate

Definition at line 47 of file circuit_builder_base.hpp.

◆ real_variable_index

template<typename FF_ >
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::real_variable_index

Map from witness index to real variable index.

The "real_variable_index" acts as a map from a "witness index" (e.g. the one stored by a stdlib object) to an index into the variables array. This extra layer of indirection is used to support copy constraints by allowing, for example, two witnesses with differing witness indices to have the same "real variable index" and thus the same witness value. If the witness is not involved in any copy constraints, then real_variable_index[index] == index, i.e., it is the identity map.

Note
If there is a copy constraint between witness indices idx_a and idx_b, then they will both point to the same element in real_variable_index.
Copy cycles, the mediating data structure used to translate copy constraint into sigma polynomials, will be indexed on those real_variable_indices that are actually pointed to at the end of circuit construction.

Definition at line 105 of file circuit_builder_base.hpp.

◆ real_variable_tags

template<typename FF_ >
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::real_variable_tags

real_variable_tags is the tagging mechanism for the the multiset-equality check.

The generalized permutation argument checks both copy constraints and multiset equalities. This is mediated by a tag; each real variable has a tag. (By default, the tags are set to DUMMY_TAG == 0. We assume that these are not involved in any non-trivial multiset-equality checks.)

Definition at line 114 of file circuit_builder_base.hpp.

◆ variable_names

template<typename FF_ >
std::unordered_map<uint32_t, std::string> bb::CircuitBuilderBase< FF_ >::variable_names
protected

Definition at line 241 of file circuit_builder_base.hpp.

◆ variables

template<typename FF_ >
std::vector<FF> bb::CircuitBuilderBase< FF_ >::variables
private

Definition at line 31 of file circuit_builder_base.hpp.


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