From 94b5f94b59e9434f32e0125d174cfe96440fd3d7 Mon Sep 17 00:00:00 2001 From: ledwards2225 Date: Fri, 8 Dec 2023 19:22:49 +0000 Subject: [PATCH] copy constructors for builders --- .../plonk/composer/ultra_composer.cpp | 8 +- .../arithmetization/arithmetization.hpp | 33 + .../goblin_ultra_circuit_builder.cpp | 220 +-- .../goblin_ultra_circuit_builder.hpp | 21 +- .../goblin_ultra_circuit_builder.test.cpp | 63 +- .../standard_circuit_builder.cpp | 164 +-- .../standard_circuit_builder.hpp | 34 +- .../circuit_builder/ultra_circuit_builder.cpp | 1230 ++++++++--------- .../circuit_builder/ultra_circuit_builder.hpp | 151 +- .../ultra_circuit_builder.test.cpp | 34 + .../composer/composer_lib.test.cpp | 10 +- .../stdlib/primitives/field/field.test.cpp | 4 +- 12 files changed, 1058 insertions(+), 914 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp index e34787f26d3..d83c9706eff 100644 --- a/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/plonk/composer/ultra_composer.cpp @@ -43,10 +43,10 @@ void UltraComposer::compute_witness(CircuitBuilder& circuit_constructor) // Note: the remaining NUM_RESERVED_GATES indices are padded with zeros within `compute_witness_base` (called // next). for (size_t i = filled_gates; i < total_num_gates; ++i) { - circuit_constructor.w_l.emplace_back(circuit_constructor.zero_idx); - circuit_constructor.w_r.emplace_back(circuit_constructor.zero_idx); - circuit_constructor.w_o.emplace_back(circuit_constructor.zero_idx); - circuit_constructor.w_4.emplace_back(circuit_constructor.zero_idx); + circuit_constructor.w_l().emplace_back(circuit_constructor.zero_idx); + circuit_constructor.w_r().emplace_back(circuit_constructor.zero_idx); + circuit_constructor.w_o().emplace_back(circuit_constructor.zero_idx); + circuit_constructor.w_4().emplace_back(circuit_constructor.zero_idx); } auto wire_polynomial_evaluations = construct_wire_polynomials_base(circuit_constructor, subgroup_size); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/arithmetization/arithmetization.hpp b/barretenberg/cpp/src/barretenberg/proof_system/arithmetization/arithmetization.hpp index 05121c857f4..df0cd534a5f 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/arithmetization/arithmetization.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/arithmetization/arithmetization.hpp @@ -47,6 +47,12 @@ template class Standard { SelectorType& q_3() { return selectors[3]; }; SelectorType& q_c() { return selectors[4]; }; + const SelectorType& q_m() const { return selectors[0]; }; + const SelectorType& q_1() const { return selectors[1]; }; + const SelectorType& q_2() const { return selectors[2]; }; + const SelectorType& q_3() const { return selectors[3]; }; + const SelectorType& q_c() const { return selectors[4]; }; + Standard() : selectors(NUM_SELECTORS) {} @@ -87,6 +93,18 @@ template class Ultra { SelectorType& q_aux() { return selectors[9]; }; SelectorType& q_lookup_type() { return selectors[10]; }; + const SelectorType& q_m() const { return selectors[0]; }; + const SelectorType& q_c() const { return selectors[1]; }; + const SelectorType& q_1() const { return selectors[2]; }; + const SelectorType& q_2() const { return selectors[3]; }; + const SelectorType& q_3() const { return selectors[4]; }; + const SelectorType& q_4() const { return selectors[5]; }; + const SelectorType& q_arith() const { return selectors[6]; }; + const SelectorType& q_sort() const { return selectors[7]; }; + const SelectorType& q_elliptic() const { return selectors[8]; }; + const SelectorType& q_aux() const { return selectors[9]; }; + const SelectorType& q_lookup_type() const { return selectors[10]; }; + const auto& get() const { return selectors; }; void reserve(size_t size_hint) @@ -141,6 +159,21 @@ template class UltraHonk { SelectorType& q_poseidon2_external() { return this->selectors[12]; }; SelectorType& q_poseidon2_internal() { return this->selectors[13]; }; + const SelectorType& q_m() const { return selectors[0]; }; + const SelectorType& q_c() const { return selectors[1]; }; + const SelectorType& q_1() const { return selectors[2]; }; + const SelectorType& q_2() const { return selectors[3]; }; + const SelectorType& q_3() const { return selectors[4]; }; + const SelectorType& q_4() const { return selectors[5]; }; + const SelectorType& q_arith() const { return selectors[6]; }; + const SelectorType& q_sort() const { return selectors[7]; }; + const SelectorType& q_elliptic() const { return selectors[8]; }; + const SelectorType& q_aux() const { return selectors[9]; }; + const SelectorType& q_lookup_type() const { return selectors[10]; }; + const SelectorType& q_busread() const { return selectors[11]; }; + const SelectorType& q_poseidon2_external() const { return this->selectors[12]; }; + const SelectorType& q_poseidon2_internal() const { return this->selectors[13]; }; + const auto& get() const { return selectors; }; void reserve(size_t size_hint) diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.cpp index 0ce5b9fdfa1..8b30c606781 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.cpp @@ -43,72 +43,72 @@ template void GoblinUltraCircuitBuilder_::add_gates_to_ensure_ } // Construct gate corresponding to a single calldata read - size_t read_idx = 1; // index into calldata array at which we want to read - this->w_l.emplace_back(public_calldata[read_idx]); // populate with value of calldata at read index - this->w_r.emplace_back(this->add_variable(FF(read_idx))); // populate with read index as witness - calldata_read_counts[read_idx]++; // increment read count at read index - q_busread().emplace_back(1); // read selector on + size_t read_idx = 1; // index into calldata array at which we want to read + this->w_l().emplace_back(public_calldata[read_idx]); // populate with value of calldata at read index + this->w_r().emplace_back(this->add_variable(FF(read_idx))); // populate with read index as witness + calldata_read_counts[read_idx]++; // increment read count at read index + q_busread().emplace_back(1); // read selector on // populate all other components with zero - this->w_o.emplace_back(this->zero_idx); - this->w_4.emplace_back(this->zero_idx); - this->q_m.emplace_back(0); - this->q_1.emplace_back(0); - this->q_2.emplace_back(0); - this->q_3.emplace_back(0); - this->q_c.emplace_back(0); - this->q_sort.emplace_back(0); - this->q_arith.emplace_back(0); - this->q_4.emplace_back(0); - this->q_lookup_type.emplace_back(0); - this->q_elliptic.emplace_back(0); - this->q_aux.emplace_back(0); - this->q_poseidon2_external.emplace_back(0); - this->q_poseidon2_internal.emplace_back(0); + this->w_o().emplace_back(this->zero_idx); + this->w_4().emplace_back(this->zero_idx); + this->q_m().emplace_back(0); + this->q_1().emplace_back(0); + this->q_2().emplace_back(0); + this->q_3().emplace_back(0); + this->q_c().emplace_back(0); + this->q_sort().emplace_back(0); + this->q_arith().emplace_back(0); + this->q_4().emplace_back(0); + this->q_lookup_type().emplace_back(0); + this->q_elliptic().emplace_back(0); + this->q_aux().emplace_back(0); + this->q_poseidon2_external().emplace_back(0); + this->q_poseidon2_internal().emplace_back(0); ++this->num_gates; // mock gates that use poseidon selectors, with all zeros as input - this->w_l.emplace_back(this->zero_idx); - this->w_r.emplace_back(this->zero_idx); - this->w_o.emplace_back(this->zero_idx); - this->w_4.emplace_back(this->zero_idx); - this->q_m.emplace_back(0); - this->q_1.emplace_back(0); - this->q_2.emplace_back(0); - this->q_3.emplace_back(0); - this->q_c.emplace_back(0); - this->q_arith.emplace_back(0); - this->q_4.emplace_back(0); - this->q_sort.emplace_back(0); - this->q_lookup_type.emplace_back(0); - this->q_elliptic.emplace_back(0); - this->q_aux.emplace_back(0); + this->w_l().emplace_back(this->zero_idx); + this->w_r().emplace_back(this->zero_idx); + this->w_o().emplace_back(this->zero_idx); + this->w_4().emplace_back(this->zero_idx); + this->q_m().emplace_back(0); + this->q_1().emplace_back(0); + this->q_2().emplace_back(0); + this->q_3().emplace_back(0); + this->q_c().emplace_back(0); + this->q_arith().emplace_back(0); + this->q_4().emplace_back(0); + this->q_sort().emplace_back(0); + this->q_lookup_type().emplace_back(0); + this->q_elliptic().emplace_back(0); + this->q_aux().emplace_back(0); this->q_busread().emplace_back(0); - this->q_poseidon2_external.emplace_back(1); - this->q_poseidon2_internal.emplace_back(1); + this->q_poseidon2_external().emplace_back(1); + this->q_poseidon2_internal().emplace_back(1); ++this->num_gates; // second gate that stores the output of all zeros of the poseidon gates - this->w_l.emplace_back(this->zero_idx); - this->w_r.emplace_back(this->zero_idx); - this->w_o.emplace_back(this->zero_idx); - this->w_4.emplace_back(this->zero_idx); - this->q_m.emplace_back(0); - this->q_1.emplace_back(0); - this->q_2.emplace_back(0); - this->q_3.emplace_back(0); - this->q_c.emplace_back(0); - this->q_arith.emplace_back(0); - this->q_4.emplace_back(0); - this->q_sort.emplace_back(0); - this->q_lookup_type.emplace_back(0); - this->q_elliptic.emplace_back(0); - this->q_aux.emplace_back(0); + this->w_l().emplace_back(this->zero_idx); + this->w_r().emplace_back(this->zero_idx); + this->w_o().emplace_back(this->zero_idx); + this->w_4().emplace_back(this->zero_idx); + this->q_m().emplace_back(0); + this->q_1().emplace_back(0); + this->q_2().emplace_back(0); + this->q_3().emplace_back(0); + this->q_c().emplace_back(0); + this->q_arith().emplace_back(0); + this->q_4().emplace_back(0); + this->q_sort().emplace_back(0); + this->q_lookup_type().emplace_back(0); + this->q_elliptic().emplace_back(0); + this->q_aux().emplace_back(0); this->q_busread().emplace_back(0); - this->q_poseidon2_external.emplace_back(0); - this->q_poseidon2_internal.emplace_back(0); + this->q_poseidon2_external().emplace_back(0); + this->q_poseidon2_internal().emplace_back(0); ++this->num_gates; } @@ -233,15 +233,15 @@ ecc_op_tuple GoblinUltraCircuitBuilder_::decompose_ecc_operands(uint32_t op_ */ template void GoblinUltraCircuitBuilder_::populate_ecc_op_wires(const ecc_op_tuple& in) { - ecc_op_wire_1.emplace_back(in.op); - ecc_op_wire_2.emplace_back(in.x_lo); - ecc_op_wire_3.emplace_back(in.x_hi); - ecc_op_wire_4.emplace_back(in.y_lo); + ecc_op_wire_1().emplace_back(in.op); + ecc_op_wire_2().emplace_back(in.x_lo); + ecc_op_wire_3().emplace_back(in.x_hi); + ecc_op_wire_4().emplace_back(in.y_lo); - ecc_op_wire_1.emplace_back(this->zero_idx); - ecc_op_wire_2.emplace_back(in.y_hi); - ecc_op_wire_3.emplace_back(in.z_1); - ecc_op_wire_4.emplace_back(in.z_2); + ecc_op_wire_1().emplace_back(this->zero_idx); + ecc_op_wire_2().emplace_back(in.y_hi); + ecc_op_wire_3().emplace_back(in.z_1); + ecc_op_wire_4().emplace_back(in.z_2); num_ecc_op_gates += 2; }; @@ -249,48 +249,48 @@ template void GoblinUltraCircuitBuilder_::populate_ecc_op_wire template void GoblinUltraCircuitBuilder_::create_poseidon2_external_gate(const poseidon2_external_gate_& in) { - this->w_l.emplace_back(in.a); - this->w_r.emplace_back(in.b); - this->w_o.emplace_back(in.c); - this->w_4.emplace_back(in.d); - this->q_m.emplace_back(0); - this->q_1.emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][0]); - this->q_2.emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][1]); - this->q_3.emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][2]); - this->q_c.emplace_back(0); - this->q_arith.emplace_back(0); - this->q_4.emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][3]); - this->q_sort.emplace_back(0); - this->q_lookup_type.emplace_back(0); - this->q_elliptic.emplace_back(0); - this->q_aux.emplace_back(0); + this->w_l().emplace_back(in.a); + this->w_r().emplace_back(in.b); + this->w_o().emplace_back(in.c); + this->w_4().emplace_back(in.d); + this->q_m().emplace_back(0); + this->q_1().emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][0]); + this->q_2().emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][1]); + this->q_3().emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][2]); + this->q_c().emplace_back(0); + this->q_arith().emplace_back(0); + this->q_4().emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][3]); + this->q_sort().emplace_back(0); + this->q_lookup_type().emplace_back(0); + this->q_elliptic().emplace_back(0); + this->q_aux().emplace_back(0); this->q_busread().emplace_back(0); - this->q_poseidon2_external.emplace_back(1); - this->q_poseidon2_internal.emplace_back(0); + this->q_poseidon2_external().emplace_back(1); + this->q_poseidon2_internal().emplace_back(0); ++this->num_gates; } template void GoblinUltraCircuitBuilder_::create_poseidon2_internal_gate(const poseidon2_internal_gate_& in) { - this->w_l.emplace_back(in.a); - this->w_r.emplace_back(in.b); - this->w_o.emplace_back(in.c); - this->w_4.emplace_back(in.d); - this->q_m.emplace_back(0); - this->q_1.emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][0]); - this->q_2.emplace_back(0); - this->q_3.emplace_back(0); - this->q_c.emplace_back(0); - this->q_arith.emplace_back(0); - this->q_4.emplace_back(0); - this->q_sort.emplace_back(0); - this->q_lookup_type.emplace_back(0); - this->q_elliptic.emplace_back(0); - this->q_aux.emplace_back(0); + this->w_l().emplace_back(in.a); + this->w_r().emplace_back(in.b); + this->w_o().emplace_back(in.c); + this->w_4().emplace_back(in.d); + this->q_m().emplace_back(0); + this->q_1().emplace_back(Poseidon2Bn254ScalarFieldParams::round_constants[in.round_idx][0]); + this->q_2().emplace_back(0); + this->q_3().emplace_back(0); + this->q_c().emplace_back(0); + this->q_arith().emplace_back(0); + this->q_4().emplace_back(0); + this->q_sort().emplace_back(0); + this->q_lookup_type().emplace_back(0); + this->q_elliptic().emplace_back(0); + this->q_aux().emplace_back(0); this->q_busread().emplace_back(0); - this->q_poseidon2_external.emplace_back(0); - this->q_poseidon2_internal.emplace_back(1); + this->q_poseidon2_external().emplace_back(0); + this->q_poseidon2_internal().emplace_back(1); ++this->num_gates; } @@ -420,25 +420,25 @@ template bool GoblinUltraCircuitBuilder_::check_circuit() FF w_3_value; FF w_4_value; // Get the values of selectors and wires and update tag products along the way - q_poseidon2_external_value = this->q_poseidon2_external[i]; - q_poseidon2_internal_value = this->q_poseidon2_internal[i]; - q_1_value = this->q_1[i]; - q_2_value = this->q_2[i]; - q_3_value = this->q_3[i]; - q_4_value = this->q_4[i]; - w_1_value = this->get_variable(this->w_l[i]); - w_2_value = this->get_variable(this->w_r[i]); - w_3_value = this->get_variable(this->w_o[i]); - w_4_value = this->get_variable(this->w_4[i]); + q_poseidon2_external_value = this->q_poseidon2_external()[i]; + q_poseidon2_internal_value = this->q_poseidon2_internal()[i]; + q_1_value = this->q_1()[i]; + q_2_value = this->q_2()[i]; + q_3_value = this->q_3()[i]; + q_4_value = this->q_4()[i]; + w_1_value = this->get_variable(this->w_l()[i]); + w_2_value = this->get_variable(this->w_r()[i]); + w_3_value = this->get_variable(this->w_o()[i]); + w_4_value = this->get_variable(this->w_4()[i]); FF w_1_shifted_value; FF w_2_shifted_value; FF w_3_shifted_value; FF w_4_shifted_value; if (i < (this->num_gates - 1)) { - w_1_shifted_value = this->get_variable(this->w_l[i + 1]); - w_2_shifted_value = this->get_variable(this->w_r[i + 1]); - w_3_shifted_value = this->get_variable(this->w_o[i + 1]); - w_4_shifted_value = this->get_variable(this->w_4[i + 1]); + w_1_shifted_value = this->get_variable(this->w_l()[i + 1]); + w_2_shifted_value = this->get_variable(this->w_r()[i + 1]); + w_3_shifted_value = this->get_variable(this->w_o()[i + 1]); + w_4_shifted_value = this->get_variable(this->w_4()[i + 1]); } else { w_1_shifted_value = FF::zero(); w_2_shifted_value = FF::zero(); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp index e037fe2571d..8e5c6b14018 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.hpp @@ -37,14 +37,23 @@ template class GoblinUltraCircuitBuilder_ : public UltraCircuitBui // Wires storing ecc op queue data; values are indices into the variables array std::array::NUM_WIRES> ecc_op_wires; - WireVector& ecc_op_wire_1 = std::get<0>(ecc_op_wires); - WireVector& ecc_op_wire_2 = std::get<1>(ecc_op_wires); - WireVector& ecc_op_wire_3 = std::get<2>(ecc_op_wires); - WireVector& ecc_op_wire_4 = std::get<3>(ecc_op_wires); + WireVector& ecc_op_wire_1() { return std::get<0>(ecc_op_wires); }; + WireVector& ecc_op_wire_2() { return std::get<1>(ecc_op_wires); }; + WireVector& ecc_op_wire_3() { return std::get<2>(ecc_op_wires); }; + WireVector& ecc_op_wire_4() { return std::get<3>(ecc_op_wires); }; + + const WireVector& ecc_op_wire_1() const { return std::get<0>(ecc_op_wires); }; + const WireVector& ecc_op_wire_2() const { return std::get<1>(ecc_op_wires); }; + const WireVector& ecc_op_wire_3() const { return std::get<2>(ecc_op_wires); }; + const WireVector& ecc_op_wire_4() const { return std::get<3>(ecc_op_wires); }; SelectorVector& q_busread() { return this->selectors.q_busread(); }; - SelectorVector& q_poseidon2_external = this->selectors.q_poseidon2_external(); - SelectorVector& q_poseidon2_internal = this->selectors.q_poseidon2_internal(); + SelectorVector& q_poseidon2_external() { return this->selectors.q_poseidon2_external(); }; + SelectorVector& q_poseidon2_internal() { return this->selectors.q_poseidon2_internal(); }; + + const SelectorVector& q_busread() const { return this->selectors.q_busread(); }; + const SelectorVector& q_poseidon2_external() const { return this->selectors.q_poseidon2_external(); }; + const SelectorVector& q_poseidon2_internal() const { return this->selectors.q_poseidon2_internal(); }; // DataBus call/return data arrays std::vector public_calldata; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp index 7a3424626ae..87529305ecf 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/goblin_ultra_circuit_builder.test.cpp @@ -8,6 +8,47 @@ auto& engine = numeric::random::get_debug_engine(); } namespace proof_system { +TEST(GoblinUltraCircuitBuilder, CopyConstructor) +{ + GoblinUltraCircuitBuilder circuit_constructor = GoblinUltraCircuitBuilder(); + fr a = fr::one(); + circuit_constructor.add_public_variable(a); + + for (size_t i = 0; i < 16; ++i) { + for (size_t j = 0; j < 16; ++j) { + uint64_t left = static_cast(j); + uint64_t right = static_cast(i); + uint32_t left_idx = circuit_constructor.add_variable(fr(left)); + uint32_t right_idx = circuit_constructor.add_variable(fr(right)); + uint32_t result_idx = circuit_constructor.add_variable(fr(left ^ right)); + + uint32_t add_idx = + circuit_constructor.add_variable(fr(left) + fr(right) + circuit_constructor.get_variable(result_idx)); + circuit_constructor.create_big_add_gate( + { left_idx, right_idx, result_idx, add_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) }); + } + } + + // Compute a simple point accumulation natively + auto P1 = g1::affine_element::random_element(); + auto P2 = g1::affine_element::random_element(); + auto z = fr::random_element(); + + // Add gates corresponding to the above operations + circuit_constructor.queue_ecc_add_accum(P1); + circuit_constructor.queue_ecc_mul_accum(P2, z); + circuit_constructor.queue_ecc_eq(); + + bool result = circuit_constructor.check_circuit(); + EXPECT_EQ(result, true); + + GoblinUltraCircuitBuilder duplicate_circuit_constructor{ circuit_constructor }; + + EXPECT_EQ(duplicate_circuit_constructor.get_num_gates(), circuit_constructor.get_num_gates()); + EXPECT_EQ(duplicate_circuit_constructor.selectors.get(), circuit_constructor.selectors.get()); + EXPECT_TRUE(duplicate_circuit_constructor.check_circuit()); +} + TEST(GoblinUltraCircuitBuilder, BaseCase) { GoblinUltraCircuitBuilder circuit_constructor = GoblinUltraCircuitBuilder(); @@ -61,27 +102,27 @@ TEST(GoblinUltraCircuitBuilder, GoblinSimple) EXPECT_EQ(builder.num_ecc_op_gates, 6); // Check that the expected op codes have been correctly recorded in the 1st op wire - EXPECT_EQ(builder.ecc_op_wire_1[0], EccOpCode::ADD_ACCUM); - EXPECT_EQ(builder.ecc_op_wire_1[2], EccOpCode::MUL_ACCUM); - EXPECT_EQ(builder.ecc_op_wire_1[4], EccOpCode::EQUALITY); + EXPECT_EQ(builder.ecc_op_wire_1()[0], EccOpCode::ADD_ACCUM); + EXPECT_EQ(builder.ecc_op_wire_1()[2], EccOpCode::MUL_ACCUM); + EXPECT_EQ(builder.ecc_op_wire_1()[4], EccOpCode::EQUALITY); // Check that we can reconstruct the coordinates of P1 from the op_wires - auto P1_x_lo = uint256_t(builder.variables[builder.ecc_op_wire_2[0]]); - auto P1_x_hi = uint256_t(builder.variables[builder.ecc_op_wire_3[0]]); + auto P1_x_lo = uint256_t(builder.variables[builder.ecc_op_wire_2()[0]]); + auto P1_x_hi = uint256_t(builder.variables[builder.ecc_op_wire_3()[0]]); auto P1_x = P1_x_lo + (P1_x_hi << CHUNK_SIZE); EXPECT_EQ(P1_x, uint256_t(P1.x)); - auto P1_y_lo = uint256_t(builder.variables[builder.ecc_op_wire_4[0]]); - auto P1_y_hi = uint256_t(builder.variables[builder.ecc_op_wire_2[1]]); + auto P1_y_lo = uint256_t(builder.variables[builder.ecc_op_wire_4()[0]]); + auto P1_y_hi = uint256_t(builder.variables[builder.ecc_op_wire_2()[1]]); auto P1_y = P1_y_lo + (P1_y_hi << CHUNK_SIZE); EXPECT_EQ(P1_y, uint256_t(P1.y)); // Check that we can reconstruct the coordinates of P2 from the op_wires - auto P2_x_lo = uint256_t(builder.variables[builder.ecc_op_wire_2[2]]); - auto P2_x_hi = uint256_t(builder.variables[builder.ecc_op_wire_3[2]]); + auto P2_x_lo = uint256_t(builder.variables[builder.ecc_op_wire_2()[2]]); + auto P2_x_hi = uint256_t(builder.variables[builder.ecc_op_wire_3()[2]]); auto P2_x = P2_x_lo + (P2_x_hi << CHUNK_SIZE); EXPECT_EQ(P2_x, uint256_t(P2.x)); - auto P2_y_lo = uint256_t(builder.variables[builder.ecc_op_wire_4[2]]); - auto P2_y_hi = uint256_t(builder.variables[builder.ecc_op_wire_2[3]]); + auto P2_y_lo = uint256_t(builder.variables[builder.ecc_op_wire_4()[2]]); + auto P2_y_hi = uint256_t(builder.variables[builder.ecc_op_wire_2()[3]]); auto P2_y = P2_y_lo + (P2_y_hi << CHUNK_SIZE); EXPECT_EQ(P2_y, uint256_t(P2.y)); } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.cpp index c9bcaa65b8f..3f930ec331e 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.cpp @@ -15,20 +15,20 @@ namespace proof_system { * Create an addition gate. * * @param in An add_triple containing the indexes of variables to be placed into the - * wires w_l, w_r, w_o and addition coefficients to be placed into q_1, q_2, q_3, q_c. + * wires w_l, w_r, w_o and addition coefficients to be placed into q_1, q_2, q_3, q_c(). */ template void StandardCircuitBuilder_::create_add_gate(const add_triple_& in) { this->assert_valid_variables({ in.a, in.b, in.c }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - q_m.emplace_back(FF::zero()); - q_1.emplace_back(in.a_scaling); - q_2.emplace_back(in.b_scaling); - q_3.emplace_back(in.c_scaling); - q_c.emplace_back(in.const_scaling); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + q_m().emplace_back(FF::zero()); + q_1().emplace_back(in.a_scaling); + q_2().emplace_back(in.b_scaling); + q_3().emplace_back(in.c_scaling); + q_c().emplace_back(in.const_scaling); ++this->num_gates; } @@ -72,25 +72,25 @@ template void StandardCircuitBuilder_::create_balanced_add_gat FF temp = t0 + t1; uint32_t temp_idx = this->add_variable(temp); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(temp_idx); - q_m.emplace_back(FF::zero()); - q_1.emplace_back(in.a_scaling); - q_2.emplace_back(in.b_scaling); - q_3.emplace_back(FF::neg_one()); - q_c.emplace_back(FF::zero()); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(temp_idx); + q_m().emplace_back(FF::zero()); + q_1().emplace_back(in.a_scaling); + q_2().emplace_back(in.b_scaling); + q_3().emplace_back(FF::neg_one()); + q_c().emplace_back(FF::zero()); ++this->num_gates; - w_l.emplace_back(temp_idx); - w_r.emplace_back(in.c); - w_o.emplace_back(in.d); - q_m.emplace_back(FF::zero()); - q_1.emplace_back(FF::one()); - q_2.emplace_back(in.c_scaling); - q_3.emplace_back(in.d_scaling); - q_c.emplace_back(in.const_scaling); + w_l().emplace_back(temp_idx); + w_r().emplace_back(in.c); + w_o().emplace_back(in.d); + q_m().emplace_back(FF::zero()); + q_1().emplace_back(FF::one()); + q_2().emplace_back(in.c_scaling); + q_3().emplace_back(in.d_scaling); + q_c().emplace_back(in.const_scaling); ++this->num_gates; @@ -98,26 +98,26 @@ template void StandardCircuitBuilder_::create_balanced_add_gat // i.e. in.d * (in.d - 1) * (in.d - 2) = 0 FF temp_2 = this->get_variable(in.d).sqr() - this->get_variable(in.d); uint32_t temp_2_idx = this->add_variable(temp_2); - w_l.emplace_back(in.d); - w_r.emplace_back(in.d); - w_o.emplace_back(temp_2_idx); - q_m.emplace_back(FF::one()); - q_1.emplace_back(FF::neg_one()); - q_2.emplace_back(FF::zero()); - q_3.emplace_back(FF::neg_one()); - q_c.emplace_back(FF::zero()); + w_l().emplace_back(in.d); + w_r().emplace_back(in.d); + w_o().emplace_back(temp_2_idx); + q_m().emplace_back(FF::one()); + q_1().emplace_back(FF::neg_one()); + q_2().emplace_back(FF::zero()); + q_3().emplace_back(FF::neg_one()); + q_c().emplace_back(FF::zero()); ++this->num_gates; constexpr FF neg_two = -FF(2); - w_l.emplace_back(temp_2_idx); - w_r.emplace_back(in.d); - w_o.emplace_back(this->zero_idx); - q_m.emplace_back(FF::one()); - q_1.emplace_back(neg_two); - q_2.emplace_back(FF::zero()); - q_3.emplace_back(FF::zero()); - q_c.emplace_back(FF::zero()); + w_l().emplace_back(temp_2_idx); + w_r().emplace_back(in.d); + w_o().emplace_back(this->zero_idx); + q_m().emplace_back(FF::one()); + q_1().emplace_back(neg_two); + q_2().emplace_back(FF::zero()); + q_3().emplace_back(FF::zero()); + q_c().emplace_back(FF::zero()); ++this->num_gates; } @@ -181,20 +181,20 @@ template void StandardCircuitBuilder_::create_big_mul_gate(con * Create a multiplication gate. * * @param in A mul_tripple containing the indexes of variables to be placed into the - * wires w_l, w_r, w_o and scaling coefficients to be placed into q_m, q_3, q_c. + * wires w_l, w_r, w_o and scaling coefficients to be placed into q_m, q_3, q_c(). */ template void StandardCircuitBuilder_::create_mul_gate(const mul_triple_& in) { this->assert_valid_variables({ in.a, in.b, in.c }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - q_m.emplace_back(in.mul_scaling); - q_1.emplace_back(FF::zero()); - q_2.emplace_back(FF::zero()); - q_3.emplace_back(in.c_scaling); - q_c.emplace_back(in.const_scaling); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + q_m().emplace_back(in.mul_scaling); + q_1().emplace_back(FF::zero()); + q_2().emplace_back(FF::zero()); + q_3().emplace_back(in.c_scaling); + q_c().emplace_back(in.const_scaling); ++this->num_gates; } @@ -209,15 +209,15 @@ template void StandardCircuitBuilder_::create_bool_gate(const { this->assert_valid_variables({ variable_index }); - w_l.emplace_back(variable_index); - w_r.emplace_back(variable_index); - w_o.emplace_back(variable_index); + w_l().emplace_back(variable_index); + w_r().emplace_back(variable_index); + w_o().emplace_back(variable_index); - q_m.emplace_back(FF::one()); - q_1.emplace_back(FF::zero()); - q_2.emplace_back(FF::zero()); - q_3.emplace_back(FF::neg_one()); - q_c.emplace_back(FF::zero()); + q_m().emplace_back(FF::one()); + q_1().emplace_back(FF::zero()); + q_2().emplace_back(FF::zero()); + q_3().emplace_back(FF::neg_one()); + q_c().emplace_back(FF::zero()); ++this->num_gates; } @@ -231,14 +231,14 @@ template void StandardCircuitBuilder_::create_poly_gate(const { this->assert_valid_variables({ in.a, in.b, in.c }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - q_m.emplace_back(in.q_m); - q_1.emplace_back(in.q_l); - q_2.emplace_back(in.q_r); - q_3.emplace_back(in.q_o); - q_c.emplace_back(in.q_c); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + q_m().emplace_back(in.q_m); + q_1().emplace_back(in.q_l); + q_2().emplace_back(in.q_r); + q_3().emplace_back(in.q_o); + q_c().emplace_back(in.q_c); ++this->num_gates; } @@ -435,14 +435,14 @@ void StandardCircuitBuilder_::fix_witness(const uint32_t witness_index, cons { this->assert_valid_variables({ witness_index }); - w_l.emplace_back(witness_index); - w_r.emplace_back(this->zero_idx); - w_o.emplace_back(this->zero_idx); - q_m.emplace_back(FF::zero()); - q_1.emplace_back(FF::one()); - q_2.emplace_back(FF::zero()); - q_3.emplace_back(FF::zero()); - q_c.emplace_back(-witness_value); + w_l().emplace_back(witness_index); + w_r().emplace_back(this->zero_idx); + w_o().emplace_back(this->zero_idx); + q_m().emplace_back(FF::zero()); + q_1().emplace_back(FF::one()); + q_2().emplace_back(FF::zero()); + q_3().emplace_back(FF::zero()); + q_c().emplace_back(-witness_value); ++this->num_gates; } @@ -499,10 +499,10 @@ template bool StandardCircuitBuilder_::check_circuit() for (size_t i = 0; i < this->num_gates; i++) { gate_sum = FF::zero(); - left = this->get_variable(w_l[i]); - right = this->get_variable(w_r[i]); - output = this->get_variable(w_o[i]); - gate_sum = q_m[i] * left * right + q_1[i] * left + q_2[i] * right + q_3[i] * output + q_c[i]; + left = this->get_variable(w_l()[i]); + right = this->get_variable(w_r()[i]); + output = this->get_variable(w_o()[i]); + gate_sum = q_m()[i] * left * right + q_1()[i] * left + q_2()[i] * right + q_3()[i] * output + q_c()[i]; if (!gate_sum.is_zero()) { info("gate number", i); return false; @@ -543,11 +543,11 @@ template msgpack::sbuffer StandardCircuitBuilder_::export_circ } for (size_t i = 0; i < this->num_gates; i++) { - std::vector tmp_sel = { q_m[i], q_1[i], q_2[i], q_3[i], q_c[i] }; + std::vector tmp_sel = { q_m()[i], q_1()[i], q_2()[i], q_3()[i], q_c()[i] }; std::vector tmp_w = { - this->real_variable_index[w_l[i]], - this->real_variable_index[w_r[i]], - this->real_variable_index[w_o[i]], + this->real_variable_index[w_l()[i]], + this->real_variable_index[w_r()[i]], + this->real_variable_index[w_o()[i]], }; cir.selectors.push_back(tmp_sel); cir.wires.push_back(tmp_w); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp index 819bc5a3c51..4c379ae9acd 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp @@ -29,15 +29,25 @@ template class StandardCircuitBuilder_ : public CircuitBuilderBase using WireVector = std::vector>; using SelectorVector = std::vector>; - WireVector& w_l = std::get<0>(wires); - WireVector& w_r = std::get<1>(wires); - WireVector& w_o = std::get<2>(wires); - - SelectorVector& q_m = this->selectors.q_m(); - SelectorVector& q_1 = this->selectors.q_1(); - SelectorVector& q_2 = this->selectors.q_2(); - SelectorVector& q_3 = this->selectors.q_3(); - SelectorVector& q_c = this->selectors.q_c(); + WireVector& w_l() { return std::get<0>(wires); }; + WireVector& w_r() { return std::get<1>(wires); }; + WireVector& w_o() { return std::get<2>(wires); }; + + const WireVector& w_l() const { return std::get<0>(wires); }; + const WireVector& w_r() const { return std::get<1>(wires); }; + const WireVector& w_o() const { return std::get<2>(wires); }; + + SelectorVector& q_m() { return this->selectors.q_m(); }; + SelectorVector& q_1() { return this->selectors.q_1(); }; + SelectorVector& q_2() { return this->selectors.q_2(); }; + SelectorVector& q_3() { return this->selectors.q_3(); }; + SelectorVector& q_c() { return this->selectors.q_c(); }; + + const SelectorVector& q_m() const { return this->selectors.q_m(); }; + const SelectorVector& q_1() const { return this->selectors.q_1(); }; + const SelectorVector& q_2() const { return this->selectors.q_2(); }; + const SelectorVector& q_3() const { return this->selectors.q_3(); }; + const SelectorVector& q_c() const { return this->selectors.q_c(); }; static constexpr size_t UINT_LOG2_BASE = 2; @@ -50,9 +60,9 @@ template class StandardCircuitBuilder_ : public CircuitBuilderBase : CircuitBuilderBase(size_hint) { selectors.reserve(size_hint); - w_l.reserve(size_hint); - w_r.reserve(size_hint); - w_o.reserve(size_hint); + w_l().reserve(size_hint); + w_r().reserve(size_hint); + w_o().reserve(size_hint); // To effieciently constrain wires to zero, we set the first value of w_1 to be 0, and use copy constraints for // all future zero values. // (#216)(Adrian): This should be done in a constant way, maybe by initializing the constant_variable_indices diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp index 39443c58c7f..d3d9767bb74 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp @@ -63,22 +63,22 @@ void UltraCircuitBuilder_::add_gates_to_ensure_all_polys_are_no { // First add a gate to simultaneously ensure first entries of all wires is zero and to add a non // zero value to all selectors aside from q_c and q_lookup - w_l.emplace_back(this->zero_idx); - w_r.emplace_back(this->zero_idx); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(this->zero_idx); - q_m.emplace_back(1); - q_1.emplace_back(1); - q_2.emplace_back(1); - q_3.emplace_back(1); - q_c.emplace_back(0); - q_sort.emplace_back(1); - - q_arith.emplace_back(1); - q_4.emplace_back(1); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(1); - q_aux.emplace_back(1); + w_l().emplace_back(this->zero_idx); + w_r().emplace_back(this->zero_idx); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(this->zero_idx); + q_m().emplace_back(1); + q_1().emplace_back(1); + q_2().emplace_back(1); + q_3().emplace_back(1); + q_c().emplace_back(0); + q_sort().emplace_back(1); + + q_arith().emplace_back(1); + q_4().emplace_back(1); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(1); + q_aux().emplace_back(1); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -125,21 +125,21 @@ void UltraCircuitBuilder_::create_add_gate(const add_triple_assert_valid_variables({ in.a, in.b, in.c }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - w_4.emplace_back(this->zero_idx); - q_m.emplace_back(0); - q_1.emplace_back(in.a_scaling); - q_2.emplace_back(in.b_scaling); - q_3.emplace_back(in.c_scaling); - q_c.emplace_back(in.const_scaling); - q_arith.emplace_back(1); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + w_4().emplace_back(this->zero_idx); + q_m().emplace_back(0); + q_1().emplace_back(in.a_scaling); + q_2().emplace_back(in.b_scaling); + q_3().emplace_back(in.c_scaling); + q_c().emplace_back(in.const_scaling); + q_arith().emplace_back(1); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -158,21 +158,21 @@ void UltraCircuitBuilder_::create_big_add_gate(const add_quad_< const bool include_next_gate_w_4) { this->assert_valid_variables({ in.a, in.b, in.c, in.d }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - w_4.emplace_back(in.d); - q_m.emplace_back(0); - q_1.emplace_back(in.a_scaling); - q_2.emplace_back(in.b_scaling); - q_3.emplace_back(in.c_scaling); - q_c.emplace_back(in.const_scaling); - q_arith.emplace_back(include_next_gate_w_4 ? 2 : 1); - q_4.emplace_back(in.d_scaling); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + w_4().emplace_back(in.d); + q_m().emplace_back(0); + q_1().emplace_back(in.a_scaling); + q_2().emplace_back(in.b_scaling); + q_3().emplace_back(in.c_scaling); + q_c().emplace_back(in.const_scaling); + q_arith().emplace_back(include_next_gate_w_4 ? 2 : 1); + q_4().emplace_back(in.d_scaling); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -253,21 +253,21 @@ void UltraCircuitBuilder_::create_big_mul_gate(const mul_quad_< { this->assert_valid_variables({ in.a, in.b, in.c, in.d }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - w_4.emplace_back(in.d); - q_m.emplace_back(in.mul_scaling); - q_1.emplace_back(in.a_scaling); - q_2.emplace_back(in.b_scaling); - q_3.emplace_back(in.c_scaling); - q_c.emplace_back(in.const_scaling); - q_arith.emplace_back(1); - q_4.emplace_back(in.d_scaling); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + w_4().emplace_back(in.d); + q_m().emplace_back(in.mul_scaling); + q_1().emplace_back(in.a_scaling); + q_2().emplace_back(in.b_scaling); + q_3().emplace_back(in.c_scaling); + q_c().emplace_back(in.const_scaling); + q_arith().emplace_back(1); + q_4().emplace_back(in.d_scaling); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -280,21 +280,21 @@ void UltraCircuitBuilder_::create_balanced_add_gate(const add_q { this->assert_valid_variables({ in.a, in.b, in.c, in.d }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - w_4.emplace_back(in.d); - q_m.emplace_back(0); - q_1.emplace_back(in.a_scaling); - q_2.emplace_back(in.b_scaling); - q_3.emplace_back(in.c_scaling); - q_c.emplace_back(in.const_scaling); - q_arith.emplace_back(1); - q_4.emplace_back(in.d_scaling); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + w_4().emplace_back(in.d); + q_m().emplace_back(0); + q_1().emplace_back(in.a_scaling); + q_2().emplace_back(in.b_scaling); + q_3().emplace_back(in.c_scaling); + q_c().emplace_back(in.const_scaling); + q_arith().emplace_back(1); + q_4().emplace_back(in.d_scaling); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -323,21 +323,21 @@ void UltraCircuitBuilder_::create_mul_gate(const mul_triple_assert_valid_variables({ in.a, in.b, in.c }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - w_4.emplace_back(this->zero_idx); - q_m.emplace_back(in.mul_scaling); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(in.c_scaling); - q_c.emplace_back(in.const_scaling); - q_arith.emplace_back(1); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + w_4().emplace_back(this->zero_idx); + q_m().emplace_back(in.mul_scaling); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(in.c_scaling); + q_c().emplace_back(in.const_scaling); + q_arith().emplace_back(1); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -352,22 +352,22 @@ void UltraCircuitBuilder_::create_bool_gate(const uint32_t vari { this->assert_valid_variables({ variable_index }); - w_l.emplace_back(variable_index); - w_r.emplace_back(variable_index); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(this->zero_idx); - q_m.emplace_back(1); - q_1.emplace_back(-1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_sort.emplace_back(0); - - q_arith.emplace_back(1); - q_4.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(variable_index); + w_r().emplace_back(variable_index); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(this->zero_idx); + q_m().emplace_back(1); + q_1().emplace_back(-1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_sort().emplace_back(0); + + q_arith().emplace_back(1); + q_4().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -384,22 +384,22 @@ void UltraCircuitBuilder_::create_poly_gate(const poly_triple_< { this->assert_valid_variables({ in.a, in.b, in.c }); - w_l.emplace_back(in.a); - w_r.emplace_back(in.b); - w_o.emplace_back(in.c); - w_4.emplace_back(this->zero_idx); - q_m.emplace_back(in.q_m); - q_1.emplace_back(in.q_l); - q_2.emplace_back(in.q_r); - q_3.emplace_back(in.q_o); - q_c.emplace_back(in.q_c); - q_sort.emplace_back(0); - - q_arith.emplace_back(1); - q_4.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(in.a); + w_r().emplace_back(in.b); + w_o().emplace_back(in.c); + w_4().emplace_back(this->zero_idx); + q_m().emplace_back(in.q_m); + q_1().emplace_back(in.q_l); + q_2().emplace_back(in.q_r); + q_3().emplace_back(in.q_o); + q_c().emplace_back(in.q_c); + q_sort().emplace_back(0); + + q_arith().emplace_back(1); + q_4().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -427,53 +427,53 @@ void UltraCircuitBuilder_::create_ecc_add_gate(const ecc_add_ga this->assert_valid_variables({ in.x1, in.x2, in.x3, in.y1, in.y2, in.y3 }); bool can_fuse_into_previous_gate = true; - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_r[this->num_gates - 1] == in.x1); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_o[this->num_gates - 1] == in.y1); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_3[this->num_gates - 1] == 0); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_4[this->num_gates - 1] == 0); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_1[this->num_gates - 1] == 0); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_arith[this->num_gates - 1] == 0); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_m[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_r()[this->num_gates - 1] == in.x1); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_o()[this->num_gates - 1] == in.y1); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_3()[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_4()[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_1()[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_arith()[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_m()[this->num_gates - 1] == 0); if (can_fuse_into_previous_gate) { - q_1[this->num_gates - 1] = in.sign_coefficient; - q_elliptic[this->num_gates - 1] = 1; + q_1()[this->num_gates - 1] = in.sign_coefficient; + q_elliptic()[this->num_gates - 1] = 1; } else { - w_l.emplace_back(this->zero_idx); - w_r.emplace_back(in.x1); - w_o.emplace_back(in.y1); - w_4.emplace_back(this->zero_idx); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_1.emplace_back(in.sign_coefficient); - - q_arith.emplace_back(0); - q_2.emplace_back(0); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(1); - q_aux.emplace_back(0); + w_l().emplace_back(this->zero_idx); + w_r().emplace_back(in.x1); + w_o().emplace_back(in.y1); + w_4().emplace_back(this->zero_idx); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_1().emplace_back(in.sign_coefficient); + + q_arith().emplace_back(0); + q_2().emplace_back(0); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(1); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; } - w_l.emplace_back(in.x2); - w_4.emplace_back(in.y2); - w_r.emplace_back(in.x3); - w_o.emplace_back(in.y3); - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(in.x2); + w_4().emplace_back(in.y2); + w_r().emplace_back(in.x3); + w_o().emplace_back(in.y3); + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -496,51 +496,51 @@ void UltraCircuitBuilder_::create_ecc_dbl_gate(const ecc_dbl_ga * can also chain double gates together **/ bool can_fuse_into_previous_gate = true; - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_r[this->num_gates - 1] == in.x1); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_o[this->num_gates - 1] == in.y1); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_arith[this->num_gates - 1] == 0); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_lookup_type[this->num_gates - 1] == 0); - can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_aux[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_r()[this->num_gates - 1] == in.x1); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (w_o()[this->num_gates - 1] == in.y1); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_arith()[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_lookup_type()[this->num_gates - 1] == 0); + can_fuse_into_previous_gate = can_fuse_into_previous_gate && (q_aux()[this->num_gates - 1] == 0); if (can_fuse_into_previous_gate) { - q_elliptic[this->num_gates - 1] = 1; - q_m[this->num_gates - 1] = 1; + q_elliptic()[this->num_gates - 1] = 1; + q_m()[this->num_gates - 1] = 1; } else { - w_r.emplace_back(in.x1); - w_o.emplace_back(in.y1); - w_l.emplace_back(this->zero_idx); - w_4.emplace_back(this->zero_idx); - q_elliptic.emplace_back(1); - q_m.emplace_back(1); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + w_r().emplace_back(in.x1); + w_o().emplace_back(in.y1); + w_l().emplace_back(this->zero_idx); + w_4().emplace_back(this->zero_idx); + q_elliptic().emplace_back(1); + q_m().emplace_back(1); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; } - w_r.emplace_back(in.x3); - w_o.emplace_back(in.y3); - w_l.emplace_back(this->zero_idx); - w_4.emplace_back(this->zero_idx); - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_r().emplace_back(in.x3); + w_o().emplace_back(in.y3); + w_l().emplace_back(this->zero_idx); + w_4().emplace_back(this->zero_idx); + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -557,21 +557,21 @@ void UltraCircuitBuilder_::fix_witness(const uint32_t witness_i { this->assert_valid_variables({ witness_index }); - w_l.emplace_back(witness_index); - w_r.emplace_back(this->zero_idx); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(this->zero_idx); - q_m.emplace_back(0); - q_1.emplace_back(1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(-witness_value); - q_arith.emplace_back(1); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + w_l().emplace_back(witness_index); + w_r().emplace_back(this->zero_idx); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(this->zero_idx); + q_m().emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(-witness_value); + q_arith().emplace_back(1); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -633,21 +633,21 @@ plookup::ReadData UltraCircuitBuilder_::create_gates_ read_data[plookup::ColumnIdx::C3].push_back(third_idx); this->assert_valid_variables({ first_idx, second_idx, third_idx }); - q_lookup_type.emplace_back(FF(1)); - q_3.emplace_back(FF(table.table_index)); - w_l.emplace_back(first_idx); - w_r.emplace_back(second_idx); - w_o.emplace_back(third_idx); - w_4.emplace_back(this->zero_idx); - q_1.emplace_back(0); - q_2.emplace_back((i == (num_lookups - 1) ? 0 : -multi_table.column_1_step_sizes[i + 1])); - q_m.emplace_back((i == (num_lookups - 1) ? 0 : -multi_table.column_2_step_sizes[i + 1])); - q_c.emplace_back((i == (num_lookups - 1) ? 0 : -multi_table.column_3_step_sizes[i + 1])); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + q_lookup_type().emplace_back(FF(1)); + q_3().emplace_back(FF(table.table_index)); + w_l().emplace_back(first_idx); + w_r().emplace_back(second_idx); + w_o().emplace_back(third_idx); + w_4().emplace_back(this->zero_idx); + q_1().emplace_back(0); + q_2().emplace_back((i == (num_lookups - 1) ? 0 : -multi_table.column_1_step_sizes[i + 1])); + q_m().emplace_back((i == (num_lookups - 1) ? 0 : -multi_table.column_2_step_sizes[i + 1])); + q_c().emplace_back((i == (num_lookups - 1) ? 0 : -multi_table.column_3_step_sizes[i + 1])); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); ++this->num_gates; @@ -942,42 +942,42 @@ void UltraCircuitBuilder_::create_sort_constraint(const std::ve for (size_t i = 0; i < variable_index.size(); i += gate_width) { - w_l.emplace_back(variable_index[i]); - w_r.emplace_back(variable_index[i + 1]); - w_o.emplace_back(variable_index[i + 2]); - w_4.emplace_back(variable_index[i + 3]); + w_l().emplace_back(variable_index[i]); + w_r().emplace_back(variable_index[i + 1]); + w_o().emplace_back(variable_index[i + 2]); + w_4().emplace_back(variable_index[i + 3]); ++this->num_gates; - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(1); - q_elliptic.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(1); + q_elliptic().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); } // dummy gate needed because of sort widget's check of next row - w_l.emplace_back(variable_index[variable_index.size() - 1]); - w_r.emplace_back(this->zero_idx); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(this->zero_idx); + w_l().emplace_back(variable_index[variable_index.size() - 1]); + w_r().emplace_back(this->zero_idx); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(this->zero_idx); ++this->num_gates; - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_elliptic.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_elliptic().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); } @@ -997,22 +997,22 @@ void UltraCircuitBuilder_::create_dummy_constraints(const std:: this->assert_valid_variables(padded_list); for (size_t i = 0; i < padded_list.size(); i += gate_width) { - w_l.emplace_back(padded_list[i]); - w_r.emplace_back(padded_list[i + 1]); - w_o.emplace_back(padded_list[i + 2]); - w_4.emplace_back(padded_list[i + 3]); + w_l().emplace_back(padded_list[i]); + w_r().emplace_back(padded_list[i + 1]); + w_o().emplace_back(padded_list[i + 2]); + w_4().emplace_back(padded_list[i + 3]); ++this->num_gates; - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_elliptic.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_elliptic().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); } @@ -1029,86 +1029,86 @@ void UltraCircuitBuilder_::create_sort_constraint_with_edges( this->assert_valid_variables(variable_index); // enforce range checks of first row and starting at start - w_l.emplace_back(variable_index[0]); - w_r.emplace_back(variable_index[1]); - w_o.emplace_back(variable_index[2]); - w_4.emplace_back(variable_index[3]); + w_l().emplace_back(variable_index[0]); + w_r().emplace_back(variable_index[1]); + w_o().emplace_back(variable_index[2]); + w_4().emplace_back(variable_index[3]); ++this->num_gates; - q_m.emplace_back(0); - q_1.emplace_back(1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(-start); - q_arith.emplace_back(1); - q_4.emplace_back(0); - q_sort.emplace_back(1); - q_elliptic.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + q_m().emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(-start); + q_arith().emplace_back(1); + q_4().emplace_back(0); + q_sort().emplace_back(1); + q_elliptic().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); // enforce range check for middle rows for (size_t i = gate_width; i < variable_index.size() - gate_width; i += gate_width) { - w_l.emplace_back(variable_index[i]); - w_r.emplace_back(variable_index[i + 1]); - w_o.emplace_back(variable_index[i + 2]); - w_4.emplace_back(variable_index[i + 3]); + w_l().emplace_back(variable_index[i]); + w_r().emplace_back(variable_index[i + 1]); + w_o().emplace_back(variable_index[i + 2]); + w_4().emplace_back(variable_index[i + 3]); ++this->num_gates; - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(1); - q_elliptic.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(1); + q_elliptic().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); } // enforce range checks of last row and ending at end if (variable_index.size() > gate_width) { - w_l.emplace_back(variable_index[variable_index.size() - 4]); - w_r.emplace_back(variable_index[variable_index.size() - 3]); - w_o.emplace_back(variable_index[variable_index.size() - 2]); - w_4.emplace_back(variable_index[variable_index.size() - 1]); + w_l().emplace_back(variable_index[variable_index.size() - 4]); + w_r().emplace_back(variable_index[variable_index.size() - 3]); + w_o().emplace_back(variable_index[variable_index.size() - 2]); + w_4().emplace_back(variable_index[variable_index.size() - 1]); ++this->num_gates; - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); - q_4.emplace_back(0); - q_sort.emplace_back(1); - q_elliptic.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); + q_4().emplace_back(0); + q_sort().emplace_back(1); + q_elliptic().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); } // dummy gate needed because of sort widget's check of next row // use this gate to check end condition - w_l.emplace_back(variable_index[variable_index.size() - 1]); - w_r.emplace_back(this->zero_idx); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(this->zero_idx); + w_l().emplace_back(variable_index[variable_index.size() - 1]); + w_r().emplace_back(this->zero_idx); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(this->zero_idx); ++this->num_gates; - q_m.emplace_back(0); - q_1.emplace_back(1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_c.emplace_back(-end); - q_arith.emplace_back(1); - q_4.emplace_back(0); - q_sort.emplace_back(0); - q_elliptic.emplace_back(0); - q_lookup_type.emplace_back(0); - q_aux.emplace_back(0); + q_m().emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_c().emplace_back(-end); + q_arith().emplace_back(1); + q_4().emplace_back(0); + q_sort().emplace_back(0); + q_elliptic().emplace_back(0); + q_lookup_type().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); } @@ -1213,67 +1213,67 @@ std::vector UltraCircuitBuilder_::decompose_into_defa template void UltraCircuitBuilder_::apply_aux_selectors(const AUX_SELECTORS type) { - q_aux.emplace_back(type == AUX_SELECTORS::NONE ? 0 : 1); - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); + q_aux().emplace_back(type == AUX_SELECTORS::NONE ? 0 : 1); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); switch (type) { case AUX_SELECTORS::LIMB_ACCUMULATE_1: { - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(1); - q_4.emplace_back(1); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(1); + q_4().emplace_back(1); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; } case AUX_SELECTORS::LIMB_ACCUMULATE_2: { - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(1); - q_4.emplace_back(0); - q_m.emplace_back(1); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(1); + q_4().emplace_back(0); + q_m().emplace_back(1); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; } case AUX_SELECTORS::NON_NATIVE_FIELD_1: { - q_1.emplace_back(0); - q_2.emplace_back(1); - q_3.emplace_back(1); - q_4.emplace_back(0); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(1); + q_3().emplace_back(1); + q_4().emplace_back(0); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; } case AUX_SELECTORS::NON_NATIVE_FIELD_2: { - q_1.emplace_back(0); - q_2.emplace_back(1); - q_3.emplace_back(0); - q_4.emplace_back(1); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(1); + q_3().emplace_back(0); + q_4().emplace_back(1); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; } case AUX_SELECTORS::NON_NATIVE_FIELD_3: { - q_1.emplace_back(0); - q_2.emplace_back(1); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_m.emplace_back(1); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(1); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_m().emplace_back(1); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; @@ -1283,13 +1283,13 @@ void UltraCircuitBuilder_::apply_aux_selectors(const AUX_SELECT // Apply sorted memory read checks with the following additional check: // 1. Assert that if index field across two gates does not change, the value field does not change. // Used for ROM reads and RAM reads across write/read boundaries - q_1.emplace_back(1); - q_2.emplace_back(1); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(1); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; @@ -1300,13 +1300,13 @@ void UltraCircuitBuilder_::apply_aux_selectors(const AUX_SELECT // 2. Validate record computation (r = read_write_flag + index * \eta + \timestamp * \eta^2 + value * \eta^3) // 3. If adjacent index values across 2 gates does not change, and the next gate's read_write_flag is set to // 'read', validate adjacent values do not change Used for ROM reads and RAM reads across read/write boundaries - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(1); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(1); selectors.pad_additional(); check_selector_length_consistency(); break; @@ -1314,13 +1314,13 @@ void UltraCircuitBuilder_::apply_aux_selectors(const AUX_SELECT case AUX_SELECTORS::RAM_TIMESTAMP_CHECK: { // For two adjacent RAM entries that share the same index, validate the timestamp value is monotonically // increasing - q_1.emplace_back(1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_4.emplace_back(1); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_4().emplace_back(1); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; @@ -1329,13 +1329,13 @@ void UltraCircuitBuilder_::apply_aux_selectors(const AUX_SELECT // Memory read gate for reading memory cells. // Validates record witness computation (r = read_write_flag + index * \eta + timestamp * \eta^2 + value * // \eta^3) - q_1.emplace_back(1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_m.emplace_back(1); // validate record witness is correctly computed - q_c.emplace_back(0); // read/write flag stored in q_c - q_arith.emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_m().emplace_back(1); // validate record witness is correctly computed + q_c().emplace_back(0); // read/write flag stored in q_c + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; @@ -1344,13 +1344,13 @@ void UltraCircuitBuilder_::apply_aux_selectors(const AUX_SELECT // Memory read gate for reading memory cells. // Validates record witness computation (r = read_write_flag + index * \eta + timestamp * \eta^2 + value * // \eta^3) - q_1.emplace_back(1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_m.emplace_back(1); // validate record witness is correctly computed - q_c.emplace_back(0); // read/write flag stored in q_c - q_arith.emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_m().emplace_back(1); // validate record witness is correctly computed + q_c().emplace_back(0); // read/write flag stored in q_c + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; @@ -1359,25 +1359,25 @@ void UltraCircuitBuilder_::apply_aux_selectors(const AUX_SELECT // Memory read gate for writing memory cells. // Validates record witness computation (r = read_write_flag + index * \eta + timestamp * \eta^2 + value * // \eta^3) - q_1.emplace_back(1); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_m.emplace_back(1); // validate record witness is correctly computed - q_c.emplace_back(1); // read/write flag stored in q_c - q_arith.emplace_back(0); + q_1().emplace_back(1); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_m().emplace_back(1); // validate record witness is correctly computed + q_c().emplace_back(1); // read/write flag stored in q_c + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; } default: { - q_1.emplace_back(0); - q_2.emplace_back(0); - q_3.emplace_back(0); - q_4.emplace_back(0); - q_m.emplace_back(0); - q_c.emplace_back(0); - q_arith.emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(0); + q_3().emplace_back(0); + q_4().emplace_back(0); + q_m().emplace_back(0); + q_c().emplace_back(0); + q_arith().emplace_back(0); selectors.pad_additional(); check_selector_length_consistency(); break; @@ -1445,20 +1445,20 @@ void UltraCircuitBuilder_::range_constrain_two_limbs(const uint const std::array lo_sublimbs = get_sublimbs(lo_idx, lo_masks); const std::array hi_sublimbs = get_sublimbs(hi_idx, hi_masks); - w_l.emplace_back(lo_sublimbs[0]); - w_r.emplace_back(lo_sublimbs[1]); - w_o.emplace_back(lo_sublimbs[2]); - w_4.emplace_back(lo_idx); + w_l().emplace_back(lo_sublimbs[0]); + w_r().emplace_back(lo_sublimbs[1]); + w_o().emplace_back(lo_sublimbs[2]); + w_4().emplace_back(lo_idx); - w_l.emplace_back(lo_sublimbs[3]); - w_r.emplace_back(lo_sublimbs[4]); - w_o.emplace_back(hi_sublimbs[0]); - w_4.emplace_back(hi_sublimbs[1]); + w_l().emplace_back(lo_sublimbs[3]); + w_r().emplace_back(lo_sublimbs[4]); + w_o().emplace_back(hi_sublimbs[0]); + w_4().emplace_back(hi_sublimbs[1]); - w_l.emplace_back(hi_sublimbs[2]); - w_r.emplace_back(hi_sublimbs[3]); - w_o.emplace_back(hi_sublimbs[4]); - w_4.emplace_back(hi_idx); + w_l().emplace_back(hi_sublimbs[2]); + w_r().emplace_back(hi_sublimbs[3]); + w_o().emplace_back(hi_sublimbs[4]); + w_4().emplace_back(hi_idx); apply_aux_selectors(AUX_SELECTORS::LIMB_ACCUMULATE_1); apply_aux_selectors(AUX_SELECTORS::LIMB_ACCUMULATE_2); @@ -1618,28 +1618,28 @@ std::array UltraCircuitBuilder_::evaluate_non_nati 0 }, true); - w_l.emplace_back(input.a[1]); - w_r.emplace_back(input.b[1]); - w_o.emplace_back(input.r[0]); - w_4.emplace_back(lo_0_idx); + w_l().emplace_back(input.a[1]); + w_r().emplace_back(input.b[1]); + w_o().emplace_back(input.r[0]); + w_4().emplace_back(lo_0_idx); apply_aux_selectors(AUX_SELECTORS::NON_NATIVE_FIELD_1); ++this->num_gates; - w_l.emplace_back(input.a[0]); - w_r.emplace_back(input.b[0]); - w_o.emplace_back(input.a[3]); - w_4.emplace_back(input.b[3]); + w_l().emplace_back(input.a[0]); + w_r().emplace_back(input.b[0]); + w_o().emplace_back(input.a[3]); + w_4().emplace_back(input.b[3]); apply_aux_selectors(AUX_SELECTORS::NON_NATIVE_FIELD_2); ++this->num_gates; - w_l.emplace_back(input.a[2]); - w_r.emplace_back(input.b[2]); - w_o.emplace_back(input.r[3]); - w_4.emplace_back(hi_0_idx); + w_l().emplace_back(input.a[2]); + w_r().emplace_back(input.b[2]); + w_o().emplace_back(input.r[3]); + w_4().emplace_back(hi_0_idx); apply_aux_selectors(AUX_SELECTORS::NON_NATIVE_FIELD_3); ++this->num_gates; - w_l.emplace_back(input.a[1]); - w_r.emplace_back(input.b[1]); - w_o.emplace_back(input.r[2]); - w_4.emplace_back(hi_1_idx); + w_l().emplace_back(input.a[1]); + w_r().emplace_back(input.b[1]); + w_o().emplace_back(input.r[2]); + w_4().emplace_back(hi_1_idx); apply_aux_selectors(AUX_SELECTORS::NONE); ++this->num_gates; @@ -1703,28 +1703,28 @@ void UltraCircuitBuilder_::process_non_native_field_multiplicat // iterate over the cached items and create constraints for (const auto& input : cached_partial_non_native_field_multiplications) { - w_l.emplace_back(input.a[1]); - w_r.emplace_back(input.b[1]); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(input.lo_0); + w_l().emplace_back(input.a[1]); + w_r().emplace_back(input.b[1]); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(input.lo_0); apply_aux_selectors(AUX_SELECTORS::NON_NATIVE_FIELD_1); ++this->num_gates; - w_l.emplace_back(input.a[0]); - w_r.emplace_back(input.b[0]); - w_o.emplace_back(input.a[3]); - w_4.emplace_back(input.b[3]); + w_l().emplace_back(input.a[0]); + w_r().emplace_back(input.b[0]); + w_o().emplace_back(input.a[3]); + w_4().emplace_back(input.b[3]); apply_aux_selectors(AUX_SELECTORS::NON_NATIVE_FIELD_2); ++this->num_gates; - w_l.emplace_back(input.a[2]); - w_r.emplace_back(input.b[2]); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(input.hi_0); + w_l().emplace_back(input.a[2]); + w_r().emplace_back(input.b[2]); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(input.hi_0); apply_aux_selectors(AUX_SELECTORS::NON_NATIVE_FIELD_3); ++this->num_gates; - w_l.emplace_back(input.a[1]); - w_r.emplace_back(input.b[1]); - w_o.emplace_back(this->zero_idx); - w_4.emplace_back(input.hi_1); + w_l().emplace_back(input.a[1]); + w_r().emplace_back(input.b[1]); + w_o().emplace_back(this->zero_idx); + w_4().emplace_back(input.hi_1); apply_aux_selectors(AUX_SELECTORS::NONE); ++this->num_gates; } @@ -1845,61 +1845,61 @@ std::array UltraCircuitBuilder_::evaluate_non_nati * By setting `q_arith` to `3`, we can validate `x_p + y_p + q_m = z_p` **/ // GATE 1 - w_l.emplace_back(y_p); - w_r.emplace_back(x_0); - w_o.emplace_back(y_0); - w_4.emplace_back(x_p); - w_l.emplace_back(z_p); - w_r.emplace_back(x_1); - w_o.emplace_back(y_1); // | 1 | 2 | 3 | 4 | - w_4.emplace_back(z_0); // |-----|-----|-----|-----| - w_l.emplace_back(x_2); // | y.p | x.0 | y.0 | z.p | (b.p + b.p - c.p = 0) AND (a.0 + b.0 - c.0 = 0) - w_r.emplace_back(y_2); // | x.p | x.1 | y.1 | z.0 | (a.1 + b.1 - c.1 = 0) - w_o.emplace_back(z_2); // | x.2 | y.2 | z.2 | z.1 | (a.2 + b.2 - c.2 = 0) - w_4.emplace_back(z_1); // | x.3 | y.3 | z.3 | --- | (a.3 + b.3 - c.3 = 0) - w_l.emplace_back(x_3); - w_r.emplace_back(y_3); - w_o.emplace_back(z_3); - w_4.emplace_back(this->zero_idx); - - q_m.emplace_back(addconstp); - q_1.emplace_back(0); - q_2.emplace_back(-x_mulconst0 * - 2); // scale constants by 2. If q_arith = 3 then w_4_omega value (z0) gets scaled by 2x - q_3.emplace_back(-y_mulconst0 * 2); // z_0 - (x_0 * -xmulconst0) - (y_0 * ymulconst0) = 0 => z_0 = x_0 + y_0 - q_4.emplace_back(0); - q_c.emplace_back(-addconst0 * 2); - q_arith.emplace_back(3); - - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(-x_mulconst1); - q_3.emplace_back(-y_mulconst1); - q_4.emplace_back(0); - q_c.emplace_back(-addconst1); - q_arith.emplace_back(2); - - q_m.emplace_back(0); - q_1.emplace_back(-x_mulconst2); - q_2.emplace_back(-y_mulconst2); - q_3.emplace_back(1); - q_4.emplace_back(0); - q_c.emplace_back(-addconst2); - q_arith.emplace_back(1); - - q_m.emplace_back(0); - q_1.emplace_back(-x_mulconst3); - q_2.emplace_back(-y_mulconst3); - q_3.emplace_back(1); - q_4.emplace_back(0); - q_c.emplace_back(-addconst3); - q_arith.emplace_back(1); + w_l().emplace_back(y_p); + w_r().emplace_back(x_0); + w_o().emplace_back(y_0); + w_4().emplace_back(x_p); + w_l().emplace_back(z_p); + w_r().emplace_back(x_1); + w_o().emplace_back(y_1); // | 1 | 2 | 3 | 4 | + w_4().emplace_back(z_0); // |-----|-----|-----|-----| + w_l().emplace_back(x_2); // | y.p | x.0 | y.0 | z.p | (b.p + b.p - c.p = 0) AND (a.0 + b.0 - c.0 = 0) + w_r().emplace_back(y_2); // | x.p | x.1 | y.1 | z.0 | (a.1 + b.1 - c.1 = 0) + w_o().emplace_back(z_2); // | x.2 | y.2 | z.2 | z.1 | (a.2 + b.2 - c.2 = 0) + w_4().emplace_back(z_1); // | x.3 | y.3 | z.3 | --- | (a.3 + b.3 - c.3 = 0) + w_l().emplace_back(x_3); + w_r().emplace_back(y_3); + w_o().emplace_back(z_3); + w_4().emplace_back(this->zero_idx); + + q_m().emplace_back(addconstp); + q_1().emplace_back(0); + q_2().emplace_back(-x_mulconst0 * + 2); // scale constants by 2. If q_arith = 3 then w_4_omega value (z0) gets scaled by 2x + q_3().emplace_back(-y_mulconst0 * 2); // z_0 - (x_0 * -xmulconst0) - (y_0 * ymulconst0) = 0 => z_0 = x_0 + y_0 + q_4().emplace_back(0); + q_c().emplace_back(-addconst0 * 2); + q_arith().emplace_back(3); + + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(-x_mulconst1); + q_3().emplace_back(-y_mulconst1); + q_4().emplace_back(0); + q_c().emplace_back(-addconst1); + q_arith().emplace_back(2); + + q_m().emplace_back(0); + q_1().emplace_back(-x_mulconst2); + q_2().emplace_back(-y_mulconst2); + q_3().emplace_back(1); + q_4().emplace_back(0); + q_c().emplace_back(-addconst2); + q_arith().emplace_back(1); + + q_m().emplace_back(0); + q_1().emplace_back(-x_mulconst3); + q_2().emplace_back(-y_mulconst3); + q_3().emplace_back(1); + q_4().emplace_back(0); + q_c().emplace_back(-addconst3); + q_arith().emplace_back(1); for (size_t i = 0; i < 4; ++i) { - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); } check_selector_length_consistency(); @@ -1969,60 +1969,60 @@ std::array UltraCircuitBuilder_::evaluate_non_nati * **/ // GATE 1 - w_l.emplace_back(y_p); - w_r.emplace_back(x_0); - w_o.emplace_back(y_0); - w_4.emplace_back(z_p); - w_l.emplace_back(x_p); - w_r.emplace_back(x_1); - w_o.emplace_back(y_1); // | 1 | 2 | 3 | 4 | - w_4.emplace_back(z_0); // |-----|-----|-----|-----| - w_l.emplace_back(x_2); // | y.p | x.0 | y.0 | z.p | (b.p + c.p - a.p = 0) AND (a.0 - b.0 - c.0 = 0) - w_r.emplace_back(y_2); // | x.p | x.1 | y.1 | z.0 | (a.1 - b.1 - c.1 = 0) - w_o.emplace_back(z_2); // | x.2 | y.2 | z.2 | z.1 | (a.2 - b.2 - c.2 = 0) - w_4.emplace_back(z_1); // | x.3 | y.3 | z.3 | --- | (a.3 - b.3 - c.3 = 0) - w_l.emplace_back(x_3); - w_r.emplace_back(y_3); - w_o.emplace_back(z_3); - w_4.emplace_back(this->zero_idx); - - q_m.emplace_back(-addconstp); - q_1.emplace_back(0); - q_2.emplace_back(-x_mulconst0 * 2); - q_3.emplace_back(y_mulconst0 * 2); // z_0 + (x_0 * -xmulconst0) + (y_0 * ymulconst0) = 0 => z_0 = x_0 - y_0 - q_4.emplace_back(0); - q_c.emplace_back(-addconst0 * 2); - q_arith.emplace_back(3); - - q_m.emplace_back(0); - q_1.emplace_back(0); - q_2.emplace_back(-x_mulconst1); - q_3.emplace_back(y_mulconst1); - q_4.emplace_back(0); - q_c.emplace_back(-addconst1); - q_arith.emplace_back(2); - - q_m.emplace_back(0); - q_1.emplace_back(-x_mulconst2); - q_2.emplace_back(y_mulconst2); - q_3.emplace_back(1); - q_4.emplace_back(0); - q_c.emplace_back(-addconst2); - q_arith.emplace_back(1); - - q_m.emplace_back(0); - q_1.emplace_back(-x_mulconst3); - q_2.emplace_back(y_mulconst3); - q_3.emplace_back(1); - q_4.emplace_back(0); - q_c.emplace_back(-addconst3); - q_arith.emplace_back(1); + w_l().emplace_back(y_p); + w_r().emplace_back(x_0); + w_o().emplace_back(y_0); + w_4().emplace_back(z_p); + w_l().emplace_back(x_p); + w_r().emplace_back(x_1); + w_o().emplace_back(y_1); // | 1 | 2 | 3 | 4 | + w_4().emplace_back(z_0); // |-----|-----|-----|-----| + w_l().emplace_back(x_2); // | y.p | x.0 | y.0 | z.p | (b.p + c.p - a.p = 0) AND (a.0 - b.0 - c.0 = 0) + w_r().emplace_back(y_2); // | x.p | x.1 | y.1 | z.0 | (a.1 - b.1 - c.1 = 0) + w_o().emplace_back(z_2); // | x.2 | y.2 | z.2 | z.1 | (a.2 - b.2 - c.2 = 0) + w_4().emplace_back(z_1); // | x.3 | y.3 | z.3 | --- | (a.3 - b.3 - c.3 = 0) + w_l().emplace_back(x_3); + w_r().emplace_back(y_3); + w_o().emplace_back(z_3); + w_4().emplace_back(this->zero_idx); + + q_m().emplace_back(-addconstp); + q_1().emplace_back(0); + q_2().emplace_back(-x_mulconst0 * 2); + q_3().emplace_back(y_mulconst0 * 2); // z_0 + (x_0 * -xmulconst0) + (y_0 * ymulconst0) = 0 => z_0 = x_0 - y_0 + q_4().emplace_back(0); + q_c().emplace_back(-addconst0 * 2); + q_arith().emplace_back(3); + + q_m().emplace_back(0); + q_1().emplace_back(0); + q_2().emplace_back(-x_mulconst1); + q_3().emplace_back(y_mulconst1); + q_4().emplace_back(0); + q_c().emplace_back(-addconst1); + q_arith().emplace_back(2); + + q_m().emplace_back(0); + q_1().emplace_back(-x_mulconst2); + q_2().emplace_back(y_mulconst2); + q_3().emplace_back(1); + q_4().emplace_back(0); + q_c().emplace_back(-addconst2); + q_arith().emplace_back(1); + + q_m().emplace_back(0); + q_1().emplace_back(-x_mulconst3); + q_2().emplace_back(y_mulconst3); + q_3().emplace_back(1); + q_4().emplace_back(0); + q_c().emplace_back(-addconst3); + q_arith().emplace_back(1); for (size_t i = 0; i < 4; ++i) { - q_sort.emplace_back(0); - q_lookup_type.emplace_back(0); - q_elliptic.emplace_back(0); - q_aux.emplace_back(0); + q_sort().emplace_back(0); + q_lookup_type().emplace_back(0); + q_elliptic().emplace_back(0); + q_aux().emplace_back(0); selectors.pad_additional(); } check_selector_length_consistency(); @@ -2045,10 +2045,10 @@ template void UltraCircuitBuilder_:: // Record wire value can't yet be computed record.record_witness = this->add_variable(0); apply_aux_selectors(AUX_SELECTORS::ROM_READ); - w_l.emplace_back(record.index_witness); - w_r.emplace_back(record.value_column1_witness); - w_o.emplace_back(record.value_column2_witness); - w_4.emplace_back(record.record_witness); + w_l().emplace_back(record.index_witness); + w_r().emplace_back(record.value_column1_witness); + w_o().emplace_back(record.value_column2_witness); + w_4().emplace_back(record.record_witness); record.gate_index = this->num_gates; ++this->num_gates; } @@ -2065,10 +2065,10 @@ void UltraCircuitBuilder_::create_sorted_ROM_gate(RomRecord& re { record.record_witness = this->add_variable(0); apply_aux_selectors(AUX_SELECTORS::ROM_CONSISTENCY_CHECK); - w_l.emplace_back(record.index_witness); - w_r.emplace_back(record.value_column1_witness); - w_o.emplace_back(record.value_column2_witness); - w_4.emplace_back(record.record_witness); + w_l().emplace_back(record.index_witness); + w_r().emplace_back(record.value_column1_witness); + w_o().emplace_back(record.value_column2_witness); + w_4().emplace_back(record.record_witness); record.gate_index = this->num_gates; ++this->num_gates; } @@ -2111,10 +2111,10 @@ template void UltraCircuitBuilder_:: record.record_witness = this->add_variable(0); apply_aux_selectors(record.access_type == RamRecord::AccessType::READ ? AUX_SELECTORS::RAM_READ : AUX_SELECTORS::RAM_WRITE); - w_l.emplace_back(record.index_witness); - w_r.emplace_back(record.timestamp_witness); - w_o.emplace_back(record.value_witness); - w_4.emplace_back(record.record_witness); + w_l().emplace_back(record.index_witness); + w_r().emplace_back(record.timestamp_witness); + w_o().emplace_back(record.value_witness); + w_4().emplace_back(record.record_witness); record.gate_index = this->num_gates; ++this->num_gates; } @@ -2132,10 +2132,10 @@ void UltraCircuitBuilder_::create_sorted_RAM_gate(RamRecord& re { record.record_witness = this->add_variable(0); apply_aux_selectors(AUX_SELECTORS::RAM_CONSISTENCY_CHECK); - w_l.emplace_back(record.index_witness); - w_r.emplace_back(record.timestamp_witness); - w_o.emplace_back(record.value_witness); - w_4.emplace_back(record.record_witness); + w_l().emplace_back(record.index_witness); + w_r().emplace_back(record.timestamp_witness); + w_o().emplace_back(record.value_witness); + w_4().emplace_back(record.record_witness); record.gate_index = this->num_gates; ++this->num_gates; } @@ -2627,10 +2627,10 @@ template void UltraCircuitBuilder_:: uint32_t timestamp_delta_witness = this->add_variable(timestamp_delta); apply_aux_selectors(AUX_SELECTORS::RAM_TIMESTAMP_CHECK); - w_l.emplace_back(current.index_witness); - w_r.emplace_back(current.timestamp_witness); - w_o.emplace_back(timestamp_delta_witness); - w_4.emplace_back(this->zero_idx); + w_l().emplace_back(current.index_witness); + w_r().emplace_back(current.timestamp_witness); + w_o().emplace_back(timestamp_delta_witness); + w_4().emplace_back(this->zero_idx); ++this->num_gates; // store timestamp offsets for later. Need to apply range checks to them, but calling @@ -3329,26 +3329,26 @@ template bool UltraCircuitBuilder_:: FF w_4_value; FF w_4_index; // Get the values of selectors and wires and update tag products along the way - q_arith_value = q_arith[i]; - q_aux_value = q_aux[i]; - q_elliptic_value = q_elliptic[i]; - q_sort_value = q_sort[i]; - q_lookup_type_value = q_lookup_type[i]; - q_1_value = q_1[i]; - q_2_value = q_2[i]; - q_3_value = q_3[i]; - q_4_value = q_4[i]; - q_m_value = q_m[i]; - q_c_value = q_c[i]; - w_1_value = this->get_variable(w_l[i]); - update_tag_check_information(w_l[i], w_1_value); - w_2_value = this->get_variable(w_r[i]); - update_tag_check_information(w_r[i], w_2_value); - w_3_value = this->get_variable(w_o[i]); - update_tag_check_information(w_o[i], w_3_value); - w_4_value = this->get_variable(w_4[i]); + q_arith_value = q_arith()[i]; + q_aux_value = q_aux()[i]; + q_elliptic_value = q_elliptic()[i]; + q_sort_value = q_sort()[i]; + q_lookup_type_value = q_lookup_type()[i]; + q_1_value = q_1()[i]; + q_2_value = q_2()[i]; + q_3_value = q_3()[i]; + q_4_value = q_4()[i]; + q_m_value = q_m()[i]; + q_c_value = q_c()[i]; + w_1_value = this->get_variable(w_l()[i]); + update_tag_check_information(w_l()[i], w_1_value); + w_2_value = this->get_variable(w_r()[i]); + update_tag_check_information(w_r()[i], w_2_value); + w_3_value = this->get_variable(w_o()[i]); + update_tag_check_information(w_o()[i], w_3_value); + w_4_value = this->get_variable(w_4()[i]); // We need to wait before updating tag product for w_4 - w_4_index = w_4[i]; + w_4_index = w_4()[i]; // If we are touching a gate with memory access, we need to update the value of the 4th witness if (memory_read_record_gates.contains(i)) { @@ -3364,10 +3364,10 @@ template bool UltraCircuitBuilder_:: FF w_3_shifted_value; FF w_4_shifted_value; if (i < (this->num_gates - 1)) { - w_1_shifted_value = this->get_variable(w_l[i + 1]); - w_2_shifted_value = this->get_variable(w_r[i + 1]); - w_3_shifted_value = this->get_variable(w_o[i + 1]); - w_4_shifted_value = this->get_variable(w_4[i + 1]); + w_1_shifted_value = this->get_variable(w_l()[i + 1]); + w_2_shifted_value = this->get_variable(w_r()[i + 1]); + w_3_shifted_value = this->get_variable(w_o()[i + 1]); + w_4_shifted_value = this->get_variable(w_4()[i + 1]); } else { w_1_shifted_value = FF::zero(); w_2_shifted_value = FF::zero(); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp index 9767781e72d..14c7f9cc2b9 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp @@ -344,21 +344,21 @@ class UltraCircuitBuilder_ : public CircuitBuilderBasecircuit_finalized = circuit_finalized; builder->num_gates = num_gates; builder->cached_partial_non_native_field_multiplications = cached_partial_non_native_field_multiplications; - builder->w_l.resize(num_gates); - builder->w_r.resize(num_gates); - builder->w_o.resize(num_gates); - builder->w_4.resize(num_gates); - builder->q_m.resize(num_gates); - builder->q_c.resize(num_gates); - builder->q_1.resize(num_gates); - builder->q_2.resize(num_gates); - builder->q_3.resize(num_gates); - builder->q_4.resize(num_gates); - builder->q_arith.resize(num_gates); - builder->q_sort.resize(num_gates); - builder->q_elliptic.resize(num_gates); - builder->q_aux.resize(num_gates); - builder->q_lookup_type.resize(num_gates); + builder->w_l().resize(num_gates); + builder->w_r().resize(num_gates); + builder->w_o().resize(num_gates); + builder->w_4().resize(num_gates); + builder->q_m().resize(num_gates); + builder->q_c().resize(num_gates); + builder->q_1().resize(num_gates); + builder->q_2().resize(num_gates); + builder->q_3().resize(num_gates); + builder->q_4().resize(num_gates); + builder->q_arith().resize(num_gates); + builder->q_sort().resize(num_gates); + builder->q_elliptic().resize(num_gates); + builder->q_aux().resize(num_gates); + builder->q_lookup_type().resize(num_gates); } /** * @brief Checks that the circuit state is the same as the stored circuit's one @@ -489,49 +489,49 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase>; using SelectorVector = std::vector>; - WireVector& w_l = std::get<0>(wires); - WireVector& w_r = std::get<1>(wires); - WireVector& w_o = std::get<2>(wires); - WireVector& w_4 = std::get<3>(wires); - - SelectorVector& q_m = selectors.q_m(); - SelectorVector& q_c = selectors.q_c(); - SelectorVector& q_1 = selectors.q_1(); - SelectorVector& q_2 = selectors.q_2(); - SelectorVector& q_3 = selectors.q_3(); - SelectorVector& q_4 = selectors.q_4(); - SelectorVector& q_arith = selectors.q_arith(); - SelectorVector& q_sort = selectors.q_sort(); - SelectorVector& q_elliptic = selectors.q_elliptic(); - SelectorVector& q_aux = selectors.q_aux(); - SelectorVector& q_lookup_type = selectors.q_lookup_type(); + WireVector& w_l() { return std::get<0>(wires); }; + WireVector& w_r() { return std::get<1>(wires); }; + WireVector& w_o() { return std::get<2>(wires); }; + WireVector& w_4() { return std::get<3>(wires); }; + + const WireVector& w_l() const { return std::get<0>(wires); }; + const WireVector& w_r() const { return std::get<1>(wires); }; + const WireVector& w_o() const { return std::get<2>(wires); }; + const WireVector& w_4() const { return std::get<3>(wires); }; + + SelectorVector& q_m() { return selectors.q_m(); }; + SelectorVector& q_c() { return selectors.q_c(); }; + SelectorVector& q_1() { return selectors.q_1(); }; + SelectorVector& q_2() { return selectors.q_2(); }; + SelectorVector& q_3() { return selectors.q_3(); }; + SelectorVector& q_4() { return selectors.q_4(); }; + SelectorVector& q_arith() { return selectors.q_arith(); }; + SelectorVector& q_sort() { return selectors.q_sort(); }; + SelectorVector& q_elliptic() { return selectors.q_elliptic(); }; + SelectorVector& q_aux() { return selectors.q_aux(); }; + SelectorVector& q_lookup_type() { return selectors.q_lookup_type(); }; + + const SelectorVector& q_c() const { return selectors.q_c(); }; + const SelectorVector& q_1() const { return selectors.q_1(); }; + const SelectorVector& q_2() const { return selectors.q_2(); }; + const SelectorVector& q_3() const { return selectors.q_3(); }; + const SelectorVector& q_4() const { return selectors.q_4(); }; + const SelectorVector& q_arith() const { return selectors.q_arith(); }; + const SelectorVector& q_sort() const { return selectors.q_sort(); }; + const SelectorVector& q_elliptic() const { return selectors.q_elliptic(); }; + const SelectorVector& q_aux() const { return selectors.q_aux(); }; + const SelectorVector& q_lookup_type() const { return selectors.q_lookup_type(); }; + const SelectorVector& q_m() const { return selectors.q_m(); }; // These are variables that we have used a gate on, to enforce that they are // equal to a defined value. @@ -632,14 +649,14 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase(size_hint) { selectors.reserve(size_hint); - w_l.reserve(size_hint); - w_r.reserve(size_hint); - w_o.reserve(size_hint); - w_4.reserve(size_hint); + w_l().reserve(size_hint); + w_r().reserve(size_hint); + w_o().reserve(size_hint); + w_4().reserve(size_hint); this->zero_idx = put_constant_variable(FF::zero()); this->tau.insert({ DUMMY_TAG, DUMMY_TAG }); // TODO(luke): explain this }; - UltraCircuitBuilder_(const UltraCircuitBuilder_& other) = delete; + UltraCircuitBuilder_(const UltraCircuitBuilder_& other) = default; UltraCircuitBuilder_(UltraCircuitBuilder_&& other) : CircuitBuilderBase(std::move(other)) { @@ -657,7 +674,7 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase::operator=(std::move(other)); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp index 608727c812a..6af8c8ad259 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.test.cpp @@ -11,6 +11,34 @@ namespace proof_system { using plookup::ColumnIdx; using plookup::MultiTableId; +TEST(ultra_circuit_constructor, copy_constructor) +{ + UltraCircuitBuilder circuit_constructor = UltraCircuitBuilder(); + + for (size_t i = 0; i < 16; ++i) { + for (size_t j = 0; j < 16; ++j) { + uint64_t left = static_cast(j); + uint64_t right = static_cast(i); + uint32_t left_idx = circuit_constructor.add_variable(fr(left)); + uint32_t right_idx = circuit_constructor.add_variable(fr(right)); + uint32_t result_idx = circuit_constructor.add_variable(fr(left ^ right)); + + uint32_t add_idx = + circuit_constructor.add_variable(fr(left) + fr(right) + circuit_constructor.get_variable(result_idx)); + circuit_constructor.create_big_add_gate( + { left_idx, right_idx, result_idx, add_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) }); + } + } + + bool result = circuit_constructor.check_circuit(); + EXPECT_EQ(result, true); + + UltraCircuitBuilder duplicate_circuit_constructor{ circuit_constructor }; + + EXPECT_EQ(duplicate_circuit_constructor.get_num_gates(), circuit_constructor.get_num_gates()); + EXPECT_TRUE(duplicate_circuit_constructor.check_circuit()); +} + TEST(ultra_circuit_constructor, create_gates_from_plookup_accumulators) { @@ -742,6 +770,12 @@ TEST(ultra_circuit_constructor, ram) EXPECT_EQ(result, true); EXPECT_TRUE(saved_state.is_same_state(circuit_constructor)); + + // Test the builder copy constructor for a circuit with RAM gates + UltraCircuitBuilder duplicate_circuit_constructor{ circuit_constructor }; + + EXPECT_EQ(duplicate_circuit_constructor.get_num_gates(), circuit_constructor.get_num_gates()); + EXPECT_TRUE(duplicate_circuit_constructor.check_circuit()); } TEST(ultra_circuit_constructor, range_checks_on_duplicates) diff --git a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp index 8546d793f28..0b5788b8ff7 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.test.cpp @@ -22,11 +22,11 @@ class ComposerLibTests : public ::testing::Test { TEST_F(ComposerLibTests, ConstructSelectors) { - circuit_constructor.q_m = { 1, 2, 3, 4 }; - circuit_constructor.q_1 = { 5, 6, 7, 8 }; - circuit_constructor.q_2 = { 9, 10, 11, 12 }; - circuit_constructor.q_3 = { 13, 14, 15, 16 }; - circuit_constructor.q_c = { 17, 18, 19, 20 }; + circuit_constructor.q_m() = { 1, 2, 3, 4 }; + circuit_constructor.q_1() = { 5, 6, 7, 8 }; + circuit_constructor.q_2() = { 9, 10, 11, 12 }; + circuit_constructor.q_3() = { 13, 14, 15, 16 }; + circuit_constructor.q_c() = { 17, 18, 19, 20 }; construct_selector_polynomials(circuit_constructor, &proving_key); size_t offset = 0; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp index 9ed50192778..f7670c9c7da 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/primitives/field/field.test.cpp @@ -183,7 +183,7 @@ template class stdlib_field : public testing::Test { auto gates_before = builder.get_num_gates(); uint64_t expected = fidget(builder); auto gates_after = builder.get_num_gates(); - EXPECT_EQ(builder.get_variable(builder.w_o[gates_after - 1]), fr(expected)); + EXPECT_EQ(builder.get_variable(builder.w_o()[gates_after - 1]), fr(expected)); info("Number of gates added", gates_after - gates_before); bool result = builder.check_circuit(); EXPECT_EQ(result, true); @@ -257,7 +257,7 @@ template class stdlib_field : public testing::Test { auto gates_before = builder.get_num_gates(); fibbonaci(builder); auto gates_after = builder.get_num_gates(); - EXPECT_EQ(builder.get_variable(builder.w_l[builder.get_num_gates() - 1]), fr(4181)); + EXPECT_EQ(builder.get_variable(builder.w_l()[builder.get_num_gates() - 1]), fr(4181)); EXPECT_EQ(gates_after - gates_before, 18UL); bool result = builder.check_circuit();