13template <
typename FF_>
15 : _is_write_vk_mode(is_write_vk_mode)
25 return variables.size();
30 while (prev_var_index[
index] != FIRST_VARIABLE_IN_CLASS) {
36template <
typename FF_>
39 auto cur_index =
index;
41 real_variable_index[cur_index] = new_real_index;
42 cur_index = next_var_index[cur_index];
43 }
while (cur_index != REAL_VARIABLE);
48 variables.emplace_back(in);
49 const uint32_t
index =
static_cast<uint32_t
>(variables.size()) - 1U;
50 real_variable_index.emplace_back(
index);
51 next_var_index.emplace_back(REAL_VARIABLE);
52 prev_var_index.emplace_back(FIRST_VARIABLE_IN_CLASS);
53 real_variable_tags.emplace_back(DEFAULT_TAG);
61 uint32_t first_idx = get_first_variable_in_class(
index);
63 if (variable_names.contains(first_idx)) {
64 failure(
"Attempted to assign a name to a variable that already has a name");
67 variable_names.insert({ first_idx, name });
73 if ((1UL << log2_n) != (_num_gates)) {
81 const uint32_t
index = add_variable(in);
82 BB_ASSERT_EQ(_public_inputs_finalized,
false,
"Cannot add to public inputs after they have been finalized.");
83 _public_inputs.emplace_back(
index);
89 BB_ASSERT_LT(witness_index, get_num_variables(),
"set_public_input: witness_index out of range");
90 for (
const uint32_t public_input : public_inputs()) {
91 if (public_input == witness_index) {
93 failure(
"Attempted to set a public input that is already public!");
98 uint32_t public_input_index =
static_cast<uint32_t
>(num_public_inputs());
99 BB_ASSERT_EQ(_public_inputs_finalized,
false,
"Cannot add to public inputs after they have been finalized.");
100 _public_inputs.emplace_back(witness_index);
102 return public_input_index;
112template <
typename FF>
114 const uint32_t b_variable_idx,
115 std::string
const& msg)
117 assert_valid_variables({ a_variable_idx, b_variable_idx });
118 bool values_equal = (get_variable(a_variable_idx) == get_variable(b_variable_idx));
119 if (!values_equal && !failed()) {
122 uint32_t a_real_idx = real_variable_index[a_variable_idx];
123 uint32_t b_real_idx = real_variable_index[b_variable_idx];
125 if (a_real_idx == b_real_idx) {
130 auto b_start_idx = get_first_variable_in_class(b_variable_idx);
131 update_real_variable_indices(b_start_idx, a_real_idx);
133 auto a_start_idx = get_first_variable_in_class(a_variable_idx);
134 next_var_index[b_real_idx] = a_start_idx;
135 prev_var_index[a_start_idx] = b_real_idx;
137 (real_variable_tags[a_real_idx] == DEFAULT_TAG || real_variable_tags[b_real_idx] == DEFAULT_TAG ||
138 real_variable_tags[a_real_idx] == real_variable_tags[b_real_idx]);
139 if (!no_tag_clash && !failed()) {
142 if (real_variable_tags[a_real_idx] == DEFAULT_TAG) {
143 real_variable_tags[a_real_idx] = real_variable_tags[b_real_idx];
147template <
typename FF_>
151 for (
const auto& variable_index : variable_indices) {
169#ifndef FUZZING_DISABLE_WARNINGS
170 if (!_is_write_vk_mode) {
172 info(
"(Experimental) WARNING: Builder failure when we have real witnesses! Ignore if writing vk.");
#define BB_ASSERT_DEBUG(expression,...)
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LT(left, right,...)
virtual size_t get_num_finalized_gates() const
const std::string & err() const
virtual uint32_t add_variable(const FF &in)
Add a variable to variables.
CircuitBuilderBase(bool is_write_vk_mode=false)
void failure(std::string msg)
virtual uint32_t set_public_input(uint32_t witness_index)
Make a witness variable public.
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.
virtual void assert_equal(uint32_t a_idx, uint32_t b_idx, std::string const &msg="assert_equal")
virtual size_t get_num_variables() const
virtual void set_variable_name(uint32_t index, const std::string &name)
Assign a name to a variable (equivalence class)
uint32_t get_first_variable_in_class(uint32_t index) const
Get the index of the first variable in class.
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.
virtual uint32_t add_public_variable(const FF &in)
Add a public variable to variables.
size_t get_circuit_subgroup_size(size_t num_gates) const
constexpr T get_msb(const T in)
Entry point for Barretenberg command-line interface.