Barretenberg
The ZK-SNARK library at the core of Aztec
|
#include <circuit_builder_base.hpp>
Public Types | |
using | FF = FF_ |
using | EmbeddedCurve = std::conditional_t< std::same_as< FF, bb::g1::Fq >, curve::BN254, curve::Grumpkin > |
Public Member Functions | |
CircuitBuilderBase (size_t size_hint=0, bool has_dummy_witnesses=false) | |
CircuitBuilderBase (const CircuitBuilderBase &other)=default | |
CircuitBuilderBase (CircuitBuilderBase &&other) noexcept=default | |
CircuitBuilderBase & | operator= (const CircuitBuilderBase &other)=default |
CircuitBuilderBase & | operator= (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_estimated_num_finalized_gates () const |
virtual void | print_num_estimated_finalized_gates () const |
virtual size_t | get_num_variables () const |
virtual void | create_add_gate (const add_triple_< FF > &in)=0 |
virtual void | create_mul_gate (const mul_triple_< FF > &in)=0 |
virtual void | create_bool_gate (const uint32_t a)=0 |
virtual void | create_poly_gate (const poly_triple_< FF > &in)=0 |
virtual size_t | get_num_constant_gates () const =0 |
const std::vector< FF > & | get_variables () const |
uint32_t | get_first_variable_in_class (uint32_t index) const |
void | update_real_variable_indices (uint32_t index, uint32_t new_real_index) |
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 FF & | get_variable_reference (const uint32_t index) const |
uint32_t | get_public_input_index (const uint32_t witness_index) const |
FF | get_public_input (const uint32_t index) const |
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) |
virtual void | set_variable_name (uint32_t index, const std::string &name) |
virtual void | update_variable_names (uint32_t index) |
virtual msgpack::sbuffer | export_circuit () |
virtual uint32_t | add_public_variable (const FF &in) |
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 |
void | assert_valid_variables (const std::vector< uint32_t > &variable_indices) |
bool | failed () const |
const std::string & | err () const |
void | set_err (std::string msg) |
void | failure (std::string msg) |
Public Attributes | |
size_t | num_gates = 0 |
bool | has_dummy_witnesses = false |
std::unordered_map< uint32_t, std::string > | variable_names |
std::vector< uint32_t > | next_var_index |
std::vector< uint32_t > | prev_var_index |
std::vector< uint32_t > | real_variable_index |
std::vector< uint32_t > | real_variable_tags |
uint32_t | current_tag = DUMMY_TAG |
std::map< uint32_t, uint32_t > | tau |
bool | is_recursive_circuit = false |
bool | _failed = false |
std::string | _err |
uint32_t | zero_idx = 0 |
uint32_t | one_idx = 1 |
Static Public Attributes | |
static constexpr uint32_t | REAL_VARIABLE = UINT32_MAX - 1 |
static constexpr uint32_t | FIRST_VARIABLE_IN_CLASS = UINT32_MAX - 2 |
Private Attributes | |
std::vector< FF > | variables |
std::vector< uint32_t > | public_inputs_ |
bool | public_inputs_finalized_ = false |
Definition at line 22 of file circuit_builder_base.hpp.
using bb::CircuitBuilderBase< FF_ >::EmbeddedCurve = std::conditional_t<std::same_as<FF, bb::g1::Fq>, curve::BN254, curve::Grumpkin> |
Definition at line 25 of file circuit_builder_base.hpp.
using bb::CircuitBuilderBase< FF_ >::FF = FF_ |
Definition at line 24 of file circuit_builder_base.hpp.
bb::CircuitBuilderBase< FF_ >::CircuitBuilderBase | ( | size_t | size_hint = 0 , |
bool | has_dummy_witnesses = false |
||
) |
Definition at line 14 of file circuit_builder_base_impl.hpp.
|
default |
|
defaultnoexcept |
|
virtualdefault |
|
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
in | The value of the variable |
Definition at line 146 of file circuit_builder_base_impl.hpp.
|
virtual |
Add a variable to variables
in | The value of the variable |
Definition at line 83 of file circuit_builder_base_impl.hpp.
|
virtual |
Join variable class b to variable class a.
a_variable_idx | Index of a variable in class a. |
b_variable_idx | Index of a variable in class b. |
msg | Class tag. |
Definition at line 179 of file circuit_builder_base_impl.hpp.
void bb::CircuitBuilderBase< FF_ >::assert_valid_variables | ( | const std::vector< uint32_t > & | variable_indices | ) |
Definition at line 213 of file circuit_builder_base_impl.hpp.
|
pure virtual |
Implemented in bb::TranslatorCircuitBuilder.
|
pure virtual |
|
pure virtual |
Implemented in bb::TranslatorCircuitBuilder.
|
pure virtual |
Implemented in bb::TranslatorCircuitBuilder.
const std::string & bb::CircuitBuilderBase< FF_ >::err | ( | ) | const |
Definition at line 225 of file circuit_builder_base_impl.hpp.
|
virtual |
Export the existing circuit as msgpack compatible buffer.
Reimplemented in bb::UltraCircuitBuilder_< ExecutionTrace_ >, and bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >.
Definition at line 140 of file circuit_builder_base_impl.hpp.
bool bb::CircuitBuilderBase< FF_ >::failed | ( | ) | const |
Definition at line 220 of file circuit_builder_base_impl.hpp.
void bb::CircuitBuilderBase< FF_ >::failure | ( | std::string | msg | ) |
Definition at line 235 of file circuit_builder_base_impl.hpp.
|
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 167 of file circuit_builder_base.hpp.
size_t bb::CircuitBuilderBase< FF_ >::get_circuit_subgroup_size | ( | size_t | num_gates | ) | const |
Definition at line 131 of file circuit_builder_base_impl.hpp.
|
virtual |
Reimplemented in bb::MegaCircuitBuilder_< FF >, bb::UltraCircuitBuilder_< ExecutionTrace_ >, and bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >.
Definition at line 30 of file circuit_builder_base_impl.hpp.
uint32_t bb::CircuitBuilderBase< FF_ >::get_first_variable_in_class | ( | uint32_t | index | ) | const |
Get the index of the first variable in class.
index | The index of the variable you want to look up. |
Definition at line 45 of file circuit_builder_base_impl.hpp.
|
pure virtual |
|
virtual |
Reimplemented in bb::UltraCircuitBuilder_< ExecutionTrace_ >, and bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >.
Definition at line 25 of file circuit_builder_base_impl.hpp.
|
virtual |
Definition at line 40 of file circuit_builder_base_impl.hpp.
CircuitBuilderBase< FF_ >::FF bb::CircuitBuilderBase< FF_ >::get_public_input | ( | const uint32_t | index | ) | const |
Definition at line 77 of file circuit_builder_base_impl.hpp.
uint32_t bb::CircuitBuilderBase< FF_ >::get_public_input_index | ( | const uint32_t | witness_index | ) | const |
Definition at line 63 of file circuit_builder_base_impl.hpp.
|
inline |
Get the value of the variable v_{index}.
index | The index of the variable. |
Definition at line 119 of file circuit_builder_base.hpp.
|
inline |
Get a reference to the variable v_{index}.
We need this function for check_circuit functions.
index | The index of the variable. |
Definition at line 150 of file circuit_builder_base.hpp.
|
inline |
Definition at line 95 of file circuit_builder_base.hpp.
|
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.
Definition at line 175 of file circuit_builder_base.hpp.
|
inline |
Definition at line 232 of file circuit_builder_base.hpp.
|
defaultnoexcept |
|
default |
|
default |
|
virtual |
Reimplemented in bb::MegaCircuitBuilder_< FF >, bb::UltraCircuitBuilder_< ExecutionTrace_ >, and bb::UltraCircuitBuilder_< MegaExecutionTraceBlocks >.
Definition at line 35 of file circuit_builder_base_impl.hpp.
|
inline |
Definition at line 160 of file circuit_builder_base.hpp.
void bb::CircuitBuilderBase< FF_ >::set_err | ( | std::string | msg | ) |
Definition at line 230 of file circuit_builder_base_impl.hpp.
|
virtual |
Make a witness variable public.
witness_index | The index of the witness. |
Definition at line 154 of file circuit_builder_base_impl.hpp.
|
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.
index | |
value |
Definition at line 136 of file circuit_builder_base.hpp.
|
virtual |
Assign a name to a variable(equivalence class). Should be one name per equivalence class.
index | Index of the variable you want to name. |
name | Name of the variable. |
Definition at line 94 of file circuit_builder_base_impl.hpp.
void bb::CircuitBuilderBase< FF_ >::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.
index | The index of a variable in the class we're updating. |
new_real_index | The index of the real variable to update to. |
Definition at line 54 of file circuit_builder_base_impl.hpp.
|
virtual |
After assert_equal() merge two class names if present. Preserves the first name in class.
index | Index of the variable you have previously named and used in assert_equal. |
Definition at line 106 of file circuit_builder_base_impl.hpp.
std::string bb::CircuitBuilderBase< FF_ >::_err |
Definition at line 67 of file circuit_builder_base.hpp.
bool bb::CircuitBuilderBase< FF_ >::_failed = false |
Definition at line 66 of file circuit_builder_base.hpp.
uint32_t bb::CircuitBuilderBase< FF_ >::current_tag = DUMMY_TAG |
Definition at line 53 of file circuit_builder_base.hpp.
|
staticconstexpr |
Definition at line 69 of file circuit_builder_base.hpp.
bool bb::CircuitBuilderBase< FF_ >::has_dummy_witnesses = false |
Definition at line 38 of file circuit_builder_base.hpp.
bool bb::CircuitBuilderBase< FF_ >::is_recursive_circuit = false |
Definition at line 64 of file circuit_builder_base.hpp.
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::next_var_index |
Definition at line 43 of file circuit_builder_base.hpp.
size_t bb::CircuitBuilderBase< FF_ >::num_gates = 0 |
Definition at line 36 of file circuit_builder_base.hpp.
uint32_t bb::CircuitBuilderBase< FF_ >::one_idx = 1 |
Definition at line 87 of file circuit_builder_base.hpp.
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::prev_var_index |
Definition at line 45 of file circuit_builder_base.hpp.
|
private |
Definition at line 31 of file circuit_builder_base.hpp.
|
private |
Definition at line 33 of file circuit_builder_base.hpp.
|
staticconstexpr |
Definition at line 68 of file circuit_builder_base.hpp.
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::real_variable_index |
Definition at line 51 of file circuit_builder_base.hpp.
std::vector<uint32_t> bb::CircuitBuilderBase< FF_ >::real_variable_tags |
Definition at line 52 of file circuit_builder_base.hpp.
std::map<uint32_t, uint32_t> bb::CircuitBuilderBase< FF_ >::tau |
Definition at line 57 of file circuit_builder_base.hpp.
std::unordered_map<uint32_t, std::string> bb::CircuitBuilderBase< FF_ >::variable_names |
Definition at line 40 of file circuit_builder_base.hpp.
|
private |
Definition at line 29 of file circuit_builder_base.hpp.
uint32_t bb::CircuitBuilderBase< FF_ >::zero_idx = 0 |
Definition at line 86 of file circuit_builder_base.hpp.