From 99c5127ac5c10e6637534870a689a95238ae997c Mon Sep 17 00:00:00 2001 From: Cody Gunton Date: Wed, 11 Oct 2023 12:54:37 -0400 Subject: [PATCH] feat: Simplify relation containers (#2619) The main goal of this PR is to simplify the construction of the containers that we use to accumulate relation values (in sumcheck and, soon, in Protogalaxy folding). # Core changes - Expose a `View` alias for each of the primitives that needs one (`Univariate`, `field` and `field_t`). - Add nested container classes that can be instantiated from a `std::array` of sizes. Credit: https://stackoverflow.com/a/60440611 - Remove `AccumulatorsAndViews` types, replacing each with simply an accumulator type with a intrinsic notion of view. # Other changes - Bring ECCVM more in line with the rest of the relation and circuit builder code. - Add a `get_row` function to avoid passing index values to some functions. - Use more explicit or more appropriate type names (e.g., `RelationUnivariates` becomes `TupleOfTuplesOfUnivariates`, `ClaimedEvaluations` becomes `AllValues` outside of sumcheck, where it is now used in the execution trace builders). - Replace some `auto`s with useful template parameter names, still deducing the types. - Deduce more types, especially in `accumulate` functions where now it is possible, since we don't have an 'alias container type' grouping a type with a view. - Use a more idiomatic approach to identify non-linearly independent subrelations. - Get rid of special proxy functions to `accumulate` functions. - Compile time calculation of individual relation lengths, possible now that the subrelation lengths live in a `std::array`. - Relations (always fully static) are no longer instantiated anywhere. --- .../relations_bench/relations.bench.cpp | 13 +- .../ecc/fields/field_declarations.hpp | 1 + .../honk/composer/eccvm_composer.cpp | 2 +- .../src/barretenberg/honk/flavor/ecc_vm.hpp | 423 ++++++++++-------- .../barretenberg/honk/flavor/flavor.test.cpp | 21 +- .../barretenberg/honk/flavor/goblin_ultra.hpp | 11 +- .../honk/flavor/goblin_ultra_recursive.hpp | 11 +- .../src/barretenberg/honk/flavor/ultra.hpp | 39 +- .../honk/flavor/ultra_grumpkin.hpp | 11 +- .../honk/flavor/ultra_recursive.hpp | 11 +- .../honk/proof_system/composer_lib.hpp | 2 +- .../honk/proof_system/eccvm_prover.cpp | 3 +- .../proof_system/grand_product_library.hpp | 15 +- .../honk/proof_system/lookup_library.hpp | 18 +- .../honk/proof_system/permutation_library.hpp | 18 +- .../honk/proof_system/ultra_prover.cpp | 2 +- .../sumcheck/relation_correctness.test.cpp | 56 +-- .../sumcheck/relation_definitions_fwd.hpp | 35 +- .../barretenberg/honk/sumcheck/sumcheck.hpp | 7 +- .../honk/sumcheck/sumcheck_output.hpp | 2 +- .../honk/sumcheck/sumcheck_round.hpp | 41 +- .../barretenberg/polynomials/univariate.hpp | 1 + .../eccvm/eccvm_circuit_builder.hpp | 258 +++++------ .../circuit_builder/ultra_circuit_builder.cpp | 1 - .../proof_system/composer/composer_lib.hpp | 2 +- .../proof_system/composer/permutation_lib.hpp | 3 +- .../proof_system/flavor/flavor.hpp | 6 +- .../relations/auxiliary_relation.hpp | 68 ++- .../relations/ecc_op_queue_relation.hpp | 60 ++- .../relations/ecc_vm/ecc_lookup_relation.cpp | 41 +- .../relations/ecc_vm/ecc_lookup_relation.hpp | 160 +++---- .../relations/ecc_vm/ecc_msm_relation.cpp | 108 ++--- .../relations/ecc_vm/ecc_msm_relation.hpp | 55 +-- .../ecc_vm/ecc_point_table_relation.cpp | 34 +- .../ecc_vm/ecc_point_table_relation.hpp | 19 +- .../relations/ecc_vm/ecc_set_relation.cpp | 174 ++++--- .../relations/ecc_vm/ecc_set_relation.hpp | 34 +- .../ecc_vm/ecc_transcript_relation.cpp | 68 +-- .../ecc_vm/ecc_transcript_relation.hpp | 51 +-- .../relations/ecc_vm/ecc_wnaf_relation.cpp | 38 +- .../relations/ecc_vm/ecc_wnaf_relation.hpp | 36 +- .../relations/elliptic_relation.hpp | 49 +- .../relations/gen_perm_sort_relation.hpp | 45 +- .../relations/lookup_relation.hpp | 119 +++-- .../relations/nested_containers.hpp | 38 ++ .../relations/nested_containers.test.cpp | 26 ++ .../relations/permutation_relation.hpp | 97 ++-- .../proof_system/relations/relation_types.hpp | 132 ++---- .../relations/ultra_arithmetic_relation.hpp | 82 ++-- .../ultra_relation_consistency.test.cpp | 30 +- .../stdlib/primitives/field/field.hpp | 2 + 51 files changed, 1201 insertions(+), 1378 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/proof_system/relations/nested_containers.hpp create mode 100644 barretenberg/cpp/src/barretenberg/proof_system/relations/nested_containers.test.cpp diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index df0be6fe25a..5b41002d2fb 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -30,18 +30,17 @@ template void execute_relation(::benchmark: .public_input_delta = public_input_delta, }; - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; - using RelationValues = typename Relation::RelationValues; + using AllValues = typename Flavor::AllValues; + using ArrayOfValuesOverSubrelations = typename Relation::ArrayOfValuesOverSubrelations; // Extract an array containing all the polynomial evaluations at a given row i - ClaimedEvaluations new_value; - // Define the appropriate RelationValues type for this relation and initialize to zero - RelationValues accumulator; + AllValues new_value; + // Define the appropriate ArrayOfValuesOverSubrelations type for this relation and initialize to zero + ArrayOfValuesOverSubrelations accumulator; // Evaluate each constraint in the relation and check that each is satisfied - Relation relation; for (auto _ : state) { - relation.add_full_relation_value_contribution(accumulator, new_value, params); + Relation::accumulate(accumulator, new_value, params, 1); } } diff --git a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp index 4e2b292fa8c..799c202f709 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp +++ b/barretenberg/cpp/src/barretenberg/ecc/fields/field_declarations.hpp @@ -23,6 +23,7 @@ namespace barretenberg { template struct alignas(32) field { public: + using View = field; using Params = Params_; using in_buf = const uint8_t*; using vec_in_buf = const uint8_t*; diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.cpp b/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.cpp index 0e55849f1f2..6b388cd7183 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.cpp @@ -15,7 +15,7 @@ template void ECCVMComposer_::compute_witness(Circu return; } - auto polynomials = circuit_constructor.compute_full_polynomials(); + auto polynomials = circuit_constructor.compute_polynomials(); auto key_wires = proving_key->get_wires(); auto poly_wires = polynomials.get_wires(); diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index 7cceb23abba..c787e3f9fd6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -76,8 +76,8 @@ template class ECCVMBa // static_assert(instantiate_barycentric_utils()); // define the containers for storing the contributions from each relation in Sumcheck - using RelationUnivariates = decltype(create_relation_univariates_container()); - using RelationValues = decltype(create_relation_values_container()); + using TupleOfTuplesOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfArraysOfValues = decltype(create_relation_values_container()); private: /** @@ -105,82 +105,82 @@ template class ECCVMBa class WitnessEntities : public WitnessEntities_ { public: // clang-format off - DataType& transcript_add = std::get<0>(this->_data); - DataType& transcript_mul = std::get<1>(this->_data); - DataType& transcript_eq = std::get<2>(this->_data); - DataType& transcript_collision_check = std::get<3>(this->_data); - DataType& transcript_msm_transition = std::get<4>(this->_data); - DataType& transcript_pc = std::get<5>(this->_data); - DataType& transcript_msm_count = std::get<6>(this->_data); - DataType& transcript_x = std::get<7>(this->_data); - DataType& transcript_y = std::get<8>(this->_data); - DataType& transcript_z1 = std::get<9>(this->_data); - DataType& transcript_z2 = std::get<10>(this->_data); - DataType& transcript_z1zero = std::get<11>(this->_data); - DataType& transcript_z2zero = std::get<12>(this->_data); - DataType& transcript_op = std::get<13>(this->_data); - DataType& transcript_accumulator_x = std::get<14>(this->_data); - DataType& transcript_accumulator_y = std::get<15>(this->_data); - DataType& transcript_msm_x = std::get<16>(this->_data); - DataType& transcript_msm_y = std::get<17>(this->_data); - DataType& precompute_pc = std::get<18>(this->_data); - DataType& precompute_point_transition = std::get<19>(this->_data); - DataType& precompute_round = std::get<20>(this->_data); - DataType& precompute_scalar_sum = std::get<21>(this->_data); - DataType& precompute_s1hi = std::get<22>(this->_data); - DataType& precompute_s1lo = std::get<23>(this->_data); - DataType& precompute_s2hi = std::get<24>(this->_data); - DataType& precompute_s2lo = std::get<25>(this->_data); - DataType& precompute_s3hi = std::get<26>(this->_data); - DataType& precompute_s3lo = std::get<27>(this->_data); - DataType& precompute_s4hi = std::get<28>(this->_data); - DataType& precompute_s4lo = std::get<29>(this->_data); - DataType& precompute_skew = std::get<30>(this->_data); - DataType& precompute_dx = std::get<31>(this->_data); - DataType& precompute_dy = std::get<32>(this->_data); - DataType& precompute_tx = std::get<33>(this->_data); - DataType& precompute_ty = std::get<34>(this->_data); - DataType& msm_transition = std::get<35>(this->_data); - DataType& msm_add = std::get<36>(this->_data); - DataType& msm_double = std::get<37>(this->_data); - DataType& msm_skew = std::get<38>(this->_data); - DataType& msm_accumulator_x = std::get<39>(this->_data); - DataType& msm_accumulator_y = std::get<40>(this->_data); - DataType& msm_pc = std::get<41>(this->_data); - DataType& msm_size_of_msm = std::get<42>(this->_data); - DataType& msm_count = std::get<43>(this->_data); - DataType& msm_round = std::get<44>(this->_data); - DataType& msm_add1 = std::get<45>(this->_data); - DataType& msm_add2 = std::get<46>(this->_data); - DataType& msm_add3 = std::get<47>(this->_data); - DataType& msm_add4 = std::get<48>(this->_data); - DataType& msm_x1 = std::get<49>(this->_data); - DataType& msm_y1 = std::get<50>(this->_data); - DataType& msm_x2 = std::get<51>(this->_data); - DataType& msm_y2 = std::get<52>(this->_data); - DataType& msm_x3 = std::get<53>(this->_data); - DataType& msm_y3 = std::get<54>(this->_data); - DataType& msm_x4 = std::get<55>(this->_data); - DataType& msm_y4 = std::get<56>(this->_data); - DataType& msm_collision_x1 = std::get<57>(this->_data); - DataType& msm_collision_x2 = std::get<58>(this->_data); - DataType& msm_collision_x3 = std::get<59>(this->_data); - DataType& msm_collision_x4 = std::get<60>(this->_data); - DataType& msm_lambda1 = std::get<61>(this->_data); - DataType& msm_lambda2 = std::get<62>(this->_data); - DataType& msm_lambda3 = std::get<63>(this->_data); - DataType& msm_lambda4 = std::get<64>(this->_data); - DataType& msm_slice1 = std::get<65>(this->_data); - DataType& msm_slice2 = std::get<66>(this->_data); - DataType& msm_slice3 = std::get<67>(this->_data); - DataType& msm_slice4 = std::get<68>(this->_data); - DataType& transcript_accumulator_empty = std::get<69>(this->_data); - DataType& transcript_reset_accumulator = std::get<70>(this->_data); - DataType& precompute_select = std::get<71>(this->_data); - DataType& lookup_read_counts_0 = std::get<72>(this->_data); - DataType& lookup_read_counts_1 = std::get<73>(this->_data); - DataType& z_perm = std::get<74>(this->_data); - DataType& lookup_inverses = std::get<75>(this->_data); + DataType& transcript_add = std::get<0>(this->_data); + DataType& transcript_mul = std::get<1>(this->_data); + DataType& transcript_eq = std::get<2>(this->_data); + DataType& transcript_collision_check = std::get<3>(this->_data); + DataType& transcript_msm_transition = std::get<4>(this->_data); + DataType& transcript_pc = std::get<5>(this->_data); + DataType& transcript_msm_count = std::get<6>(this->_data); + DataType& transcript_x = std::get<7>(this->_data); + DataType& transcript_y = std::get<8>(this->_data); + DataType& transcript_z1 = std::get<9>(this->_data); + DataType& transcript_z2 = std::get<10>(this->_data); + DataType& transcript_z1zero = std::get<11>(this->_data); + DataType& transcript_z2zero = std::get<12>(this->_data); + DataType& transcript_op = std::get<13>(this->_data); + DataType& transcript_accumulator_x = std::get<14>(this->_data); + DataType& transcript_accumulator_y = std::get<15>(this->_data); + DataType& transcript_msm_x = std::get<16>(this->_data); + DataType& transcript_msm_y = std::get<17>(this->_data); + DataType& precompute_pc = std::get<18>(this->_data); + DataType& precompute_point_transition = std::get<19>(this->_data); + DataType& precompute_round = std::get<20>(this->_data); + DataType& precompute_scalar_sum = std::get<21>(this->_data); + DataType& precompute_s1hi = std::get<22>(this->_data); + DataType& precompute_s1lo = std::get<23>(this->_data); + DataType& precompute_s2hi = std::get<24>(this->_data); + DataType& precompute_s2lo = std::get<25>(this->_data); + DataType& precompute_s3hi = std::get<26>(this->_data); + DataType& precompute_s3lo = std::get<27>(this->_data); + DataType& precompute_s4hi = std::get<28>(this->_data); + DataType& precompute_s4lo = std::get<29>(this->_data); + DataType& precompute_skew = std::get<30>(this->_data); + DataType& precompute_dx = std::get<31>(this->_data); + DataType& precompute_dy = std::get<32>(this->_data); + DataType& precompute_tx = std::get<33>(this->_data); + DataType& precompute_ty = std::get<34>(this->_data); + DataType& msm_transition = std::get<35>(this->_data); + DataType& msm_add = std::get<36>(this->_data); + DataType& msm_double = std::get<37>(this->_data); + DataType& msm_skew = std::get<38>(this->_data); + DataType& msm_accumulator_x = std::get<39>(this->_data); + DataType& msm_accumulator_y = std::get<40>(this->_data); + DataType& msm_pc = std::get<41>(this->_data); + DataType& msm_size_of_msm = std::get<42>(this->_data); + DataType& msm_count = std::get<43>(this->_data); + DataType& msm_round = std::get<44>(this->_data); + DataType& msm_add1 = std::get<45>(this->_data); + DataType& msm_add2 = std::get<46>(this->_data); + DataType& msm_add3 = std::get<47>(this->_data); + DataType& msm_add4 = std::get<48>(this->_data); + DataType& msm_x1 = std::get<49>(this->_data); + DataType& msm_y1 = std::get<50>(this->_data); + DataType& msm_x2 = std::get<51>(this->_data); + DataType& msm_y2 = std::get<52>(this->_data); + DataType& msm_x3 = std::get<53>(this->_data); + DataType& msm_y3 = std::get<54>(this->_data); + DataType& msm_x4 = std::get<55>(this->_data); + DataType& msm_y4 = std::get<56>(this->_data); + DataType& msm_collision_x1 = std::get<57>(this->_data); + DataType& msm_collision_x2 = std::get<58>(this->_data); + DataType& msm_collision_x3 = std::get<59>(this->_data); + DataType& msm_collision_x4 = std::get<60>(this->_data); + DataType& msm_lambda1 = std::get<61>(this->_data); + DataType& msm_lambda2 = std::get<62>(this->_data); + DataType& msm_lambda3 = std::get<63>(this->_data); + DataType& msm_lambda4 = std::get<64>(this->_data); + DataType& msm_slice1 = std::get<65>(this->_data); + DataType& msm_slice2 = std::get<66>(this->_data); + DataType& msm_slice3 = std::get<67>(this->_data); + DataType& msm_slice4 = std::get<68>(this->_data); + DataType& transcript_accumulator_empty = std::get<69>(this->_data); + DataType& transcript_reset_accumulator = std::get<70>(this->_data); + DataType& precompute_select = std::get<71>(this->_data); + DataType& lookup_read_counts_0 = std::get<72>(this->_data); + DataType& lookup_read_counts_1 = std::get<73>(this->_data); + DataType& z_perm = std::get<74>(this->_data); + DataType& lookup_inverses = std::get<75>(this->_data); // clang-format on std::vector get_wires() override @@ -279,111 +279,111 @@ template class ECCVMBa class AllEntities : public AllEntities_ { public: // clang-format off - DataType& lagrange_first = std::get<0>(this->_data); - DataType& lagrange_second = std::get<1>(this->_data); - DataType& lagrange_last = std::get<2>(this->_data); - DataType& transcript_add = std::get<3>(this->_data); - DataType& transcript_mul = std::get<4>(this->_data); - DataType& transcript_eq = std::get<5>(this->_data); - DataType& transcript_collision_check = std::get<6>(this->_data); - DataType& transcript_msm_transition = std::get<7>(this->_data); - DataType& transcript_pc = std::get<8>(this->_data); - DataType& transcript_msm_count = std::get<9>(this->_data); - DataType& transcript_x = std::get<10>(this->_data); - DataType& transcript_y = std::get<11>(this->_data); - DataType& transcript_z1 = std::get<12>(this->_data); - DataType& transcript_z2 = std::get<13>(this->_data); - DataType& transcript_z1zero = std::get<14>(this->_data); - DataType& transcript_z2zero = std::get<15>(this->_data); - DataType& transcript_op = std::get<16>(this->_data); - DataType& transcript_accumulator_x = std::get<17>(this->_data); - DataType& transcript_accumulator_y = std::get<18>(this->_data); - DataType& transcript_msm_x = std::get<19>(this->_data); - DataType& transcript_msm_y = std::get<20>(this->_data); - DataType& precompute_pc = std::get<21>(this->_data); - DataType& precompute_point_transition = std::get<22>(this->_data); - DataType& precompute_round = std::get<23>(this->_data); - DataType& precompute_scalar_sum = std::get<24>(this->_data); - DataType& precompute_s1hi = std::get<25>(this->_data); - DataType& precompute_s1lo = std::get<26>(this->_data); - DataType& precompute_s2hi = std::get<27>(this->_data); - DataType& precompute_s2lo = std::get<28>(this->_data); - DataType& precompute_s3hi = std::get<29>(this->_data); - DataType& precompute_s3lo = std::get<30>(this->_data); - DataType& precompute_s4hi = std::get<31>(this->_data); - DataType& precompute_s4lo = std::get<32>(this->_data); - DataType& precompute_skew = std::get<33>(this->_data); - DataType& precompute_dx = std::get<34>(this->_data); - DataType& precompute_dy = std::get<35>(this->_data); - DataType& precompute_tx = std::get<36>(this->_data); - DataType& precompute_ty = std::get<37>(this->_data); - DataType& msm_transition = std::get<38>(this->_data); - DataType& msm_add = std::get<39>(this->_data); - DataType& msm_double = std::get<40>(this->_data); - DataType& msm_skew = std::get<41>(this->_data); - DataType& msm_accumulator_x = std::get<42>(this->_data); - DataType& msm_accumulator_y = std::get<43>(this->_data); - DataType& msm_pc = std::get<44>(this->_data); - DataType& msm_size_of_msm = std::get<45>(this->_data); - DataType& msm_count = std::get<46>(this->_data); - DataType& msm_round = std::get<47>(this->_data); - DataType& msm_add1 = std::get<48>(this->_data); - DataType& msm_add2 = std::get<49>(this->_data); - DataType& msm_add3 = std::get<50>(this->_data); - DataType& msm_add4 = std::get<51>(this->_data); - DataType& msm_x1 = std::get<52>(this->_data); - DataType& msm_y1 = std::get<53>(this->_data); - DataType& msm_x2 = std::get<54>(this->_data); - DataType& msm_y2 = std::get<55>(this->_data); - DataType& msm_x3 = std::get<56>(this->_data); - DataType& msm_y3 = std::get<57>(this->_data); - DataType& msm_x4 = std::get<58>(this->_data); - DataType& msm_y4 = std::get<59>(this->_data); - DataType& msm_collision_x1 = std::get<60>(this->_data); - DataType& msm_collision_x2 = std::get<61>(this->_data); - DataType& msm_collision_x3 = std::get<62>(this->_data); - DataType& msm_collision_x4 = std::get<63>(this->_data); - DataType& msm_lambda1 = std::get<64>(this->_data); - DataType& msm_lambda2 = std::get<65>(this->_data); - DataType& msm_lambda3 = std::get<66>(this->_data); - DataType& msm_lambda4 = std::get<67>(this->_data); - DataType& msm_slice1 = std::get<68>(this->_data); - DataType& msm_slice2 = std::get<69>(this->_data); - DataType& msm_slice3 = std::get<70>(this->_data); - DataType& msm_slice4 = std::get<71>(this->_data); - DataType& transcript_accumulator_empty = std::get<72>(this->_data); - DataType& transcript_reset_accumulator = std::get<73>(this->_data); - DataType& precompute_select = std::get<74>(this->_data); - DataType& lookup_read_counts_0 = std::get<75>(this->_data); - DataType& lookup_read_counts_1 = std::get<76>(this->_data); - DataType& z_perm = std::get<77>(this->_data); - DataType& lookup_inverses = std::get<78>(this->_data); - DataType& transcript_mul_shift = std::get<79>(this->_data); - DataType& transcript_msm_count_shift = std::get<80>(this->_data); - DataType& transcript_accumulator_x_shift = std::get<81>(this->_data); - DataType& transcript_accumulator_y_shift = std::get<82>(this->_data); - DataType& precompute_scalar_sum_shift = std::get<83>(this->_data); - DataType& precompute_s1hi_shift = std::get<84>(this->_data); - DataType& precompute_dx_shift = std::get<85>(this->_data); - DataType& precompute_dy_shift = std::get<86>(this->_data); - DataType& precompute_tx_shift = std::get<87>(this->_data); - DataType& precompute_ty_shift = std::get<88>(this->_data); - DataType& msm_transition_shift = std::get<89>(this->_data); - DataType& msm_add_shift = std::get<90>(this->_data); - DataType& msm_double_shift = std::get<91>(this->_data); - DataType& msm_skew_shift = std::get<92>(this->_data); - DataType& msm_accumulator_x_shift = std::get<93>(this->_data); - DataType& msm_accumulator_y_shift = std::get<94>(this->_data); - DataType& msm_count_shift = std::get<95>(this->_data); - DataType& msm_round_shift = std::get<96>(this->_data); - DataType& msm_add1_shift = std::get<97>(this->_data); - DataType& msm_pc_shift = std::get<98>(this->_data); - DataType& precompute_pc_shift = std::get<99>(this->_data); - DataType& transcript_pc_shift = std::get<100>(this->_data); - DataType& precompute_round_shift = std::get<101>(this->_data); - DataType& transcript_accumulator_empty_shift= std::get<102>(this->_data); - DataType& precompute_select_shift = std::get<103>(this->_data); - DataType& z_perm_shift = std::get<104>(this->_data); + DataType& lagrange_first = std::get<0>(this->_data); + DataType& lagrange_second = std::get<1>(this->_data); + DataType& lagrange_last = std::get<2>(this->_data); + DataType& transcript_add = std::get<3>(this->_data); + DataType& transcript_mul = std::get<4>(this->_data); + DataType& transcript_eq = std::get<5>(this->_data); + DataType& transcript_collision_check = std::get<6>(this->_data); + DataType& transcript_msm_transition = std::get<7>(this->_data); + DataType& transcript_pc = std::get<8>(this->_data); + DataType& transcript_msm_count = std::get<9>(this->_data); + DataType& transcript_x = std::get<10>(this->_data); + DataType& transcript_y = std::get<11>(this->_data); + DataType& transcript_z1 = std::get<12>(this->_data); + DataType& transcript_z2 = std::get<13>(this->_data); + DataType& transcript_z1zero = std::get<14>(this->_data); + DataType& transcript_z2zero = std::get<15>(this->_data); + DataType& transcript_op = std::get<16>(this->_data); + DataType& transcript_accumulator_x = std::get<17>(this->_data); + DataType& transcript_accumulator_y = std::get<18>(this->_data); + DataType& transcript_msm_x = std::get<19>(this->_data); + DataType& transcript_msm_y = std::get<20>(this->_data); + DataType& precompute_pc = std::get<21>(this->_data); + DataType& precompute_point_transition = std::get<22>(this->_data); + DataType& precompute_round = std::get<23>(this->_data); + DataType& precompute_scalar_sum = std::get<24>(this->_data); + DataType& precompute_s1hi = std::get<25>(this->_data); + DataType& precompute_s1lo = std::get<26>(this->_data); + DataType& precompute_s2hi = std::get<27>(this->_data); + DataType& precompute_s2lo = std::get<28>(this->_data); + DataType& precompute_s3hi = std::get<29>(this->_data); + DataType& precompute_s3lo = std::get<30>(this->_data); + DataType& precompute_s4hi = std::get<31>(this->_data); + DataType& precompute_s4lo = std::get<32>(this->_data); + DataType& precompute_skew = std::get<33>(this->_data); + DataType& precompute_dx = std::get<34>(this->_data); + DataType& precompute_dy = std::get<35>(this->_data); + DataType& precompute_tx = std::get<36>(this->_data); + DataType& precompute_ty = std::get<37>(this->_data); + DataType& msm_transition = std::get<38>(this->_data); + DataType& msm_add = std::get<39>(this->_data); + DataType& msm_double = std::get<40>(this->_data); + DataType& msm_skew = std::get<41>(this->_data); + DataType& msm_accumulator_x = std::get<42>(this->_data); + DataType& msm_accumulator_y = std::get<43>(this->_data); + DataType& msm_pc = std::get<44>(this->_data); + DataType& msm_size_of_msm = std::get<45>(this->_data); + DataType& msm_count = std::get<46>(this->_data); + DataType& msm_round = std::get<47>(this->_data); + DataType& msm_add1 = std::get<48>(this->_data); + DataType& msm_add2 = std::get<49>(this->_data); + DataType& msm_add3 = std::get<50>(this->_data); + DataType& msm_add4 = std::get<51>(this->_data); + DataType& msm_x1 = std::get<52>(this->_data); + DataType& msm_y1 = std::get<53>(this->_data); + DataType& msm_x2 = std::get<54>(this->_data); + DataType& msm_y2 = std::get<55>(this->_data); + DataType& msm_x3 = std::get<56>(this->_data); + DataType& msm_y3 = std::get<57>(this->_data); + DataType& msm_x4 = std::get<58>(this->_data); + DataType& msm_y4 = std::get<59>(this->_data); + DataType& msm_collision_x1 = std::get<60>(this->_data); + DataType& msm_collision_x2 = std::get<61>(this->_data); + DataType& msm_collision_x3 = std::get<62>(this->_data); + DataType& msm_collision_x4 = std::get<63>(this->_data); + DataType& msm_lambda1 = std::get<64>(this->_data); + DataType& msm_lambda2 = std::get<65>(this->_data); + DataType& msm_lambda3 = std::get<66>(this->_data); + DataType& msm_lambda4 = std::get<67>(this->_data); + DataType& msm_slice1 = std::get<68>(this->_data); + DataType& msm_slice2 = std::get<69>(this->_data); + DataType& msm_slice3 = std::get<70>(this->_data); + DataType& msm_slice4 = std::get<71>(this->_data); + DataType& transcript_accumulator_empty = std::get<72>(this->_data); + DataType& transcript_reset_accumulator = std::get<73>(this->_data); + DataType& precompute_select = std::get<74>(this->_data); + DataType& lookup_read_counts_0 = std::get<75>(this->_data); + DataType& lookup_read_counts_1 = std::get<76>(this->_data); + DataType& z_perm = std::get<77>(this->_data); + DataType& lookup_inverses = std::get<78>(this->_data); + DataType& transcript_mul_shift = std::get<79>(this->_data); + DataType& transcript_msm_count_shift = std::get<80>(this->_data); + DataType& transcript_accumulator_x_shift = std::get<81>(this->_data); + DataType& transcript_accumulator_y_shift = std::get<82>(this->_data); + DataType& precompute_scalar_sum_shift = std::get<83>(this->_data); + DataType& precompute_s1hi_shift = std::get<84>(this->_data); + DataType& precompute_dx_shift = std::get<85>(this->_data); + DataType& precompute_dy_shift = std::get<86>(this->_data); + DataType& precompute_tx_shift = std::get<87>(this->_data); + DataType& precompute_ty_shift = std::get<88>(this->_data); + DataType& msm_transition_shift = std::get<89>(this->_data); + DataType& msm_add_shift = std::get<90>(this->_data); + DataType& msm_double_shift = std::get<91>(this->_data); + DataType& msm_skew_shift = std::get<92>(this->_data); + DataType& msm_accumulator_x_shift = std::get<93>(this->_data); + DataType& msm_accumulator_y_shift = std::get<94>(this->_data); + DataType& msm_count_shift = std::get<95>(this->_data); + DataType& msm_round_shift = std::get<96>(this->_data); + DataType& msm_add1_shift = std::get<97>(this->_data); + DataType& msm_pc_shift = std::get<98>(this->_data); + DataType& precompute_pc_shift = std::get<99>(this->_data); + DataType& transcript_pc_shift = std::get<100>(this->_data); + DataType& precompute_round_shift = std::get<101>(this->_data); + DataType& transcript_accumulator_empty_shift = std::get<102>(this->_data); + DataType& precompute_select_shift = std::get<103>(this->_data); + DataType& z_perm_shift = std::get<104>(this->_data); template [[nodiscard]] const DataType& lookup_read_counts() const @@ -649,19 +649,46 @@ template class ECCVMBa */ using VerificationKey = VerificationKey_>; - /** - * @brief A container for polynomials handles; only stores spans. - */ - using ProverPolynomials = AllEntities; - /** * @brief A container for polynomials produced after the first round of sumcheck. * @todo TODO(#394) Use polynomial classes for guaranteed memory alignment. */ using FoldedPolynomials = AllEntities, PolynomialHandle>; - using RawPolynomials = AllEntities; + /** + * @brief A field element for each entity of the flavor. + */ + class AllValues : public AllEntities { + public: + using Base = AllEntities; + using Base::Base; + AllValues(std::array _data_in) { this->_data = _data_in; } + }; + /** + * @brief An owning container of polynomials. + * @warning When this was introduced it broke some of our design principles. + * - Execution trace builders don't handle "polynomials" because the interpretation of the execution trace columns + * as polynomials is a detail of the proving system, and trace builders are (sometimes in practice, always in + * principle) reusable for different proving protocols (e.g., Plonk and Honk). + * - Polynomial storage is handled by key classes. Polynomials aren't moved, but are accessed elsewhere by + * std::spans. + * + * We will consider revising this data model: TODO(https://github.com/AztecProtocol/barretenberg/issues/743) + */ + class AllPolynomials : public AllEntities { + public: + 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) { + result[column_idx] = column[row_idx]; + column_idx++; + } + return result; + } + }; /** * @brief A container for polynomials produced after the first round of sumcheck. * @todo TODO(#394) Use polynomial classes for guaranteed memory alignment. @@ -693,14 +720,20 @@ template class ECCVMBa barretenberg::Univariate>; /** - * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the - * evaluations of polynomials committed in earlier rounds. + * @brief A container for polynomials handles; only stores spans. */ - class ClaimedEvaluations : public AllEntities { + class ProverPolynomials : public AllEntities { public: - using Base = AllEntities; - using Base::Base; - ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } + 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) { + result[column_idx] = column[row_idx]; + column_idx++; + } + return result; + } }; /** diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/flavor.test.cpp b/barretenberg/cpp/src/barretenberg/honk/flavor/flavor.test.cpp index 01508f4fb70..32395c746cc 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/flavor.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/flavor.test.cpp @@ -34,7 +34,7 @@ TEST(Flavor, Getters) Flavor::VerificationKey verification_key; Flavor::ProverPolynomials prover_polynomials; Flavor::ExtendedEdges edges; - Flavor::ClaimedEvaluations evals; + Flavor::AllValues evals; Flavor::CommitmentLabels commitment_labels; // Globals are also available through STL container sizes @@ -131,4 +131,23 @@ TEST(Flavor, AllEntitiesSpecialMemberFunctions) ASSERT_EQ(random_poly, polynomials_C.w_l); } +TEST(Flavor, GetRow) +{ + using Flavor = proof_system::honk::flavor::Ultra; + using FF = typename Flavor::FF; + std::array, Flavor::NUM_ALL_ENTITIES> data; + std::generate(data.begin(), data.end(), []() { + return std::vector({ FF::random_element(), FF::random_element() }); + }); + Flavor::ProverPolynomials prover_polynomials; + size_t poly_idx = 0; + for (auto& poly : prover_polynomials) { + poly = data[poly_idx]; + poly_idx++; + } + auto row0 = prover_polynomials.get_row(0); + auto row1 = prover_polynomials.get_row(1); + EXPECT_EQ(row0.q_elliptic, prover_polynomials.q_elliptic[0]); + EXPECT_EQ(row1.w_4_shift, prover_polynomials.w_4_shift[1]); +} } // namespace proof_system::test_flavor diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 95b79c204c2..2fc5f0f7f0e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -59,8 +59,8 @@ class GoblinUltra { static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck - using RelationUnivariates = decltype(create_relation_univariates_container()); - using RelationValues = decltype(create_relation_values_container()); + using TupleOfTuplesOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfArraysOfValues = decltype(create_relation_values_container()); // Whether or not the first row of the execution trace is reserved for 0s to enable shifts static constexpr bool has_zero_row = true; @@ -332,14 +332,13 @@ class GoblinUltra { barretenberg::Univariate>; /** - * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the - * evaluations of polynomials committed in earlier rounds. + * @brief A field element for each entity of the flavor. */ - class ClaimedEvaluations : public AllEntities { + class AllValues : public AllEntities { public: using Base = AllEntities; using Base::Base; - ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } + AllValues(std::array _data_in) { this->_data = _data_in; } }; /** diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp index 12f96ff105c..25c70d2b5b6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp @@ -85,8 +85,8 @@ template class GoblinUltraRecursive_ { static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck - using RelationUnivariates = decltype(create_relation_univariates_container()); - using RelationValues = decltype(create_relation_values_container()); + using TupleOfTuplesOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfArraysOfValues = decltype(create_relation_values_container()); private: template @@ -343,14 +343,13 @@ template class GoblinUltraRecursive_ { }; /** - * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the - * evaluations of polynomials committed in earlier rounds. + * @brief A field element for each entity of the flavor. */ - class ClaimedEvaluations : public AllEntities { + class AllValues : public AllEntities { public: using Base = AllEntities; using Base::Base; - ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } + AllValues(std::array _data_in) { this->_data = _data_in; } }; /** diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 2e1ca263dfe..9d2582b92de 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -61,8 +61,8 @@ class Ultra { static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck - using RelationUnivariates = decltype(create_relation_univariates_container()); - using RelationValues = decltype(create_relation_values_container()); + using TupleOfTuplesOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfArraysOfValues = decltype(create_relation_values_container()); // Whether or not the first row of the execution trace is reserved for 0s to enable shifts static constexpr bool has_zero_row = true; @@ -271,10 +271,32 @@ class Ultra { */ using VerificationKey = VerificationKey_>; + /** + * @brief A field element for each entity of the flavor. + */ + class AllValues : public AllEntities { + public: + using Base = AllEntities; + using Base::Base; + AllValues(std::array _data_in) { this->_data = _data_in; } + }; + /** * @brief A container for polynomials handles; only stores spans. */ - using ProverPolynomials = AllEntities; + class ProverPolynomials : public AllEntities { + public: + 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) { + result[column_idx] = column[row_idx]; + column_idx++; + } + return result; + } + }; /** * @brief A container for storing the partially evaluated multivariates produced by sumcheck. @@ -300,17 +322,6 @@ class Ultra { using ExtendedEdges = AllEntities, barretenberg::Univariate>; - /** - * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the - * evaluations of polynomials committed in earlier rounds. - */ - class ClaimedEvaluations : public AllEntities { - public: - using Base = AllEntities; - using Base::Base; - ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } - }; - /** * @brief A container for commitment labels. * @note It's debatable whether this should inherit from AllEntities. since most entries are not strictly needed. It diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp index 979aaceed7b..8b1f71f317d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp @@ -70,8 +70,8 @@ class UltraGrumpkin { static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck - using RelationUnivariates = decltype(create_relation_univariates_container()); - using RelationValues = decltype(create_relation_values_container()); + using TupleOfTuplesOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfArraysOfValues = decltype(create_relation_values_container()); // Whether or not the first row of the execution trace is reserved for 0s to enable shifts static constexpr bool has_zero_row = true; @@ -308,14 +308,13 @@ class UltraGrumpkin { barretenberg::Univariate>; /** - * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the - * evaluations of polynomials committed in earlier rounds. + * @brief A field element for each entity of the flavor. */ - class ClaimedEvaluations : public AllEntities { + class AllValues : public AllEntities { public: using Base = AllEntities; using Base::Base; - ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } + AllValues(std::array _data_in) { this->_data = _data_in; } }; /** diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 5168265cc08..c5c4e382ab2 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -84,8 +84,8 @@ template class UltraRecursive_ { static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck - using RelationUnivariates = decltype(create_relation_univariates_container()); - using RelationValues = decltype(create_relation_values_container()); + using TupleOfTuplesOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfArraysOfValues = decltype(create_relation_values_container()); private: template @@ -308,14 +308,13 @@ template class UltraRecursive_ { }; /** - * @brief A container for the polynomials evaluations produced during sumcheck, which are purported to be the - * evaluations of polynomials committed in earlier rounds. + * @brief A field element for each entity of the flavor. */ - class ClaimedEvaluations : public AllEntities { + class AllValues : public AllEntities { public: using Base = AllEntities; using Base::Base; - ClaimedEvaluations(std::array _data_in) { this->_data = _data_in; } + AllValues(std::array _data_in) { this->_data = _data_in; } }; /** diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp index 557570d90d9..1219b2a586b 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp @@ -26,7 +26,7 @@ std::shared_ptr compute_verification_key_commo auto commitment_key = typename Flavor::CommitmentKey(proving_key->circuit_size, proving_key->crs); - size_t poly_idx = 0; // TODO(#391) zip + size_t poly_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip for (auto& polynomial : proving_key) { verification_key[poly_idx] = commitment_key.commit(polynomial); ++polynomial_idx; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp index c44589b0578..dd4139cbbcf 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp @@ -144,6 +144,7 @@ ECCVMProver_::ECCVMProver_(std::shared_ptr prover_polynomials.lookup_inverses = key->lookup_inverses; key->z_perm = Polynomial(key->circuit_size); prover_polynomials.z_perm = key->z_perm; + prover_polynomials.z_perm_shift = key->z_perm; // this will be initialized properly later } /** @@ -247,7 +248,7 @@ template void ECCVMProver_::execute_univariatizatio // Batch the unshifted polynomials and the to-be-shifted polynomials using ρ Polynomial batched_poly_unshifted(key->circuit_size); // batched unshifted polynomials - size_t poly_idx = 0; // TODO(#391) zip + size_t poly_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip for (auto& unshifted_poly : prover_polynomials.get_unshifted()) { batched_poly_unshifted.add_scaled(unshifted_poly, rhos[poly_idx]); ++poly_idx; 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 acb530965c6..fa6334e2303 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 @@ -47,12 +47,12 @@ namespace proof_system::honk::grand_product_library { */ template void compute_grand_product(const size_t circuit_size, - auto& full_polynomials, + typename Flavor::ProverPolynomials& full_polynomials, proof_system::RelationParameters& relation_parameters) { using FF = typename Flavor::FF; using Polynomial = typename Flavor::Polynomial; - using ValueAccumulatorsAndViews = typename GrandProdRelation::ValueAccumulatorsAndViews; + using Accumulator = std::tuple_element_t<0, typename GrandProdRelation::ArrayOfValuesOverSubrelations>; // 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 @@ -67,15 +67,14 @@ void compute_grand_product(const size_t circuit_size, 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::ClaimedEvaluations evaluations; + 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, i); - denominator[i] = GrandProdRelation::template compute_grand_product_denominator( - evaluations, relation_parameters, i); + numerator[i] = GrandProdRelation::template compute_grand_product_numerator( + evaluations, relation_parameters); + denominator[i] = GrandProdRelation::template compute_grand_product_denominator( + evaluations, relation_parameters); } }); diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/lookup_library.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/lookup_library.hpp index bb590b49a52..a2c83cfc8d8 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/lookup_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/lookup_library.hpp @@ -23,33 +23,33 @@ namespace proof_system::honk::lookup_library { * The specific algebraic relations that define read terms and write terms are defined in Flavor::LookupRelation * */ -template -void compute_logderivative_inverse(auto& polynomials, +template +void compute_logderivative_inverse(Polynomials& polynomials, proof_system::RelationParameters& relation_parameters, const size_t circuit_size) { using FF = typename Flavor::FF; - using Accumulator = typename Relation::ValueAccumulatorsAndViews; + using Accumulator = typename Relation::ValueAccumulator0; constexpr size_t READ_TERMS = Relation::READ_TERMS; constexpr size_t WRITE_TERMS = Relation::WRITE_TERMS; auto& inverse_polynomial = polynomials.lookup_inverses; auto lookup_relation = Relation(); for (size_t i = 0; i < circuit_size; ++i) { - bool has_inverse = - lookup_relation.template lookup_exists_at_row_index(polynomials, relation_parameters, i); + auto row = polynomials.get_row(i); + bool has_inverse = lookup_relation.lookup_exists_at_row(row); if (!has_inverse) { continue; } FF denominator = 1; barretenberg::constexpr_for<0, READ_TERMS, 1>([&] { - auto denominator_term = lookup_relation.template compute_read_term( - polynomials, relation_parameters, i); + auto denominator_term = + lookup_relation.template compute_read_term(row, relation_parameters); denominator *= denominator_term; }); barretenberg::constexpr_for<0, WRITE_TERMS, 1>([&] { - auto denominator_term = lookup_relation.template compute_write_term( - polynomials, relation_parameters, i); + auto denominator_term = + lookup_relation.template compute_write_term(row, relation_parameters); denominator *= denominator_term; }); inverse_polynomial[i] = denominator; 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 f2a46e2c1dc..e61c4a311d2 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/permutation_library.hpp @@ -42,14 +42,14 @@ namespace proof_system::honk::permutation_library { * * Note: Step (3) utilizes Montgomery batch inversion to replace n-many inversions with */ -template +template void compute_permutation_grand_product(const size_t circuit_size, auto& full_polynomials, proof_system::RelationParameters& relation_parameters) { using FF = typename Flavor::FF; using Polynomial = typename Flavor::Polynomial; - using ValueAccumulatorsAndViews = typename PermutationRelation::ValueAccumulatorsAndViews; + using Accumulator = std::tuple_element_t<0, typename GrandProdRelation::ArrayOfValuesOverSubrelations>; // Allocate numerator/denominator polynomials that will serve as scratch space // TODO(zac) we can re-use the permutation polynomial as the numerator polynomial. @@ -58,7 +58,7 @@ void compute_permutation_grand_product(const size_t circuit_size, Polynomial denominator = Polynomial{ circuit_size }; // Step (1) - // Populate `numerator` and `denominator` with the algebra described by PermutationRelation + // Populate `numerator` and `denominator` with the algebra described by GrandProdRelation static constexpr size_t MIN_CIRCUIT_SIZE_TO_MULTITHREAD = 64; const size_t num_threads = circuit_size >= MIN_CIRCUIT_SIZE_TO_MULTITHREAD ? (circuit_size >= get_num_cpus_pow2() ? get_num_cpus_pow2() : 1) @@ -69,14 +69,14 @@ void compute_permutation_grand_product(const size_t circuit_size, const size_t end = (thread_idx + 1) * block_size; for (size_t i = start; i < end; ++i) { - typename Flavor::ClaimedEvaluations evaluations; + 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] = PermutationRelation::template compute_permutation_numerator( - evaluations, relation_parameters, i); - denominator[i] = PermutationRelation::template compute_permutation_denominator( - evaluations, relation_parameters, i); + numerator[i] = GrandProdRelation::template compute_permutation_numerator(evaluations, + relation_parameters); + denominator[i] = GrandProdRelation::template compute_permutation_denominator( + evaluations, relation_parameters); } }); @@ -128,7 +128,7 @@ void compute_permutation_grand_product(const size_t circuit_size, }); // Step (3) Compute z_perm[i] = numerator[i] / denominator[i] - auto& grand_product_polynomial = PermutationRelation::get_grand_product_polynomial(full_polynomials); + auto& grand_product_polynomial = GrandProdRelation::get_grand_product_polynomial(full_polynomials); grand_product_polynomial[0] = 0; parallel_for(num_threads, [&](size_t thread_idx) { const size_t start = thread_idx * block_size; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp index 618df552869..887bb096a2a 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp @@ -125,7 +125,7 @@ template void UltraProver_::execute_univariatizatio // Batch the unshifted polynomials and the to-be-shifted polynomials using ρ Polynomial batched_poly_unshifted(instance->proving_key->circuit_size); // batched unshifted polynomials - size_t poly_idx = 0; // TODO(#391) zip + size_t poly_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip for (auto& unshifted_poly : instance->prover_polynomials.get_unshifted()) { batched_poly_unshifted.add_scaled(unshifted_poly, rhos[poly_idx]); ++poly_idx; 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 d73918737cc..ed902506b03 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp @@ -29,28 +29,28 @@ void ensure_non_zero(auto& polynomial) * @tparam relation_idx Index into a tuple of provided relations * @tparam Flavor */ -template void check_relation(auto relation, auto circuit_size, auto polynomials, auto params) +template void check_relation(auto circuit_size, auto polynomials, auto params) { - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; + using AllValues = typename Flavor::AllValues; for (size_t i = 0; i < circuit_size; i++) { // Extract an array containing all the polynomial evaluations at a given row i - ClaimedEvaluations evaluations_at_index_i; + AllValues evaluations_at_index_i; size_t poly_idx = 0; for (auto& poly : polynomials) { evaluations_at_index_i[poly_idx] = poly[i]; ++poly_idx; } - // Define the appropriate RelationValues type for this relation and initialize to zero - using RelationValues = typename decltype(relation)::RelationValues; - RelationValues result; + // Define the appropriate ArrayOfValuesOverSubrelations type for this relation and initialize to zero + using ArrayOfValuesOverSubrelations = typename Relation::ArrayOfValuesOverSubrelations; + ArrayOfValuesOverSubrelations result; for (auto& element : result) { element = 0; } // Evaluate each constraint in the relation and check that each is satisfied - relation.add_full_relation_value_contribution(result, evaluations_at_index_i, params); + Relation::accumulate(result, evaluations_at_index_i, params, 1); for (auto& element : result) { ASSERT_EQ(element, 0); } @@ -253,22 +253,17 @@ TEST_F(RelationCorrectnessTests, UltraRelationCorrectness) ensure_non_zero(proving_key->q_aux); // Construct the round for applying sumcheck relations and results for storing computed results - auto relations = std::tuple(proof_system::UltraArithmeticRelation(), - proof_system::UltraPermutationRelation(), - proof_system::LookupRelation(), - proof_system::GenPermSortRelation(), - proof_system::EllipticRelation(), - proof_system::AuxiliaryRelation()); + using Relations = typename Flavor::Relations; auto prover_polynomials = instance->prover_polynomials; auto params = instance->relation_parameters; // Check that each relation is satisfied across each row of the prover polynomials - check_relation(std::get<0>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<1>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<2>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<3>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<4>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<5>(relations), circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); } TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) @@ -311,25 +306,18 @@ TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) ensure_non_zero(proving_key->q_aux); // Construct the round for applying sumcheck relations and results for storing computed results - auto relations = std::tuple(proof_system::UltraArithmeticRelation(), - proof_system::UltraPermutationRelation(), - proof_system::LookupRelation(), - proof_system::GenPermSortRelation(), - proof_system::EllipticRelation(), - proof_system::AuxiliaryRelation(), - proof_system::EccOpQueueRelation()); - + using Relations = typename Flavor::Relations; auto prover_polynomials = instance->prover_polynomials; auto params = instance->relation_parameters; // Check that each relation is satisfied across each row of the prover polynomials - check_relation(std::get<0>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<1>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<2>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<3>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<4>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<5>(relations), circuit_size, prover_polynomials, params); - check_relation(std::get<6>(relations), circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); + check_relation>(circuit_size, prover_polynomials, params); } } // namespace test_honk_relations diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_definitions_fwd.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_definitions_fwd.hpp index f6ced1d7aa5..1f7d3f0d520 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_definitions_fwd.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_definitions_fwd.hpp @@ -3,32 +3,31 @@ #include "barretenberg/proof_system/relations/relation_types.hpp" #define ExtendedEdge(Flavor) Flavor::ExtendedEdges -#define EvaluationEdge(Flavor) Flavor::ClaimedEvaluations +#define EvaluationEdge(Flavor) Flavor::AllValues #define EntityEdge(Flavor) Flavor::AllEntities -#define ADD_EDGE_CONTRIBUTION(...) _ADD_EDGE_CONTRIBUTION(__VA_ARGS__) -#define _ADD_EDGE_CONTRIBUTION(Preface, RelationBase, Flavor, AccumulatorType, EdgeType) \ +#define ACCUMULATE(...) _ACCUMULATE(__VA_ARGS__) +#define _ACCUMULATE(Preface, RelationBase, Flavor, AccumulatorType, EdgeType) \ Preface template void \ RelationBase::accumulate>::AccumulatorType, \ EdgeType(Flavor)>( \ - proof_system::Relation>::AccumulatorType::Accumulators&, \ + proof_system::Relation>::AccumulatorType&, \ EdgeType(Flavor) const&, \ RelationParameters const&, \ Flavor::FF const&); #define PERMUTATION_METHOD(...) _PERMUTATION_METHOD(__VA_ARGS__) #define _PERMUTATION_METHOD(Preface, MethodName, RelationBase, Flavor, AccumulatorType, EdgeType) \ - Preface template RelationBase::template Accumulator< \ - proof_system::Relation>::AccumulatorType> \ + Preface template typename proof_system::Relation>::AccumulatorType \ RelationBase::MethodName>::AccumulatorType, \ - EdgeType(Flavor)>( \ - EdgeType(Flavor) const&, RelationParameters const&, size_t const); + EdgeType(Flavor)>(EdgeType(Flavor) const&, \ + RelationParameters const&); #define SUMCHECK_RELATION_CLASS(...) _SUMCHECK_RELATION_CLASS(__VA_ARGS__) #define _SUMCHECK_RELATION_CLASS(Preface, RelationBase, Flavor) \ - ADD_EDGE_CONTRIBUTION(Preface, RelationBase, Flavor, UnivariateAccumulatorsAndViews, ExtendedEdge) \ - ADD_EDGE_CONTRIBUTION(Preface, RelationBase, Flavor, ValueAccumulatorsAndViews, EvaluationEdge) \ - ADD_EDGE_CONTRIBUTION(Preface, RelationBase, Flavor, ValueAccumulatorsAndViews, EntityEdge) + ACCUMULATE(Preface, RelationBase, Flavor, TupleOfUnivariatesOverSubrelations, ExtendedEdge) \ + ACCUMULATE(Preface, RelationBase, Flavor, ArrayOfValuesOverSubrelations, EvaluationEdge) \ + ACCUMULATE(Preface, RelationBase, Flavor, ArrayOfValuesOverSubrelations, EntityEdge) #define DECLARE_SUMCHECK_RELATION_CLASS(RelationBase, Flavor) SUMCHECK_RELATION_CLASS(extern, RelationBase, Flavor) #define DEFINE_SUMCHECK_RELATION_CLASS(RelationBase, Flavor) SUMCHECK_RELATION_CLASS(, RelationBase, Flavor) @@ -36,17 +35,15 @@ #define SUMCHECK_PERMUTATION_CLASS(...) _SUMCHECK_PERMUTATION_CLASS(__VA_ARGS__) #define _SUMCHECK_PERMUTATION_CLASS(Preface, RelationBase, Flavor) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_numerator, RelationBase, Flavor, UnivariateAccumulatorsAndViews, ExtendedEdge) \ - PERMUTATION_METHOD( \ - Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulatorsAndViews, EvaluationEdge) \ - PERMUTATION_METHOD( \ - Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulatorsAndViews, EntityEdge) \ + Preface, compute_permutation_numerator, RelationBase, Flavor, UnivariateAccumulator0, ExtendedEdge) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_denominator, RelationBase, Flavor, UnivariateAccumulatorsAndViews, ExtendedEdge) \ + Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulator0, EvaluationEdge) \ + PERMUTATION_METHOD(Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulator0, EntityEdge) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulatorsAndViews, EvaluationEdge) \ + Preface, compute_permutation_denominator, RelationBase, Flavor, UnivariateAccumulator0, ExtendedEdge) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulatorsAndViews, EntityEdge) + Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulator0, EvaluationEdge) \ + PERMUTATION_METHOD(Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulator0, EntityEdge) #define DECLARE_SUMCHECK_PERMUTATION_CLASS(RelationBase, Flavor) \ SUMCHECK_PERMUTATION_CLASS(extern, RelationBase, Flavor) diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 48f2283700e..d51f8c207b8 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -15,7 +15,7 @@ template class SumcheckProver { public: using FF = typename Flavor::FF; using PartiallyEvaluatedMultivariates = typename Flavor::PartiallyEvaluatedMultivariates; - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; + using ClaimedEvaluations = typename Flavor::AllValues; ProverTranscript& transcript; const size_t multivariate_n; @@ -108,7 +108,8 @@ template class SumcheckProver { // Final round: Extract multivariate evaluations from partially_evaluated_polynomials and add to transcript ClaimedEvaluations multivariate_evaluations; size_t evaluation_idx = 0; - for (auto& polynomial : partially_evaluated_polynomials) { // TODO(#391) zip + // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip + for (auto& polynomial : partially_evaluated_polynomials) { multivariate_evaluations[evaluation_idx] = polynomial[0]; ++evaluation_idx; } @@ -150,7 +151,7 @@ template class SumcheckVerifier { public: using FF = typename Flavor::FF; - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; + using ClaimedEvaluations = typename Flavor::AllValues; static constexpr size_t MAX_RANDOM_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; static constexpr size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_output.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_output.hpp index a274c9df3ab..d300d6d4d72 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_output.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_output.hpp @@ -11,7 +11,7 @@ namespace proof_system::honk::sumcheck { */ template struct SumcheckOutput { using FF = typename Flavor::FF; - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; + using ClaimedEvaluations = typename Flavor::AllValues; // u = (u_0, ..., u_{d-1}) std::vector challenge; // Evaluations in `u` of the polynomials used in Sumcheck diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 353433c756f..d718c05080b 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -6,6 +6,7 @@ #include "barretenberg/polynomials/pow.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" #include "barretenberg/proof_system/relations/relation_parameters.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system::honk::sumcheck { @@ -54,7 +55,7 @@ namespace proof_system::honk::sumcheck { template class SumcheckProverRound { using Relations = typename Flavor::Relations; - using RelationUnivariates = typename Flavor::RelationUnivariates; + using TupleOfTuplesOfUnivariates = typename Flavor::TupleOfTuplesOfUnivariates; public: using FF = typename Flavor::FF; @@ -63,12 +64,11 @@ template class SumcheckProverRound { size_t round_size; // a power of 2 - Relations relations; static constexpr size_t NUM_RELATIONS = Flavor::NUM_RELATIONS; static constexpr size_t MAX_RELATION_LENGTH = Flavor::MAX_RELATION_LENGTH; static constexpr size_t MAX_RANDOM_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; - RelationUnivariates univariate_accumulators; + TupleOfTuplesOfUnivariates univariate_accumulators; // TODO(#224)(Cody): this should go away barretenberg::BarycentricData barycentric_2_to_max; @@ -110,7 +110,7 @@ template class SumcheckProverRound { */ void extend_edges(auto& extended_edges, auto& multivariates, size_t edge_idx) { - size_t univariate_idx = 0; // TODO(#391) zip + 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] = barycentric_2_to_max.extend(edge); @@ -147,7 +147,7 @@ template class SumcheckProverRound { size_t iterations_per_thread = round_size / num_threads; // actual iterations per thread // Constuct univariate accumulator containers; one per thread - std::vector thread_univariate_accumulators(num_threads); + std::vector thread_univariate_accumulators(num_threads); for (auto& accum : thread_univariate_accumulators) { zero_univariates(accum); } @@ -204,12 +204,13 @@ template class SumcheckProverRound { * appropriate scaling factors, produces S_l. */ template - void accumulate_relation_univariates(RelationUnivariates& univariate_accumulators, + void accumulate_relation_univariates(TupleOfTuplesOfUnivariates& univariate_accumulators, const auto& extended_edges, const proof_system::RelationParameters& relation_parameters, const FF& scaling_factor) { - std::get(relations).add_edge_contribution( + using Relation = std::tuple_element_t; + Relation::accumulate( std::get(univariate_accumulators), extended_edges, relation_parameters, scaling_factor); // Repeat for the next relation. @@ -220,9 +221,8 @@ template class SumcheckProverRound { } public: - // TODO(luke): Potentially make RelationUnivarites (tuple of tuples of Univariates) a class and make these utility - // functions class methods. Alternatively, move all of these tuple utilities (and the ones living elsewhere) to - // their own module. + // TODO(luke): Potentially make TupleOfTuplesOfUnivariates a class and make these utility functions class methods. + // Alternatively, move all of these tuple utilities (and the ones living elsewhere) to their own module. /** * Utility methods for tuple of tuples of Univariates */ @@ -253,9 +253,7 @@ template class SumcheckProverRound { barretenberg::BarycentricData barycentric_utils; auto extended = barycentric_utils.extend(element); - const bool is_subrelation_linearly_independent = - Relation::template is_subrelation_linearly_independent(); - if (is_subrelation_linearly_independent) { + if constexpr (subrelation_is_linearly_independent()) { // if subrelation is linearly independent, multiply by random polynomial result += extended * extended_random_polynomial_edge; } else { @@ -368,21 +366,20 @@ template class SumcheckProverRound { template class SumcheckVerifierRound { using Relations = typename Flavor::Relations; - using RelationEvaluations = typename Flavor::RelationValues; + using TupleOfArraysOfValues = typename Flavor::TupleOfArraysOfValues; public: using FF = typename Flavor::FF; - using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; + using ClaimedEvaluations = typename Flavor::AllValues; bool round_failed = false; - Relations relations; static constexpr size_t NUM_RELATIONS = Flavor::NUM_RELATIONS; static constexpr size_t MAX_RANDOM_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; FF target_total_sum = 0; - RelationEvaluations relation_evaluations; + TupleOfArraysOfValues relation_evaluations; // Verifier constructor explicit SumcheckVerifierRound() { zero_elements(relation_evaluations); }; @@ -470,11 +467,11 @@ template class SumcheckVerifierRound { const proof_system::RelationParameters& relation_parameters, const FF& partial_evaluation_constant) { - std::get(relations).add_full_relation_value_contribution( - std::get(relation_evaluations), - purported_evaluations, - relation_parameters, - partial_evaluation_constant); + using Relation = std::tuple_element_t; + Relation::accumulate(std::get(relation_evaluations), + purported_evaluations, + relation_parameters, + partial_evaluation_constant); // Repeat for the next relation. if constexpr (relation_idx + 1 < NUM_RELATIONS) { diff --git a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index 42f6090f329..afa5aa5c0b3 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -21,6 +21,7 @@ template class UnivariateView; template class Univariate { public: static constexpr size_t LENGTH = _length; + using View = UnivariateView; // TODO(https://github.com/AztecProtocol/barretenberg/issues/714) Try out std::valarray? std::array evaluations; 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 119b8410040..8f71dd6244c 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 @@ -17,10 +17,13 @@ namespace proof_system { template class ECCVMCircuitBuilder { public: using CycleGroup = typename Flavor::CycleGroup; - using CycleScalar = typename CycleGroup::subgroup_field; using FF = typename Flavor::FF; + using Polynomial = typename Flavor::Polynomial; + + using CycleScalar = typename CycleGroup::subgroup_field; using Element = typename CycleGroup::element; using AffineElement = typename CycleGroup::affine_element; + static constexpr size_t NUM_SCALAR_BITS = proof_system_eccvm::NUM_SCALAR_BITS; static constexpr size_t WNAF_SLICE_BITS = proof_system_eccvm::WNAF_SLICE_BITS; static constexpr size_t NUM_WNAF_SLICES = proof_system_eccvm::NUM_WNAF_SLICES; @@ -36,8 +39,7 @@ template class ECCVMCircuitBuilder { using VMOperation = proof_system_eccvm::VMOperation; std::vector vm_operations; using ScalarMul = proof_system_eccvm::ScalarMul; - using RawPolynomials = typename Flavor::RawPolynomials; - using Polynomial = barretenberg::Polynomial; + using AllPolynomials = typename Flavor::AllPolynomials; ECCVMCircuitBuilder() = default; @@ -312,9 +314,9 @@ template class ECCVMCircuitBuilder { (reads come from msm_x/y1, msm_x/y2) * lookup_read_counts_1: stores number of times a point has been read from a Straus precomputation table (reads come from msm_x/y3, msm_x/y4) - * @return RawPolynomials + * @return AllPolynomials */ - RawPolynomials compute_full_polynomials() + AllPolynomials compute_polynomials() { const auto msms = get_msms(); const auto flattened_muls = get_flattened_scalar_muls(msms); @@ -336,14 +338,14 @@ template class ECCVMCircuitBuilder { const auto num_rows_log2 = static_cast(numeric::get_msb64(num_rows)); size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); - RawPolynomials rows; + AllPolynomials polys; for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { - rows[j] = Polynomial(num_rows_pow2); + polys[j] = Polynomial(num_rows_pow2); } - rows.lagrange_first[0] = 1; - rows.lagrange_second[1] = 1; - rows.lagrange_last[rows.lagrange_last.size() - 1] = 1; + polys.lagrange_first[0] = 1; + polys.lagrange_second[1] = 1; + polys.lagrange_last[polys.lagrange_last.size() - 1] = 1; for (size_t i = 0; i < point_table_read_counts[0].size(); ++i) { // Explanation of off-by-one offset @@ -352,30 +354,30 @@ template class ECCVMCircuitBuilder { // `lookup_read_counts`. We do this mapping in `ecc_msm_relation`. We are off-by-one because we add an empty // row at the start of the WNAF columns that is not accounted for (index of lookup_read_counts maps to the // row in our WNAF columns that computes a slice for a given value of pc and round) - rows.lookup_read_counts_0[i + 1] = point_table_read_counts[0][i]; - rows.lookup_read_counts_1[i + 1] = point_table_read_counts[1][i]; + polys.lookup_read_counts_0[i + 1] = point_table_read_counts[0][i]; + polys.lookup_read_counts_1[i + 1] = point_table_read_counts[1][i]; } for (size_t i = 0; i < transcript_state.size(); ++i) { - rows.transcript_accumulator_empty[i] = transcript_state[i].accumulator_empty; - rows.transcript_add[i] = transcript_state[i].q_add; - rows.transcript_mul[i] = transcript_state[i].q_mul; - rows.transcript_eq[i] = transcript_state[i].q_eq; - rows.transcript_reset_accumulator[i] = transcript_state[i].q_reset_accumulator; - rows.transcript_msm_transition[i] = transcript_state[i].msm_transition; - rows.transcript_pc[i] = transcript_state[i].pc; - rows.transcript_msm_count[i] = transcript_state[i].msm_count; - rows.transcript_x[i] = transcript_state[i].base_x; - rows.transcript_y[i] = transcript_state[i].base_y; - rows.transcript_z1[i] = transcript_state[i].z1; - rows.transcript_z2[i] = transcript_state[i].z2; - rows.transcript_z1zero[i] = transcript_state[i].z1_zero; - rows.transcript_z2zero[i] = transcript_state[i].z2_zero; - rows.transcript_op[i] = transcript_state[i].opcode; - rows.transcript_accumulator_x[i] = transcript_state[i].accumulator_x; - rows.transcript_accumulator_y[i] = transcript_state[i].accumulator_y; - rows.transcript_msm_x[i] = transcript_state[i].msm_output_x; - rows.transcript_msm_y[i] = transcript_state[i].msm_output_y; - rows.transcript_collision_check[i] = transcript_state[i].collision_check; + polys.transcript_accumulator_empty[i] = transcript_state[i].accumulator_empty; + polys.transcript_add[i] = transcript_state[i].q_add; + polys.transcript_mul[i] = transcript_state[i].q_mul; + polys.transcript_eq[i] = transcript_state[i].q_eq; + polys.transcript_reset_accumulator[i] = transcript_state[i].q_reset_accumulator; + polys.transcript_msm_transition[i] = transcript_state[i].msm_transition; + polys.transcript_pc[i] = transcript_state[i].pc; + polys.transcript_msm_count[i] = transcript_state[i].msm_count; + polys.transcript_x[i] = transcript_state[i].base_x; + polys.transcript_y[i] = transcript_state[i].base_y; + polys.transcript_z1[i] = transcript_state[i].z1; + polys.transcript_z2[i] = transcript_state[i].z2; + polys.transcript_z1zero[i] = transcript_state[i].z1_zero; + polys.transcript_z2zero[i] = transcript_state[i].z2_zero; + polys.transcript_op[i] = transcript_state[i].opcode; + polys.transcript_accumulator_x[i] = transcript_state[i].accumulator_x; + polys.transcript_accumulator_y[i] = transcript_state[i].accumulator_y; + polys.transcript_msm_x[i] = transcript_state[i].msm_output_x; + polys.transcript_msm_y[i] = transcript_state[i].msm_output_y; + polys.transcript_collision_check[i] = transcript_state[i].collision_check; } // TODO(@zac-williamson) if final opcode resets accumulator, all subsequent "is_accumulator_empty" row values @@ -383,102 +385,101 @@ template class ECCVMCircuitBuilder { // all zero (issue #2217) if (transcript_state[transcript_state.size() - 1].accumulator_empty == 1) { for (size_t i = transcript_state.size(); i < num_rows_pow2; ++i) { - rows.transcript_accumulator_empty[i] = 1; + polys.transcript_accumulator_empty[i] = 1; } } for (size_t i = 0; i < precompute_table_state.size(); ++i) { // first row is always an empty row (to accomodate shifted polynomials which must have 0 as 1st // coefficient). All other rows in the precompute_table_state represent active wnaf gates (i.e. // precompute_select = 1) - rows.precompute_select[i] = (i != 0) ? 1 : 0; - rows.precompute_pc[i] = precompute_table_state[i].pc; - rows.precompute_point_transition[i] = static_cast(precompute_table_state[i].point_transition); - rows.precompute_round[i] = precompute_table_state[i].round; - rows.precompute_scalar_sum[i] = precompute_table_state[i].scalar_sum; - - rows.precompute_s1hi[i] = precompute_table_state[i].s1; - rows.precompute_s1lo[i] = precompute_table_state[i].s2; - rows.precompute_s2hi[i] = precompute_table_state[i].s3; - rows.precompute_s2lo[i] = precompute_table_state[i].s4; - rows.precompute_s3hi[i] = precompute_table_state[i].s5; - rows.precompute_s3lo[i] = precompute_table_state[i].s6; - rows.precompute_s4hi[i] = precompute_table_state[i].s7; - rows.precompute_s4lo[i] = precompute_table_state[i].s8; + polys.precompute_select[i] = (i != 0) ? 1 : 0; + polys.precompute_pc[i] = precompute_table_state[i].pc; + polys.precompute_point_transition[i] = static_cast(precompute_table_state[i].point_transition); + polys.precompute_round[i] = precompute_table_state[i].round; + polys.precompute_scalar_sum[i] = precompute_table_state[i].scalar_sum; + + polys.precompute_s1hi[i] = precompute_table_state[i].s1; + polys.precompute_s1lo[i] = precompute_table_state[i].s2; + polys.precompute_s2hi[i] = precompute_table_state[i].s3; + polys.precompute_s2lo[i] = precompute_table_state[i].s4; + polys.precompute_s3hi[i] = precompute_table_state[i].s5; + polys.precompute_s3lo[i] = precompute_table_state[i].s6; + polys.precompute_s4hi[i] = precompute_table_state[i].s7; + polys.precompute_s4lo[i] = precompute_table_state[i].s8; // If skew is active (i.e. we need to subtract a base point from the msm result), // write `7` into rows.precompute_skew. `7`, in binary representation, equals `-1` when converted into WNAF // form - rows.precompute_skew[i] = precompute_table_state[i].skew ? 7 : 0; + polys.precompute_skew[i] = precompute_table_state[i].skew ? 7 : 0; - rows.precompute_dx[i] = precompute_table_state[i].precompute_double.x; - rows.precompute_dy[i] = precompute_table_state[i].precompute_double.y; - rows.precompute_tx[i] = precompute_table_state[i].precompute_accumulator.x; - rows.precompute_ty[i] = precompute_table_state[i].precompute_accumulator.y; + polys.precompute_dx[i] = precompute_table_state[i].precompute_double.x; + polys.precompute_dy[i] = precompute_table_state[i].precompute_double.y; + polys.precompute_tx[i] = precompute_table_state[i].precompute_accumulator.x; + polys.precompute_ty[i] = precompute_table_state[i].precompute_accumulator.y; } for (size_t i = 0; i < msm_state.size(); ++i) { - rows.msm_transition[i] = static_cast(msm_state[i].msm_transition); - rows.msm_add[i] = static_cast(msm_state[i].q_add); - rows.msm_double[i] = static_cast(msm_state[i].q_double); - rows.msm_skew[i] = static_cast(msm_state[i].q_skew); - rows.msm_accumulator_x[i] = msm_state[i].accumulator_x; - rows.msm_accumulator_y[i] = msm_state[i].accumulator_y; - rows.msm_pc[i] = msm_state[i].pc; - rows.msm_size_of_msm[i] = msm_state[i].msm_size; - rows.msm_count[i] = msm_state[i].msm_count; - rows.msm_round[i] = msm_state[i].msm_round; - rows.msm_add1[i] = static_cast(msm_state[i].add_state[0].add); - rows.msm_add2[i] = static_cast(msm_state[i].add_state[1].add); - rows.msm_add3[i] = static_cast(msm_state[i].add_state[2].add); - rows.msm_add4[i] = static_cast(msm_state[i].add_state[3].add); - rows.msm_x1[i] = msm_state[i].add_state[0].point.x; - rows.msm_y1[i] = msm_state[i].add_state[0].point.y; - rows.msm_x2[i] = msm_state[i].add_state[1].point.x; - rows.msm_y2[i] = msm_state[i].add_state[1].point.y; - rows.msm_x3[i] = msm_state[i].add_state[2].point.x; - rows.msm_y3[i] = msm_state[i].add_state[2].point.y; - rows.msm_x4[i] = msm_state[i].add_state[3].point.x; - rows.msm_y4[i] = msm_state[i].add_state[3].point.y; - rows.msm_collision_x1[i] = msm_state[i].add_state[0].collision_inverse; - rows.msm_collision_x2[i] = msm_state[i].add_state[1].collision_inverse; - rows.msm_collision_x3[i] = msm_state[i].add_state[2].collision_inverse; - rows.msm_collision_x4[i] = msm_state[i].add_state[3].collision_inverse; - rows.msm_lambda1[i] = msm_state[i].add_state[0].lambda; - rows.msm_lambda2[i] = msm_state[i].add_state[1].lambda; - rows.msm_lambda3[i] = msm_state[i].add_state[2].lambda; - rows.msm_lambda4[i] = msm_state[i].add_state[3].lambda; - rows.msm_slice1[i] = msm_state[i].add_state[0].slice; - rows.msm_slice2[i] = msm_state[i].add_state[1].slice; - rows.msm_slice3[i] = msm_state[i].add_state[2].slice; - rows.msm_slice4[i] = msm_state[i].add_state[3].slice; + polys.msm_transition[i] = static_cast(msm_state[i].msm_transition); + polys.msm_add[i] = static_cast(msm_state[i].q_add); + polys.msm_double[i] = static_cast(msm_state[i].q_double); + polys.msm_skew[i] = static_cast(msm_state[i].q_skew); + polys.msm_accumulator_x[i] = msm_state[i].accumulator_x; + polys.msm_accumulator_y[i] = msm_state[i].accumulator_y; + polys.msm_pc[i] = msm_state[i].pc; + polys.msm_size_of_msm[i] = msm_state[i].msm_size; + polys.msm_count[i] = msm_state[i].msm_count; + polys.msm_round[i] = msm_state[i].msm_round; + polys.msm_add1[i] = static_cast(msm_state[i].add_state[0].add); + polys.msm_add2[i] = static_cast(msm_state[i].add_state[1].add); + polys.msm_add3[i] = static_cast(msm_state[i].add_state[2].add); + polys.msm_add4[i] = static_cast(msm_state[i].add_state[3].add); + polys.msm_x1[i] = msm_state[i].add_state[0].point.x; + polys.msm_y1[i] = msm_state[i].add_state[0].point.y; + polys.msm_x2[i] = msm_state[i].add_state[1].point.x; + polys.msm_y2[i] = msm_state[i].add_state[1].point.y; + polys.msm_x3[i] = msm_state[i].add_state[2].point.x; + polys.msm_y3[i] = msm_state[i].add_state[2].point.y; + polys.msm_x4[i] = msm_state[i].add_state[3].point.x; + polys.msm_y4[i] = msm_state[i].add_state[3].point.y; + polys.msm_collision_x1[i] = msm_state[i].add_state[0].collision_inverse; + polys.msm_collision_x2[i] = msm_state[i].add_state[1].collision_inverse; + polys.msm_collision_x3[i] = msm_state[i].add_state[2].collision_inverse; + polys.msm_collision_x4[i] = msm_state[i].add_state[3].collision_inverse; + polys.msm_lambda1[i] = msm_state[i].add_state[0].lambda; + polys.msm_lambda2[i] = msm_state[i].add_state[1].lambda; + polys.msm_lambda3[i] = msm_state[i].add_state[2].lambda; + polys.msm_lambda4[i] = msm_state[i].add_state[3].lambda; + polys.msm_slice1[i] = msm_state[i].add_state[0].slice; + polys.msm_slice2[i] = msm_state[i].add_state[1].slice; + polys.msm_slice3[i] = msm_state[i].add_state[2].slice; + polys.msm_slice4[i] = msm_state[i].add_state[3].slice; } - rows.transcript_mul_shift = typename Flavor::Polynomial(rows.transcript_mul.shifted()); - rows.transcript_msm_count_shift = typename Flavor::Polynomial(rows.transcript_msm_count.shifted()); - rows.transcript_accumulator_x_shift = typename Flavor::Polynomial(rows.transcript_accumulator_x.shifted()); - rows.transcript_accumulator_y_shift = typename Flavor::Polynomial(rows.transcript_accumulator_y.shifted()); - rows.precompute_scalar_sum_shift = typename Flavor::Polynomial(rows.precompute_scalar_sum.shifted()); - rows.precompute_s1hi_shift = typename Flavor::Polynomial(rows.precompute_s1hi.shifted()); - rows.precompute_dx_shift = typename Flavor::Polynomial(rows.precompute_dx.shifted()); - rows.precompute_dy_shift = typename Flavor::Polynomial(rows.precompute_dy.shifted()); - rows.precompute_tx_shift = typename Flavor::Polynomial(rows.precompute_tx.shifted()); - rows.precompute_ty_shift = typename Flavor::Polynomial(rows.precompute_ty.shifted()); - rows.msm_transition_shift = typename Flavor::Polynomial(rows.msm_transition.shifted()); - rows.msm_add_shift = typename Flavor::Polynomial(rows.msm_add.shifted()); - rows.msm_double_shift = typename Flavor::Polynomial(rows.msm_double.shifted()); - rows.msm_skew_shift = typename Flavor::Polynomial(rows.msm_skew.shifted()); - rows.msm_accumulator_x_shift = typename Flavor::Polynomial(rows.msm_accumulator_x.shifted()); - rows.msm_accumulator_y_shift = typename Flavor::Polynomial(rows.msm_accumulator_y.shifted()); - rows.msm_count_shift = typename Flavor::Polynomial(rows.msm_count.shifted()); - rows.msm_round_shift = typename Flavor::Polynomial(rows.msm_round.shifted()); - rows.msm_add1_shift = typename Flavor::Polynomial(rows.msm_add1.shifted()); - rows.msm_pc_shift = typename Flavor::Polynomial(rows.msm_pc.shifted()); - rows.precompute_pc_shift = typename Flavor::Polynomial(rows.precompute_pc.shifted()); - rows.transcript_pc_shift = typename Flavor::Polynomial(rows.transcript_pc.shifted()); - rows.precompute_round_shift = typename Flavor::Polynomial(rows.precompute_round.shifted()); - rows.transcript_accumulator_empty_shift = - typename Flavor::Polynomial(rows.transcript_accumulator_empty.shifted()); - rows.precompute_select_shift = typename Flavor::Polynomial(rows.precompute_select.shifted()); - return rows; + polys.transcript_mul_shift = Polynomial(polys.transcript_mul.shifted()); + polys.transcript_msm_count_shift = Polynomial(polys.transcript_msm_count.shifted()); + polys.transcript_accumulator_x_shift = Polynomial(polys.transcript_accumulator_x.shifted()); + polys.transcript_accumulator_y_shift = Polynomial(polys.transcript_accumulator_y.shifted()); + polys.precompute_scalar_sum_shift = Polynomial(polys.precompute_scalar_sum.shifted()); + polys.precompute_s1hi_shift = Polynomial(polys.precompute_s1hi.shifted()); + polys.precompute_dx_shift = Polynomial(polys.precompute_dx.shifted()); + polys.precompute_dy_shift = Polynomial(polys.precompute_dy.shifted()); + polys.precompute_tx_shift = Polynomial(polys.precompute_tx.shifted()); + polys.precompute_ty_shift = Polynomial(polys.precompute_ty.shifted()); + polys.msm_transition_shift = Polynomial(polys.msm_transition.shifted()); + polys.msm_add_shift = Polynomial(polys.msm_add.shifted()); + polys.msm_double_shift = Polynomial(polys.msm_double.shifted()); + polys.msm_skew_shift = Polynomial(polys.msm_skew.shifted()); + polys.msm_accumulator_x_shift = Polynomial(polys.msm_accumulator_x.shifted()); + polys.msm_accumulator_y_shift = Polynomial(polys.msm_accumulator_y.shifted()); + polys.msm_count_shift = Polynomial(polys.msm_count.shifted()); + polys.msm_round_shift = Polynomial(polys.msm_round.shifted()); + polys.msm_add1_shift = Polynomial(polys.msm_add1.shifted()); + polys.msm_pc_shift = Polynomial(polys.msm_pc.shifted()); + polys.precompute_pc_shift = Polynomial(polys.precompute_pc.shifted()); + polys.transcript_pc_shift = Polynomial(polys.transcript_pc.shifted()); + polys.precompute_round_shift = Polynomial(polys.precompute_round.shifted()); + polys.transcript_accumulator_empty_shift = Polynomial(polys.transcript_accumulator_empty.shifted()); + polys.precompute_select_shift = Polynomial(polys.precompute_select.shifted()); + return polys; } bool check_circuit() @@ -501,31 +502,26 @@ template class ECCVMCircuitBuilder { .eccvm_set_permutation_delta = eccvm_set_permutation_delta, }; - auto rows = compute_full_polynomials(); - const size_t num_rows = rows[0].size(); + auto polynomials = compute_polynomials(); + const size_t num_rows = polynomials[0].size(); proof_system::honk::lookup_library::compute_logderivative_inverse>( - rows, params, num_rows); + polynomials, params, num_rows); honk::permutation_library::compute_permutation_grand_product>( - num_rows, rows, params); + num_rows, polynomials, params); - rows.z_perm_shift = typename Flavor::Polynomial(rows.z_perm.shifted()); + polynomials.z_perm_shift = Polynomial(polynomials.z_perm.shifted()); const auto evaluate_relation = [&](const std::string& relation_name) { - auto relation = Relation(); - typename Relation::RelationValues result; + typename Relation::ArrayOfValuesOverSubrelations result; for (auto& r : result) { r = 0; } constexpr size_t NUM_SUBRELATIONS = result.size(); for (size_t i = 0; i < num_rows; ++i) { - typename Flavor::RowPolynomials row; - for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { - row[j] = rows[j][i]; - } - relation.add_full_relation_value_contribution(result, row, params, 1); + Relation::accumulate(result, polynomials.get_row(i), params, 1); bool x = true; for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) { @@ -553,19 +549,13 @@ template class ECCVMCircuitBuilder { result = result && evaluate_relation.template operator()>("ECCVMSetRelation"); - auto lookup_relation = honk::sumcheck::ECCVMLookupRelation(); - typename honk::sumcheck::ECCVMLookupRelation::RelationValues lookup_result; + using LookupRelation = honk::sumcheck::ECCVMLookupRelation; + typename honk::sumcheck::ECCVMLookupRelation::ArrayOfValuesOverSubrelations lookup_result; for (auto& r : lookup_result) { r = 0; } for (size_t i = 0; i < num_rows; ++i) { - typename Flavor::RowPolynomials row; - for (size_t j = 0; j < NUM_POLYNOMIALS; ++j) { - row[j] = rows[j][i]; - } - { - lookup_relation.add_full_relation_value_contribution(lookup_result, row, params, 1); - } + LookupRelation::accumulate(lookup_result, polynomials.get_row(i), params, 1); } for (auto r : lookup_result) { if (r != 0) { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp index 76fdd6e87dd..9149df90b85 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/circuit_builder/ultra_circuit_builder.cpp @@ -3334,7 +3334,6 @@ template bool UltraCircuitBuilder_::check_circuit() FF w_3_shifted_value; FF w_4_shifted_value; if (i < (this->num_gates - 1)) { - w_1_shifted_value = this->get_variable(w_l[i + 1]); w_2_shifted_value = this->get_variable(w_r[i + 1]); w_3_shifted_value = this->get_variable(w_o[i + 1]); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp index df2c83ce6f4..8f7db1a3327 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/composer/composer_lib.hpp @@ -38,7 +38,7 @@ void construct_selector_polynomials(const typename Flavor::CircuitBuilder& circu } // TODO(#398): Loose coupling here! Would rather build up pk from arithmetization - size_t selector_idx = 0; // TODO(#391) zip + size_t selector_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip for (auto& selector_values : circuit_constructor.selectors) { ASSERT(proving_key->circuit_size >= selector_values.size()); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.hpp b/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.hpp index 73750323b9a..82ae802c1e4 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/composer/permutation_lib.hpp @@ -183,7 +183,8 @@ PermutationMapping compute_permutation_mapping( PermutationMapping mapping; // Initialize the table of permutations so that every element points to itself - for (size_t i = 0; i < Flavor::NUM_WIRES; ++i) { // TODO(#391) zip and split + // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip + for (size_t i = 0; i < Flavor::NUM_WIRES; ++i) { mapping.sigmas[i].reserve(proving_key->circuit_size); if constexpr (generalized) { mapping.ids[i].reserve(proving_key->circuit_size); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 093f5ab8123..225cf7c178a 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -227,7 +227,7 @@ template static constexpr auto if constexpr (Index >= std::tuple_size::value) { return std::tuple<>{}; // Return empty when reach end of the tuple } else { - using UnivariateTuple = typename std::tuple_element_t::RelationUnivariates; + using UnivariateTuple = typename std::tuple_element_t::TupleOfUnivariatesOverSubrelations; return std::tuple_cat(std::tuple{}, create_relation_univariates_container()); } @@ -243,8 +243,8 @@ template static constexpr auto if constexpr (Index >= std::tuple_size::value) { return std::tuple<>{}; // Return empty when reach end of the tuple } else { - using ValuesArray = typename std::tuple_element_t::RelationValues; - return std::tuple_cat(std::tuple{}, create_relation_values_container()); + using Values = typename std::tuple_element_t::ArrayOfValuesOverSubrelations; + return std::tuple_cat(std::tuple{}, create_relation_values_container()); } } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp index 05078bf638f..a9b66cfa450 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -9,17 +9,14 @@ template class AuxiliaryRelationImpl { public: using FF = FF_; - // 1 + polynomial degree of this relation - static constexpr size_t RELATION_LENGTH = 6; - - static constexpr size_t LEN_1 = 6; // auxiliary sub-relation - static constexpr size_t LEN_2 = 6; // ROM consistency sub-relation 1 - static constexpr size_t LEN_3 = 6; // ROM consistency sub-relation 2 - static constexpr size_t LEN_4 = 6; // RAM consistency sub-relation 1 - static constexpr size_t LEN_5 = 6; // RAM consistency sub-relation 2 - static constexpr size_t LEN_6 = 6; // RAM consistency sub-relation 3 - template