From 030c9124ef197d3921609353f5ffa201a0948211 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 30 Nov 2023 19:07:03 +0000 Subject: [PATCH 1/3] chore: remove usage of pointer_view --- .../cpp/src/barretenberg/common/ref_array.hpp | 13 ++-- .../src/barretenberg/common/ref_vector.hpp | 2 +- .../cpp/src/barretenberg/common/serialize.hpp | 10 +-- .../src/barretenberg/eccvm/eccvm_prover.cpp | 13 ++-- .../cpp/src/barretenberg/flavor/ecc_vm.hpp | 17 ++--- .../cpp/src/barretenberg/flavor/flavor.hpp | 10 +-- .../src/barretenberg/flavor/flavor.test.cpp | 4 +- .../src/barretenberg/flavor/flavor_macros.hpp | 24 +------ .../flavor/generated/AvmMini_flavor.hpp | 8 +-- .../flavor/generated/Fib_flavor.hpp | 8 +-- .../barretenberg/flavor/goblin_translator.hpp | 19 ++---- .../src/barretenberg/flavor/goblin_ultra.hpp | 8 +-- .../cpp/src/barretenberg/flavor/ultra.hpp | 8 +-- .../honk/proof_system/permutation_library.hpp | 4 +- .../src/barretenberg/honk/utils/testing.hpp | 15 ++--- .../barretenberg/honk/utils/testing.test.cpp | 2 +- .../eccvm/eccvm_circuit_builder.hpp | 4 +- .../generated/AvmMini_circuit_builder.hpp | 4 +- .../generated/Fib_circuit_builder.hpp | 4 +- .../proof_system/composer/composer_lib.hpp | 6 +- .../library/grand_product_library.hpp | 7 +- .../protogalaxy/protogalaxy_prover.hpp | 5 +- .../sumcheck/instance/instances.hpp | 16 ++--- .../sumcheck/partial_evaluation.test.cpp | 24 +++---- .../src/barretenberg/sumcheck/sumcheck.hpp | 21 +++--- .../barretenberg/sumcheck/sumcheck.test.cpp | 29 ++++---- .../barretenberg/sumcheck/sumcheck_round.hpp | 7 +- .../ultra_honk/relation_correctness.test.cpp | 66 +++++++++---------- 28 files changed, 152 insertions(+), 206 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/common/ref_array.hpp b/barretenberg/cpp/src/barretenberg/common/ref_array.hpp index f9c9fa11f3b..95224d8f7da 100644 --- a/barretenberg/cpp/src/barretenberg/common/ref_array.hpp +++ b/barretenberg/cpp/src/barretenberg/common/ref_array.hpp @@ -25,15 +25,11 @@ template class RefArray { storage[i++] = &elem; } } - RefArray(std::initializer_list init) + template RefArray(T& ref, Ts&... rest) { - if (init.size() != N) { - throw std::invalid_argument("Initializer list size does not match RefArray size"); - } - std::size_t i = 0; - for (auto& elem : init) { - storage[i++] = &elem; - } + storage[0] = &ref; + int i = 1; + ((storage[i++] = &rest), ...); } T& operator[](std::size_t idx) const @@ -82,6 +78,7 @@ template class RefArray { std::size_t pos; }; + constexpr std::size_t size() const { return N; } /** * @brief Returns an iterator to the beginning of the RefArray. * diff --git a/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp b/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp index fa47379ba83..5304f8ea77a 100644 --- a/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp +++ b/barretenberg/cpp/src/barretenberg/common/ref_vector.hpp @@ -84,7 +84,7 @@ template class RefVector { std::size_t pos; }; - [[nodiscard]] std::size_t size() const { return storage.size(); } + std::size_t size() const { return storage.size(); } void push_back(T& element) { storage.push_back(element); } iterator begin() const { return iterator(this, 0); } diff --git a/barretenberg/cpp/src/barretenberg/common/serialize.hpp b/barretenberg/cpp/src/barretenberg/common/serialize.hpp index 7142b99cb32..2489b3703b1 100644 --- a/barretenberg/cpp/src/barretenberg/common/serialize.hpp +++ b/barretenberg/cpp/src/barretenberg/common/serialize.hpp @@ -371,14 +371,14 @@ template inline void read(B& it, std::optional& opt_ } template -concept HasPointerView = requires(T t) { t.pointer_view(); }; +concept HasGetAll = requires(T t) { t.get_all(); }; -// Write out a struct that defines pointer_view() -template inline void write(B& buf, T const& value) +// Write out a struct that defines get_all() +template inline void write(B& buf, T const& value) { using serialize::write; - for (auto* pointer : value.pointer_view()) { - write(buf, *pointer); + for (auto& reference : value.get_all()) { + write(buf, reference); } } diff --git a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp index f06aea8497b..3aadb40a639 100644 --- a/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/eccvm/eccvm_prover.cpp @@ -1,6 +1,7 @@ #include "eccvm_prover.hpp" #include "barretenberg/commitment_schemes/claim.hpp" #include "barretenberg/commitment_schemes/commitment_key.hpp" +#include "barretenberg/common/ref_array.hpp" #include "barretenberg/honk/proof_system/lookup_library.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/honk/proof_system/power_polynomial.hpp" @@ -344,18 +345,16 @@ template void ECCVMProver_::execute_transcript_cons FF batching_challenge = transcript.get_challenge("Translation:batching_challenge"); // Collect the polynomials and evaluations to be batched - const size_t NUM_UNIVARIATES = 6; // 5 transcript polynomials plus the constant hack poly - std::array univariate_polynomials = { &key->transcript_op, &key->transcript_Px, - &key->transcript_Py, &key->transcript_z1, - &key->transcript_z2, &hack }; - std::array univariate_evaluations; + RefArray univariate_polynomials{ key->transcript_op, key->transcript_Px, key->transcript_Py, + key->transcript_z1, key->transcript_z2, hack }; + std::array univariate_evaluations; // Constuct the batched polynomial and batched evaluation Polynomial batched_univariate{ key->circuit_size }; FF batched_evaluation{ 0 }; auto batching_scalar = FF(1); - for (auto [eval, polynomial] : zip_view(univariate_evaluations, univariate_polynomials)) { - batched_univariate.add_scaled(*polynomial, batching_scalar); + for (auto [polynomial, eval] : zip_view(univariate_polynomials, univariate_evaluations)) { + batched_univariate.add_scaled(polynomial, batching_scalar); batched_evaluation += eval * batching_scalar; batching_scalar *= batching_challenge; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 0b938556ae5..ef2360bdb55 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -202,8 +202,6 @@ template class ECCVMBa class WitnessEntities : public WireEntities, public DerivedWitnessEntities { public: DEFINE_COMPOUND_GET_ALL(WireEntities::get_all(), DerivedWitnessEntities::get_all()) - DEFINE_COMPOUND_POINTER_VIEW(WireEntities::pointer_view(), - DerivedWitnessEntities::pointer_view()) RefVector get_wires() { return WireEntities::get_all(); }; // The sorted concatenations of table and witness data needed for plookup. RefVector get_sorted_polynomials() { return {}; }; @@ -268,9 +266,6 @@ template class ECCVMBa DEFINE_COMPOUND_GET_ALL(PrecomputedEntities::get_all(), WitnessEntities::get_all(), ShiftedEntities::get_all()) - DEFINE_COMPOUND_POINTER_VIEW(PrecomputedEntities::pointer_view(), - WitnessEntities::pointer_view(), - ShiftedEntities::pointer_view()) // Gemini-specific getters. RefVector get_unshifted() { @@ -369,8 +364,8 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { + result_field = polynomial[row_idx]; } return result; } @@ -391,8 +386,8 @@ template class ECCVMBa PartiallyEvaluatedMultivariates(const size_t circuit_size) { // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) - for (auto* poly : this->pointer_view()) { - *poly = Polynomial(circuit_size / 2); + for (auto& poly : this->get_all()) { + poly = Polynomial(circuit_size / 2); } } }; @@ -419,8 +414,8 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { + result_field = polynomial[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 4d29ca7ffb2..d2b16d473cf 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -105,7 +105,7 @@ class ProvingKey_ : public PrecomputedPolynomials, public WitnessPolynomials { std::vector recursive_proof_public_input_indices; barretenberg::EvaluationDomain evaluation_domain; - auto precomputed_polynomials_pointer_view() { return PrecomputedPolynomials::pointer_view(); } + auto precomputed_polynomials_get_all() { return PrecomputedPolynomials::get_all(); } ProvingKey_() = default; ProvingKey_(const size_t circuit_size, const size_t num_public_inputs) { @@ -114,12 +114,12 @@ class ProvingKey_ : public PrecomputedPolynomials, public WitnessPolynomials { this->log_circuit_size = numeric::get_msb(circuit_size); this->num_public_inputs = num_public_inputs; // Allocate memory for precomputed polynomials - for (auto* poly : PrecomputedPolynomials::pointer_view()) { - *poly = Polynomial(circuit_size); + for (auto& poly : PrecomputedPolynomials::get_all()) { + poly = Polynomial(circuit_size); } // Allocate memory for witness polynomials - for (auto* poly : WitnessPolynomials::pointer_view()) { - *poly = Polynomial(circuit_size); + for (auto& poly : WitnessPolynomials::get_all()) { + poly = Polynomial(circuit_size); } }; }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp index 4b2c8fc2752..ad4692dc26b 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.test.cpp @@ -135,8 +135,8 @@ TEST(Flavor, GetRow) return std::vector({ FF::random_element(), FF::random_element() }); }); Flavor::ProverPolynomials prover_polynomials; - for (auto [poly, entry] : zip_view(prover_polynomials.pointer_view(), data)) { - *poly = entry; + for (auto [poly, entry] : zip_view(prover_polynomials.get_all(), data)) { + poly = entry; } auto row0 = prover_polynomials.get_row(0); auto row1 = prover_polynomials.get_row(1); diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor_macros.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor_macros.hpp index c378aa51489..d25bb4eb513 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor_macros.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor_macros.hpp @@ -3,7 +3,7 @@ // Macros for defining the flavor classes. // These are used to derive iterator methods along with the body of a 'flavor' class. // DEFINE_FLAVOR_MEMBERS lets you define a flavor entity as a collection of individual members, and derive an iterator. -// while DEFINE_COMPOUND_GET_ALL and DEFINE_COMPOUND_POINTER_VIEW let you combine the iterators of substructures or base +// while DEFINE_COMPOUND_GET_ALL lets you combine the iterators of substructures or base // classes. #include "barretenberg/common/ref_vector.hpp" @@ -17,17 +17,6 @@ template auto _refs_to_pointer_array(Refs&... refs) return std::array{ &refs... }; } -// @deprecated this was less natural than the ref view -#define DEFINE_POINTER_VIEW(...) \ - [[nodiscard]] auto pointer_view() \ - { \ - return _refs_to_pointer_array(__VA_ARGS__); \ - } \ - [[nodiscard]] auto pointer_view() const \ - { \ - return _refs_to_pointer_array(__VA_ARGS__); \ - } - #define DEFINE_REF_VIEW(...) \ [[nodiscard]] auto get_all() \ { \ @@ -47,19 +36,8 @@ template auto _refs_to_pointer_array(Refs&... refs) */ #define DEFINE_FLAVOR_MEMBERS(DataType, ...) \ DataType __VA_ARGS__; \ - DEFINE_POINTER_VIEW(__VA_ARGS__) \ DEFINE_REF_VIEW(__VA_ARGS__) -#define DEFINE_COMPOUND_POINTER_VIEW(...) \ - [[nodiscard]] auto pointer_view() \ - { \ - return concatenate(__VA_ARGS__); \ - } \ - [[nodiscard]] auto pointer_view() const \ - { \ - return concatenate(__VA_ARGS__); \ - } - #define DEFINE_COMPOUND_GET_ALL(...) \ [[nodiscard]] auto get_all() \ { \ diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp index 7f2b128a3f2..8eba8ee485c 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/AvmMini_flavor.hpp @@ -222,8 +222,8 @@ class AvmMiniFlavor { [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), get_all())) { + result_field = polynomial[row_idx]; } return result; } @@ -237,8 +237,8 @@ class AvmMiniFlavor { PartiallyEvaluatedMultivariates(const size_t circuit_size) { // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) - for (auto* poly : pointer_view()) { - *poly = Polynomial(circuit_size / 2); + for (auto& poly : get_all()) { + poly = Polynomial(circuit_size / 2); } } }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/generated/Fib_flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/generated/Fib_flavor.hpp index 031410e2df2..064a9c101c3 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/generated/Fib_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/generated/Fib_flavor.hpp @@ -164,8 +164,8 @@ class FibFlavor { [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), get_all())) { + result_field = polynomial[row_idx]; } return result; } @@ -179,8 +179,8 @@ class FibFlavor { PartiallyEvaluatedMultivariates(const size_t circuit_size) { // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) - for (auto* poly : pointer_view()) { - *poly = Polynomial(circuit_size / 2); + for (auto& poly : get_all()) { + poly = Polynomial(circuit_size / 2); } } }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index d649a88f392..bfdcfd4e438 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -250,10 +250,6 @@ class GoblinTranslator { WireToBeShiftedEntities::get_all(), DerivedWitnessEntities::get_all(), ConcatenatedRangeConstraints::get_all()) - DEFINE_COMPOUND_POINTER_VIEW(WireNonshiftedEntities::pointer_view(), - WireToBeShiftedEntities::pointer_view(), - DerivedWitnessEntities::pointer_view(), - ConcatenatedRangeConstraints::pointer_view()) RefVector get_wires() { @@ -654,9 +650,6 @@ class GoblinTranslator { DEFINE_COMPOUND_GET_ALL(PrecomputedEntities::get_all(), WitnessEntities::get_all(), ShiftedEntities::get_all()) - DEFINE_COMPOUND_POINTER_VIEW(PrecomputedEntities::pointer_view(), - WitnessEntities::pointer_view(), - ShiftedEntities::pointer_view()) /** * @brief Get the polynomials that are concatenated for the permutation relation * @@ -1036,8 +1029,8 @@ class GoblinTranslator { [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { + result_field = polynomial[row_idx]; } return result; } @@ -1064,8 +1057,8 @@ class GoblinTranslator { [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { + result_field = polynomial[row_idx]; } return result; } @@ -1086,8 +1079,8 @@ class GoblinTranslator { PartiallyEvaluatedMultivariates(const size_t circuit_size) { // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) - for (auto* poly : this->pointer_view()) { - *poly = Polynomial(circuit_size / 2); + for (auto& poly : this->get_all()) { + poly = Polynomial(circuit_size / 2); } } }; diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 96cf254eb1d..68dd2dfa2f1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -333,8 +333,8 @@ class GoblinUltra { PartiallyEvaluatedMultivariates(const size_t circuit_size) { // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) - for (auto* poly : this->pointer_view()) { - *poly = Polynomial(circuit_size / 2); + for (auto& poly : this->get_all()) { + poly = Polynomial(circuit_size / 2); } } }; @@ -369,8 +369,8 @@ class GoblinUltra { [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) { + result_field = polynomial[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp index 93a716820cd..d8c2d87668b 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -272,8 +272,8 @@ class Ultra { [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.pointer_view(), pointer_view())) { - *result_field = (*polynomial)[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_all(), get_all())) { + result_field = polynomial[row_idx]; } return result; } @@ -289,8 +289,8 @@ class Ultra { PartiallyEvaluatedMultivariates(const size_t circuit_size) { // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) - for (auto* poly : this->pointer_view()) { - *poly = Polynomial(circuit_size / 2); + for (auto& poly : this->get_all()) { + poly = Polynomial(circuit_size / 2); } } }; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp index de07bda2534..5c1c4392a8f 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -70,8 +70,8 @@ void compute_permutation_grand_product(const size_t circuit_size, for (size_t i = start; i < end; ++i) { typename Flavor::AllValues evaluations; - for (auto [eval, poly] : zip_view(evaluations.pointer_view(), full_polynomials.pointer_view())) { - *eval = poly->size() > i ? (*poly)[i] : 0; + for (auto [eval, poly] : zip_view(evaluations.get_all(), full_polynomials.get_all())) { + eval = poly.size() > i ? poly[i] : 0; } numerator[i] = GrandProdRelation::template compute_permutation_numerator(evaluations, relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index fa7c124a843..37c056609ee 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -1,4 +1,5 @@ #pragma once +#include "barretenberg/common/zip_view.hpp" #include "barretenberg/polynomials/polynomial.hpp" namespace proof_system::honk { @@ -27,11 +28,8 @@ get_sequential_prover_polynomials(const size_t log_circuit_size, const size_t st } ProverPolynomials prover_polynomials; - auto prover_polynomials_pointers = prover_polynomials.pointer_view(); - size_t poly_idx = 0; - for (auto& polynomial : storage) { - *prover_polynomials_pointers[poly_idx] = polynomial; - poly_idx++; + for (auto [prover_poly, storage_poly] : zip_view(prover_polynomials.get_all(), storage)) { + prover_poly = storage_poly; } return std::pair(std::move(storage), prover_polynomials); @@ -56,11 +54,8 @@ get_zero_prover_polynomials(const size_t log_circuit_size) } ProverPolynomials prover_polynomials; - size_t poly_idx = 0; - auto prover_polynomial_pointers = prover_polynomials.pointer_view(); - for (auto& polynomial : storage) { - *prover_polynomial_pointers[poly_idx] = polynomial; - poly_idx++; + for (auto [prover_poly, storage_poly] : zip_view(prover_polynomials.get_all(), storage)) { + prover_poly = storage_poly; } return std::pair(std::move(storage), prover_polynomials); diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.test.cpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.test.cpp index 01e816c5fb8..c4b5fda266c 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.test.cpp @@ -9,7 +9,7 @@ TEST(HonkTestingUtils, ProverPolynomials) using Flavor = proof_system::honk::flavor::Ultra; auto [storage, prover_polynomials] = proof_system::honk::get_sequential_prover_polynomials(/*log_circuit_size=*/2, /*starting_value=*/0); - auto& first_polynomial = *prover_polynomials.pointer_view()[0]; + auto& first_polynomial = prover_polynomials.get_all()[0]; EXPECT_EQ(storage[0][0], first_polynomial[0]); EXPECT_EQ(storage[0][1], first_polynomial[1]); }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp index 9468df3aa6e..4abbd5bc91f 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp @@ -340,8 +340,8 @@ template class ECCVMCircuitBuilder { size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); AllPolynomials polys; - for (auto* poly : polys.pointer_view()) { - *poly = Polynomial(num_rows_pow2); + for (auto& poly : polys.get_all()) { + poly = Polynomial(num_rows_pow2); } polys.lagrange_first[0] = 1; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp index 1bf6093681e..7495c9a23f2 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/AvmMini_circuit_builder.hpp @@ -36,8 +36,8 @@ class AvmMiniCircuitBuilder { AllPolynomials polys; // Allocate mem for each column - for (auto* poly : polys.pointer_view()) { - *poly = Polynomial(num_rows); + for (auto& poly : polys.get_all()) { + poly = Polynomial(num_rows); } for (size_t i = 0; i < rows.size(); i++) { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp index 3af3ba87fac..a233692ebf7 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/generated/Fib_circuit_builder.hpp @@ -36,8 +36,8 @@ class FibCircuitBuilder { AllPolynomials polys; // Allocate mem for each column - for (auto* poly : polys.pointer_view()) { - *poly = Polynomial(num_rows); + for (auto& poly : polys.get_all()) { + poly = Polynomial(num_rows); } for (size_t i = 0; i < rows.size(); i++) { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp index 93884466ba0..728a5cbfda3 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp @@ -40,8 +40,8 @@ void construct_selector_polynomials(const typename Flavor::CircuitBuilder& circu // TODO(#398): Loose coupling here! Would rather build up pk from arithmetization if constexpr (IsHonkFlavor) { - for (auto [poly_ptr, selector_values] : - zip_view(proving_key->precomputed_polynomials_pointer_view(), circuit_constructor.selectors.get())) { + for (auto [poly, selector_values] : + zip_view(proving_key->precomputed_polynomials_get_all(), circuit_constructor.selectors.get())) { ASSERT(proving_key->circuit_size >= selector_values.size()); // Copy the selector values for all gates, keeping the rows at which we store public inputs as 0. @@ -50,7 +50,7 @@ void construct_selector_polynomials(const typename Flavor::CircuitBuilder& circu for (size_t i = 0; i < selector_values.size(); ++i) { selector_poly_lagrange[i + gate_offset] = selector_values[i]; } - *poly_ptr = selector_poly_lagrange; + poly = selector_poly_lagrange; } } else if constexpr (IsPlonkFlavor) { size_t selector_idx = 0; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp index e20214639f8..e1c2ac20115 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/library/grand_product_library.hpp @@ -64,16 +64,15 @@ void compute_grand_product(const size_t circuit_size, // Populate `numerator` and `denominator` with the algebra described by Relation const size_t num_threads = circuit_size >= get_num_cpus_pow2() ? get_num_cpus_pow2() : 1; const size_t block_size = circuit_size / num_threads; - auto full_polynomial_pointers = full_polynomials.pointer_view(); + auto full_polynomial_pointers = full_polynomials.get_all(); parallel_for(num_threads, [&](size_t thread_idx) { const size_t start = thread_idx * block_size; const size_t end = (thread_idx + 1) * block_size; for (size_t i = start; i < end; ++i) { typename Flavor::AllValues evaluations; - auto evaluations_pointer = evaluations.pointer_view(); + auto evaluations_pointer = evaluations.get_all(); for (size_t k = 0; k < Flavor::NUM_ALL_ENTITIES; ++k) { - *evaluations_pointer[k] = - (*full_polynomial_pointers[k]).size() > i ? (*full_polynomial_pointers[k])[i] : 0; + evaluations_pointer[k] = full_polynomial_pointers[k].size() > i ? full_polynomial_pointers[k][i] : 0; } numerator[i] = GrandProdRelation::template compute_grand_product_numerator( evaluations, relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 5429be9161f..0a5c8777768 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -213,9 +213,8 @@ template class ProtoGalaxyProver_ { const size_t row_idx) { auto base_univariates = instances.row_to_univariates(row_idx); - for (auto [extended_univariate, base_univariate] : - zip_view(extended_univariates.pointer_view(), base_univariates)) { - *extended_univariate = base_univariate.template extend_to(); + for (auto [extended_univariate, base_univariate] : zip_view(extended_univariates.get_all(), base_univariates)) { + extended_univariate = base_univariate.template extend_to(); } } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp index 0a30c6d3ecb..1fc658eae9c 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/instance/instances.hpp @@ -54,17 +54,17 @@ template struct ProverInstances_ { */ std::vector> row_to_univariates(size_t row_idx) const { - auto instance_polynomial_views = get_polynomial_pointer_views(); + auto instance_polynomial_views = get_polynomial_views(); std::vector> results; // Initialize to our amount of columns results.resize(instance_polynomial_views[0].size()); size_t instance_idx = 0; // Iterate instances - for (auto& pointer_view : instance_polynomial_views) { + for (auto& get_all : instance_polynomial_views) { // Iterate columns - for (auto [result, poly_ptr] : zip_view(results, pointer_view)) { + for (auto [result, poly_ptr] : zip_view(results, get_all)) { // Assign row for each instance - result.evaluations[instance_idx] = (*poly_ptr)[row_idx]; + result.evaluations[instance_idx] = (poly_ptr)[row_idx]; } instance_idx++; } @@ -72,15 +72,15 @@ template struct ProverInstances_ { } private: - auto get_polynomial_pointer_views() const + auto get_polynomial_views() const { // As a practical measure, get the first instance's pointer view to deduce the vector type - std::vector pointer_views{ _data[0]->prover_polynomials.pointer_view() }; + std::vector get_alls{ _data[0]->prover_polynomials.get_all() }; // complete the views, starting from the second item for (size_t i = 1; i < NUM; i++) { - pointer_views.push_back(_data[i]->prover_polynomials.pointer_view()); + get_alls.push_back(_data[i]->prover_polynomials.get_all()); } - return pointer_views; + return get_alls; } }; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index 52c92c707ec..c262d274d05 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -66,7 +66,7 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + auto& first_polynomial = sumcheck.partially_evaluated_polynomials.get_all()[0]; EXPECT_EQ(first_polynomial[0], round_challenge_0); EXPECT_EQ(first_polynomial[1], FF(0)); @@ -102,7 +102,7 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) FF expected_hi = v01 * (FF(1) - round_challenge_0) + v11 * round_challenge_0; sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + auto& first_polynomial = sumcheck.partially_evaluated_polynomials.get_all()[0]; EXPECT_EQ(first_polynomial[0], expected_lo); EXPECT_EQ(first_polynomial[1], expected_hi); @@ -167,7 +167,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + auto& first_polynomial = sumcheck.partially_evaluated_polynomials.get_all()[0]; EXPECT_EQ(first_polynomial[0], expected_q1); EXPECT_EQ(first_polynomial[1], expected_q2); EXPECT_EQ(first_polynomial[2], expected_q3); @@ -217,7 +217,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) FF expected_q3 = v001 * (FF(1) - round_challenge_0) + v101 * round_challenge_0; FF expected_q4 = v011 * (FF(1) - round_challenge_0) + v111 * round_challenge_0; - auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + auto& first_polynomial = sumcheck.partially_evaluated_polynomials.get_all()[0]; sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); EXPECT_EQ(first_polynomial[0], expected_q1); @@ -287,12 +287,12 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto polynomial_pointer_view = sumcheck.partially_evaluated_polynomials.pointer_view(); + auto polynomial_get_all = sumcheck.partially_evaluated_polynomials.get_all(); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_q1[i]); - EXPECT_EQ((*polynomial_pointer_view[i])[1], expected_q2[i]); - EXPECT_EQ((*polynomial_pointer_view[i])[2], expected_q3[i]); - EXPECT_EQ((*polynomial_pointer_view[i])[3], expected_q4[i]); + EXPECT_EQ((polynomial_get_all[i])[0], expected_q1[i]); + EXPECT_EQ((polynomial_get_all[i])[1], expected_q2[i]); + EXPECT_EQ((polynomial_get_all[i])[2], expected_q3[i]); + EXPECT_EQ((polynomial_get_all[i])[3], expected_q4[i]); } FF round_challenge_1 = FF::random_element(); @@ -304,8 +304,8 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_lo[i]); - EXPECT_EQ((*polynomial_pointer_view[i])[1], expected_hi[i]); + EXPECT_EQ((polynomial_get_all[i])[0], expected_lo[i]); + EXPECT_EQ((polynomial_get_all[i])[1], expected_hi[i]); } FF round_challenge_2 = FF::random_element(); std::array expected_val; @@ -314,7 +314,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_val[i]); + EXPECT_EQ((polynomial_get_all[i])[0], expected_val[i]); } } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 980afc3490b..da4e2a9e61b 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -108,8 +108,8 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; for (auto [eval, poly] : - zip_view(multivariate_evaluations.pointer_view(), partially_evaluated_polynomials.pointer_view())) { - *eval = (*poly)[0]; + zip_view(multivariate_evaluations.get_all(), partially_evaluated_polynomials.get_all())) { + eval = (poly)[0]; } transcript.send_to_verifier("Sumcheck:evaluations", multivariate_evaluations); @@ -142,13 +142,12 @@ template class SumcheckProver { */ void partially_evaluate(auto& polynomials, size_t round_size, FF round_challenge) { - auto pep_view = partially_evaluated_polynomials.pointer_view(); - auto poly_view = polynomials.pointer_view(); + auto pep_view = partially_evaluated_polynomials.get_all(); + auto poly_view = polynomials.get_all(); // after the first round, operate in place on partially_evaluated_polynomials parallel_for(poly_view.size(), [&](size_t j) { for (size_t i = 0; i < round_size; i += 2) { - (*pep_view[j])[i >> 1] = - (*poly_view[j])[i] + round_challenge * ((*poly_view[j])[i + 1] - (*poly_view[j])[i]); + pep_view[j][i >> 1] = poly_view[j][i] + round_challenge * (poly_view[j][i + 1] - poly_view[j][i]); } }); }; @@ -159,12 +158,11 @@ template class SumcheckProver { template void partially_evaluate(std::array& polynomials, size_t round_size, FF round_challenge) { - auto pep_view = partially_evaluated_polynomials.pointer_view(); + auto pep_view = partially_evaluated_polynomials.get_all(); // after the first round, operate in place on partially_evaluated_polynomials parallel_for(polynomials.size(), [&](size_t j) { for (size_t i = 0; i < round_size; i += 2) { - (*pep_view[j])[i >> 1] = - polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]); + pep_view[j][i >> 1] = polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]); } }); }; @@ -236,9 +234,8 @@ template class SumcheckVerifier { ClaimedEvaluations purported_evaluations; auto transcript_evaluations = transcript.template receive_from_prover>("Sumcheck:evaluations"); - for (auto [eval_ptr, transcript_eval] : - zip_view(purported_evaluations.pointer_view(), transcript_evaluations)) { - *eval_ptr = transcript_eval; + for (auto [eval, transcript_eval] : zip_view(purported_evaluations.get_all(), transcript_evaluations)) { + eval = transcript_eval; } FF full_honk_relation_purported_value = round.compute_full_honk_relation_purported_value( diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index 33864bb8442..15e150e679d 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -136,26 +136,21 @@ TEST_F(SumcheckTests, PolynomialNormalization) FF l_7 = ( u_0) * ( u_1) * ( u_2); // clang-format on FF hand_computed_value; - auto partially_evaluated_polynomials_array = sumcheck.partially_evaluated_polynomials.pointer_view(); - size_t i = 0; - for (auto* full_polynomial_pointer : full_polynomials.pointer_view()) { + for (auto [full_poly, partial_eval_poly] : + zip_view(full_polynomials.get_all(), sumcheck.partially_evaluated_polynomials.get_all())) { // full_polynomials[0][0] = w_l[0], full_polynomials[1][1] = w_r[1], and so on. - hand_computed_value = l_0 * (*full_polynomial_pointer)[0] + l_1 * (*full_polynomial_pointer)[1] + - l_2 * (*full_polynomial_pointer)[2] + l_3 * (*full_polynomial_pointer)[3] + - l_4 * (*full_polynomial_pointer)[4] + l_5 * (*full_polynomial_pointer)[5] + - l_6 * (*full_polynomial_pointer)[6] + l_7 * (*full_polynomial_pointer)[7]; - EXPECT_EQ(hand_computed_value, (*partially_evaluated_polynomials_array[i])[0]); - i++; + hand_computed_value = l_0 * full_poly[0] + l_1 * full_poly[1] + l_2 * full_poly[2] + l_3 * full_poly[3] + + l_4 * full_poly[4] + l_5 * full_poly[5] + l_6 * full_poly[6] + l_7 * full_poly[7]; + EXPECT_EQ(hand_computed_value, partial_eval_poly[0]); } // We can also check the correctness of the multilinear evaluations produced by Sumcheck by directly evaluating the // full polynomials at challenge u via the evaluate_mle() function std::vector u_challenge = { u_0, u_1, u_2 }; - for (auto [full_poly, claimed_eval] : - zip_view(full_polynomials.pointer_view(), output.claimed_evaluations.pointer_view())) { - barretenberg::Polynomial poly(*full_poly); + for (auto [full_poly, claimed_eval] : zip_view(full_polynomials.get_all(), output.claimed_evaluations.get_all())) { + barretenberg::Polynomial poly(full_poly); auto v_expected = poly.evaluate_mle(u_challenge); - EXPECT_EQ(v_expected, *claimed_eval); + EXPECT_EQ(v_expected, claimed_eval); } } @@ -181,8 +176,8 @@ TEST_F(SumcheckTests, Prover) FF u_0 = output.challenge[0]; FF u_1 = output.challenge[1]; std::vector expected_values; - for (auto* polynomial_ptr : full_polynomials.pointer_view()) { - auto& polynomial = *polynomial_ptr; + for (auto& polynomial_ptr : full_polynomials.get_all()) { + auto& polynomial = polynomial_ptr; // using knowledge of inputs here to derive the evaluation FF expected_lo = polynomial[0] * (FF(1) - u_0) + polynomial[1] * u_0; expected_lo *= (FF(1) - u_1); @@ -191,8 +186,8 @@ TEST_F(SumcheckTests, Prover) expected_values.emplace_back(expected_lo + expected_hi); } - for (auto [eval, expected] : zip_view(output.claimed_evaluations.pointer_view(), expected_values)) { - *eval = expected; + for (auto [eval, expected] : zip_view(output.claimed_evaluations.get_all(), expected_values)) { + eval = expected; } } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 66ceeedcf52..b5c366be750 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -88,10 +88,9 @@ template class SumcheckProverRound { const ProverPolynomialsOrPartiallyEvaluatedMultivariates& multivariates, size_t edge_idx) { - for (auto [extended_edge, multivariate] : - zip_view(extended_edges.pointer_view(), multivariates.pointer_view())) { - auto edge = barretenberg::Univariate({ (*multivariate)[edge_idx], (*multivariate)[edge_idx + 1] }); - *extended_edge = edge.template extend_to(); + for (auto [extended_edge, multivariate] : zip_view(extended_edges.get_all(), multivariates.get_all())) { + auto edge = barretenberg::Univariate({ multivariate[edge_idx], multivariate[edge_idx + 1] }); + extended_edge = edge.template extend_to(); } } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp index d2f7bd8afb6..67848bfecd4 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -38,8 +38,8 @@ template void check_relation(auto circuit_s // Extract an array containing all the polynomial evaluations at a given row i AllValues evaluations_at_index_i; - for (auto [eval, poly] : zip_view(evaluations_at_index_i.pointer_view(), polynomials.pointer_view())) { - *eval = (*poly)[i]; + for (auto [eval, poly] : zip_view(evaluations_at_index_i.get_all(), polynomials.get_all())) { + eval = poly[i]; } // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to zero @@ -81,8 +81,8 @@ void check_linearly_dependent_relation(auto circuit_size, auto polynomials, auto // Extract an array containing all the polynomial evaluations at a given row i AllValues evaluations_at_index_i; - for (auto [eval, poly] : zip_view(evaluations_at_index_i.pointer_view(), polynomials.pointer_view())) { - *eval = (*poly)[i]; + for (auto [eval, poly] : zip_view(evaluations_at_index_i.get_all(), polynomials.get_all())) { + eval = poly[i]; } // Evaluate each constraint in the relation and check that each is satisfied @@ -389,17 +389,17 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorPermutationRelationCorrectness) // Create storage for polynomials ProverPolynomials prover_polynomials; std::vector polynomial_container; - auto polynomial_pointer_view = prover_polynomials.pointer_view(); + auto polynomial_get_all = prover_polynomials.get_all(); size_t z_perm_index = 0; - for (size_t i = 0; i < polynomial_pointer_view.size(); i++) { + for (size_t i = 0; i < polynomial_get_all.size(); i++) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/743) wouldn't be needed if ProverPolynomials held // memory - if (&prover_polynomials.z_perm == polynomial_pointer_view[i]) { + if (&prover_polynomials.z_perm == &polynomial_get_all[i]) { z_perm_index = i; } Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - *polynomial_pointer_view[i] = polynomial_container[i]; + polynomial_get_all[i] = polynomial_container[i]; } // Fill in lagrange polynomials used in the permutation relation @@ -515,18 +515,18 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) ProverPolynomials prover_polynomials; std::vector polynomial_container; - auto polynomial_pointer_view = prover_polynomials.pointer_view(); + auto polynomial_get_all = prover_polynomials.get_all(); size_t ordered_range_constraints_index = 0; // Allocate polynomials - for (size_t i = 0; i < polynomial_pointer_view.size(); i++) { + for (size_t i = 0; i < polynomial_get_all.size(); i++) { Polynomial temporary_polynomial(circuit_size); // TODO(https://github.com/AztecProtocol/barretenberg/issues/743) wouldn't be needed if ProverPolynomials held // memory - if (&prover_polynomials.ordered_range_constraints_0 == polynomial_pointer_view[i]) { + if (&prover_polynomials.ordered_range_constraints_0 == &polynomial_get_all[i]) { ordered_range_constraints_index = i; } polynomial_container.push_back(temporary_polynomial); - *polynomial_pointer_view[i] = polynomial_container[i]; + polynomial_get_all[i] = polynomial_container[i]; } // Construct lagrange polynomials that are needed for Goblin Translator's GenPermSort Relation @@ -616,16 +616,16 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) ProverPolynomials prover_polynomials; // We use polynomial ids to make shifting the polynomials easier ProverPolynomialIds prover_polynomial_ids; - auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); + auto polynomial_id_get_all = prover_polynomial_ids.get_all(); std::vector polynomial_container; std::vector polynomial_ids; - for (size_t i = 0; i < polynomial_id_pointer_view.size(); i++) { + for (size_t i = 0; i < polynomial_id_get_all.size(); i++) { Polynomial temporary_polynomial(circuit_size); // Allocate polynomials polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - *polynomial_id_pointer_view[i] = polynomial_ids[i]; + polynomial_id_get_all[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -634,10 +634,10 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) shifted_id_set.emplace(id); } // Assign spans to non-shifted prover polynomials - auto polynomial_pointer_view = prover_polynomials.pointer_view(); - for (size_t i = 0; i < polynomial_pointer_view.size(); i++) { + auto polynomial_get_all = prover_polynomials.get_all(); + for (size_t i = 0; i < polynomial_get_all.size(); i++) { if (!shifted_id_set.contains(i)) { - *polynomial_pointer_view[i] = polynomial_container[i]; + polynomial_get_all[i] = polynomial_container[i]; } } @@ -645,7 +645,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) for (size_t i = 0; i < shifted_ids.size(); i++) { auto shifted_id = shifted_ids[i]; auto to_be_shifted_id = prover_polynomial_ids.get_to_be_shifted()[i]; - *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + polynomial_get_all[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange even polynomial @@ -716,15 +716,15 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes ProverPolynomialIds prover_polynomial_ids; std::vector polynomial_container; std::vector polynomial_ids; - auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); - auto polynomial_pointer_view = prover_polynomials.pointer_view(); - for (size_t i = 0; i < polynomial_id_pointer_view.size(); i++) { + auto polynomial_id_get_all = prover_polynomial_ids.get_all(); + auto polynomial_get_all = prover_polynomials.get_all(); + for (size_t i = 0; i < polynomial_id_get_all.size(); i++) { Polynomial temporary_polynomial(circuit_size); // Allocate polynomials polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - *polynomial_id_pointer_view[i] = polynomial_ids[i]; + polynomial_id_get_all[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -733,9 +733,9 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes shifted_id_set.emplace(id); } // Assign spans to non-shifted prover polynomials - for (size_t i = 0; i < polynomial_pointer_view.size(); i++) { + for (size_t i = 0; i < polynomial_get_all.size(); i++) { if (!shifted_id_set.contains(i)) { - *polynomial_pointer_view[i] = polynomial_container[i]; + polynomial_get_all[i] = polynomial_container[i]; } } @@ -743,7 +743,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes for (size_t i = 0; i < shifted_ids.size(); i++) { auto shifted_id = shifted_ids[i]; auto to_be_shifted_id = prover_polynomial_ids.get_to_be_shifted()[i]; - *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + polynomial_get_all[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange odd polynomial (the only non-witness one we are using) @@ -1135,15 +1135,15 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) ProverPolynomialIds prover_polynomial_ids; std::vector polynomial_container; std::vector polynomial_ids; - auto polynomial_pointer_view = prover_polynomials.pointer_view(); - auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); - for (size_t i = 0; i < polynomial_pointer_view.size(); i++) { + auto polynomial_get_all = prover_polynomials.get_all(); + auto polynomial_id_get_all = prover_polynomial_ids.get_all(); + for (size_t i = 0; i < polynomial_get_all.size(); i++) { Polynomial temporary_polynomial(circuit_size); // Allocate polynomials polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - *polynomial_id_pointer_view[i] = polynomial_ids[i]; + polynomial_id_get_all[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -1152,9 +1152,9 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) shifted_id_set.emplace(id); } // Assign spans to non-shifted prover polynomials - for (size_t i = 0; i < polynomial_pointer_view.size(); i++) { + for (size_t i = 0; i < polynomial_get_all.size(); i++) { if (!shifted_id_set.contains(i)) { - *polynomial_pointer_view[i] = polynomial_container[i]; + polynomial_get_all[i] = polynomial_container[i]; } } @@ -1162,7 +1162,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) for (size_t i = 0; i < shifted_ids.size(); i++) { auto shifted_id = shifted_ids[i]; auto to_be_shifted_id = prover_polynomial_ids.get_to_be_shifted()[i]; - *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + polynomial_get_all[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Copy values of wires used in the non-native field relation from the circuit builder From 48c057d3bf6e99dc62f48fe2ead09af0abd06cac Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 1 Dec 2023 19:56:30 +0000 Subject: [PATCH 2/3] refactor: reuse entities in GoblinUltra --- .../src/barretenberg/flavor/goblin_ultra.hpp | 419 ++++++++------- .../flavor/goblin_ultra_recursive.hpp | 484 +----------------- 2 files changed, 222 insertions(+), 681 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 68dd2dfa2f1..a41e49d5258 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -48,14 +48,17 @@ class GoblinUltra { std::tuple, proof_system::LookupRelation>; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - proof_system::UltraPermutationRelation, - proof_system::LookupRelation, - proof_system::GenPermSortRelation, - proof_system::EllipticRelation, - proof_system::AuxiliaryRelation, - proof_system::EccOpQueueRelation, - proof_system::DatabusLookupRelation>; + // Note: made generic for use in GoblinUltraRecursive. + template + using Relations_ = std::tuple, + proof_system::UltraPermutationRelation, + proof_system::LookupRelation, + proof_system::GenPermSortRelation, + proof_system::EllipticRelation, + proof_system::AuxiliaryRelation, + proof_system::EccOpQueueRelation, + proof_system::DatabusLookupRelation>; + using Relations = Relations_; using LogDerivLookupRelation = proof_system::DatabusLookupRelation; @@ -128,17 +131,20 @@ class GoblinUltra { RefVector get_table_polynomials() { return { table_1, table_2, table_3, table_4 }; }; }; - /** - * @brief Container for all witness polynomials used/constructed by the prover. - * @details Shifts are not included here since they do not occupy their own memory. - */ - template class WitnessEntities { + // WireEntities for basic witness entities + template class WireEntities { + public: + DEFINE_FLAVOR_MEMBERS(DataType, + w_l, // column 0 + w_r, // column 1 + w_o, // column 2 + w_4); // column 3 + }; + + // DerivedEntities for derived witness entities + template class DerivedEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, - w_l, // column 0 - w_r, // column 1 - w_o, // column 2 - w_4, // column 3 sorted_1, // column 4 sorted_2, // column 5 sorted_3, // column 6 @@ -152,15 +158,46 @@ class GoblinUltra { ecc_op_wire_4, // column 14 calldata, // column 15 calldata_read_counts, // column 16 - lookup_inverses // column 17 - ) - RefVector get_wires() { return { w_l, w_r, w_o, w_4 }; }; + lookup_inverses); // column 17 + }; + + /** + * @brief Container for all witness polynomials used/constructed by the prover. + * @details Shifts are not included here since they do not occupy their own memory. + * Combines WireEntities + DerivedEntities. + */ + template + class WitnessEntities : public WireEntities, public DerivedEntities { + public: + DEFINE_COMPOUND_GET_ALL(WireEntities::get_all(), DerivedEntities::get_all()) + + RefVector get_wires() { return WireEntities::get_all(); }; RefVector get_ecc_op_wires() { - return { ecc_op_wire_1, ecc_op_wire_2, ecc_op_wire_3, ecc_op_wire_4 }; - }; + return { this->ecc_op_wire_1, this->ecc_op_wire_2, this->ecc_op_wire_3, this->ecc_op_wire_4 }; + } // The sorted concatenations of table and witness data needed for plookup. - RefVector get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; }; + RefVector get_sorted_polynomials() + { + return { this->sorted_1, this->sorted_2, this->sorted_3, this->sorted_4 }; + }; + }; + + template class ShiftedEntities { + public: + DEFINE_FLAVOR_MEMBERS(DataType, + table_1_shift, // column 0 + table_2_shift, // column 1 + table_3_shift, // column 2 + table_4_shift, // column 3 + w_l_shift, // column 4 + w_r_shift, // column 5 + w_o_shift, // column 6 + w_4_shift, // column 7 + sorted_accum_shift, // column 8 + z_perm_shift, // column 9 + z_lookup_shift // column 10 + ) }; /** @@ -172,124 +209,72 @@ class GoblinUltra { * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be * implemented as such, but we have this now. */ - template class AllEntities { + template + class AllEntities : public PrecomputedEntities, + public WitnessEntities, + public ShiftedEntities { public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_c, // column 0 - q_l, // column 1 - q_r, // column 2 - q_o, // column 3 - q_4, // column 4 - q_m, // column 5 - q_arith, // column 6 - q_sort, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - q_busread, // column 11 - sigma_1, // column 12 - sigma_2, // column 13 - sigma_3, // column 14 - sigma_4, // column 15 - id_1, // column 16 - id_2, // column 17 - id_3, // column 18 - id_4, // column 19 - table_1, // column 20 - table_2, // column 21 - table_3, // column 22 - table_4, // column 23 - lagrange_first, // column 24 - lagrange_last, // column 25 - lagrange_ecc_op, // column 26 - databus_id, // column 27 - w_l, // column 28 - w_r, // column 29 - w_o, // column 30 - w_4, // column 31 - sorted_accum, // column 32 - z_perm, // column 33 - z_lookup, // column 34 - ecc_op_wire_1, // column 35 - ecc_op_wire_2, // column 36 - ecc_op_wire_3, // column 37 - ecc_op_wire_4, // column 38 - calldata, // column 39 - calldata_read_counts, // column 40 - lookup_inverses, // column 41 - table_1_shift, // column 42 - table_2_shift, // column 43 - table_3_shift, // column 44 - table_4_shift, // column 45 - w_l_shift, // column 46 - w_r_shift, // column 47 - w_o_shift, // column 48 - w_4_shift, // column 49 - sorted_accum_shift, // column 50 - z_perm_shift, // column 51 - z_lookup_shift // column 52 - ) + DEFINE_COMPOUND_GET_ALL(PrecomputedEntities::get_all(), + WitnessEntities::get_all(), + ShiftedEntities::get_all()) - RefVector get_wires() { return { w_l, w_r, w_o, w_4 }; }; + RefVector get_wires() { return { this->w_l, this->w_r, this->w_o, this->w_4 }; }; RefVector get_ecc_op_wires() { - return { ecc_op_wire_1, ecc_op_wire_2, ecc_op_wire_3, ecc_op_wire_4 }; + return { this->ecc_op_wire_1, this->ecc_op_wire_2, this->ecc_op_wire_3, this->ecc_op_wire_4 }; }; // Gemini-specific getters. RefVector get_unshifted() { - return { q_c, - q_l, - q_r, - q_o, - q_4, - q_m, - q_arith, - q_sort, - q_elliptic, - q_aux, - q_lookup, - q_busread, - sigma_1, - sigma_2, - sigma_3, - sigma_4, - id_1, - id_2, - id_3, - id_4, - table_1, - table_2, - table_3, - table_4, - lagrange_first, - lagrange_last, - lagrange_ecc_op, - databus_id, - w_l, - w_r, - w_o, - w_4, - sorted_accum, - z_perm, - z_lookup, - ecc_op_wire_1, - ecc_op_wire_2, - ecc_op_wire_3, - ecc_op_wire_4, - calldata, - calldata_read_counts, - lookup_inverses }; + return { this->q_c, + this->q_l, + this->q_r, + this->q_o, + this->q_4, + this->q_m, + this->q_arith, + this->q_sort, + this->q_elliptic, + this->q_aux, + this->q_lookup, + this->q_busread, + this->sigma_1, + this->sigma_2, + this->sigma_3, + this->sigma_4, + this->id_1, + this->id_2, + this->id_3, + this->id_4, + this->table_1, + this->table_2, + this->table_3, + this->table_4, + this->lagrange_first, + this->lagrange_last, + this->lagrange_ecc_op, + this->databus_id, + this->w_l, + this->w_r, + this->w_o, + this->w_4, + this->sorted_accum, + this->z_perm, + this->z_lookup, + this->ecc_op_wire_1, + this->ecc_op_wire_2, + this->ecc_op_wire_3, + this->ecc_op_wire_4, + this->calldata, + this->calldata_read_counts, + this->lookup_inverses }; }; RefVector get_to_be_shifted() { - return { table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; - }; - RefVector get_shifted() - { - return { table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, w_r_shift, - w_o_shift, w_4_shift, sorted_accum_shift, z_perm_shift, z_lookup_shift }; + return { this->table_1, this->table_2, this->table_3, this->table_4, this->w_l, this->w_r, + this->w_o, this->w_4, this->sorted_accum, this->z_perm, this->z_lookup }; }; + RefVector get_shifted() { return ShiftedEntities::get_all(); }; }; public: @@ -432,43 +417,47 @@ class GoblinUltra { }; }; - class VerifierCommitments : public AllEntities { + /** + * Note: Made generic for use in GoblinUltraRecursive. + **/ + template class VerifierCommitments_ : public AllEntities { public: - VerifierCommitments(std::shared_ptr verification_key, - [[maybe_unused]] const BaseTranscript& transcript) + VerifierCommitments_(const std::shared_ptr& verification_key, + [[maybe_unused]] const BaseTranscript& transcript) { static_cast(transcript); - q_m = verification_key->q_m; - q_l = verification_key->q_l; - q_r = verification_key->q_r; - q_o = verification_key->q_o; - q_4 = verification_key->q_4; - q_c = verification_key->q_c; - q_arith = verification_key->q_arith; - q_sort = verification_key->q_sort; - q_elliptic = verification_key->q_elliptic; - q_aux = verification_key->q_aux; - q_lookup = verification_key->q_lookup; - q_busread = verification_key->q_busread; - sigma_1 = verification_key->sigma_1; - sigma_2 = verification_key->sigma_2; - sigma_3 = verification_key->sigma_3; - sigma_4 = verification_key->sigma_4; - id_1 = verification_key->id_1; - id_2 = verification_key->id_2; - id_3 = verification_key->id_3; - id_4 = verification_key->id_4; - table_1 = verification_key->table_1; - table_2 = verification_key->table_2; - table_3 = verification_key->table_3; - table_4 = verification_key->table_4; - lagrange_first = verification_key->lagrange_first; - lagrange_last = verification_key->lagrange_last; - lagrange_ecc_op = verification_key->lagrange_ecc_op; - databus_id = verification_key->databus_id; + this->q_m = verification_key->q_m; + this->q_l = verification_key->q_l; + this->q_r = verification_key->q_r; + this->q_o = verification_key->q_o; + this->q_4 = verification_key->q_4; + this->q_c = verification_key->q_c; + this->q_arith = verification_key->q_arith; + this->q_sort = verification_key->q_sort; + this->q_elliptic = verification_key->q_elliptic; + this->q_aux = verification_key->q_aux; + this->q_lookup = verification_key->q_lookup; + this->q_busread = verification_key->q_busread; + this->sigma_1 = verification_key->sigma_1; + this->sigma_2 = verification_key->sigma_2; + this->sigma_3 = verification_key->sigma_3; + this->sigma_4 = verification_key->sigma_4; + this->id_1 = verification_key->id_1; + this->id_2 = verification_key->id_2; + this->id_3 = verification_key->id_3; + this->id_4 = verification_key->id_4; + this->table_1 = verification_key->table_1; + this->table_2 = verification_key->table_2; + this->table_3 = verification_key->table_3; + this->table_4 = verification_key->table_4; + this->lagrange_first = verification_key->lagrange_first; + this->lagrange_last = verification_key->lagrange_last; + this->lagrange_ecc_op = verification_key->lagrange_ecc_op; + this->databus_id = verification_key->databus_id; } }; - + // Specialize for GoblinUltra (general case used in GoblinUltraRecursive). + using VerifierCommitments = VerifierCommitments_; class FoldingParameters { public: std::vector gate_separation_challenges; @@ -477,9 +466,9 @@ class GoblinUltra { /** * @brief Derived class that defines proof structure for GoblinUltra proofs, as well as supporting functions. - * + * Note: Made generic for use in GoblinUltraRecursive. */ - class Transcript : public BaseTranscript { + template class Transcript_ : public BaseTranscript { public: uint32_t circuit_size; uint32_t public_input_size; @@ -505,9 +494,9 @@ class GoblinUltra { Commitment zm_cq_comm; Commitment zm_pi_comm; - Transcript() = default; + Transcript_() = default; - Transcript(const std::vector& proof) + Transcript_(const std::vector& proof) : BaseTranscript(proof) {} @@ -515,80 +504,82 @@ class GoblinUltra { { // take current proof and put them into the struct size_t num_bytes_read = 0; - circuit_size = deserialize_from_buffer(proof_data, num_bytes_read); + circuit_size = deserialize_from_buffer(this->proof_data, num_bytes_read); size_t log_n = numeric::get_msb(circuit_size); - public_input_size = deserialize_from_buffer(proof_data, num_bytes_read); - pub_inputs_offset = deserialize_from_buffer(proof_data, num_bytes_read); + public_input_size = deserialize_from_buffer(this->proof_data, num_bytes_read); + pub_inputs_offset = deserialize_from_buffer(this->proof_data, num_bytes_read); for (size_t i = 0; i < public_input_size; ++i) { - public_inputs.push_back(deserialize_from_buffer(proof_data, num_bytes_read)); + public_inputs.push_back(deserialize_from_buffer(this->proof_data, num_bytes_read)); } - w_l_comm = deserialize_from_buffer(proof_data, num_bytes_read); - w_r_comm = deserialize_from_buffer(proof_data, num_bytes_read); - w_o_comm = deserialize_from_buffer(proof_data, num_bytes_read); - ecc_op_wire_1_comm = deserialize_from_buffer(proof_data, num_bytes_read); - ecc_op_wire_2_comm = deserialize_from_buffer(proof_data, num_bytes_read); - ecc_op_wire_3_comm = deserialize_from_buffer(proof_data, num_bytes_read); - ecc_op_wire_4_comm = deserialize_from_buffer(proof_data, num_bytes_read); - calldata_comm = deserialize_from_buffer(proof_data, num_bytes_read); - calldata_read_counts_comm = deserialize_from_buffer(proof_data, num_bytes_read); - lookup_inverses_comm = deserialize_from_buffer(proof_data, num_bytes_read); - sorted_accum_comm = deserialize_from_buffer(proof_data, num_bytes_read); - w_4_comm = deserialize_from_buffer(proof_data, num_bytes_read); - z_perm_comm = deserialize_from_buffer(proof_data, num_bytes_read); - z_lookup_comm = deserialize_from_buffer(proof_data, num_bytes_read); + w_l_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + w_r_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + w_o_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + ecc_op_wire_1_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + ecc_op_wire_2_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + ecc_op_wire_3_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + ecc_op_wire_4_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + calldata_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + calldata_read_counts_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + lookup_inverses_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + sorted_accum_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + w_4_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + z_perm_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + z_lookup_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); for (size_t i = 0; i < log_n; ++i) { sumcheck_univariates.push_back( deserialize_from_buffer>( - proof_data, num_bytes_read)); + this->proof_data, num_bytes_read)); } sumcheck_evaluations = - deserialize_from_buffer>(proof_data, num_bytes_read); + deserialize_from_buffer>(this->proof_data, num_bytes_read); for (size_t i = 0; i < log_n; ++i) { - zm_cq_comms.push_back(deserialize_from_buffer(proof_data, num_bytes_read)); + zm_cq_comms.push_back(deserialize_from_buffer(this->proof_data, num_bytes_read)); } - zm_cq_comm = deserialize_from_buffer(proof_data, num_bytes_read); - zm_pi_comm = deserialize_from_buffer(proof_data, num_bytes_read); + zm_cq_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); + zm_pi_comm = deserialize_from_buffer(this->proof_data, num_bytes_read); } void serialize_full_transcript() override { - size_t old_proof_length = proof_data.size(); - proof_data.clear(); + size_t old_proof_length = this->proof_data.size(); + this->proof_data.clear(); size_t log_n = numeric::get_msb(circuit_size); - serialize_to_buffer(circuit_size, proof_data); - serialize_to_buffer(public_input_size, proof_data); - serialize_to_buffer(pub_inputs_offset, proof_data); + serialize_to_buffer(circuit_size, this->proof_data); + serialize_to_buffer(public_input_size, this->proof_data); + serialize_to_buffer(pub_inputs_offset, this->proof_data); for (size_t i = 0; i < public_input_size; ++i) { - serialize_to_buffer(public_inputs[i], proof_data); + serialize_to_buffer(public_inputs[i], this->proof_data); } - serialize_to_buffer(w_l_comm, proof_data); - serialize_to_buffer(w_r_comm, proof_data); - serialize_to_buffer(w_o_comm, proof_data); - serialize_to_buffer(ecc_op_wire_1_comm, proof_data); - serialize_to_buffer(ecc_op_wire_2_comm, proof_data); - serialize_to_buffer(ecc_op_wire_3_comm, proof_data); - serialize_to_buffer(ecc_op_wire_4_comm, proof_data); - serialize_to_buffer(calldata_comm, proof_data); - serialize_to_buffer(calldata_read_counts_comm, proof_data); - serialize_to_buffer(lookup_inverses_comm, proof_data); - serialize_to_buffer(sorted_accum_comm, proof_data); - serialize_to_buffer(w_4_comm, proof_data); - serialize_to_buffer(z_perm_comm, proof_data); - serialize_to_buffer(z_lookup_comm, proof_data); + serialize_to_buffer(w_l_comm, this->proof_data); + serialize_to_buffer(w_r_comm, this->proof_data); + serialize_to_buffer(w_o_comm, this->proof_data); + serialize_to_buffer(ecc_op_wire_1_comm, this->proof_data); + serialize_to_buffer(ecc_op_wire_2_comm, this->proof_data); + serialize_to_buffer(ecc_op_wire_3_comm, this->proof_data); + serialize_to_buffer(ecc_op_wire_4_comm, this->proof_data); + serialize_to_buffer(calldata_comm, this->proof_data); + serialize_to_buffer(calldata_read_counts_comm, this->proof_data); + serialize_to_buffer(lookup_inverses_comm, this->proof_data); + serialize_to_buffer(sorted_accum_comm, this->proof_data); + serialize_to_buffer(w_4_comm, this->proof_data); + serialize_to_buffer(z_perm_comm, this->proof_data); + serialize_to_buffer(z_lookup_comm, this->proof_data); for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(sumcheck_univariates[i], proof_data); + serialize_to_buffer(sumcheck_univariates[i], this->proof_data); } - serialize_to_buffer(sumcheck_evaluations, proof_data); + serialize_to_buffer(sumcheck_evaluations, this->proof_data); for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(zm_cq_comms[i], proof_data); + serialize_to_buffer(zm_cq_comms[i], this->proof_data); } - serialize_to_buffer(zm_cq_comm, proof_data); - serialize_to_buffer(zm_pi_comm, proof_data); + serialize_to_buffer(zm_cq_comm, this->proof_data); + serialize_to_buffer(zm_pi_comm, this->proof_data); - ASSERT(proof_data.size() == old_proof_length); + ASSERT(this->proof_data.size() == old_proof_length); } }; + // Specialize for GoblinUltra (general case used in GoblinUltraRecursive). + using Transcript = Transcript_; }; } // namespace proof_system::honk::flavor \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp index 691e99fdda3..1c97ff0e4e9 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp @@ -50,34 +50,19 @@ template class GoblinUltraRecursive_ { public: using CircuitBuilder = BuilderType; // Determines arithmetization of circuit instantiated with this flavor using Curve = plonk::stdlib::bn254; - using GroupElement = typename Curve::Element; - using Commitment = typename Curve::Element; - using CommitmentHandle = typename Curve::Element; - using FF = typename Curve::ScalarField; + using GroupElement = Curve::Element; + using Commitment = Curve::Element; + using CommitmentHandle = Curve::Element; + using FF = Curve::ScalarField; // Note(luke): Eventually this may not be needed at all using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_WIRES = flavor::GoblinUltra::NUM_WIRES; - // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often - // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS`. - // Note: this number does not include the individual sorted list polynomials. - static constexpr size_t NUM_ALL_ENTITIES = 53; - // The number of polynomials precomputed to describe a circuit and to aid a prover in constructing a satisfying - // assignment of witnesses. We again choose a neutral name. - static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 28; - // The total number of witness entities not including shifts. - static constexpr size_t NUM_WITNESS_ENTITIES = 18; - + static constexpr size_t NUM_ALL_ENTITIES = flavor::GoblinUltra::NUM_ALL_ENTITIES; // define the tuple of Relations that comprise the Sumcheck relation - using Relations = std::tuple, - proof_system::UltraPermutationRelation, - proof_system::LookupRelation, - proof_system::GenPermSortRelation, - proof_system::EllipticRelation, - proof_system::AuxiliaryRelation, - proof_system::EccOpQueueRelation, - proof_system::DatabusLookupRelation>; + // Reuse the Relations from GoblinUltra + using Relations = GoblinUltra::Relations_; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -92,219 +77,9 @@ template class GoblinUltraRecursive_ { using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); private: - template - /** - * @brief A base class labelling precomputed entities and (ordered) subsets of interest. - * @details Used to build the proving key and verification key. - */ - class PrecomputedEntities : public PrecomputedEntitiesBase { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_m, // column 0 - q_c, // column 1 - q_l, // column 2 - q_r, // column 3 - q_o, // column 4 - q_4, // column 5 - q_arith, // column 6 - q_sort, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - q_busread, // column 11 - sigma_1, // column 12 - sigma_2, // column 13 - sigma_3, // column 14 - sigma_4, // column 15 - id_1, // column 16 - id_2, // column 17 - id_3, // column 18 - id_4, // column 19 - table_1, // column 20 - table_2, // column 21 - table_3, // column 22 - table_4, // column 23 - lagrange_first, // column 24 - lagrange_last, // column 25 - lagrange_ecc_op, // column 26 // indicator poly for ecc op gates - databus_id // column 27 // id polynomial, i.e. id_i = i - ) - - static constexpr CircuitType CIRCUIT_TYPE = CircuitBuilder::CIRCUIT_TYPE; - - RefVector get_selectors() - { - return { q_m, q_c, q_l, q_r, q_o, q_4, q_arith, q_sort, q_elliptic, q_aux, q_lookup, q_busread }; - }; - RefVector get_sigma_polynomials() { return { sigma_1, sigma_2, sigma_3, sigma_4 }; }; - RefVector get_id_polynomials() { return { id_1, id_2, id_3, id_4 }; }; - - RefVector get_table_polynomials() { return { table_1, table_2, table_3, table_4 }; }; - }; - - /** - * @brief Container for all witness polynomials used/constructed by the prover. - * @details Shifts are not included here since they do not occupy their own memory. - */ - template class WitnessEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - w_l, // column 0 - w_r, // column 1 - w_o, // column 2 - w_4, // column 3 - sorted_1, // column 4 - sorted_2, // column 5 - sorted_3, // column 6 - sorted_4, // column 7 - sorted_accum, // column 8 - z_perm, // column 9 - z_lookup, // column 10 - ecc_op_wire_1, // column 11 - ecc_op_wire_2, // column 12 - ecc_op_wire_3, // column 13 - ecc_op_wire_4, // column 14 - calldata, // column 15 - calldata_read_counts, // column 16 - lookup_inverses // column 17 - ) - - RefVector get_wires() { return { w_l, w_r, w_o, w_4 }; }; - RefVector get_ecc_op_wires() - { - return { ecc_op_wire_1, ecc_op_wire_2, ecc_op_wire_3, ecc_op_wire_4 }; - }; - // The sorted concatenations of table and witness data needed for plookup. - RefVector get_sorted_polynomials() { return { sorted_1, sorted_2, sorted_3, sorted_4 }; }; - }; - - /** - * @brief A base class labelling all entities (for instance, all of the polynomials used by the prover during - * sumcheck) in this Honk variant along with particular subsets of interest - * @details Used to build containers for: the prover's polynomial during sumcheck; the sumcheck's folded - * polynomials; the univariates consturcted during during sumcheck; the evaluations produced by sumcheck. - * - * Symbolically we have: AllEntities = PrecomputedEntities + WitnessEntities + "ShiftedEntities". It could be - * implemented as such, but we have this now. - */ - template class AllEntities { - public: - DEFINE_FLAVOR_MEMBERS(DataType, - q_c, // column 0 - q_l, // column 1 - q_r, // column 2 - q_o, // column 3 - q_4, // column 4 - q_m, // column 5 - q_arith, // column 6 - q_sort, // column 7 - q_elliptic, // column 8 - q_aux, // column 9 - q_lookup, // column 10 - q_busread, // column 11 - sigma_1, // column 12 - sigma_2, // column 13 - sigma_3, // column 14 - sigma_4, // column 15 - id_1, // column 16 - id_2, // column 17 - id_3, // column 18 - id_4, // column 19 - table_1, // column 20 - table_2, // column 21 - table_3, // column 22 - table_4, // column 23 - lagrange_first, // column 24 - lagrange_last, // column 25 - lagrange_ecc_op, // column 26 - databus_id, // column 27 - w_l, // column 28 - w_r, // column 29 - w_o, // column 30 - w_4, // column 31 - sorted_accum, // column 32 - z_perm, // column 33 - z_lookup, // column 34 - ecc_op_wire_1, // column 35 - ecc_op_wire_2, // column 36 - ecc_op_wire_3, // column 37 - ecc_op_wire_4, // column 38 - calldata, // column 39 - calldata_read_counts, // column 40 - lookup_inverses, // column 41 - table_1_shift, // column 42 - table_2_shift, // column 43 - table_3_shift, // column 44 - table_4_shift, // column 45 - w_l_shift, // column 46 - w_r_shift, // column 47 - w_o_shift, // column 48 - w_4_shift, // column 49 - sorted_accum_shift, // column 50 - z_perm_shift, // column 51 - z_lookup_shift); // column 52 - - RefVector get_wires() { return { w_l, w_r, w_o, w_4 }; }; - RefVector get_ecc_op_wires() - { - return { ecc_op_wire_1, ecc_op_wire_2, ecc_op_wire_3, ecc_op_wire_4 }; - }; - // Gemini-specific getters. - RefVector get_unshifted() - { - return { q_c, - q_l, - q_r, - q_o, - q_4, - q_m, - q_arith, - q_sort, - q_elliptic, - q_aux, - q_lookup, - q_busread, - sigma_1, - sigma_2, - sigma_3, - sigma_4, - id_1, - id_2, - id_3, - id_4, - table_1, - table_2, - table_3, - table_4, - lagrange_first, - lagrange_last, - lagrange_ecc_op, - databus_id, - w_l, - w_r, - w_o, - w_4, - sorted_accum, - z_perm, - z_lookup, - ecc_op_wire_1, - ecc_op_wire_2, - ecc_op_wire_3, - ecc_op_wire_4, - calldata, - calldata_read_counts, - lookup_inverses }; - }; - RefVector get_to_be_shifted() - { - return { table_1, table_2, table_3, table_4, w_l, w_r, w_o, w_4, sorted_accum, z_perm, z_lookup }; - }; - RefVector get_shifted() - { - return { table_1_shift, table_2_shift, table_3_shift, table_4_shift, w_l_shift, w_r_shift, - w_o_shift, w_4_shift, sorted_accum_shift, z_perm_shift, z_lookup_shift }; - }; - }; + template using PrecomputedEntities = GoblinUltra::PrecomputedEntities; + template using WitnessEntities = GoblinUltra::WitnessEntities; + template using AllEntities = GoblinUltra::AllEntities; public: /** @@ -314,6 +89,7 @@ template class GoblinUltraRecursive_ { * @note Note the discrepancy with what sort of data is stored here vs in the proving key. We may want to resolve * that, and split out separate PrecomputedPolynomials/Commitments data for clarity but also for portability of our * circuits. + * This differs from GoblinUltra in how we construct the commitments. */ class VerificationKey : public VerificationKey_> { public: @@ -324,7 +100,7 @@ template class GoblinUltraRecursive_ { * @param builder * @param native_key Native verification key from which to extract the precomputed commitments */ - VerificationKey(CircuitBuilder* builder, auto native_key) + VerificationKey(CircuitBuilder* builder, const auto& native_key) : VerificationKey_>(native_key->circuit_size, native_key->num_public_inputs) { this->q_m = Commitment::from_witness(builder, native_key->q_m); @@ -358,237 +134,11 @@ template class GoblinUltraRecursive_ { }; }; - /** - * @brief A field element for each entity of the flavor. These entities represent the prover polynomials evaluated - * at one point. - */ - class AllValues : public AllEntities { - public: - using Base = AllEntities; - using Base::Base; - AllValues(std::array _data_in) { this->_data = _data_in; } - }; - - /** - * @brief A container for commitment labels. - * @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly needed. It - * has, however, been useful during debugging to have these labels available. - * - */ - class CommitmentLabels : public AllEntities { - public: - CommitmentLabels() - { - this->w_l = "W_L"; - this->w_r = "W_R"; - this->w_o = "W_O"; - this->w_4 = "W_4"; - this->z_perm = "Z_PERM"; - this->z_lookup = "Z_LOOKUP"; - this->sorted_accum = "SORTED_ACCUM"; - this->ecc_op_wire_1 = "ECC_OP_WIRE_1"; - this->ecc_op_wire_2 = "ECC_OP_WIRE_2"; - this->ecc_op_wire_3 = "ECC_OP_WIRE_3"; - this->ecc_op_wire_4 = "ECC_OP_WIRE_4"; - this->calldata = "CALLDATA"; - this->calldata_read_counts = "CALLDATA_READ_COUNTS"; - this->lookup_inverses = "LOOKUP_INVERSES"; - - // The ones beginning with "__" are only used for debugging - this->q_c = "__Q_C"; - this->q_l = "__Q_L"; - this->q_r = "__Q_R"; - this->q_o = "__Q_O"; - this->q_4 = "__Q_4"; - this->q_m = "__Q_M"; - this->q_arith = "__Q_ARITH"; - this->q_sort = "__Q_SORT"; - this->q_elliptic = "__Q_ELLIPTIC"; - this->q_aux = "__Q_AUX"; - this->q_lookup = "__Q_LOOKUP"; - this->q_busread = "__Q_BUSREAD"; - this->sigma_1 = "__SIGMA_1"; - this->sigma_2 = "__SIGMA_2"; - this->sigma_3 = "__SIGMA_3"; - this->sigma_4 = "__SIGMA_4"; - this->id_1 = "__ID_1"; - this->id_2 = "__ID_2"; - this->id_3 = "__ID_3"; - this->id_4 = "__ID_4"; - this->table_1 = "__TABLE_1"; - this->table_2 = "__TABLE_2"; - this->table_3 = "__TABLE_3"; - this->table_4 = "__TABLE_4"; - this->lagrange_first = "__LAGRANGE_FIRST"; - this->lagrange_last = "__LAGRANGE_LAST"; - this->lagrange_ecc_op = "__Q_ECC_OP_QUEUE"; - }; - }; - - class VerifierCommitments : public AllEntities { - public: - VerifierCommitments(std::shared_ptr verification_key) - { - this->q_m = verification_key->q_m; - this->q_l = verification_key->q_l; - this->q_r = verification_key->q_r; - this->q_o = verification_key->q_o; - this->q_4 = verification_key->q_4; - this->q_c = verification_key->q_c; - this->q_arith = verification_key->q_arith; - this->q_sort = verification_key->q_sort; - this->q_elliptic = verification_key->q_elliptic; - this->q_aux = verification_key->q_aux; - this->q_lookup = verification_key->q_lookup; - this->q_busread = verification_key->q_busread; - this->sigma_1 = verification_key->sigma_1; - this->sigma_2 = verification_key->sigma_2; - this->sigma_3 = verification_key->sigma_3; - this->sigma_4 = verification_key->sigma_4; - this->id_1 = verification_key->id_1; - this->id_2 = verification_key->id_2; - this->id_3 = verification_key->id_3; - this->id_4 = verification_key->id_4; - this->table_1 = verification_key->table_1; - this->table_2 = verification_key->table_2; - this->table_3 = verification_key->table_3; - this->table_4 = verification_key->table_4; - this->lagrange_first = verification_key->lagrange_first; - this->lagrange_last = verification_key->lagrange_last; - this->lagrange_ecc_op = verification_key->lagrange_ecc_op; - this->databus_id = verification_key->databus_id; - } - }; - - /** - * @brief Derived class that defines proof structure for GoblinUltraRecursive proofs, as well as supporting - * functions. - * - */ - class Transcript : public BaseTranscript { - public: - uint32_t circuit_size; - uint32_t public_input_size; - uint32_t pub_inputs_offset; - std::vector public_inputs; - Commitment w_l_comm; - Commitment w_r_comm; - Commitment w_o_comm; - Commitment ecc_op_wire_1_comm; - Commitment ecc_op_wire_2_comm; - Commitment ecc_op_wire_3_comm; - Commitment ecc_op_wire_4_comm; - Commitment calldata_comm; - Commitment calldata_read_counts_comm; - Commitment lookup_inverses_comm; - Commitment sorted_accum_comm; - Commitment w_4_comm; - Commitment z_perm_comm; - Commitment z_lookup_comm; - std::vector> sumcheck_univariates; - std::array sumcheck_evaluations; - std::vector zm_cq_comms; - Commitment zm_cq_comm; - Commitment zm_pi_comm; - - Transcript() = default; - - Transcript(const std::vector& proof) - : BaseTranscript(proof) - {} - /** - * @brief Takes a FULL GoblinUltraRecursive proof and deserializes it into the public member - * variables that compose the structure. Must be called in order to access the structure of the - * proof. - * - */ - void deserialize_full_transcript() - { - // take current proof and put them into the struct - size_t num_bytes_read = 0; - circuit_size = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - size_t log_n = numeric::get_msb(circuit_size); - - public_input_size = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - pub_inputs_offset = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - for (size_t i = 0; i < public_input_size; ++i) { - public_inputs.push_back(deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read)); - } - w_l_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - w_r_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - w_o_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - ecc_op_wire_1_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - ecc_op_wire_2_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - ecc_op_wire_3_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - ecc_op_wire_4_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - calldata_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - calldata_read_counts_comm = - deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - lookup_inverses_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - sorted_accum_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - w_4_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - z_perm_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - z_lookup_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - for (size_t i = 0; i < log_n; ++i) { - sumcheck_univariates.push_back( - deserialize_from_buffer>( - BaseTranscript::proof_data, num_bytes_read)); - } - sumcheck_evaluations = deserialize_from_buffer>( - BaseTranscript::proof_data, num_bytes_read); - for (size_t i = 0; i < log_n; ++i) { - zm_cq_comms.push_back( - deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read)); - } - zm_cq_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - zm_pi_comm = deserialize_from_buffer(BaseTranscript::proof_data, num_bytes_read); - } - - /** - * @brief Serializes the structure variables into a FULL GoblinUltraRecursive proof. Should be - * called only if deserialize_full_transcript() was called and some transcript variable was - * modified. - * - */ - void serialize_full_transcript() - { - size_t old_proof_length = BaseTranscript::proof_data.size(); - BaseTranscript::proof_data.clear(); - size_t log_n = numeric::get_msb(circuit_size); - serialize_to_buffer(circuit_size, BaseTranscript::proof_data); - serialize_to_buffer(public_input_size, BaseTranscript::proof_data); - serialize_to_buffer(pub_inputs_offset, BaseTranscript::proof_data); - for (size_t i = 0; i < public_input_size; ++i) { - serialize_to_buffer(public_inputs[i], BaseTranscript::proof_data); - } - serialize_to_buffer(w_l_comm, BaseTranscript::proof_data); - serialize_to_buffer(w_r_comm, BaseTranscript::proof_data); - serialize_to_buffer(w_o_comm, BaseTranscript::proof_data); - serialize_to_buffer(ecc_op_wire_1_comm, BaseTranscript::proof_data); - serialize_to_buffer(ecc_op_wire_2_comm, BaseTranscript::proof_data); - serialize_to_buffer(ecc_op_wire_3_comm, BaseTranscript::proof_data); - serialize_to_buffer(ecc_op_wire_4_comm, BaseTranscript::proof_data); - serialize_to_buffer(calldata_comm, BaseTranscript::proof_data); - serialize_to_buffer(calldata_read_counts_comm, BaseTranscript::proof_data); - serialize_to_buffer(lookup_inverses_comm, BaseTranscript::proof_data); - serialize_to_buffer(sorted_accum_comm, BaseTranscript::proof_data); - serialize_to_buffer(w_4_comm, BaseTranscript::proof_data); - serialize_to_buffer(z_perm_comm, BaseTranscript::proof_data); - serialize_to_buffer(z_lookup_comm, BaseTranscript::proof_data); - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(sumcheck_univariates[i], BaseTranscript::proof_data); - } - serialize_to_buffer(sumcheck_evaluations, BaseTranscript::proof_data); - for (size_t i = 0; i < log_n; ++i) { - serialize_to_buffer(zm_cq_comms[i], BaseTranscript::proof_data); - } - serialize_to_buffer(zm_cq_comm, BaseTranscript::proof_data); - serialize_to_buffer(zm_pi_comm, BaseTranscript::proof_data); - - // sanity check to make sure we generate the same length of proof as before. - ASSERT(BaseTranscript::proof_data.size() == old_proof_length); - } - }; + using CommitmentLabels = GoblinUltra::CommitmentLabels; + // Reuse the VerifierCommitments from GoblinUltra + using VerifierCommitments = GoblinUltra::VerifierCommitments_; + // Reuse the transcript from GoblinUltra + using Transcript = GoblinUltra::Transcript_; }; } // namespace proof_system::honk::flavor From 52a43664e919e5f2819d6834c7ca572e295d644c Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 1 Dec 2023 20:29:59 +0000 Subject: [PATCH 3/3] refactor: fix build --- .../src/barretenberg/flavor/goblin_ultra_recursive.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp index 0e9274746df..cbce512e6ed 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra_recursive.hpp @@ -50,10 +50,10 @@ template class GoblinUltraRecursive_ { public: using CircuitBuilder = BuilderType; // Determines arithmetization of circuit instantiated with this flavor using Curve = plonk::stdlib::bn254; - using GroupElement = Curve::Element; - using Commitment = Curve::Element; - using CommitmentHandle = Curve::Element; - using FF = Curve::ScalarField; + using GroupElement = typename Curve::Element; + using Commitment = typename Curve::Element; + using CommitmentHandle = typename Curve::Element; + using FF = typename Curve::ScalarField; // Note(luke): Eventually this may not be needed at all using VerifierCommitmentKey = pcs::VerifierCommitmentKey;