From 50a0abaa158603dbef6e53c030be0e67eb0787ee Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 19:20:37 +0000 Subject: [PATCH 01/47] refactor(flavor): try to remove operator[] --- .../barretenberg/honk/flavor/goblin_ultra.hpp | 37 ++++++++++++- .../src/barretenberg/honk/flavor/ultra.hpp | 55 ++++++++++++++++++- 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 9912dcf5c18..5f7c3aef53a 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -210,6 +210,36 @@ class GoblinUltra { DataType& z_perm_shift = std::get<46>(this->_data); DataType& z_lookup_shift = std::get<47>(this->_data); + auto get_pointer_array() + { + return std::array{ + &q_c, &q_l, + &q_r, &q_o, + &q_4, &q_m, + &q_arith, &q_sort, + &q_elliptic, &q_aux, + &q_lookup, &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, + &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, &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, + }; + } + std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; std::vector get_ecc_op_wires() { @@ -351,12 +381,13 @@ class GoblinUltra { */ class ProverPolynomials : public AllEntities { public: - AllValues get_row(const size_t row_idx) const + AllValues get_row(const size_t row_idx) { AllValues result; + auto result_pointer_array = result.get_pointer_array(); size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; + for (auto& member_pointer : get_pointer_array()) { + *result_pointer_array[column_idx] = (*member_pointer)[row_idx]; column_idx++; } return result; diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 4521e7dbd6e..a85e7fb165f 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -199,6 +199,54 @@ class Ultra { DataType& z_perm_shift = std::get<41>(this->_data); DataType& z_lookup_shift = std::get<42>(this->_data); + auto get_pointer_array() + { + return std::array{ + &q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &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, + &w_l, + &w_r, + &w_o, + &w_4, + &sorted_accum, + &z_perm, + &z_lookup, + &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, + }; + } std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; // Gemini-specific getters. std::vector get_unshifted() override @@ -293,12 +341,13 @@ class Ultra { */ class ProverPolynomials : public AllEntities { public: - AllValues get_row(const size_t row_idx) const + AllValues get_row(const size_t row_idx) { AllValues result; + auto result_pointers = result.get_pointer_array(); size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; + for (auto* column : get_pointer_array()) { + *result[column_idx] = (*column)[row_idx]; column_idx++; } return result; From a96aa39cc79ed73fee1e7d334fccc3097c181330 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 21:13:17 +0000 Subject: [PATCH 02/47] REVERTME comment out all array usage of polynomials --- .../src/barretenberg/honk/flavor/ecc_vm.hpp | 16 +++-- .../barretenberg/honk/flavor/goblin_ultra.hpp | 9 +-- .../src/barretenberg/honk/flavor/ultra.hpp | 7 +- .../proof_system/grand_product_library.hpp | 34 ++++++---- .../honk/proof_system/permutation_library.hpp | 3 +- .../honk/proof_system/protogalaxy_prover.cpp | 2 +- .../honk/proof_system/protogalaxy_prover.hpp | 6 +- .../honk/sumcheck/partial_evaluation.test.cpp | 67 ++++++++++--------- .../sumcheck/relation_correctness.test.cpp | 32 +++++---- .../barretenberg/honk/sumcheck/sumcheck.hpp | 30 +++++---- .../honk/sumcheck/sumcheck.test.cpp | 34 +++++----- .../honk/sumcheck/sumcheck_round.hpp | 16 +++-- .../src/barretenberg/honk/utils/testing.hpp | 6 +- .../eccvm/eccvm_circuit_builder.hpp | 6 +- .../proof_system/flavor/flavor.hpp | 2 +- 15 files changed, 155 insertions(+), 115 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index 2f4725bd6a8..6290c8e1a8d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -683,11 +683,12 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) const { AllValues result; - size_t column_idx = 0; // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; - column_idx++; - } + (void)row_idx; + // size_t column_idx = 0; // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip + // for (auto& column : this->_data) { + // // result[column_idx] = column[row_idx]; + // column_idx++; + // } return result; } }; @@ -738,7 +739,10 @@ template class ECCVMBa AllValues result; size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; + (void)column_idx; + (void)row_idx; + (void)column; + // result[column_idx] = column[row_idx]; column_idx++; } return result; diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 5f7c3aef53a..9d044f979c1 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -210,7 +210,7 @@ class GoblinUltra { DataType& z_perm_shift = std::get<46>(this->_data); DataType& z_lookup_shift = std::get<47>(this->_data); - auto get_pointer_array() + [[nodiscard]] auto get_pointer_array() const { return std::array{ &q_c, &q_l, @@ -381,13 +381,14 @@ class GoblinUltra { */ class ProverPolynomials : public AllEntities { public: - AllValues get_row(const size_t row_idx) + [[nodiscard]] size_t get_polynomial_size() const { return q_c.size(); } + [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; auto result_pointer_array = result.get_pointer_array(); size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& member_pointer : get_pointer_array()) { - *result_pointer_array[column_idx] = (*member_pointer)[row_idx]; + for (auto* member_pointer : get_pointer_array()) { + *(result_pointer_array[column_idx]) = (*member_pointer)[row_idx]; column_idx++; } return result; diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index a85e7fb165f..357620d3536 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -199,7 +199,7 @@ class Ultra { DataType& z_perm_shift = std::get<41>(this->_data); DataType& z_lookup_shift = std::get<42>(this->_data); - auto get_pointer_array() + [[nodiscard]] auto get_pointer_array() const { return std::array{ &q_c, @@ -341,13 +341,14 @@ class Ultra { */ class ProverPolynomials : public AllEntities { public: - AllValues get_row(const size_t row_idx) + [[nodiscard]] size_t get_polynomial_size() const { return q_c.size(); } + [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; auto result_pointers = result.get_pointer_array(); size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip for (auto* column : get_pointer_array()) { - *result[column_idx] = (*column)[row_idx]; + *(result_pointers[column_idx]) = (*column)[row_idx]; column_idx++; } return result; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp index c36ecfe7038..2d2415b8206 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/grand_product_library.hpp @@ -50,10 +50,13 @@ void compute_grand_product(const size_t circuit_size, typename Flavor::ProverPolynomials& full_polynomials, proof_system::RelationParameters& relation_parameters) { + (void)relation_parameters; using FF = typename Flavor::FF; using Polynomial = typename Flavor::Polynomial; using Accumulator = std::tuple_element_t<0, typename GrandProdRelation::SumcheckArrayOfValuesOverSubrelations>; + Accumulator* v = nullptr; + (void)v; // Allocate numerator/denominator polynomials that will serve as scratch space // TODO(zac) we can re-use the permutation polynomial as the numerator polynomial. Reduces readability Polynomial numerator = Polynomial{ circuit_size }; @@ -63,20 +66,23 @@ 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; - 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; - for (size_t k = 0; k < Flavor::NUM_ALL_ENTITIES; ++k) { - evaluations[k] = full_polynomials[k].size() > i ? full_polynomials[k][i] : 0; - } - numerator[i] = GrandProdRelation::template compute_grand_product_numerator( - evaluations, relation_parameters); - denominator[i] = GrandProdRelation::template compute_grand_product_denominator( - evaluations, relation_parameters); - } - }); + // auto full_polynomial_pointers = full_polynomials.get_pointer_array(); + // 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.get_pointer_array(); + // 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; + // } + // numerator[i] = GrandProdRelation::template compute_grand_product_numerator( + // evaluations, relation_parameters); + // denominator[i] = GrandProdRelation::template compute_grand_product_denominator( + // evaluations, relation_parameters); + // } + // }); // Step (2) // Compute the accumulating product of the numerator and denominator terms. 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 ca40775d2b0..4728481ba7b 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -71,7 +71,8 @@ void compute_permutation_grand_product(const size_t circuit_size, typename Flavor::AllValues evaluations; for (size_t k = 0; k < Flavor::NUM_ALL_ENTITIES; ++k) { - evaluations[k] = full_polynomials[k].size() > i ? full_polynomials[k][i] : 0; + (void)k; + // evaluations[k] = full_polynomials[k].size() > i ? full_polynomials[k][i] : 0; } numerator[i] = GrandProdRelation::template compute_permutation_numerator(evaluations, relation_parameters); diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp index ef64c21c924..7cf49812a08 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp @@ -44,7 +44,7 @@ ProverFoldingResult ProtoGalaxyProver_prover_polynomials[0].size(); + auto instance_size = accumulator->prover_polynomials.get_polynomial_size(); auto log_instance_size = static_cast(numeric::get_msb(instance_size)); auto deltas = compute_round_challenge_pows(log_instance_size, delta); auto perturbator = compute_perturbator(accumulator, deltas, alpha); diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index abc4bc0059b..db0b8f421d6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -190,9 +190,11 @@ template class ProtoGalaxyProver_ { const ProverInstances& instances, const size_t row_idx) { - for (size_t poly_idx = 0; poly_idx < Flavor::NUM_ALL_ENTITIES; poly_idx++) { + size_t poly_idx = 0; + for (auto* member_pointer : extended_univariates.get_pointer_array()) { auto base_univariate = instances.row_to_univariate(poly_idx, row_idx); - extended_univariates[poly_idx] = base_univariate.template extend_to(); + *member_pointer = base_univariate.template extend_to(); + poly_idx++; } } diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp index 2a5e49c4cf7..139f7cac9ba 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/partial_evaluation.test.cpp @@ -65,14 +65,15 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], FF(0)); + auto partially_evaluated_polynomial_pointers = sumcheck.partially_evaluated_polynomials; + // EXPECT_EQ((*partially_evaluated_polynomial_pointers[0])[0], round_challenge_0); + // EXPECT_EQ((*partially_evaluated_polynomial_pointers[0])[1], FF(0)); FF round_challenge_1 = 2; FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) @@ -101,13 +102,13 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); FF round_challenge_1 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } /* @@ -164,23 +165,23 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); FF round_challenge_1 = 2; FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; // 6 FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; // 10 sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); FF round_challenge_2 = 3; FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; // 18 sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) @@ -215,23 +216,23 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); FF round_challenge_1 = FF::random_element(); FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); FF round_challenge_2 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) @@ -282,12 +283,12 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - for (size_t i = 0; i < 3; i++) { - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_q1[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_q2[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][2], expected_q3[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][3], expected_q4[i]); - } + // for (size_t i = 0; i < 3; i++) { + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_q1[i]); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_q2[i]); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][2], expected_q3[i]); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][3], expected_q4[i]); + // } FF round_challenge_1 = FF::random_element(); std::array expected_lo; @@ -297,19 +298,19 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) expected_hi[i] = expected_q3[i] * (FF(1) - round_challenge_1) + expected_q4[i] * round_challenge_1; } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - for (size_t i = 0; i < 3; i++) { - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_lo[i]); - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_hi[i]); - } + // for (size_t i = 0; i < 3; i++) { + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_lo[i]); + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_hi[i]); + // } FF round_challenge_2 = FF::random_element(); std::array expected_val; for (size_t i = 0; i < 3; i++) { expected_val[i] = expected_lo[i] * (FF(1) - round_challenge_2) + expected_hi[i] * round_challenge_2; } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - for (size_t i = 0; i < 3; i++) { - EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_val[i]); - } + // for (size_t i = 0; i < 3; i++) { + // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_val[i]); + // } } } // namespace test_sumcheck_polynomials diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp index 0048d7a4189..209c04cfb3a 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp @@ -40,7 +40,9 @@ template void check_relation(auto circuit_s AllValues evaluations_at_index_i; size_t poly_idx = 0; for (auto& poly : polynomials) { - evaluations_at_index_i[poly_idx] = poly[i]; + (void)poly_idx; + (void)poly; + // evaluations_at_index_i[poly_idx] = poly[i]; ++poly_idx; } @@ -348,7 +350,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorPermutationRelationCorrectness) for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - prover_polynomials[i] = polynomial_container[i]; + // prover_polynomials[i] = polynomial_container[i]; } // Fill in lagrange polynomials used in the permutation relation @@ -468,7 +470,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - prover_polynomials[i] = polynomial_container[i]; + // prover_polynomials[i] = polynomial_container[i]; } // Construct lagrange polynomials that are needed for Goblin Translator's GenPermSort Relation @@ -566,7 +568,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - prover_polynomial_ids[i] = polynomial_ids[i]; + // prover_polynomial_ids[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -577,7 +579,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - prover_polynomials[i] = polynomial_container[i]; + // prover_polynomials[i] = polynomial_container[i]; } } @@ -585,7 +587,9 @@ 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]; - prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + (void)shifted_id; + (void)to_be_shifted_id; + // prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange even polynomial @@ -662,7 +666,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - prover_polynomial_ids[i] = polynomial_ids[i]; + // prover_polynomial_ids[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -673,7 +677,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - prover_polynomials[i] = polynomial_container[i]; + // prover_polynomials[i] = polynomial_container[i]; } } @@ -681,7 +685,9 @@ 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]; - prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + (void)shifted_id; + (void)to_be_shifted_id; + // prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange odd polynomial (the only non-witness one we are using) @@ -1079,7 +1085,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - prover_polynomial_ids[i] = polynomial_ids[i]; + // prover_polynomial_ids[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -1090,7 +1096,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - prover_polynomials[i] = polynomial_container[i]; + // prover_polynomials[i] = polynomial_container[i]; } } @@ -1098,7 +1104,9 @@ 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]; - prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + (void)shifted_id; + (void)to_be_shifted_id; + // prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Copy values of wires used in the non-native field relation from the circuit builder diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 40e0d09b664..1997b12b51e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -111,12 +111,13 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; - size_t evaluation_idx = 0; - // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& polynomial : partially_evaluated_polynomials) { - multivariate_evaluations[evaluation_idx] = polynomial[0]; - ++evaluation_idx; - } + // auto multivariate_evaluations_pointers = multivariate_evaluations.get_pointer_array(); + // size_t evaluation_idx = 0; + // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip + // for (auto* polynomial : partially_evaluated_polynomials.get_pointer_array()) { + // *multivariate_evaluations_pointers[evaluation_idx] = (*polynomial)[0]; + // ++evaluation_idx; + // } transcript.send_to_verifier("Sumcheck:evaluations", multivariate_evaluations._data); return { multivariate_challenge, multivariate_evaluations }; @@ -150,13 +151,16 @@ template class SumcheckProver { */ void partially_evaluate(auto& polynomials, size_t round_size, FF round_challenge) { - // 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) { - partially_evaluated_polynomials[j][i >> 1] = - polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]); - } - }); + (void)polynomials; + (void)round_size; + (void)round_challenge; + // // 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) { + // partially_evaluated_polynomials[j][i >> 1] = + // polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]); + // } + // }); }; }; diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp index 35ced6e72ef..8d8afac9ce6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.test.cpp @@ -136,24 +136,28 @@ TEST_F(SumcheckTests, PolynomialNormalization) FF l_7 = ( u_0) * ( u_1) * ( u_2); // clang-format on FF hand_computed_value; - for (size_t i = 0; i < NUM_POLYNOMIALS; i++) { + auto partially_evaluated_polynomials_array = sumcheck.partially_evaluated_polynomials.get_pointer_array(); + size_t i = 0; + for (auto* full_polynomial_pointer : full_polynomials.get_pointer_array()) { // full_polynomials[0][0] = w_l[0], full_polynomials[1][1] = w_r[1], and so on. - hand_computed_value = l_0 * full_polynomials[i][0] + l_1 * full_polynomials[i][1] + - l_2 * full_polynomials[i][2] + l_3 * full_polynomials[i][3] + - l_4 * full_polynomials[i][4] + l_5 * full_polynomials[i][5] + - l_6 * full_polynomials[i][6] + l_7 * full_polynomials[i][7]; - EXPECT_EQ(hand_computed_value, sumcheck.partially_evaluated_polynomials[i][0]); + 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++; } // 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 (size_t i = 0; i < NUM_POLYNOMIALS; i++) { - barretenberg::Polynomial poly(full_polynomials[i]); - auto v_expected = poly.evaluate_mle(u_challenge); - auto v_result = output.claimed_evaluations[i]; - EXPECT_EQ(v_expected, v_result); - } + (void)u_challenge; + // for (size_t i = 0; i < NUM_POLYNOMIALS; i++) { + // barretenberg::Polynomial poly(full_polynomials[i]); + // auto v_expected = poly.evaluate_mle(u_challenge); + // auto v_result = output.claimed_evaluations[i]; + // EXPECT_EQ(v_expected, v_result); + // } } TEST_F(SumcheckTests, Prover) @@ -186,9 +190,9 @@ TEST_F(SumcheckTests, Prover) expected_values.emplace_back(expected_lo + expected_hi); } - for (size_t poly_idx = 0; poly_idx < NUM_POLYNOMIALS; poly_idx++) { - EXPECT_EQ(output.claimed_evaluations[poly_idx], expected_values[poly_idx]); - } + // for (size_t poly_idx = 0; poly_idx < NUM_POLYNOMIALS; poly_idx++) { + // EXPECT_EQ(output.claimed_evaluations[poly_idx], expected_values[poly_idx]); + // } } // TODO(#225): make the inputs to this test more interesting, e.g. non-trivial permutations diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index e048c48fcbc..822fbc5e9bb 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -90,12 +90,16 @@ template class SumcheckProverRound { /* const */ ProverPolynomialsOrPartiallyEvaluatedMultivariates& multivariates, size_t edge_idx) { - size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& poly : multivariates) { - auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); - extended_edges[univariate_idx] = edge.template extend_to(); - ++univariate_idx; - } + (void)extended_edges; + (void)multivariates; + (void)edge_idx; + // auto extended_edges_pointer = extended_edges.get_pointer_array(); + // size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip + // for (auto& poly : multivariates) { + // auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); + // *extended_edges_pointer[univariate_idx] = edge.template extend_to(); + // ++univariate_idx; + // } } /** diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index 07275e9327d..828e73b256f 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -27,9 +27,10 @@ get_sequential_prover_polynomials(const size_t log_circuit_size, const size_t st } ProverPolynomials prover_polynomials; + auto prover_polynomials_pointers = prover_polynomials.get_pointer_array(); size_t poly_idx = 0; for (auto& polynomial : storage) { - prover_polynomials[poly_idx] = polynomial; + *(prover_polynomials_pointers[poly_idx]) = polynomial; poly_idx++; } @@ -56,8 +57,9 @@ get_zero_prover_polynomials(const size_t log_circuit_size) ProverPolynomials prover_polynomials; size_t poly_idx = 0; + auto prover_polynomial_pointers = prover_polynomials.get_pointer_array(); for (auto& polynomial : storage) { - prover_polynomials[poly_idx] = polynomial; + *prover_polynomial_pointers[poly_idx] = polynomial; poly_idx++; } 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 78895165144..aad175caa96 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 @@ -339,8 +339,10 @@ template class ECCVMCircuitBuilder { size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); AllPolynomials polys; + // auto poly_pointers = polys.get_pointer_array(); for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { - polys[j] = Polynomial(num_rows_pow2); + // TODO(array) + // poly_pointers[j] = Polynomial(num_rows_pow2); } polys.lagrange_first[0] = 1; @@ -503,7 +505,7 @@ template class ECCVMCircuitBuilder { }; auto polynomials = compute_polynomials(); - const size_t num_rows = polynomials[0].size(); + const size_t num_rows = 0; // polynomials[0].size(); proof_system::honk::lookup_library::compute_logderivative_inverse>( polynomials, params, num_rows); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 7b8bc126206..58c6d21a9b7 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -88,7 +88,7 @@ template class Ent virtual ~Entities_() = default; - DataType& operator[](size_t idx) { return _data[idx]; }; + // DataType& operator[](size_t idx) { return _data[idx]; }; typename ArrayType::iterator begin() { return _data.begin(); }; typename ArrayType::iterator end() { return _data.end(); }; From 844c3104c5cbb3686351dd8e128af57b99a8959b Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 22:51:09 +0000 Subject: [PATCH 03/47] try to remove operator[] --- .../cpp/src/barretenberg/flavor/flavor.hpp | 11 +++ .../src/barretenberg/flavor/goblin_ultra.hpp | 86 ++++++++++------- .../cpp/src/barretenberg/flavor/ultra.hpp | 95 +++++++++---------- .../honk/proof_system/protogalaxy_prover.hpp | 2 +- .../src/barretenberg/honk/utils/testing.hpp | 4 +- .../eccvm/eccvm_circuit_builder.hpp | 2 +- .../library/grand_product_library.hpp | 4 +- .../src/barretenberg/sumcheck/sumcheck.hpp | 4 +- .../barretenberg/sumcheck/sumcheck.test.cpp | 4 +- .../barretenberg/sumcheck/sumcheck_round.hpp | 2 +- 10 files changed, 119 insertions(+), 95 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 58c6d21a9b7..679876292e2 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -64,6 +64,7 @@ */ #pragma once +#include "barretenberg/common/zip_view.hpp" #include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/univariate.hpp" @@ -74,6 +75,16 @@ namespace proof_system::honk::flavor { +#define DEFINE_GET_REF_ARRAY(...) \ + [[nodiscard]] auto get_ref_array() \ + { \ + return std::array{ __VA_ARGS__ }; \ + } \ + [[nodiscard]] auto get_ref_array() const \ + { \ + return std::array{ __VA_ARGS__ }; \ + } + /** * @brief Base data class template, a wrapper for std::array, from which every flavor class ultimately derives. * diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 4b1471e2c62..3aa1c9ca7d1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -210,35 +210,54 @@ class GoblinUltra { DataType& z_perm_shift = std::get<46>(this->_data); DataType& z_lookup_shift = std::get<47>(this->_data); - [[nodiscard]] auto get_pointer_array() const - { - return std::array{ - &q_c, &q_l, - &q_r, &q_o, - &q_4, &q_m, - &q_arith, &q_sort, - &q_elliptic, &q_aux, - &q_lookup, &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, - &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, &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, - }; - } + DEFINE_GET_REF_ARRAY(&q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &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, + &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, + &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); std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; std::vector get_ecc_op_wires() @@ -382,14 +401,11 @@ class GoblinUltra { class ProverPolynomials : public AllEntities { public: [[nodiscard]] size_t get_polynomial_size() const { return q_c.size(); } - [[nodiscard]] AllValues get_row(const size_t row_idx) const + [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - auto result_pointer_array = result.get_pointer_array(); - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto* member_pointer : get_pointer_array()) { - *(result_pointer_array[column_idx]) = (*member_pointer)[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.get_ref_array(), get_ref_array())) { + *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 4e9e1979089..29a9923c829 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -199,52 +199,52 @@ class Ultra { DataType& z_perm_shift = std::get<41>(this->_data); DataType& z_lookup_shift = std::get<42>(this->_data); - [[nodiscard]] auto get_pointer_array() const + [[nodiscard]] auto get_ref_array() const { return std::array{ - &q_c, - &q_l, - &q_r, - &q_o, - &q_4, - &q_m, - &q_arith, - &q_sort, - &q_elliptic, - &q_aux, - &q_lookup, - &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, - &w_l, - &w_r, - &w_o, - &w_4, - &sorted_accum, - &z_perm, - &z_lookup, - &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, + q_c, + q_l, + q_r, + q_o, + q_4, + q_m, + q_arith, + q_sort, + q_elliptic, + q_aux, + q_lookup, + 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, + w_l, + w_r, + w_o, + w_4, + sorted_accum, + z_perm, + z_lookup, + 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, }; } std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; @@ -345,11 +345,8 @@ class Ultra { [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - auto result_pointers = result.get_pointer_array(); - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto* column : get_pointer_array()) { - *(result_pointers[column_idx]) = (*column)[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.get_ref_array(), get_ref_array())) { + *result_field = (*polynomial)[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index eb8a5470d18..baa8df93cb1 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -191,7 +191,7 @@ template class ProtoGalaxyProver_ { const size_t row_idx) { size_t poly_idx = 0; - for (auto* member_pointer : extended_univariates.get_pointer_array()) { + for (auto* member_pointer : extended_univariates.get_ref_array()) { auto base_univariate = instances.row_to_univariate(poly_idx, row_idx); *member_pointer = base_univariate.template extend_to(); poly_idx++; diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index 828e73b256f..85afd4153ef 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -27,7 +27,7 @@ get_sequential_prover_polynomials(const size_t log_circuit_size, const size_t st } ProverPolynomials prover_polynomials; - auto prover_polynomials_pointers = prover_polynomials.get_pointer_array(); + auto prover_polynomials_pointers = prover_polynomials.get_ref_array(); size_t poly_idx = 0; for (auto& polynomial : storage) { *(prover_polynomials_pointers[poly_idx]) = polynomial; @@ -57,7 +57,7 @@ get_zero_prover_polynomials(const size_t log_circuit_size) ProverPolynomials prover_polynomials; size_t poly_idx = 0; - auto prover_polynomial_pointers = prover_polynomials.get_pointer_array(); + auto prover_polynomial_pointers = prover_polynomials.get_ref_array(); for (auto& polynomial : storage) { *prover_polynomial_pointers[poly_idx] = polynomial; poly_idx++; 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 8eb7ce5bb8b..df3212fc07d 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 @@ -338,7 +338,7 @@ template class ECCVMCircuitBuilder { size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); AllPolynomials polys; - // auto poly_pointers = polys.get_pointer_array(); + // auto poly_pointers = polys.get_ref_array(); for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { // TODO(array) // poly_pointers[j] = Polynomial(num_rows_pow2); 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 0d18e1efd15..594d98b7354 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 @@ -67,13 +67,13 @@ 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.get_pointer_array(); + // auto full_polynomial_pointers = full_polynomials.get_ref_array(); // 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.get_pointer_array(); + // auto evaluations_pointer = evaluations.get_ref_array(); // 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; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 1d233bfb517..ef76be2b6c5 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -111,10 +111,10 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; - // auto multivariate_evaluations_pointers = multivariate_evaluations.get_pointer_array(); + // auto multivariate_evaluations_pointers = multivariate_evaluations.get_ref_array(); // size_t evaluation_idx = 0; // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - // for (auto* polynomial : partially_evaluated_polynomials.get_pointer_array()) { + // for (auto* polynomial : partially_evaluated_polynomials.get_ref_array()) { // *multivariate_evaluations_pointers[evaluation_idx] = (*polynomial)[0]; // ++evaluation_idx; // } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index b8203ad600b..510a484fa2a 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -136,9 +136,9 @@ 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.get_pointer_array(); + auto partially_evaluated_polynomials_array = sumcheck.partially_evaluated_polynomials.get_ref_array(); size_t i = 0; - for (auto* full_polynomial_pointer : full_polynomials.get_pointer_array()) { + for (auto* full_polynomial_pointer : full_polynomials.get_ref_array()) { // 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] + diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index d0720766323..e0c7925377d 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -93,7 +93,7 @@ template class SumcheckProverRound { (void)extended_edges; (void)multivariates; (void)edge_idx; - // auto extended_edges_pointer = extended_edges.get_pointer_array(); + // auto extended_edges_pointer = extended_edges.get_ref_array(); // size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip // for (auto& poly : multivariates) { // auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); From a02ca70c837ac9fe18b15cd7580f69364a2d7f0b Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 22:55:50 +0000 Subject: [PATCH 04/47] try to remove operator[] --- .../cpp/src/barretenberg/flavor/ultra.hpp | 91 +++++++++---------- .../sumcheck/partial_evaluation.test.cpp | 3 + 2 files changed, 46 insertions(+), 48 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp index 29a9923c829..4c736668777 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -199,54 +199,49 @@ class Ultra { DataType& z_perm_shift = std::get<41>(this->_data); DataType& z_lookup_shift = std::get<42>(this->_data); - [[nodiscard]] auto get_ref_array() const - { - return std::array{ - q_c, - q_l, - q_r, - q_o, - q_4, - q_m, - q_arith, - q_sort, - q_elliptic, - q_aux, - q_lookup, - 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, - w_l, - w_r, - w_o, - w_4, - sorted_accum, - z_perm, - z_lookup, - 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, - }; - } + DEFINE_GET_REF_ARRAY(&q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &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, + &w_l, + &w_r, + &w_o, + &w_4, + &sorted_accum, + &z_perm, + &z_lookup, + &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); std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; // Gemini-specific getters. std::vector get_unshifted() override diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index 154aa42f603..72fa0ab0303 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -72,6 +72,7 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsSpecial) FF round_challenge_1 = 2; FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; + (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); @@ -108,6 +109,7 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) FF round_challenge_1 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; + (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } @@ -181,6 +183,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) FF round_challenge_2 = 3; FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; // 18 + (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } From 264dc1811e56cc4b204f76f682e5f41bf6d30e95 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 22:57:08 +0000 Subject: [PATCH 05/47] try to remove operator[] --- .../cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index 72fa0ab0303..f70218ba927 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -235,6 +235,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) FF round_challenge_2 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; + (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } From 2444a59ae946912d8d65e3640f9afa620bacd96c Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 22:59:43 +0000 Subject: [PATCH 06/47] try to remove operator[] --- .../cpp/src/barretenberg/flavor/flavor.hpp | 6 +- .../src/barretenberg/flavor/goblin_ultra.hpp | 97 ++++++++++--------- .../cpp/src/barretenberg/flavor/ultra.hpp | 87 +++++++++-------- 3 files changed, 96 insertions(+), 94 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 679876292e2..546a0dc6d62 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -75,12 +75,12 @@ namespace proof_system::honk::flavor { -#define DEFINE_GET_REF_ARRAY(...) \ - [[nodiscard]] auto get_ref_array() \ +#define DEFINE_GET_POINTER_ARRAY(...) \ + [[nodiscard]] auto get_pointer_array() \ { \ return std::array{ __VA_ARGS__ }; \ } \ - [[nodiscard]] auto get_ref_array() const \ + [[nodiscard]] auto get_pointer_array() const \ { \ return std::array{ __VA_ARGS__ }; \ } diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 3aa1c9ca7d1..3785c0f3d05 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -210,54 +210,55 @@ class GoblinUltra { DataType& z_perm_shift = std::get<46>(this->_data); DataType& z_lookup_shift = std::get<47>(this->_data); - DEFINE_GET_REF_ARRAY(&q_c, - &q_l, - &q_r, - &q_o, - &q_4, - &q_m, - &q_arith, - &q_sort, - &q_elliptic, - &q_aux, - &q_lookup, - &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, - &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, - &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); + // defines a method get_pointer_array that returns the following, with const and non-const variants + DEFINE_GET_POINTER_ARRAY(&q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &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, + &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, + &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); std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; std::vector get_ecc_op_wires() diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp index 4c736668777..8f3ba16b449 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -199,49 +199,50 @@ class Ultra { DataType& z_perm_shift = std::get<41>(this->_data); DataType& z_lookup_shift = std::get<42>(this->_data); - DEFINE_GET_REF_ARRAY(&q_c, - &q_l, - &q_r, - &q_o, - &q_4, - &q_m, - &q_arith, - &q_sort, - &q_elliptic, - &q_aux, - &q_lookup, - &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, - &w_l, - &w_r, - &w_o, - &w_4, - &sorted_accum, - &z_perm, - &z_lookup, - &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); + // defines a method get_pointer_array that returns the following, with const and non-const variants + DEFINE_GET_POINTER_ARRAY(&q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &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, + &w_l, + &w_r, + &w_o, + &w_4, + &sorted_accum, + &z_perm, + &z_lookup, + &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); std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; // Gemini-specific getters. std::vector get_unshifted() override From 6ff2adb2ccba3ba818b288353495c1d1de91fd55 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 23:00:21 +0000 Subject: [PATCH 07/47] try to remove operator[] --- barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp | 2 +- barretenberg/cpp/src/barretenberg/flavor/ultra.hpp | 2 +- .../src/barretenberg/honk/proof_system/protogalaxy_prover.hpp | 2 +- barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp | 4 ++-- .../circuit_builder/eccvm/eccvm_circuit_builder.hpp | 2 +- .../proof_system/library/grand_product_library.hpp | 4 ++-- barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp | 4 ++-- barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp | 4 ++-- barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 3785c0f3d05..79bac7f048c 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -405,7 +405,7 @@ class GoblinUltra { [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_ref_array(), get_ref_array())) { + for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), get_pointer_array())) { *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 8f3ba16b449..f5c00dbe314 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -341,7 +341,7 @@ class Ultra { [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_ref_array(), get_ref_array())) { + for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), get_pointer_array())) { *result_field = (*polynomial)[row_idx]; } return result; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index baa8df93cb1..eb8a5470d18 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -191,7 +191,7 @@ template class ProtoGalaxyProver_ { const size_t row_idx) { size_t poly_idx = 0; - for (auto* member_pointer : extended_univariates.get_ref_array()) { + for (auto* member_pointer : extended_univariates.get_pointer_array()) { auto base_univariate = instances.row_to_univariate(poly_idx, row_idx); *member_pointer = base_univariate.template extend_to(); poly_idx++; diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index 85afd4153ef..828e73b256f 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -27,7 +27,7 @@ get_sequential_prover_polynomials(const size_t log_circuit_size, const size_t st } ProverPolynomials prover_polynomials; - auto prover_polynomials_pointers = prover_polynomials.get_ref_array(); + auto prover_polynomials_pointers = prover_polynomials.get_pointer_array(); size_t poly_idx = 0; for (auto& polynomial : storage) { *(prover_polynomials_pointers[poly_idx]) = polynomial; @@ -57,7 +57,7 @@ get_zero_prover_polynomials(const size_t log_circuit_size) ProverPolynomials prover_polynomials; size_t poly_idx = 0; - auto prover_polynomial_pointers = prover_polynomials.get_ref_array(); + auto prover_polynomial_pointers = prover_polynomials.get_pointer_array(); for (auto& polynomial : storage) { *prover_polynomial_pointers[poly_idx] = polynomial; poly_idx++; 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 df3212fc07d..8eb7ce5bb8b 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 @@ -338,7 +338,7 @@ template class ECCVMCircuitBuilder { size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); AllPolynomials polys; - // auto poly_pointers = polys.get_ref_array(); + // auto poly_pointers = polys.get_pointer_array(); for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { // TODO(array) // poly_pointers[j] = Polynomial(num_rows_pow2); 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 594d98b7354..0d18e1efd15 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 @@ -67,13 +67,13 @@ 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.get_ref_array(); + // auto full_polynomial_pointers = full_polynomials.get_pointer_array(); // 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.get_ref_array(); + // auto evaluations_pointer = evaluations.get_pointer_array(); // 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; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index ef76be2b6c5..1d233bfb517 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -111,10 +111,10 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; - // auto multivariate_evaluations_pointers = multivariate_evaluations.get_ref_array(); + // auto multivariate_evaluations_pointers = multivariate_evaluations.get_pointer_array(); // size_t evaluation_idx = 0; // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - // for (auto* polynomial : partially_evaluated_polynomials.get_ref_array()) { + // for (auto* polynomial : partially_evaluated_polynomials.get_pointer_array()) { // *multivariate_evaluations_pointers[evaluation_idx] = (*polynomial)[0]; // ++evaluation_idx; // } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index 510a484fa2a..b8203ad600b 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -136,9 +136,9 @@ 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.get_ref_array(); + auto partially_evaluated_polynomials_array = sumcheck.partially_evaluated_polynomials.get_pointer_array(); size_t i = 0; - for (auto* full_polynomial_pointer : full_polynomials.get_ref_array()) { + for (auto* full_polynomial_pointer : full_polynomials.get_pointer_array()) { // 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] + diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index e0c7925377d..d0720766323 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -93,7 +93,7 @@ template class SumcheckProverRound { (void)extended_edges; (void)multivariates; (void)edge_idx; - // auto extended_edges_pointer = extended_edges.get_ref_array(); + // auto extended_edges_pointer = extended_edges.get_pointer_array(); // size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip // for (auto& poly : multivariates) { // auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); From ad991415288dd7e9ac4228bd1392bef6f88b3763 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 23:24:08 +0000 Subject: [PATCH 08/47] Start of implementing --- .../cpp/src/barretenberg/flavor/ecc_vm.hpp | 114 ++++++++++++++++-- 1 file changed, 107 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index d7515b79015..19fe0994d74 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -394,6 +394,111 @@ template class ECCVMBa } // clang-format on + DEFINE_GET_POINTER_ARRAY(&lagrange_first, + &lagrange_second, + &lagrange_last, + &transcript_add, + &transcript_mul, + &transcript_eq, + &transcript_collision_check, + &transcript_msm_transition, + &transcript_pc, + &transcript_msm_count, + &transcript_x, + &transcript_y, + &transcript_z1, + &transcript_z2, + &transcript_z1zero, + &transcript_z2zero, + &transcript_op, + &transcript_accumulator_x, + &transcript_accumulator_y, + &transcript_msm_x, + &transcript_msm_y, + &precompute_pc, + &precompute_point_transition, + &precompute_round, + &precompute_scalar_sum, + &precompute_s1hi, + &precompute_s1lo, + &precompute_s2hi, + &precompute_s2lo, + &precompute_s3hi, + &precompute_s3lo, + &precompute_s4hi, + &precompute_s4lo, + &precompute_skew, + &precompute_dx, + &precompute_dy, + &precompute_tx, + &precompute_ty, + &msm_transition, + &msm_add, + &msm_double, + &msm_skew, + &msm_accumulator_x, + &msm_accumulator_y, + &msm_pc, + &msm_size_of_msm, + &msm_count, + &msm_round, + &msm_add1, + &msm_add2, + &msm_add3, + &msm_add4, + &msm_x1, + &msm_y1, + &msm_x2, + &msm_y2, + &msm_x3, + &msm_y3, + &msm_x4, + &msm_y4, + &msm_collision_x1, + &msm_collision_x2, + &msm_collision_x3, + &msm_collision_x4, + &msm_lambda1, + &msm_lambda2, + &msm_lambda3, + &msm_lambda4, + &msm_slice1, + &msm_slice2, + &msm_slice3, + &msm_slice4, + &transcript_accumulator_empty, + &transcript_reset_accumulator, + &precompute_select, + &lookup_read_counts_0, + &lookup_read_counts_1, + &z_perm, + &lookup_inverses, + &transcript_mul_shift, + &transcript_msm_count_shift, + &transcript_accumulator_x_shift, + &transcript_accumulator_y_shift, + &precompute_scalar_sum_shift, + &precompute_s1hi_shift, + &precompute_dx_shift, + &precompute_dy_shift, + &precompute_tx_shift, + &precompute_ty_shift, + &msm_transition_shift, + &msm_add_shift, + &msm_double_shift, + &msm_skew_shift, + &msm_accumulator_x_shift, + &msm_accumulator_y_shift, + &msm_count_shift, + &msm_round_shift, + &msm_add1_shift, + &msm_pc_shift, + &precompute_pc_shift, + &transcript_pc_shift, + &precompute_round_shift, + &transcript_accumulator_empty_shift, + &precompute_select_shift, + &z_perm_shift) std::vector get_wires() override { return { @@ -737,13 +842,8 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) { AllValues result; - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - (void)column_idx; - (void)row_idx; - (void)column; - // result[column_idx] = column[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result, this->get_pointer_array())) { + result_field = polynomial[row_idx]; } return result; } From e57c811da2c4296702b1e4b5bec320a5f2dd9449 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 23:25:15 +0000 Subject: [PATCH 09/47] Start of implementing --- barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 19fe0994d74..973abcdb648 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -788,12 +788,9 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) const { AllValues result; - (void)row_idx; - // size_t column_idx = 0; // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - // for (auto& column : this->_data) { - // // result[column_idx] = column[row_idx]; - // column_idx++; - // } + for (auto [result_field, polynomial] : zip_view(result, this->get_pointer_array())) { + result_field = polynomial[row_idx]; + } return result; } }; From 82bae8020a5eb9428980ddf3772ea24c89bfafd7 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 23:39:59 +0000 Subject: [PATCH 10/47] Start of implementing --- .../barretenberg/flavor/goblin_translator.hpp | 194 +++++++++++++++++- .../library/grand_product_library.hpp | 37 ++-- 2 files changed, 206 insertions(+), 25 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index 340e4f24554..36586bc0464 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -834,6 +834,191 @@ template class GoblinTranslator_ { DataType& lagrange_second_to_last_in_minicircuit = std::get<182>(this->_data); DataType& ordered_extra_range_constraints_numerator = std::get<183>(this->_data); + DEFINE_GET_POINTER_ARRAY(&op, + &x_lo_y_hi, + &x_hi_z_1, + &y_lo_z_2, + &p_x_low_limbs, + &p_x_low_limbs_range_constraint_0, + &p_x_low_limbs_range_constraint_1, + &p_x_low_limbs_range_constraint_2, + &p_x_low_limbs_range_constraint_3, + &p_x_low_limbs_range_constraint_4, + &p_x_low_limbs_range_constraint_tail, + &p_x_high_limbs, + &p_x_high_limbs_range_constraint_0, + &p_x_high_limbs_range_constraint_1, + &p_x_high_limbs_range_constraint_2, + &p_x_high_limbs_range_constraint_3, + &p_x_high_limbs_range_constraint_4, + &p_x_high_limbs_range_constraint_tail, + &p_y_low_limbs, + &p_y_low_limbs_range_constraint_0, + &p_y_low_limbs_range_constraint_1, + &p_y_low_limbs_range_constraint_2, + &p_y_low_limbs_range_constraint_3, + &p_y_low_limbs_range_constraint_4, + &p_y_low_limbs_range_constraint_tail, + &p_y_high_limbs, + &p_y_high_limbs_range_constraint_0, + &p_y_high_limbs_range_constraint_1, + &p_y_high_limbs_range_constraint_2, + &p_y_high_limbs_range_constraint_3, + &p_y_high_limbs_range_constraint_4, + &p_y_high_limbs_range_constraint_tail, + &z_low_limbs, + &z_low_limbs_range_constraint_0, + &z_low_limbs_range_constraint_1, + &z_low_limbs_range_constraint_2, + &z_low_limbs_range_constraint_3, + &z_low_limbs_range_constraint_4, + &z_low_limbs_range_constraint_tail, + &z_high_limbs, + &z_high_limbs_range_constraint_0, + &z_high_limbs_range_constraint_1, + &z_high_limbs_range_constraint_2, + &z_high_limbs_range_constraint_3, + &z_high_limbs_range_constraint_4, + &z_high_limbs_range_constraint_tail, + &accumulators_binary_limbs_0, + &accumulators_binary_limbs_1, + &accumulators_binary_limbs_2, + &accumulators_binary_limbs_3, + &accumulator_low_limbs_range_constraint_0, + &accumulator_low_limbs_range_constraint_1, + &accumulator_low_limbs_range_constraint_2, + &accumulator_low_limbs_range_constraint_3, + &accumulator_low_limbs_range_constraint_4, + &accumulator_low_limbs_range_constraint_tail, + &accumulator_high_limbs_range_constraint_0, + &accumulator_high_limbs_range_constraint_1, + &accumulator_high_limbs_range_constraint_2, + &accumulator_high_limbs_range_constraint_3, + &accumulator_high_limbs_range_constraint_4, + &accumulator_high_limbs_range_constraint_tail, + "ient_low_binary_limbs, + "ient_high_binary_limbs, + "ient_low_limbs_range_constraint_0, + "ient_low_limbs_range_constraint_1, + "ient_low_limbs_range_constraint_2, + "ient_low_limbs_range_constraint_3, + "ient_low_limbs_range_constraint_4, + "ient_low_limbs_range_constraint_tail, + "ient_high_limbs_range_constraint_0, + "ient_high_limbs_range_constraint_1, + "ient_high_limbs_range_constraint_2, + "ient_high_limbs_range_constraint_3, + "ient_high_limbs_range_constraint_4, + "ient_high_limbs_range_constraint_tail, + &relation_wide_limbs, + &relation_wide_limbs_range_constraint_0, + &relation_wide_limbs_range_constraint_1, + &relation_wide_limbs_range_constraint_2, + &relation_wide_limbs_range_constraint_3, + &concatenated_range_constraints_0, + &concatenated_range_constraints_1, + &concatenated_range_constraints_2, + &concatenated_range_constraints_3, + &ordered_range_constraints_0, + &ordered_range_constraints_1, + &ordered_range_constraints_2, + &ordered_range_constraints_3, + &ordered_range_constraints_4, + &z_perm, + &x_lo_y_hi_shift, + &x_hi_z_1_shift, + &y_lo_z_2_shift, + &p_x_low_limbs_shift, + &p_x_low_limbs_range_constraint_0_shift, + &p_x_low_limbs_range_constraint_1_shift, + &p_x_low_limbs_range_constraint_2_shift, + &p_x_low_limbs_range_constraint_3_shift, + &p_x_low_limbs_range_constraint_4_shift, + &p_x_low_limbs_range_constraint_tail_shift, + &p_x_high_limbs_shift, + &p_x_high_limbs_range_constraint_0_shift, + &p_x_high_limbs_range_constraint_1_shift, + &p_x_high_limbs_range_constraint_2_shift, + &p_x_high_limbs_range_constraint_3_shift, + &p_x_high_limbs_range_constraint_4_shift, + &p_x_high_limbs_range_constraint_tail_shift, + &p_y_low_limbs_shift, + &p_y_low_limbs_range_constraint_0_shift, + &p_y_low_limbs_range_constraint_1_shift, + &p_y_low_limbs_range_constraint_2_shift, + &p_y_low_limbs_range_constraint_3_shift, + &p_y_low_limbs_range_constraint_4_shift, + &p_y_low_limbs_range_constraint_tail_shift, + &p_y_high_limbs_shift, + &p_y_high_limbs_range_constraint_0_shift, + &p_y_high_limbs_range_constraint_1_shift, + &p_y_high_limbs_range_constraint_2_shift, + &p_y_high_limbs_range_constraint_3_shift, + &p_y_high_limbs_range_constraint_4_shift, + &p_y_high_limbs_range_constraint_tail_shift, + &z_low_limbs_shift, + &z_low_limbs_range_constraint_0_shift, + &z_low_limbs_range_constraint_1_shift, + &z_low_limbs_range_constraint_2_shift, + &z_low_limbs_range_constraint_3_shift, + &z_low_limbs_range_constraint_4_shift, + &z_low_limbs_range_constraint_tail_shift, + &z_high_limbs_shift, + &z_high_limbs_range_constraint_0_shift, + &z_high_limbs_range_constraint_1_shift, + &z_high_limbs_range_constraint_2_shift, + &z_high_limbs_range_constraint_3_shift, + &z_high_limbs_range_constraint_4_shift, + &z_high_limbs_range_constraint_tail_shift, + &accumulators_binary_limbs_0_shift, + &accumulators_binary_limbs_1_shift, + &accumulators_binary_limbs_2_shift, + &accumulators_binary_limbs_3_shift, + &accumulator_low_limbs_range_constraint_0_shift, + &accumulator_low_limbs_range_constraint_1_shift, + &accumulator_low_limbs_range_constraint_2_shift, + &accumulator_low_limbs_range_constraint_3_shift, + &accumulator_low_limbs_range_constraint_4_shift, + &accumulator_low_limbs_range_constraint_tail_shift, + &accumulator_high_limbs_range_constraint_0_shift, + &accumulator_high_limbs_range_constraint_1_shift, + &accumulator_high_limbs_range_constraint_2_shift, + &accumulator_high_limbs_range_constraint_3_shift, + &accumulator_high_limbs_range_constraint_4_shift, + &accumulator_high_limbs_range_constraint_tail_shift, + "ient_low_binary_limbs_shift, + "ient_high_binary_limbs_shift, + "ient_low_limbs_range_constraint_0_shift, + "ient_low_limbs_range_constraint_1_shift, + "ient_low_limbs_range_constraint_2_shift, + "ient_low_limbs_range_constraint_3_shift, + "ient_low_limbs_range_constraint_4_shift, + "ient_low_limbs_range_constraint_tail_shift, + "ient_high_limbs_range_constraint_0_shift, + "ient_high_limbs_range_constraint_1_shift, + "ient_high_limbs_range_constraint_2_shift, + "ient_high_limbs_range_constraint_3_shift, + "ient_high_limbs_range_constraint_4_shift, + "ient_high_limbs_range_constraint_tail_shift, + &relation_wide_limbs_shift, + &relation_wide_limbs_range_constraint_0_shift, + &relation_wide_limbs_range_constraint_1_shift, + &relation_wide_limbs_range_constraint_2_shift, + &relation_wide_limbs_range_constraint_3_shift, + &ordered_range_constraints_0_shift, + &ordered_range_constraints_1_shift, + &ordered_range_constraints_2_shift, + &ordered_range_constraints_3_shift, + &ordered_range_constraints_4_shift, + &z_perm_shift, + &lagrange_first, + &lagrange_last, + &lagrange_odd_in_minicircuit, + &lagrange_even_in_minicircuit, + &lagrange_second, + &lagrange_second_to_last_in_minicircuit, + &ordered_extra_range_constraints_numerator) + std::vector get_wires() override { @@ -1430,17 +1615,16 @@ template class GoblinTranslator_ { */ class ProverPolynomials : public AllEntities { public: + [[nodiscard]] size_t get_polynomial_size() const { return this->op.size(); } /** * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which * represents one row in the execution trace. */ - AllValues get_row(const size_t row_idx) + [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - size_t column_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - for (auto& column : this->_data) { - result[column_idx] = column[row_idx]; - column_idx++; + for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), get_pointer_array())) { + *result_field = (*polynomial)[row_idx]; } return result; } 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 0d18e1efd15..351b2a21ff1 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 @@ -51,13 +51,10 @@ void compute_grand_product(const size_t circuit_size, typename Flavor::ProverPolynomials& full_polynomials, proof_system::RelationParameters& relation_parameters) { - (void)relation_parameters; using FF = typename Flavor::FF; using Polynomial = typename Flavor::Polynomial; using Accumulator = std::tuple_element_t<0, typename GrandProdRelation::SumcheckArrayOfValuesOverSubrelations>; - Accumulator* v = nullptr; - (void)v; // Allocate numerator/denominator polynomials that will serve as scratch space // TODO(zac) we can re-use the permutation polynomial as the numerator polynomial. Reduces readability Polynomial numerator = Polynomial{ circuit_size }; @@ -67,23 +64,23 @@ 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.get_pointer_array(); - // 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.get_pointer_array(); - // 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; - // } - // numerator[i] = GrandProdRelation::template compute_grand_product_numerator( - // evaluations, relation_parameters); - // denominator[i] = GrandProdRelation::template compute_grand_product_denominator( - // evaluations, relation_parameters); - // } - // }); + auto full_polynomial_pointers = full_polynomials.get_pointer_array(); + 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.get_pointer_array(); + 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; + } + numerator[i] = GrandProdRelation::template compute_grand_product_numerator( + evaluations, relation_parameters); + denominator[i] = GrandProdRelation::template compute_grand_product_denominator( + evaluations, relation_parameters); + } + }); // Step (2) // Compute the accumulating product of the numerator and denominator terms. From acf9c75a594fa8bd31f352aed54c297a2ecb7477 Mon Sep 17 00:00:00 2001 From: ludamad Date: Thu, 2 Nov 2023 23:46:39 +0000 Subject: [PATCH 11/47] Start of implementing --- barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp | 8 ++++---- .../cpp/src/barretenberg/flavor/goblin_translator.hpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 973abcdb648..78308ae6a23 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -788,8 +788,8 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result, this->get_pointer_array())) { - result_field = polynomial[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), this->get_pointer_array())) { + *result_field = (*polynomial)[row_idx]; } return result; } @@ -839,8 +839,8 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) { AllValues result; - for (auto [result_field, polynomial] : zip_view(result, this->get_pointer_array())) { - result_field = polynomial[row_idx]; + for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), this->get_pointer_array())) { + *result_field = (*polynomial)[row_idx]; } return result; } diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index 36586bc0464..e30964b2358 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -1623,7 +1623,7 @@ template class GoblinTranslator_ { [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), get_pointer_array())) { + for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), this->get_pointer_array())) { *result_field = (*polynomial)[row_idx]; } return result; From fd819a84a6ac4402b831fb0a56016325c4ca5399 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:08:08 +0000 Subject: [PATCH 12/47] Start of implementing --- .../honk/proof_system/protogalaxy_prover.hpp | 4 +- .../sumcheck/partial_evaluation.test.cpp | 77 ++++++++++--------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index eb8a5470d18..8d7be3e6f4d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -191,9 +191,9 @@ template class ProtoGalaxyProver_ { const size_t row_idx) { size_t poly_idx = 0; - for (auto* member_pointer : extended_univariates.get_pointer_array()) { + for (auto* extended_univariate : extended_univariates.get_pointer_array()) { auto base_univariate = instances.row_to_univariate(poly_idx, row_idx); - *member_pointer = base_univariate.template extend_to(); + *extended_univariate = base_univariate.template extend_to(); poly_idx++; } } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index f70218ba927..e400bdac173 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -66,16 +66,15 @@ TYPED_TEST(PartialEvaluationTests, TwoRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto partially_evaluated_polynomial_pointers = sumcheck.partially_evaluated_polynomials; - // EXPECT_EQ((*partially_evaluated_polynomial_pointers[0])[0], round_challenge_0); - // EXPECT_EQ((*partially_evaluated_polynomial_pointers[0])[1], FF(0)); + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.get_pointer_array()[0]; + EXPECT_EQ(first_polynomial[0], round_challenge_0); + EXPECT_EQ(first_polynomial[1], FF(0)); FF round_challenge_1 = 2; FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; - (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } TYPED_TEST(PartialEvaluationTests, TwoRoundsGeneric) @@ -103,15 +102,15 @@ 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 polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + EXPECT_EQ((*polynomials[0])[0], expected_lo); + EXPECT_EQ((*polynomials[0])[1], expected_hi); FF round_challenge_1 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; - (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ((*polynomials[0])[0], expected_val); } /* @@ -168,24 +167,25 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); + auto polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); + EXPECT_EQ((*polynomials[0])[0], expected_q1); + EXPECT_EQ((*polynomials[0])[1], expected_q2); + EXPECT_EQ((*polynomials[0])[2], expected_q3); + EXPECT_EQ((*polynomials[0])[3], expected_q4); FF round_challenge_1 = 2; FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; // 6 FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; // 10 sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + EXPECT_EQ((*polynomials[0])[0], expected_lo); + EXPECT_EQ((*polynomials[0])[1], expected_hi); FF round_challenge_2 = 3; FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; // 18 (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ((*polynomials[0])[0], expected_val); } TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) @@ -218,26 +218,28 @@ 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.get_pointer_array()[0]; + EXPECT_EQ(first_polynomial[0], round_challenge_0); + EXPECT_EQ(first_polynomial[1], FF(0)); sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][2], expected_q3); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][3], expected_q4); + EXPECT_EQ(first_polynomial[0], expected_q1); + EXPECT_EQ(first_polynomial[1], expected_q2); + EXPECT_EQ(first_polynomial[2], expected_q3); + EXPECT_EQ(first_polynomial[3], expected_q4); FF round_challenge_1 = FF::random_element(); FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); + EXPECT_EQ(first_polynomial[0], expected_lo); + EXPECT_EQ(first_polynomial[1], expected_hi); FF round_challenge_2 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; - (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) @@ -288,12 +290,13 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - // for (size_t i = 0; i < 3; i++) { - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_q1[i]); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_q2[i]); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][2], expected_q3[i]); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][3], expected_q4[i]); - // } + auto* polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); + for (size_t i = 0; i < 3; i++) { + EXPECT_EQ((*polynomials[i])[0], expected_q1[i]); + EXPECT_EQ((*polynomials[i])[1], expected_q2[i]); + EXPECT_EQ((*polynomials[i])[2], expected_q3[i]); + EXPECT_EQ((*polynomials[i])[3], expected_q4[i]); + } FF round_challenge_1 = FF::random_element(); std::array expected_lo; @@ -303,19 +306,19 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) expected_hi[i] = expected_q3[i] * (FF(1) - round_challenge_1) + expected_q4[i] * round_challenge_1; } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - // for (size_t i = 0; i < 3; i++) { - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_lo[i]); - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_hi[i]); - // } + for (size_t i = 0; i < 3; i++) { + EXPECT_EQ((*polynomials[i])[0], expected_lo[i]); + EXPECT_EQ((*polynomials[i])[1], expected_hi[i]); + } FF round_challenge_2 = FF::random_element(); std::array expected_val; for (size_t i = 0; i < 3; i++) { expected_val[i] = expected_lo[i] * (FF(1) - round_challenge_2) + expected_hi[i] * round_challenge_2; } sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - // for (size_t i = 0; i < 3; i++) { - // EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_val[i]); - // } + for (size_t i = 0; i < 3; i++) { + EXPECT_EQ((*polynomials[i])[0], expected_val[i]); + } } } // namespace test_sumcheck_polynomials From 661618935dba78ff60051b9d7c3a91a8568d3e23 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:09:40 +0000 Subject: [PATCH 13/47] Start of implementing --- .../cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index e400bdac173..932ec1cb0e5 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -290,7 +290,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto* polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); + auto polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); for (size_t i = 0; i < 3; i++) { EXPECT_EQ((*polynomials[i])[0], expected_q1[i]); EXPECT_EQ((*polynomials[i])[1], expected_q2[i]); From 981584501cceac63b5c2dce4adbf67f4ffe783da Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:19:42 +0000 Subject: [PATCH 14/47] more implementation --- .../cpp/src/barretenberg/flavor/ecc_vm.hpp | 215 +++++----- .../cpp/src/barretenberg/flavor/flavor.hpp | 6 +- .../barretenberg/flavor/goblin_translator.hpp | 371 +++++++++--------- .../src/barretenberg/flavor/goblin_ultra.hpp | 100 ++--- .../cpp/src/barretenberg/flavor/ultra.hpp | 90 ++--- .../composer/relation_correctness.test.cpp | 10 +- .../honk/proof_system/protogalaxy_prover.hpp | 2 +- .../src/barretenberg/honk/utils/testing.hpp | 4 +- .../eccvm/eccvm_circuit_builder.hpp | 2 +- .../library/grand_product_library.hpp | 4 +- .../sumcheck/partial_evaluation.test.cpp | 10 +- .../src/barretenberg/sumcheck/sumcheck.hpp | 4 +- .../barretenberg/sumcheck/sumcheck.test.cpp | 4 +- .../barretenberg/sumcheck/sumcheck_round.hpp | 2 +- 14 files changed, 411 insertions(+), 413 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 78308ae6a23..5d12dfa6d10 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -394,111 +394,112 @@ template class ECCVMBa } // clang-format on - DEFINE_GET_POINTER_ARRAY(&lagrange_first, - &lagrange_second, - &lagrange_last, - &transcript_add, - &transcript_mul, - &transcript_eq, - &transcript_collision_check, - &transcript_msm_transition, - &transcript_pc, - &transcript_msm_count, - &transcript_x, - &transcript_y, - &transcript_z1, - &transcript_z2, - &transcript_z1zero, - &transcript_z2zero, - &transcript_op, - &transcript_accumulator_x, - &transcript_accumulator_y, - &transcript_msm_x, - &transcript_msm_y, - &precompute_pc, - &precompute_point_transition, - &precompute_round, - &precompute_scalar_sum, - &precompute_s1hi, - &precompute_s1lo, - &precompute_s2hi, - &precompute_s2lo, - &precompute_s3hi, - &precompute_s3lo, - &precompute_s4hi, - &precompute_s4lo, - &precompute_skew, - &precompute_dx, - &precompute_dy, - &precompute_tx, - &precompute_ty, - &msm_transition, - &msm_add, - &msm_double, - &msm_skew, - &msm_accumulator_x, - &msm_accumulator_y, - &msm_pc, - &msm_size_of_msm, - &msm_count, - &msm_round, - &msm_add1, - &msm_add2, - &msm_add3, - &msm_add4, - &msm_x1, - &msm_y1, - &msm_x2, - &msm_y2, - &msm_x3, - &msm_y3, - &msm_x4, - &msm_y4, - &msm_collision_x1, - &msm_collision_x2, - &msm_collision_x3, - &msm_collision_x4, - &msm_lambda1, - &msm_lambda2, - &msm_lambda3, - &msm_lambda4, - &msm_slice1, - &msm_slice2, - &msm_slice3, - &msm_slice4, - &transcript_accumulator_empty, - &transcript_reset_accumulator, - &precompute_select, - &lookup_read_counts_0, - &lookup_read_counts_1, - &z_perm, - &lookup_inverses, - &transcript_mul_shift, - &transcript_msm_count_shift, - &transcript_accumulator_x_shift, - &transcript_accumulator_y_shift, - &precompute_scalar_sum_shift, - &precompute_s1hi_shift, - &precompute_dx_shift, - &precompute_dy_shift, - &precompute_tx_shift, - &precompute_ty_shift, - &msm_transition_shift, - &msm_add_shift, - &msm_double_shift, - &msm_skew_shift, - &msm_accumulator_x_shift, - &msm_accumulator_y_shift, - &msm_count_shift, - &msm_round_shift, - &msm_add1_shift, - &msm_pc_shift, - &precompute_pc_shift, - &transcript_pc_shift, - &precompute_round_shift, - &transcript_accumulator_empty_shift, - &precompute_select_shift, - &z_perm_shift) + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(&lagrange_first, + &lagrange_second, + &lagrange_last, + &transcript_add, + &transcript_mul, + &transcript_eq, + &transcript_collision_check, + &transcript_msm_transition, + &transcript_pc, + &transcript_msm_count, + &transcript_x, + &transcript_y, + &transcript_z1, + &transcript_z2, + &transcript_z1zero, + &transcript_z2zero, + &transcript_op, + &transcript_accumulator_x, + &transcript_accumulator_y, + &transcript_msm_x, + &transcript_msm_y, + &precompute_pc, + &precompute_point_transition, + &precompute_round, + &precompute_scalar_sum, + &precompute_s1hi, + &precompute_s1lo, + &precompute_s2hi, + &precompute_s2lo, + &precompute_s3hi, + &precompute_s3lo, + &precompute_s4hi, + &precompute_s4lo, + &precompute_skew, + &precompute_dx, + &precompute_dy, + &precompute_tx, + &precompute_ty, + &msm_transition, + &msm_add, + &msm_double, + &msm_skew, + &msm_accumulator_x, + &msm_accumulator_y, + &msm_pc, + &msm_size_of_msm, + &msm_count, + &msm_round, + &msm_add1, + &msm_add2, + &msm_add3, + &msm_add4, + &msm_x1, + &msm_y1, + &msm_x2, + &msm_y2, + &msm_x3, + &msm_y3, + &msm_x4, + &msm_y4, + &msm_collision_x1, + &msm_collision_x2, + &msm_collision_x3, + &msm_collision_x4, + &msm_lambda1, + &msm_lambda2, + &msm_lambda3, + &msm_lambda4, + &msm_slice1, + &msm_slice2, + &msm_slice3, + &msm_slice4, + &transcript_accumulator_empty, + &transcript_reset_accumulator, + &precompute_select, + &lookup_read_counts_0, + &lookup_read_counts_1, + &z_perm, + &lookup_inverses, + &transcript_mul_shift, + &transcript_msm_count_shift, + &transcript_accumulator_x_shift, + &transcript_accumulator_y_shift, + &precompute_scalar_sum_shift, + &precompute_s1hi_shift, + &precompute_dx_shift, + &precompute_dy_shift, + &precompute_tx_shift, + &precompute_ty_shift, + &msm_transition_shift, + &msm_add_shift, + &msm_double_shift, + &msm_skew_shift, + &msm_accumulator_x_shift, + &msm_accumulator_y_shift, + &msm_count_shift, + &msm_round_shift, + &msm_add1_shift, + &msm_pc_shift, + &precompute_pc_shift, + &transcript_pc_shift, + &precompute_round_shift, + &transcript_accumulator_empty_shift, + &precompute_select_shift, + &z_perm_shift) std::vector get_wires() override { return { @@ -788,7 +789,7 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), this->get_pointer_array())) { + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { *result_field = (*polynomial)[row_idx]; } return result; @@ -839,7 +840,7 @@ template class ECCVMBa AllValues get_row(const size_t row_idx) { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), this->get_pointer_array())) { + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { *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 546a0dc6d62..95cb3adf4a7 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -75,12 +75,12 @@ namespace proof_system::honk::flavor { -#define DEFINE_GET_POINTER_ARRAY(...) \ - [[nodiscard]] auto get_pointer_array() \ +#define DEFINE_POINTER_VIEW(...) \ + [[nodiscard]] auto pointer_view() \ { \ return std::array{ __VA_ARGS__ }; \ } \ - [[nodiscard]] auto get_pointer_array() const \ + [[nodiscard]] auto pointer_view() const \ { \ return std::array{ __VA_ARGS__ }; \ } diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index e30964b2358..222154e095b 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -834,190 +834,191 @@ template class GoblinTranslator_ { DataType& lagrange_second_to_last_in_minicircuit = std::get<182>(this->_data); DataType& ordered_extra_range_constraints_numerator = std::get<183>(this->_data); - DEFINE_GET_POINTER_ARRAY(&op, - &x_lo_y_hi, - &x_hi_z_1, - &y_lo_z_2, - &p_x_low_limbs, - &p_x_low_limbs_range_constraint_0, - &p_x_low_limbs_range_constraint_1, - &p_x_low_limbs_range_constraint_2, - &p_x_low_limbs_range_constraint_3, - &p_x_low_limbs_range_constraint_4, - &p_x_low_limbs_range_constraint_tail, - &p_x_high_limbs, - &p_x_high_limbs_range_constraint_0, - &p_x_high_limbs_range_constraint_1, - &p_x_high_limbs_range_constraint_2, - &p_x_high_limbs_range_constraint_3, - &p_x_high_limbs_range_constraint_4, - &p_x_high_limbs_range_constraint_tail, - &p_y_low_limbs, - &p_y_low_limbs_range_constraint_0, - &p_y_low_limbs_range_constraint_1, - &p_y_low_limbs_range_constraint_2, - &p_y_low_limbs_range_constraint_3, - &p_y_low_limbs_range_constraint_4, - &p_y_low_limbs_range_constraint_tail, - &p_y_high_limbs, - &p_y_high_limbs_range_constraint_0, - &p_y_high_limbs_range_constraint_1, - &p_y_high_limbs_range_constraint_2, - &p_y_high_limbs_range_constraint_3, - &p_y_high_limbs_range_constraint_4, - &p_y_high_limbs_range_constraint_tail, - &z_low_limbs, - &z_low_limbs_range_constraint_0, - &z_low_limbs_range_constraint_1, - &z_low_limbs_range_constraint_2, - &z_low_limbs_range_constraint_3, - &z_low_limbs_range_constraint_4, - &z_low_limbs_range_constraint_tail, - &z_high_limbs, - &z_high_limbs_range_constraint_0, - &z_high_limbs_range_constraint_1, - &z_high_limbs_range_constraint_2, - &z_high_limbs_range_constraint_3, - &z_high_limbs_range_constraint_4, - &z_high_limbs_range_constraint_tail, - &accumulators_binary_limbs_0, - &accumulators_binary_limbs_1, - &accumulators_binary_limbs_2, - &accumulators_binary_limbs_3, - &accumulator_low_limbs_range_constraint_0, - &accumulator_low_limbs_range_constraint_1, - &accumulator_low_limbs_range_constraint_2, - &accumulator_low_limbs_range_constraint_3, - &accumulator_low_limbs_range_constraint_4, - &accumulator_low_limbs_range_constraint_tail, - &accumulator_high_limbs_range_constraint_0, - &accumulator_high_limbs_range_constraint_1, - &accumulator_high_limbs_range_constraint_2, - &accumulator_high_limbs_range_constraint_3, - &accumulator_high_limbs_range_constraint_4, - &accumulator_high_limbs_range_constraint_tail, - "ient_low_binary_limbs, - "ient_high_binary_limbs, - "ient_low_limbs_range_constraint_0, - "ient_low_limbs_range_constraint_1, - "ient_low_limbs_range_constraint_2, - "ient_low_limbs_range_constraint_3, - "ient_low_limbs_range_constraint_4, - "ient_low_limbs_range_constraint_tail, - "ient_high_limbs_range_constraint_0, - "ient_high_limbs_range_constraint_1, - "ient_high_limbs_range_constraint_2, - "ient_high_limbs_range_constraint_3, - "ient_high_limbs_range_constraint_4, - "ient_high_limbs_range_constraint_tail, - &relation_wide_limbs, - &relation_wide_limbs_range_constraint_0, - &relation_wide_limbs_range_constraint_1, - &relation_wide_limbs_range_constraint_2, - &relation_wide_limbs_range_constraint_3, - &concatenated_range_constraints_0, - &concatenated_range_constraints_1, - &concatenated_range_constraints_2, - &concatenated_range_constraints_3, - &ordered_range_constraints_0, - &ordered_range_constraints_1, - &ordered_range_constraints_2, - &ordered_range_constraints_3, - &ordered_range_constraints_4, - &z_perm, - &x_lo_y_hi_shift, - &x_hi_z_1_shift, - &y_lo_z_2_shift, - &p_x_low_limbs_shift, - &p_x_low_limbs_range_constraint_0_shift, - &p_x_low_limbs_range_constraint_1_shift, - &p_x_low_limbs_range_constraint_2_shift, - &p_x_low_limbs_range_constraint_3_shift, - &p_x_low_limbs_range_constraint_4_shift, - &p_x_low_limbs_range_constraint_tail_shift, - &p_x_high_limbs_shift, - &p_x_high_limbs_range_constraint_0_shift, - &p_x_high_limbs_range_constraint_1_shift, - &p_x_high_limbs_range_constraint_2_shift, - &p_x_high_limbs_range_constraint_3_shift, - &p_x_high_limbs_range_constraint_4_shift, - &p_x_high_limbs_range_constraint_tail_shift, - &p_y_low_limbs_shift, - &p_y_low_limbs_range_constraint_0_shift, - &p_y_low_limbs_range_constraint_1_shift, - &p_y_low_limbs_range_constraint_2_shift, - &p_y_low_limbs_range_constraint_3_shift, - &p_y_low_limbs_range_constraint_4_shift, - &p_y_low_limbs_range_constraint_tail_shift, - &p_y_high_limbs_shift, - &p_y_high_limbs_range_constraint_0_shift, - &p_y_high_limbs_range_constraint_1_shift, - &p_y_high_limbs_range_constraint_2_shift, - &p_y_high_limbs_range_constraint_3_shift, - &p_y_high_limbs_range_constraint_4_shift, - &p_y_high_limbs_range_constraint_tail_shift, - &z_low_limbs_shift, - &z_low_limbs_range_constraint_0_shift, - &z_low_limbs_range_constraint_1_shift, - &z_low_limbs_range_constraint_2_shift, - &z_low_limbs_range_constraint_3_shift, - &z_low_limbs_range_constraint_4_shift, - &z_low_limbs_range_constraint_tail_shift, - &z_high_limbs_shift, - &z_high_limbs_range_constraint_0_shift, - &z_high_limbs_range_constraint_1_shift, - &z_high_limbs_range_constraint_2_shift, - &z_high_limbs_range_constraint_3_shift, - &z_high_limbs_range_constraint_4_shift, - &z_high_limbs_range_constraint_tail_shift, - &accumulators_binary_limbs_0_shift, - &accumulators_binary_limbs_1_shift, - &accumulators_binary_limbs_2_shift, - &accumulators_binary_limbs_3_shift, - &accumulator_low_limbs_range_constraint_0_shift, - &accumulator_low_limbs_range_constraint_1_shift, - &accumulator_low_limbs_range_constraint_2_shift, - &accumulator_low_limbs_range_constraint_3_shift, - &accumulator_low_limbs_range_constraint_4_shift, - &accumulator_low_limbs_range_constraint_tail_shift, - &accumulator_high_limbs_range_constraint_0_shift, - &accumulator_high_limbs_range_constraint_1_shift, - &accumulator_high_limbs_range_constraint_2_shift, - &accumulator_high_limbs_range_constraint_3_shift, - &accumulator_high_limbs_range_constraint_4_shift, - &accumulator_high_limbs_range_constraint_tail_shift, - "ient_low_binary_limbs_shift, - "ient_high_binary_limbs_shift, - "ient_low_limbs_range_constraint_0_shift, - "ient_low_limbs_range_constraint_1_shift, - "ient_low_limbs_range_constraint_2_shift, - "ient_low_limbs_range_constraint_3_shift, - "ient_low_limbs_range_constraint_4_shift, - "ient_low_limbs_range_constraint_tail_shift, - "ient_high_limbs_range_constraint_0_shift, - "ient_high_limbs_range_constraint_1_shift, - "ient_high_limbs_range_constraint_2_shift, - "ient_high_limbs_range_constraint_3_shift, - "ient_high_limbs_range_constraint_4_shift, - "ient_high_limbs_range_constraint_tail_shift, - &relation_wide_limbs_shift, - &relation_wide_limbs_range_constraint_0_shift, - &relation_wide_limbs_range_constraint_1_shift, - &relation_wide_limbs_range_constraint_2_shift, - &relation_wide_limbs_range_constraint_3_shift, - &ordered_range_constraints_0_shift, - &ordered_range_constraints_1_shift, - &ordered_range_constraints_2_shift, - &ordered_range_constraints_3_shift, - &ordered_range_constraints_4_shift, - &z_perm_shift, - &lagrange_first, - &lagrange_last, - &lagrange_odd_in_minicircuit, - &lagrange_even_in_minicircuit, - &lagrange_second, - &lagrange_second_to_last_in_minicircuit, - &ordered_extra_range_constraints_numerator) + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(&op, + &x_lo_y_hi, + &x_hi_z_1, + &y_lo_z_2, + &p_x_low_limbs, + &p_x_low_limbs_range_constraint_0, + &p_x_low_limbs_range_constraint_1, + &p_x_low_limbs_range_constraint_2, + &p_x_low_limbs_range_constraint_3, + &p_x_low_limbs_range_constraint_4, + &p_x_low_limbs_range_constraint_tail, + &p_x_high_limbs, + &p_x_high_limbs_range_constraint_0, + &p_x_high_limbs_range_constraint_1, + &p_x_high_limbs_range_constraint_2, + &p_x_high_limbs_range_constraint_3, + &p_x_high_limbs_range_constraint_4, + &p_x_high_limbs_range_constraint_tail, + &p_y_low_limbs, + &p_y_low_limbs_range_constraint_0, + &p_y_low_limbs_range_constraint_1, + &p_y_low_limbs_range_constraint_2, + &p_y_low_limbs_range_constraint_3, + &p_y_low_limbs_range_constraint_4, + &p_y_low_limbs_range_constraint_tail, + &p_y_high_limbs, + &p_y_high_limbs_range_constraint_0, + &p_y_high_limbs_range_constraint_1, + &p_y_high_limbs_range_constraint_2, + &p_y_high_limbs_range_constraint_3, + &p_y_high_limbs_range_constraint_4, + &p_y_high_limbs_range_constraint_tail, + &z_low_limbs, + &z_low_limbs_range_constraint_0, + &z_low_limbs_range_constraint_1, + &z_low_limbs_range_constraint_2, + &z_low_limbs_range_constraint_3, + &z_low_limbs_range_constraint_4, + &z_low_limbs_range_constraint_tail, + &z_high_limbs, + &z_high_limbs_range_constraint_0, + &z_high_limbs_range_constraint_1, + &z_high_limbs_range_constraint_2, + &z_high_limbs_range_constraint_3, + &z_high_limbs_range_constraint_4, + &z_high_limbs_range_constraint_tail, + &accumulators_binary_limbs_0, + &accumulators_binary_limbs_1, + &accumulators_binary_limbs_2, + &accumulators_binary_limbs_3, + &accumulator_low_limbs_range_constraint_0, + &accumulator_low_limbs_range_constraint_1, + &accumulator_low_limbs_range_constraint_2, + &accumulator_low_limbs_range_constraint_3, + &accumulator_low_limbs_range_constraint_4, + &accumulator_low_limbs_range_constraint_tail, + &accumulator_high_limbs_range_constraint_0, + &accumulator_high_limbs_range_constraint_1, + &accumulator_high_limbs_range_constraint_2, + &accumulator_high_limbs_range_constraint_3, + &accumulator_high_limbs_range_constraint_4, + &accumulator_high_limbs_range_constraint_tail, + "ient_low_binary_limbs, + "ient_high_binary_limbs, + "ient_low_limbs_range_constraint_0, + "ient_low_limbs_range_constraint_1, + "ient_low_limbs_range_constraint_2, + "ient_low_limbs_range_constraint_3, + "ient_low_limbs_range_constraint_4, + "ient_low_limbs_range_constraint_tail, + "ient_high_limbs_range_constraint_0, + "ient_high_limbs_range_constraint_1, + "ient_high_limbs_range_constraint_2, + "ient_high_limbs_range_constraint_3, + "ient_high_limbs_range_constraint_4, + "ient_high_limbs_range_constraint_tail, + &relation_wide_limbs, + &relation_wide_limbs_range_constraint_0, + &relation_wide_limbs_range_constraint_1, + &relation_wide_limbs_range_constraint_2, + &relation_wide_limbs_range_constraint_3, + &concatenated_range_constraints_0, + &concatenated_range_constraints_1, + &concatenated_range_constraints_2, + &concatenated_range_constraints_3, + &ordered_range_constraints_0, + &ordered_range_constraints_1, + &ordered_range_constraints_2, + &ordered_range_constraints_3, + &ordered_range_constraints_4, + &z_perm, + &x_lo_y_hi_shift, + &x_hi_z_1_shift, + &y_lo_z_2_shift, + &p_x_low_limbs_shift, + &p_x_low_limbs_range_constraint_0_shift, + &p_x_low_limbs_range_constraint_1_shift, + &p_x_low_limbs_range_constraint_2_shift, + &p_x_low_limbs_range_constraint_3_shift, + &p_x_low_limbs_range_constraint_4_shift, + &p_x_low_limbs_range_constraint_tail_shift, + &p_x_high_limbs_shift, + &p_x_high_limbs_range_constraint_0_shift, + &p_x_high_limbs_range_constraint_1_shift, + &p_x_high_limbs_range_constraint_2_shift, + &p_x_high_limbs_range_constraint_3_shift, + &p_x_high_limbs_range_constraint_4_shift, + &p_x_high_limbs_range_constraint_tail_shift, + &p_y_low_limbs_shift, + &p_y_low_limbs_range_constraint_0_shift, + &p_y_low_limbs_range_constraint_1_shift, + &p_y_low_limbs_range_constraint_2_shift, + &p_y_low_limbs_range_constraint_3_shift, + &p_y_low_limbs_range_constraint_4_shift, + &p_y_low_limbs_range_constraint_tail_shift, + &p_y_high_limbs_shift, + &p_y_high_limbs_range_constraint_0_shift, + &p_y_high_limbs_range_constraint_1_shift, + &p_y_high_limbs_range_constraint_2_shift, + &p_y_high_limbs_range_constraint_3_shift, + &p_y_high_limbs_range_constraint_4_shift, + &p_y_high_limbs_range_constraint_tail_shift, + &z_low_limbs_shift, + &z_low_limbs_range_constraint_0_shift, + &z_low_limbs_range_constraint_1_shift, + &z_low_limbs_range_constraint_2_shift, + &z_low_limbs_range_constraint_3_shift, + &z_low_limbs_range_constraint_4_shift, + &z_low_limbs_range_constraint_tail_shift, + &z_high_limbs_shift, + &z_high_limbs_range_constraint_0_shift, + &z_high_limbs_range_constraint_1_shift, + &z_high_limbs_range_constraint_2_shift, + &z_high_limbs_range_constraint_3_shift, + &z_high_limbs_range_constraint_4_shift, + &z_high_limbs_range_constraint_tail_shift, + &accumulators_binary_limbs_0_shift, + &accumulators_binary_limbs_1_shift, + &accumulators_binary_limbs_2_shift, + &accumulators_binary_limbs_3_shift, + &accumulator_low_limbs_range_constraint_0_shift, + &accumulator_low_limbs_range_constraint_1_shift, + &accumulator_low_limbs_range_constraint_2_shift, + &accumulator_low_limbs_range_constraint_3_shift, + &accumulator_low_limbs_range_constraint_4_shift, + &accumulator_low_limbs_range_constraint_tail_shift, + &accumulator_high_limbs_range_constraint_0_shift, + &accumulator_high_limbs_range_constraint_1_shift, + &accumulator_high_limbs_range_constraint_2_shift, + &accumulator_high_limbs_range_constraint_3_shift, + &accumulator_high_limbs_range_constraint_4_shift, + &accumulator_high_limbs_range_constraint_tail_shift, + "ient_low_binary_limbs_shift, + "ient_high_binary_limbs_shift, + "ient_low_limbs_range_constraint_0_shift, + "ient_low_limbs_range_constraint_1_shift, + "ient_low_limbs_range_constraint_2_shift, + "ient_low_limbs_range_constraint_3_shift, + "ient_low_limbs_range_constraint_4_shift, + "ient_low_limbs_range_constraint_tail_shift, + "ient_high_limbs_range_constraint_0_shift, + "ient_high_limbs_range_constraint_1_shift, + "ient_high_limbs_range_constraint_2_shift, + "ient_high_limbs_range_constraint_3_shift, + "ient_high_limbs_range_constraint_4_shift, + "ient_high_limbs_range_constraint_tail_shift, + &relation_wide_limbs_shift, + &relation_wide_limbs_range_constraint_0_shift, + &relation_wide_limbs_range_constraint_1_shift, + &relation_wide_limbs_range_constraint_2_shift, + &relation_wide_limbs_range_constraint_3_shift, + &ordered_range_constraints_0_shift, + &ordered_range_constraints_1_shift, + &ordered_range_constraints_2_shift, + &ordered_range_constraints_3_shift, + &ordered_range_constraints_4_shift, + &z_perm_shift, + &lagrange_first, + &lagrange_last, + &lagrange_odd_in_minicircuit, + &lagrange_even_in_minicircuit, + &lagrange_second, + &lagrange_second_to_last_in_minicircuit, + &ordered_extra_range_constraints_numerator) std::vector get_wires() override { @@ -1623,7 +1624,7 @@ template class GoblinTranslator_ { [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), this->get_pointer_array())) { + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), this->pointer_view())) { *result_field = (*polynomial)[row_idx]; } return result; diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 79bac7f048c..3853e60d7ea 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -210,55 +210,55 @@ class GoblinUltra { DataType& z_perm_shift = std::get<46>(this->_data); DataType& z_lookup_shift = std::get<47>(this->_data); - // defines a method get_pointer_array that returns the following, with const and non-const variants - DEFINE_GET_POINTER_ARRAY(&q_c, - &q_l, - &q_r, - &q_o, - &q_4, - &q_m, - &q_arith, - &q_sort, - &q_elliptic, - &q_aux, - &q_lookup, - &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, - &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, - &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); + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(&q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &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, + &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, + &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); std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; std::vector get_ecc_op_wires() @@ -405,7 +405,7 @@ class GoblinUltra { [[nodiscard]] AllValues get_row(size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), get_pointer_array())) { + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), pointer_view())) { *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 f5c00dbe314..80846744581 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -199,50 +199,50 @@ class Ultra { DataType& z_perm_shift = std::get<41>(this->_data); DataType& z_lookup_shift = std::get<42>(this->_data); - // defines a method get_pointer_array that returns the following, with const and non-const variants - DEFINE_GET_POINTER_ARRAY(&q_c, - &q_l, - &q_r, - &q_o, - &q_4, - &q_m, - &q_arith, - &q_sort, - &q_elliptic, - &q_aux, - &q_lookup, - &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, - &w_l, - &w_r, - &w_o, - &w_4, - &sorted_accum, - &z_perm, - &z_lookup, - &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); + // defines a method pointer_view that returns the following, with const and non-const variants + DEFINE_POINTER_VIEW(&q_c, + &q_l, + &q_r, + &q_o, + &q_4, + &q_m, + &q_arith, + &q_sort, + &q_elliptic, + &q_aux, + &q_lookup, + &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, + &w_l, + &w_r, + &w_o, + &w_4, + &sorted_accum, + &z_perm, + &z_lookup, + &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); std::vector get_wires() override { return { w_l, w_r, w_o, w_4 }; }; // Gemini-specific getters. std::vector get_unshifted() override @@ -341,7 +341,7 @@ class Ultra { [[nodiscard]] AllValues get_row(const size_t row_idx) const { AllValues result; - for (auto [result_field, polynomial] : zip_view(result.get_pointer_array(), get_pointer_array())) { + for (auto [result_field, polynomial] : zip_view(result.pointer_view(), pointer_view())) { *result_field = (*polynomial)[row_idx]; } return result; diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index c0b8917f4b2..47e69939a15 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -38,16 +38,12 @@ 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; - size_t poly_idx = 0; - for (auto& poly : polynomials) { - (void)poly_idx; - (void)poly; - // evaluations_at_index_i[poly_idx] = poly[i]; - ++poly_idx; + for (auto [poly, eval] : zip_view(polynomials.pointer_view(), evaluations_at_index_i.pointer_view())) { + *eval = (*poly)[i]; } // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to zero - using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; + using SumcheckArrayOfValuesOverSubrelations = Relation::SumcheckArrayOfValuesOverSubrelations; SumcheckArrayOfValuesOverSubrelations result; for (auto& element : result) { element = 0; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 8d7be3e6f4d..4591d2070ea 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -191,7 +191,7 @@ template class ProtoGalaxyProver_ { const size_t row_idx) { size_t poly_idx = 0; - for (auto* extended_univariate : extended_univariates.get_pointer_array()) { + for (auto* extended_univariate : extended_univariates.pointer_view()) { auto base_univariate = instances.row_to_univariate(poly_idx, row_idx); *extended_univariate = base_univariate.template extend_to(); poly_idx++; diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index 828e73b256f..9c2d2697267 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -27,7 +27,7 @@ get_sequential_prover_polynomials(const size_t log_circuit_size, const size_t st } ProverPolynomials prover_polynomials; - auto prover_polynomials_pointers = prover_polynomials.get_pointer_array(); + auto prover_polynomials_pointers = prover_polynomials.pointer_view(); size_t poly_idx = 0; for (auto& polynomial : storage) { *(prover_polynomials_pointers[poly_idx]) = polynomial; @@ -57,7 +57,7 @@ get_zero_prover_polynomials(const size_t log_circuit_size) ProverPolynomials prover_polynomials; size_t poly_idx = 0; - auto prover_polynomial_pointers = prover_polynomials.get_pointer_array(); + auto prover_polynomial_pointers = prover_polynomials.pointer_view(); for (auto& polynomial : storage) { *prover_polynomial_pointers[poly_idx] = polynomial; poly_idx++; 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 8eb7ce5bb8b..30341bcb436 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 @@ -338,7 +338,7 @@ template class ECCVMCircuitBuilder { size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); AllPolynomials polys; - // auto poly_pointers = polys.get_pointer_array(); + // auto poly_pointers = polys.pointer_view(); for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { // TODO(array) // poly_pointers[j] = Polynomial(num_rows_pow2); 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 351b2a21ff1..c3eeef1497f 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,13 +64,13 @@ 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.get_pointer_array(); + auto full_polynomial_pointers = full_polynomials.pointer_view(); 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.get_pointer_array(); + auto evaluations_pointer = evaluations.pointer_view(); 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; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index 932ec1cb0e5..c83a315b47d 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.get_pointer_array()[0]; + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[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 polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); + auto polynomials = sumcheck.partially_evaluated_polynomials.pointer_view(); EXPECT_EQ((*polynomials[0])[0], expected_lo); EXPECT_EQ((*polynomials[0])[1], expected_hi); @@ -167,7 +167,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); + auto polynomials = sumcheck.partially_evaluated_polynomials.pointer_view(); EXPECT_EQ((*polynomials[0])[0], expected_q1); EXPECT_EQ((*polynomials[0])[1], expected_q2); EXPECT_EQ((*polynomials[0])[2], expected_q3); @@ -218,7 +218,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.get_pointer_array()[0]; + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; EXPECT_EQ(first_polynomial[0], round_challenge_0); EXPECT_EQ(first_polynomial[1], FF(0)); sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); @@ -290,7 +290,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto polynomials = sumcheck.partially_evaluated_polynomials.get_pointer_array(); + auto polynomials = sumcheck.partially_evaluated_polynomials.pointer_view(); for (size_t i = 0; i < 3; i++) { EXPECT_EQ((*polynomials[i])[0], expected_q1[i]); EXPECT_EQ((*polynomials[i])[1], expected_q2[i]); diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 1d233bfb517..a17af6ea41b 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -111,10 +111,10 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; - // auto multivariate_evaluations_pointers = multivariate_evaluations.get_pointer_array(); + // auto multivariate_evaluations_pointers = multivariate_evaluations.pointer_view(); // size_t evaluation_idx = 0; // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - // for (auto* polynomial : partially_evaluated_polynomials.get_pointer_array()) { + // for (auto* polynomial : partially_evaluated_polynomials.pointer_view()) { // *multivariate_evaluations_pointers[evaluation_idx] = (*polynomial)[0]; // ++evaluation_idx; // } diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index b8203ad600b..7eef5ec9a55 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -136,9 +136,9 @@ 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.get_pointer_array(); + auto partially_evaluated_polynomials_array = sumcheck.partially_evaluated_polynomials.pointer_view(); size_t i = 0; - for (auto* full_polynomial_pointer : full_polynomials.get_pointer_array()) { + for (auto* full_polynomial_pointer : full_polynomials.pointer_view()) { // 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] + diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index d0720766323..95cc34bfbd4 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -93,7 +93,7 @@ template class SumcheckProverRound { (void)extended_edges; (void)multivariates; (void)edge_idx; - // auto extended_edges_pointer = extended_edges.get_pointer_array(); + // auto extended_edges_pointer = extended_edges.pointer_view(); // size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip // for (auto& poly : multivariates) { // auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); From 0831ddfe33c4d27c7a1f04fd207f54a7bb942199 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:37:11 +0000 Subject: [PATCH 15/47] refactor: finish extend_edges --- .../barretenberg/sumcheck/sumcheck_round.hpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 95cc34bfbd4..407ad52f5b1 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -87,19 +87,14 @@ template class SumcheckProverRound { */ template void extend_edges(ExtendedEdges& extended_edges, - /* const */ ProverPolynomialsOrPartiallyEvaluatedMultivariates& multivariates, + const ProverPolynomialsOrPartiallyEvaluatedMultivariates& multivariates, size_t edge_idx) { - (void)extended_edges; - (void)multivariates; - (void)edge_idx; - // auto extended_edges_pointer = extended_edges.pointer_view(); - // size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - // for (auto& poly : multivariates) { - // auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); - // *extended_edges_pointer[univariate_idx] = edge.template extend_to(); - // ++univariate_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[univariate_idx] = edge.template extend_to(); + } } /** From cd1068765274b1ba1c07302cc22c20e317f88509 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:38:37 +0000 Subject: [PATCH 16/47] refactor: finish extend_edges --- barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 407ad52f5b1..55273370ca7 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -93,7 +93,7 @@ template class SumcheckProverRound { 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[univariate_idx] = edge.template extend_to(); + *extended_edge = edge.template extend_to(); } } From 414eb9ab247bd70a5f851bc991b807be796187a9 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:39:55 +0000 Subject: [PATCH 17/47] comment --- barretenberg/cpp/src/barretenberg/flavor/flavor.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 95cb3adf4a7..9335e68fe27 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -98,8 +98,7 @@ template class Ent ArrayType _data; virtual ~Entities_() = default; - - // DataType& operator[](size_t idx) { return _data[idx]; }; + // TODO(AD): remove these with the backing array typename ArrayType::iterator begin() { return _data.begin(); }; typename ArrayType::iterator end() { return _data.end(); }; From 488a23f804d924c4eca02f5654660f672bbb6768 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:46:37 +0000 Subject: [PATCH 18/47] more implementation --- .../composer/relation_correctness.test.cpp | 7 ++-- .../sumcheck/partial_evaluation.test.cpp | 40 +++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index 47e69939a15..f8a9aacb12d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -38,7 +38,7 @@ 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 [poly, eval] : zip_view(polynomials.pointer_view(), evaluations_at_index_i.pointer_view())) { + for (auto [eval, poly] : zip_view(evaluations_at_index_i.pointer_view(), polynomials.pointer_view())) { *eval = (*poly)[i]; } @@ -343,10 +343,11 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorPermutationRelationCorrectness) // Create storage for polynomials ProverPolynomials prover_polynomials; std::vector polynomial_container; + auto polynomial_pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - // prover_polynomials[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } // Fill in lagrange polynomials used in the permutation relation @@ -466,7 +467,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - // prover_polynomials[i] = polynomial_container[i]; + prover_polynomials[i] = polynomial_container[i]; } // Construct lagrange polynomials that are needed for Goblin Translator's GenPermSort Relation diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index c83a315b47d..db86c82f326 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -102,15 +102,15 @@ 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 polynomials = sumcheck.partially_evaluated_polynomials.pointer_view(); + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; - EXPECT_EQ((*polynomials[0])[0], expected_lo); - EXPECT_EQ((*polynomials[0])[1], expected_hi); + EXPECT_EQ(first_polynomial[0], expected_lo); + EXPECT_EQ(first_polynomial[1], expected_hi); FF round_challenge_1 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ((*polynomials[0])[0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } /* @@ -167,25 +167,25 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto polynomials = sumcheck.partially_evaluated_polynomials.pointer_view(); - EXPECT_EQ((*polynomials[0])[0], expected_q1); - EXPECT_EQ((*polynomials[0])[1], expected_q2); - EXPECT_EQ((*polynomials[0])[2], expected_q3); - EXPECT_EQ((*polynomials[0])[3], expected_q4); + auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + EXPECT_EQ(first_polynomial[0], expected_q1); + EXPECT_EQ(first_polynomial[1], expected_q2); + EXPECT_EQ(first_polynomial[2], expected_q3); + EXPECT_EQ(first_polynomial[3], expected_q4); FF round_challenge_1 = 2; FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; // 6 FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; // 10 sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); - EXPECT_EQ((*polynomials[0])[0], expected_lo); - EXPECT_EQ((*polynomials[0])[1], expected_hi); + EXPECT_EQ(first_polynomial[0], expected_lo); + EXPECT_EQ(first_polynomial[1], expected_hi); FF round_challenge_2 = 3; FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; // 18 (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); - EXPECT_EQ((*polynomials[0])[0], expected_val); + EXPECT_EQ(first_polynomial[0], expected_val); } TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) @@ -290,12 +290,12 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto polynomials = sumcheck.partially_evaluated_polynomials.pointer_view(); + auto pointer_view = sumcheck.partially_evaluated_polynomials.pointer_view(); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ((*polynomials[i])[0], expected_q1[i]); - EXPECT_EQ((*polynomials[i])[1], expected_q2[i]); - EXPECT_EQ((*polynomials[i])[2], expected_q3[i]); - EXPECT_EQ((*polynomials[i])[3], expected_q4[i]); + EXPECT_EQ((*pointer_view[i])[0], expected_q1[i]); + EXPECT_EQ((*pointer_view[i])[1], expected_q2[i]); + EXPECT_EQ((*pointer_view[i])[2], expected_q3[i]); + EXPECT_EQ((*pointer_view[i])[3], expected_q4[i]); } FF round_challenge_1 = FF::random_element(); @@ -307,8 +307,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((*polynomials[i])[0], expected_lo[i]); - EXPECT_EQ((*polynomials[i])[1], expected_hi[i]); + EXPECT_EQ((*pointer_view[i])[0], expected_lo[i]); + EXPECT_EQ((*pointer_view[i])[1], expected_hi[i]); } FF round_challenge_2 = FF::random_element(); std::array expected_val; @@ -317,7 +317,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((*polynomials[i])[0], expected_val[i]); + EXPECT_EQ((*pointer_view[i])[0], expected_val[i]); } } From 4d5ac93c750bc2bc79f83d036179a58dfa22767c Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:49:19 +0000 Subject: [PATCH 19/47] more implementation --- .../honk/composer/relation_correctness.test.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index f8a9aacb12d..eab4ad25cd5 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -463,11 +463,12 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) ProverPolynomials prover_polynomials; std::vector polynomial_container; + auto pointer_view = prover_polynomials.pointer_view(); // Allocate polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - prover_polynomials[i] = polynomial_container[i]; + *pointer_view[i] = polynomial_container[i]; } // Construct lagrange polynomials that are needed for Goblin Translator's GenPermSort Relation @@ -565,7 +566,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - // prover_polynomial_ids[i] = polynomial_ids[i]; + prover_polynomial_ids[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -574,9 +575,10 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) shifted_id_set.emplace(id); } // Assign spans to non-shifted prover polynomials + auto pointer_view = prover_polynomials.get_pointer_array(); for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - // prover_polynomials[i] = polynomial_container[i]; + *pointer_view[i] = polynomial_container[i]; } } @@ -584,9 +586,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]; - (void)shifted_id; - (void)to_be_shifted_id; - // prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange even polynomial From 51690f81fd76c564f8e22474f2dcca7f3a9cdd85 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:51:47 +0000 Subject: [PATCH 20/47] more implementation --- .../barretenberg/honk/composer/relation_correctness.test.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index eab4ad25cd5..3cf8c3853c1 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -558,6 +558,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) ProverPolynomials prover_polynomials; // We use polynomial ids to make shifting the polynomials easier ProverPolynomialIds prover_polynomial_ids; + auto id_pointer_view = prover_polynomial_ids.pointer_view(); std::vector polynomial_container; std::vector polynomial_ids; for (size_t i = 0; i < prover_polynomials.size(); i++) { @@ -566,7 +567,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - prover_polynomial_ids[i] = polynomial_ids[i]; + *id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -575,7 +576,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) shifted_id_set.emplace(id); } // Assign spans to non-shifted prover polynomials - auto pointer_view = prover_polynomials.get_pointer_array(); + auto pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { *pointer_view[i] = polynomial_container[i]; From 2c101400f38f4373e420a590a1acee2d3195e018 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:53:49 +0000 Subject: [PATCH 21/47] fix --- .../barretenberg/honk/composer/relation_correctness.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index 3cf8c3853c1..d8b1ea7a781 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -587,7 +587,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]; - prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange even polynomial From 012cb5fcc3a1bd637c0689bb4a4c50631a84f4fb Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 00:55:38 +0000 Subject: [PATCH 22/47] add zip_view utility --- .../cpp/src/barretenberg/common/zip_view.hpp | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 barretenberg/cpp/src/barretenberg/common/zip_view.hpp diff --git a/barretenberg/cpp/src/barretenberg/common/zip_view.hpp b/barretenberg/cpp/src/barretenberg/common/zip_view.hpp new file mode 100644 index 00000000000..a055d82dada --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/common/zip_view.hpp @@ -0,0 +1,190 @@ +#pragma once +/* ********************************* FILE ************************************/ +/** \file mzip.hpp + * + * \brief This header contains the zip iterator class. + * + * WARNING this is a zip view, not a zip copy! + * + * \remark + * - c++17 + * - no dependencies + * - header only + * - tested by test_zip_iterator.cpp + * - not thread safe + * - view ! + * - extends lifetime of rvalue inputs untill the end of the for loop + * + * \todo + * - add algorithm tests, probably does not work at all... + * + * + * \example + * std::vector as{1,2},bs{1,2,3}; + * for(auto [index, a,b]: zip(as,bs)){ + * a++; + * } + * cout<= 201703L, + " must be c++17 or greater"); // could be rewritten in c++11, but the features you must use will be buggy + // in an older compiler anyways. +#include +#include +#include +#include +#include +#include +#include + +template +/** + * @brief The zip_iterator class + * + * Provides a zip iterator which is at end when any is at end + */ +class zip_iterator { + public: + // speeds up compilation a little bit... + using tuple_indexes = std::make_index_sequence>>; + + zip_iterator(T iter, T iter_end) + : iter(iter) + , iter_end(iter_end) + {} + // prefix, inc first, then return + zip_iterator& operator++() + { + for_each_in_tuple([](auto&& x) { return x++; }, iter); + // then if any hit end, update all to point to end. + auto end = apply2([](auto x, auto y) { return x == y; }, iter, iter_end); + if (if_any_in(end)) { + apply2([](auto& x, auto y) { return x = y; }, iter, iter_end); + } + index++; + return *this; + } + // sufficient because ++ keeps track and sets all to end when any is + bool operator!=(const zip_iterator& other) const { return other.iter != iter; } + auto operator*() const + { + return std::forward(get_refs(iter, tuple_indexes{})); + } + + private: + T iter, iter_end; + std::size_t index = 0; + + template auto get_refs(T t, std::index_sequence) const + { + return std::make_tuple(std::ref(*std::get(t))...); + } + + template auto apply2_impl(F&& f, A&& a, A&& b, std::index_sequence) + { + return std::make_tuple(f(std::get(a), std::get(b))...); + } + template auto apply2(F&& f, A&& a, A&& b) + { + return apply2_impl(std::forward(f), std::forward(a), std::forward(b), tuple_indexes{}); + } + template bool if_any_impl(const A& t, std::index_sequence) const + { + return (... || std::get(t)); // c++17 + } + + // in general context we must enforce that these are tuples + template bool if_any_in(A&& t) const { return if_any_impl(std::forward(t), tuple_indexes{}); } + + template + auto for_each_in_impl(F&& f, Tuple&& t, std::index_sequence) const + { + return std::make_tuple(f(std::get(t))...); + } + + template void for_each_in_tuple(F&& f, A&& t) const + { + for_each_in_impl(std::forward(f), std::forward(t), tuple_indexes{}); + } +}; + +template class zip_view { + using arg_indexes = std::make_index_sequence; + + public: + zip_view(S... args) + : args(std::forward(args)...) + {} + auto begin() const { return get_begins(arg_indexes{}); } + auto end() const { return get_ends(arg_indexes{}); } + [[nodiscard]] std::size_t size() const { return size_impl(arg_indexes{}); } + + private: + std::tuple args; + template auto get_begins(std::index_sequence) const + { + return zip_iterator(std::make_tuple(std::get(args).begin()...), std::make_tuple(std::get(args).end()...)); + } + template auto get_ends(std::index_sequence) const + { + return zip_iterator(std::make_tuple(std::get(args).end()...), std::make_tuple(std::get(args).end()...)); + } + template auto size_impl(std::index_sequence) const + { + return std::max({ std::size_t(std::get(args).size())... }); + } + + template bool if_any_impl(const A& t, std::index_sequence) const + { + return (... || std::get(t)); // c++17 + } +}; + +// deduction guide, +template zip_view(S&&...) -> zip_view; From df2f1ff8236772144b02454c1c194e5899df89c8 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:03:47 +0000 Subject: [PATCH 23/47] renaming --- .../composer/relation_correctness.test.cpp | 29 +++++++++---------- .../sumcheck/partial_evaluation.test.cpp | 16 +++++----- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index d8b1ea7a781..ee0fab2c014 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -463,12 +463,12 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) ProverPolynomials prover_polynomials; std::vector polynomial_container; - auto pointer_view = prover_polynomials.pointer_view(); + auto polynomial_pointer_view = prover_polynomials.pointer_view(); // Allocate polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); polynomial_container.push_back(temporary_polynomial); - *pointer_view[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } // Construct lagrange polynomials that are needed for Goblin Translator's GenPermSort Relation @@ -576,10 +576,10 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) shifted_id_set.emplace(id); } // Assign spans to non-shifted prover polynomials - auto pointer_view = prover_polynomials.pointer_view(); + auto polynomial_pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - *pointer_view[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } } @@ -587,7 +587,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]; - *pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange even polynomial @@ -658,13 +658,15 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes ProverPolynomialIds prover_polynomial_ids; std::vector polynomial_container; std::vector polynomial_ids; + auto id_pointer_view = prover_polynomial_ids.pointer_view(); + auto pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.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); - // prover_polynomial_ids[i] = polynomial_ids[i]; + *id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -675,7 +677,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - // prover_polynomials[i] = polynomial_container[i]; + *pointer_view[i] = polynomial_container[i]; } } @@ -683,9 +685,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]; - (void)shifted_id; - (void)to_be_shifted_id; - // prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange odd polynomial (the only non-witness one we are using) @@ -1077,13 +1077,14 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) ProverPolynomialIds prover_polynomial_ids; std::vector polynomial_container; std::vector polynomial_ids; + auto polynomial_pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.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); - // prover_polynomial_ids[i] = polynomial_ids[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -1094,7 +1095,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - // prover_polynomials[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } } @@ -1102,9 +1103,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]; - (void)shifted_id; - (void)to_be_shifted_id; - // prover_polynomials[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Copy values of wires used in the non-native field relation from the circuit builder diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index db86c82f326..aa0928ab783 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -290,12 +290,12 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGenericMultiplePolys) } sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - auto pointer_view = sumcheck.partially_evaluated_polynomials.pointer_view(); + auto polynomial_pointer_view = sumcheck.partially_evaluated_polynomials.pointer_view(); for (size_t i = 0; i < 3; i++) { - EXPECT_EQ((*pointer_view[i])[0], expected_q1[i]); - EXPECT_EQ((*pointer_view[i])[1], expected_q2[i]); - EXPECT_EQ((*pointer_view[i])[2], expected_q3[i]); - EXPECT_EQ((*pointer_view[i])[3], expected_q4[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]); } FF round_challenge_1 = FF::random_element(); @@ -307,8 +307,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((*pointer_view[i])[0], expected_lo[i]); - EXPECT_EQ((*pointer_view[i])[1], expected_hi[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_lo[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[1], expected_hi[i]); } FF round_challenge_2 = FF::random_element(); std::array expected_val; @@ -317,7 +317,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((*pointer_view[i])[0], expected_val[i]); + EXPECT_EQ((*polynomial_pointer_view[i])[0], expected_val[i]); } } From 12f72fe5b5fdd2d5782671a3c7c074894184c5ed Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:06:14 +0000 Subject: [PATCH 24/47] more addressing TODOs --- .../barretenberg/honk/proof_system/permutation_library.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 f3480d51e4f..e95be163e01 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -70,9 +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 (size_t k = 0; k < Flavor::NUM_ALL_ENTITIES; ++k) { - (void)k; - // evaluations[k] = full_polynomials[k].size() > i ? full_polynomials[k][i] : 0; + for (auto [eval, poly] : zip_view(evaluations, full_polynomials)) { + eval = poly->size() > i ? (*poly)[i] : 0; } numerator[i] = GrandProdRelation::template compute_permutation_numerator(evaluations, relation_parameters); From 5649093d290eac23caa19d3d294f3b6bd70fa08c Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:07:20 +0000 Subject: [PATCH 25/47] more addressing TODOs --- .../circuit_builder/eccvm/eccvm_circuit_builder.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 30341bcb436..897925d58ab 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 @@ -339,9 +339,8 @@ template class ECCVMCircuitBuilder { AllPolynomials polys; // auto poly_pointers = polys.pointer_view(); - for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { - // TODO(array) - // poly_pointers[j] = Polynomial(num_rows_pow2); + for (auto* poly : polys.pointer_view()) { + *poly = Polynomial(num_rows_pow2); } polys.lagrange_first[0] = 1; From 82aa8563032f0f7c1666b26c4545a627664b8e29 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:08:34 +0000 Subject: [PATCH 26/47] more addressing TODOs --- .../honk/composer/relation_correctness.test.cpp | 8 ++++---- .../circuit_builder/eccvm/eccvm_circuit_builder.hpp | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index ee0fab2c014..553627e6469 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -558,7 +558,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) ProverPolynomials prover_polynomials; // We use polynomial ids to make shifting the polynomials easier ProverPolynomialIds prover_polynomial_ids; - auto id_pointer_view = prover_polynomial_ids.pointer_view(); + auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); std::vector polynomial_container; std::vector polynomial_ids; for (size_t i = 0; i < prover_polynomials.size(); i++) { @@ -567,7 +567,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - *id_pointer_view[i] = polynomial_ids[i]; + *polynomial_id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); @@ -658,7 +658,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes ProverPolynomialIds prover_polynomial_ids; std::vector polynomial_container; std::vector polynomial_ids; - auto id_pointer_view = prover_polynomial_ids.pointer_view(); + auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); auto pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); @@ -666,7 +666,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes polynomial_container.push_back(temporary_polynomial); // Push sequential ids to polynomial ids polynomial_ids.push_back(i); - *id_pointer_view[i] = polynomial_ids[i]; + *polynomial_id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); 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 897925d58ab..85d72736357 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 @@ -338,7 +338,6 @@ template class ECCVMCircuitBuilder { size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); AllPolynomials polys; - // auto poly_pointers = polys.pointer_view(); for (auto* poly : polys.pointer_view()) { *poly = Polynomial(num_rows_pow2); } From ab62aa1bdc5b651d993bf1983e130563c4cd54c4 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:09:23 +0000 Subject: [PATCH 27/47] more addressing TODOs --- .../honk/composer/relation_correctness.test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index 553627e6469..85384b54cf4 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -659,7 +659,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes std::vector polynomial_container; std::vector polynomial_ids; auto polynomial_id_pointer_view = prover_polynomial_ids.pointer_view(); - auto pointer_view = prover_polynomials.pointer_view(); + auto polynomial_pointer_view = prover_polynomials.pointer_view(); for (size_t i = 0; i < prover_polynomials.size(); i++) { Polynomial temporary_polynomial(circuit_size); // Allocate polynomials @@ -677,7 +677,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes // Assign spans to non-shifted prover polynomials for (size_t i = 0; i < prover_polynomials.size(); i++) { if (!shifted_id_set.contains(i)) { - *pointer_view[i] = polynomial_container[i]; + *polynomial_pointer_view[i] = polynomial_container[i]; } } @@ -685,7 +685,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]; - *pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); + *polynomial_pointer_view[shifted_id] = polynomial_container[to_be_shifted_id].shifted(); } // Fill in lagrange odd polynomial (the only non-witness one we are using) From c0bdb36e48f425fb37ef9940a26451a69fc546db Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:11:31 +0000 Subject: [PATCH 28/47] more addressing TODOs --- barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp | 2 +- .../circuit_builder/eccvm/eccvm_circuit_builder.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp index 9c2d2697267..fa7c124a843 100644 --- a/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/utils/testing.hpp @@ -30,7 +30,7 @@ get_sequential_prover_polynomials(const size_t log_circuit_size, const size_t st auto prover_polynomials_pointers = prover_polynomials.pointer_view(); size_t poly_idx = 0; for (auto& polynomial : storage) { - *(prover_polynomials_pointers[poly_idx]) = polynomial; + *prover_polynomials_pointers[poly_idx] = polynomial; poly_idx++; } 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 85d72736357..459a6cb7b41 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 @@ -502,7 +502,7 @@ template class ECCVMCircuitBuilder { }; auto polynomials = compute_polynomials(); - const size_t num_rows = 0; // polynomials[0].size(); + const size_t num_rows = polynomials.get_polynomial_size(); proof_system::honk::lookup_library::compute_logderivative_inverse>( polynomials, params, num_rows); From a6346acab3a79cce7072c66daac372e95920814f Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:12:15 +0000 Subject: [PATCH 29/47] more addressing TODOs --- .../src/barretenberg/honk/proof_system/permutation_library.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e95be163e01..773b580ee76 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -70,7 +70,7 @@ 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, full_polynomials)) { + for (auto [eval, poly] : zip_view(evaluations.pointer_view(), full_polynomials.pointer_view())) { eval = poly->size() > i ? (*poly)[i] : 0; } numerator[i] = GrandProdRelation::template compute_permutation_numerator(evaluations, From 8f032693790f3ab10f58984b0357a6dab601e5b7 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:16:11 +0000 Subject: [PATCH 30/47] more addressing TODOs --- barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp | 1 + .../src/barretenberg/honk/proof_system/permutation_library.hpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 5d12dfa6d10..9a24c23dd74 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -786,6 +786,7 @@ template class ECCVMBa */ class AllPolynomials : public AllEntities { public: + size_t get_polynomial_size() const { return lagrange_first.size(); } AllValues get_row(const size_t row_idx) const { AllValues result; 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 773b580ee76..0471f818ca6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -71,7 +71,7 @@ void compute_permutation_grand_product(const size_t circuit_size, typename Flavor::AllValues evaluations; for (auto [eval, poly] : zip_view(evaluations.pointer_view(), full_polynomials.pointer_view())) { - eval = poly->size() > i ? (*poly)[i] : 0; + *eval = poly->size() > i ? (*poly)[i] : 0; } numerator[i] = GrandProdRelation::template compute_permutation_numerator(evaluations, relation_parameters); From 570a339f3f197d571d969827423b3ec7ec2fba74 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:16:38 +0000 Subject: [PATCH 31/47] more addressing TODOs --- barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 9a24c23dd74..82b53760671 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -786,7 +786,7 @@ template class ECCVMBa */ class AllPolynomials : public AllEntities { public: - size_t get_polynomial_size() const { return lagrange_first.size(); } + size_t get_polynomial_size() const { return this->lagrange_first.size(); } AllValues get_row(const size_t row_idx) const { AllValues result; From 8213351b66ca5540af9f90205a885326153acea0 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:17:11 +0000 Subject: [PATCH 32/47] more addressing TODOs --- barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 82b53760671..e14a3e4ad4c 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -786,7 +786,7 @@ template class ECCVMBa */ class AllPolynomials : public AllEntities { public: - size_t get_polynomial_size() const { return this->lagrange_first.size(); } + [[nodiscard]] size_t get_polynomial_size() const { return this->lagrange_first.size(); } AllValues get_row(const size_t row_idx) const { AllValues result; From 6d002b0b3f627af4eb8a33c8d9bee7c6fad13dfd Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:20:37 +0000 Subject: [PATCH 33/47] more addressing TODOs --- .../src/barretenberg/sumcheck/sumcheck.hpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index a17af6ea41b..d4f7f7b3a2c 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -151,16 +151,15 @@ template class SumcheckProver { */ void partially_evaluate(auto& polynomials, size_t round_size, FF round_challenge) { - (void)polynomials; - (void)round_size; - (void)round_challenge; - // // 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) { - // partially_evaluated_polynomials[j][i >> 1] = - // polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]); - // } - // }); + auto pep_view = partially_evaluated_polynomials.pointer_view(); + auto poly_view = polynomials.pointer_view(); + // 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] = + (*poly_view[j])[i] + round_challenge * ((*poly_view[j])[i + 1] - (*poly_view[j])[i]); + } + }); }; }; From 67e4305ad11e30e751c81ad7d6bc2c66830fb8a4 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:29:31 +0000 Subject: [PATCH 34/47] fix: rest --- .../barretenberg/sumcheck/sumcheck.test.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp index 7eef5ec9a55..ffaa2225e20 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.test.cpp @@ -151,13 +151,12 @@ TEST_F(SumcheckTests, PolynomialNormalization) // 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 }; - (void)u_challenge; - // for (size_t i = 0; i < NUM_POLYNOMIALS; i++) { - // barretenberg::Polynomial poly(full_polynomials[i]); - // auto v_expected = poly.evaluate_mle(u_challenge); - // auto v_result = output.claimed_evaluations[i]; - // EXPECT_EQ(v_expected, v_result); - // } + for (auto [full_poly, claimed_eval] : + zip_view(full_polynomials.pointer_view(), output.claimed_evaluations.pointer_view())) { + barretenberg::Polynomial poly(*full_poly); + auto v_expected = poly.evaluate_mle(u_challenge); + EXPECT_EQ(v_expected, *claimed_eval); + } } TEST_F(SumcheckTests, Prover) @@ -190,9 +189,9 @@ TEST_F(SumcheckTests, Prover) expected_values.emplace_back(expected_lo + expected_hi); } - // for (size_t poly_idx = 0; poly_idx < NUM_POLYNOMIALS; poly_idx++) { - // EXPECT_EQ(output.claimed_evaluations[poly_idx], expected_values[poly_idx]); - // } + for (auto [eval, expected] : zip_view(output.claimed_evaluations.pointer_view(), expected_values)) { + *eval = expected; + } } // TODO(#225): make the inputs to this test more interesting, e.g. non-trivial permutations From 919a9980beb5abc27b31c1d823004bc37d1bab54 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 01:30:55 +0000 Subject: [PATCH 35/47] fix: rest --- barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index d4f7f7b3a2c..8bf5ff3159e 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -152,12 +152,11 @@ 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(); // 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] = - (*poly_view[j])[i] + round_challenge * ((*poly_view[j])[i + 1] - (*poly_view[j])[i]); + polynomials[j][i] + round_challenge * (polynomials[j][i + 1] - polynomials[j][i]); } }); }; From 774a6d468e0ab3d6f992af12995bcd19290bb2e0 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 16:18:32 +0000 Subject: [PATCH 36/47] fix: the final operator[] eradication TODOs --- .../src/barretenberg/sumcheck/sumcheck.hpp | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 8bf5ff3159e..7dbe5b9cf33 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -111,13 +111,10 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; - // auto multivariate_evaluations_pointers = multivariate_evaluations.pointer_view(); - // size_t evaluation_idx = 0; - // // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip - // for (auto* polynomial : partially_evaluated_polynomials.pointer_view()) { - // *multivariate_evaluations_pointers[evaluation_idx] = (*polynomial)[0]; - // ++evaluation_idx; - // } + for (auto [eval, poly] : + zip_view(multivariate_evaluations.pointer_view(), partially_evaluated_polynomials.pointer_view())) { + *eval = (*poly)[0]; + } transcript.send_to_verifier("Sumcheck:evaluations", multivariate_evaluations._data); return { multivariate_challenge, multivariate_evaluations }; @@ -146,10 +143,25 @@ template class SumcheckProver { * \- v5 X0 (1-X1) X2 --/ / * g3 -- v6 (1-X0) X1 X2 --- (v6(1-X0) + v7 X0) X1 X2 -/ * \- v7 X0 X1 X2 --/ - * - * @param challenge */ 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(); + // 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] = + (*poly_view[j])[i] + round_challenge * ((*poly_view[j])[i + 1] - (*poly_view[j])[i]); + } + }); + }; + /** + * @brief Evaluate at the round challenge and prepare class for next round. + * Specialization for array, see generic version above. + */ + template + void partially_evaluate(std::array& polynomials, size_t round_size, FF round_challenge) { auto pep_view = partially_evaluated_polynomials.pointer_view(); // after the first round, operate in place on partially_evaluated_polynomials From 7ecc83c68a587f3ca44bc81a4f8f3d19404c2a89 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 16:26:40 +0000 Subject: [PATCH 37/47] fix: cant remove typename. all well --- .../barretenberg/honk/composer/relation_correctness.test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index 85384b54cf4..c5b1c9ffde4 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -43,7 +43,7 @@ template void check_relation(auto circuit_s } // Define the appropriate SumcheckArrayOfValuesOverSubrelations type for this relation and initialize to zero - using SumcheckArrayOfValuesOverSubrelations = Relation::SumcheckArrayOfValuesOverSubrelations; + using SumcheckArrayOfValuesOverSubrelations = typename Relation::SumcheckArrayOfValuesOverSubrelations; SumcheckArrayOfValuesOverSubrelations result; for (auto& element : result) { element = 0; From 4bfc72f536b896fe938fca820c93a9d9f6d2cc4e Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 17:03:27 +0000 Subject: [PATCH 38/47] gdwarf --- barretenberg/cpp/CMakePresets.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index 7927b0ba494..0749612fb84 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -46,8 +46,12 @@ "displayName": "Debugging build with Clang-16", "description": "Build with globally installed Clang-16 in debug mode", "inherits": "clang16", + "binaryDir": "build-debug", "environment": { - "CMAKE_BUILD_TYPE": "Debug" + "CMAKE_BUILD_TYPE": "Debug", + "CFLAGS": "-gdwarf-aranges", + "CXXFLAGS": "-gdwarf-aranges", + "LDFLAGS": "-gdwarf-aranges" }, "cacheVariables": { "ENABLE_ASAN": "OFF", From 4332247c106534a7010c66be75707b67ed0f0ff2 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 17:06:51 +0000 Subject: [PATCH 39/47] gdwarf --- barretenberg/cpp/CMakePresets.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index 0749612fb84..a061d6892f9 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -49,9 +49,9 @@ "binaryDir": "build-debug", "environment": { "CMAKE_BUILD_TYPE": "Debug", - "CFLAGS": "-gdwarf-aranges", - "CXXFLAGS": "-gdwarf-aranges", - "LDFLAGS": "-gdwarf-aranges" + "CFLAGS": "-gdwarf-aranges -gdwarf-4", + "CXXFLAGS": "-gdwarf-aranges -gdwarf-4", + "LDFLAGS": "-gdwarf-aranges -gdwarf-4" }, "cacheVariables": { "ENABLE_ASAN": "OFF", From 1ea92177b7a8b02e111607e5d0506391bcabcf18 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 3 Nov 2023 17:22:39 +0000 Subject: [PATCH 40/47] Fix bug in test --- barretenberg/cpp/CMakePresets.json | 6 +++--- .../honk/composer/relation_correctness.test.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index a061d6892f9..5a0f30c8c85 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -49,9 +49,9 @@ "binaryDir": "build-debug", "environment": { "CMAKE_BUILD_TYPE": "Debug", - "CFLAGS": "-gdwarf-aranges -gdwarf-4", - "CXXFLAGS": "-gdwarf-aranges -gdwarf-4", - "LDFLAGS": "-gdwarf-aranges -gdwarf-4" + "CFLAGS": "-gdwarf-4", + "CXXFLAGS": "-gdwarf-4", + "LDFLAGS": "-gdwarf-4" }, "cacheVariables": { "ENABLE_ASAN": "OFF", diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp index c5b1c9ffde4..4d3fd7561cc 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/relation_correctness.test.cpp @@ -1078,13 +1078,14 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) 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 < prover_polynomials.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_pointer_view[i] = polynomial_container[i]; + *polynomial_id_pointer_view[i] = polynomial_ids[i]; } // Get ids of shifted polynomials and put them in a set auto shifted_ids = prover_polynomial_ids.get_shifted(); From df79b8bd1b144d5e724572d5bfd2eb79963a9c45 Mon Sep 17 00:00:00 2001 From: ludamad Date: Sat, 4 Nov 2023 01:09:35 +0000 Subject: [PATCH 41/47] Fix bug in test --- .../cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index aa0928ab783..8e324c1e301 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -167,6 +167,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); + std::cout << sumcheck.partially_evaluated_polynomials.q_c << std::endl; auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; EXPECT_EQ(first_polynomial[0], expected_q1); EXPECT_EQ(first_polynomial[1], expected_q2); @@ -183,7 +184,6 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) FF round_challenge_2 = 3; FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; // 18 - (void)expected_val; sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); EXPECT_EQ(first_polynomial[0], expected_val); } @@ -219,6 +219,7 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) FF expected_q4 = v011 * (FF(1) - round_challenge_0) + v111 * round_challenge_0; auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; + std::cout << sumcheck.partially_evaluated_polynomials.q_c[0] << std::endl; EXPECT_EQ(first_polynomial[0], round_challenge_0); EXPECT_EQ(first_polynomial[1], FF(0)); sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); From be5d158f877539485469bd0241d9d0b8614b19c4 Mon Sep 17 00:00:00 2001 From: ludamad Date: Sat, 4 Nov 2023 01:44:55 +0000 Subject: [PATCH 42/47] fix: accidental extra EXPERCT_EQQ --- .../cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index 8e324c1e301..2c17ab9c905 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -219,9 +219,6 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsGeneric) FF expected_q4 = v011 * (FF(1) - round_challenge_0) + v111 * round_challenge_0; auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; - std::cout << sumcheck.partially_evaluated_polynomials.q_c[0] << std::endl; - EXPECT_EQ(first_polynomial[0], round_challenge_0); - EXPECT_EQ(first_polynomial[1], FF(0)); sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); EXPECT_EQ(first_polynomial[0], expected_q1); From 6ba90302ea1a7c765c588c0ec499bcfcc099006e Mon Sep 17 00:00:00 2001 From: ludamad Date: Sat, 4 Nov 2023 01:47:52 +0000 Subject: [PATCH 43/47] fix: accidental extra EXPERCT_EQQ --- .../cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp index 2c17ab9c905..52c92c707ec 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/partial_evaluation.test.cpp @@ -167,7 +167,6 @@ TYPED_TEST(PartialEvaluationTests, ThreeRoundsSpecial) sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); - std::cout << sumcheck.partially_evaluated_polynomials.q_c << std::endl; auto& first_polynomial = *sumcheck.partially_evaluated_polynomials.pointer_view()[0]; EXPECT_EQ(first_polynomial[0], expected_q1); EXPECT_EQ(first_polynomial[1], expected_q2); From a06ae1eef8283e76f80e643bde2a1e6c576d776b Mon Sep 17 00:00:00 2001 From: ludamad Date: Mon, 6 Nov 2023 12:58:45 -0600 Subject: [PATCH 44/47] Update yarn-project --- yarn-project/noir-contracts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/noir-contracts/package.json b/yarn-project/noir-contracts/package.json index ec1249fe8a7..e098ee47798 100644 --- a/yarn-project/noir-contracts/package.json +++ b/yarn-project/noir-contracts/package.json @@ -58,7 +58,7 @@ "src", "!*.test.*" ], - "types": "./dest/types/index.d.ts", + "types": "./dest/index.d.ts", "engines": { "node": ">=18" } From 5cc1c97c55de6fc4ffa07240152ebe2a32723724 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 10 Nov 2023 11:27:37 +0000 Subject: [PATCH 45/47] Revert yarn-project --- yarn-project/noir-contracts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn-project/noir-contracts/package.json b/yarn-project/noir-contracts/package.json index e098ee47798..ec1249fe8a7 100644 --- a/yarn-project/noir-contracts/package.json +++ b/yarn-project/noir-contracts/package.json @@ -58,7 +58,7 @@ "src", "!*.test.*" ], - "types": "./dest/index.d.ts", + "types": "./dest/types/index.d.ts", "engines": { "node": ">=18" } From d70b08f037c9edaa7525308cd81c44f51eefe04f Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 10 Nov 2023 11:49:02 +0000 Subject: [PATCH 46/47] chore: assert sizes in define pointer view --- barretenberg/cpp/src/barretenberg/flavor/flavor.hpp | 13 ++++++++++--- .../src/barretenberg/flavor/goblin_translator.hpp | 3 ++- .../cpp/src/barretenberg/flavor/goblin_ultra.hpp | 3 ++- barretenberg/cpp/src/barretenberg/flavor/ultra.hpp | 3 ++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 9335e68fe27..7a37e57d6c1 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -75,14 +75,21 @@ namespace proof_system::honk::flavor { -#define DEFINE_POINTER_VIEW(...) \ +template static auto _assert_array_size(std::array&& array) +{ + static_assert(N == ExpectedSize, + "Expected array size to match given size (first parameter) in DEFINE_POINTER_VIEW"); + return array; +} + +#define DEFINE_POINTER_VIEW(ExpectedSize, ...) \ [[nodiscard]] auto pointer_view() \ { \ - return std::array{ __VA_ARGS__ }; \ + return _assert_array_size(std::array{ __VA_ARGS__ }); \ } \ [[nodiscard]] auto pointer_view() const \ { \ - return std::array{ __VA_ARGS__ }; \ + return _assert_array_size(std::array{ __VA_ARGS__ }); \ } /** diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index ba7db7a346c..136d60e6cc5 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -836,7 +836,8 @@ template class GoblinTranslator_ { DataType& ordered_extra_range_constraints_numerator = std::get<183>(this->_data); // defines a method pointer_view that returns the following, with const and non-const variants - DEFINE_POINTER_VIEW(&op, + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &op, &x_lo_y_hi, &x_hi_z_1, &y_lo_z_2, diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 131b30dc298..266621e7355 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -218,7 +218,8 @@ class GoblinUltra { DataType& z_lookup_shift = std::get<50>(this->_data); // defines a method pointer_view that returns the following, with const and non-const variants - DEFINE_POINTER_VIEW(&q_c, + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &q_c, &q_l, &q_r, &q_o, diff --git a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp index 721c13117fd..f596b20d890 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ultra.hpp @@ -200,7 +200,8 @@ class Ultra { DataType& z_lookup_shift = std::get<42>(this->_data); // defines a method pointer_view that returns the following, with const and non-const variants - DEFINE_POINTER_VIEW(&q_c, + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &q_c, &q_l, &q_r, &q_o, From a23c1628d5e0adaf7124f5862defa7d1cf1419e1 Mon Sep 17 00:00:00 2001 From: ludamad Date: Fri, 10 Nov 2023 11:54:33 +0000 Subject: [PATCH 47/47] fix: size asserts --- barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp | 3 ++- barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index 9f07b08b4e8..366616e9322 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -395,7 +395,8 @@ template class ECCVMBa // clang-format on // defines a method pointer_view that returns the following, with const and non-const variants - DEFINE_POINTER_VIEW(&lagrange_first, + DEFINE_POINTER_VIEW(NUM_ALL_ENTITIES, + &lagrange_first, &lagrange_second, &lagrange_last, &transcript_add, diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp index 266621e7355..120ff0badfc 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_ultra.hpp @@ -230,6 +230,7 @@ class GoblinUltra { &q_elliptic, &q_aux, &q_lookup, + &q_busread, &sigma_1, &sigma_2, &sigma_3, @@ -256,6 +257,8 @@ class GoblinUltra { &ecc_op_wire_2, &ecc_op_wire_3, &ecc_op_wire_4, + &calldata, + &calldata_read_counts, &table_1_shift, &table_2_shift, &table_3_shift,