From 13f295747521082fbb802f985ff6702a8b0b12db Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 27 Sep 2023 21:46:23 +0000 Subject: [PATCH 01/45] Get rid of proxies to accumulate. --- .../relations_bench/relations.bench.cpp | 3 +- .../sumcheck/relation_correctness.test.cpp | 49 +++++++------------ .../sumcheck/relation_definitions_fwd.hpp | 10 ++-- .../honk/sumcheck/sumcheck_round.hpp | 8 +-- .../eccvm/eccvm_circuit_builder.hpp | 8 +-- .../proof_system/relations/relation_types.hpp | 17 ------- .../ultra_relation_consistency.test.cpp | 3 +- 7 files changed, 35 insertions(+), 63 deletions(-) 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..cfa9edb70c3 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -39,9 +39,8 @@ template void execute_relation(::benchmark: RelationValues 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::template accumulate(accumulator, new_value, params, 1); } } 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..15c23deda33 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp @@ -29,7 +29,7 @@ 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; for (size_t i = 0; i < circuit_size; i++) { @@ -43,14 +43,15 @@ template void check_relation(auto relation, auto circuit_size, } // Define the appropriate RelationValues type for this relation and initialize to zero - using RelationValues = typename decltype(relation)::RelationValues; + using RelationValues = typename Relation::RelationValues; RelationValues 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::template accumulate( + result, evaluations_at_index_i, params, 1); for (auto& element : result) { ASSERT_EQ(element, 0); } @@ -253,22 +254,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 +307,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..78f721f3864 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_definitions_fwd.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_definitions_fwd.hpp @@ -6,8 +6,8 @@ #define EvaluationEdge(Flavor) Flavor::ClaimedEvaluations #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)>( \ @@ -26,9 +26,9 @@ #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, UnivariateAccumulatorsAndViews, ExtendedEdge) \ + ACCUMULATE(Preface, RelationBase, Flavor, ValueAccumulatorsAndViews, EvaluationEdge) \ + ACCUMULATE(Preface, RelationBase, Flavor, ValueAccumulatorsAndViews, 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) diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 353433c756f..26851ea5c19 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -63,7 +63,6 @@ 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; @@ -209,7 +208,8 @@ template class SumcheckProverRound { const proof_system::RelationParameters& relation_parameters, const FF& scaling_factor) { - std::get(relations).add_edge_contribution( + using Relation = std::tuple_element_t; + Relation::template accumulate( std::get(univariate_accumulators), extended_edges, relation_parameters, scaling_factor); // Repeat for the next relation. @@ -376,7 +376,6 @@ template class SumcheckVerifierRound { 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; @@ -470,7 +469,8 @@ template class SumcheckVerifierRound { const proof_system::RelationParameters& relation_parameters, const FF& partial_evaluation_constant) { - std::get(relations).add_full_relation_value_contribution( + using Relation = std::tuple_element_t; + Relation::template accumulate( std::get(relation_evaluations), purported_evaluations, relation_parameters, 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..b78d669178a 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 @@ -513,7 +513,6 @@ template class ECCVMCircuitBuilder { rows.z_perm_shift = typename Flavor::Polynomial(rows.z_perm.shifted()); const auto evaluate_relation = [&](const std::string& relation_name) { - auto relation = Relation(); typename Relation::RelationValues result; for (auto& r : result) { r = 0; @@ -525,7 +524,7 @@ template class ECCVMCircuitBuilder { 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::template accumulate(result, row, params, 1); bool x = true; for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) { @@ -553,7 +552,7 @@ template class ECCVMCircuitBuilder { result = result && evaluate_relation.template operator()>("ECCVMSetRelation"); - auto lookup_relation = honk::sumcheck::ECCVMLookupRelation(); + using LookupRelation = honk::sumcheck::ECCVMLookupRelation; typename honk::sumcheck::ECCVMLookupRelation::RelationValues lookup_result; for (auto& r : lookup_result) { r = 0; @@ -564,7 +563,8 @@ template class ECCVMCircuitBuilder { row[j] = rows[j][i]; } { - lookup_relation.add_full_relation_value_contribution(lookup_result, row, params, 1); + LookupRelation::template accumulate( + lookup_result, row, params, 1); } } for (auto r : lookup_result) { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp index ca9a8cfa1bf..e1b86012973 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -108,23 +108,6 @@ template class Relation : public RelationImpl { using RelationValues = typename ValueAccumulatorsAndViews::Accumulators; static constexpr size_t RELATION_LENGTH = RelationImpl::RELATION_LENGTH; - static inline void add_edge_contribution(RelationUnivariates& accumulator, - const auto& input, - const RelationParameters& relation_parameters, - const FF& scaling_factor) - { - Relation::template accumulate( - accumulator, input, relation_parameters, scaling_factor); - } - - static void add_full_relation_value_contribution(RelationValues& accumulator, - auto& input, - const RelationParameters& relation_parameters, - const FF& scaling_factor = 1) - { - Relation::template accumulate( - accumulator, input, relation_parameters, scaling_factor); - } /** * @brief Check is subrelation is linearly independent * Method is active if relation has SUBRELATION_LINEARLY_INDEPENDENT array defined diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp index a5d6ad5fc32..14f1aeaa00c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp @@ -101,7 +101,8 @@ class UltraRelationConsistency : public testing::Test { { typename Relation::RelationValues accumulator; std::fill(accumulator.begin(), accumulator.end(), FF(0)); - Relation::add_full_relation_value_contribution(accumulator, input_elements, parameters); + Relation::template accumulate( + accumulator, input_elements, parameters, 1); EXPECT_EQ(accumulator, expected_values); }; }; From b4d7f6d8052a78f642956f3420910d888e0b583c Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 28 Sep 2023 01:54:05 +0000 Subject: [PATCH 02/45] More explicit names for accumulator types. --- .../relations_bench/relations.bench.cpp | 6 ++--- .../src/barretenberg/honk/flavor/ecc_vm.hpp | 4 +-- .../barretenberg/honk/flavor/goblin_ultra.hpp | 4 +-- .../honk/flavor/goblin_ultra_recursive.hpp | 4 +-- .../src/barretenberg/honk/flavor/ultra.hpp | 4 +-- .../honk/flavor/ultra_grumpkin.hpp | 4 +-- .../honk/flavor/ultra_recursive.hpp | 4 +-- .../sumcheck/relation_correctness.test.cpp | 6 ++--- .../honk/sumcheck/sumcheck_round.hpp | 17 ++++++------ .../eccvm/eccvm_circuit_builder.hpp | 4 +-- .../proof_system/flavor/flavor.hpp | 4 +-- .../proof_system/relations/relation_types.hpp | 4 +-- .../ultra_relation_consistency.test.cpp | 26 +++++++++---------- 13 files changed, 45 insertions(+), 46 deletions(-) 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 cfa9edb70c3..6138c39600c 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -31,12 +31,12 @@ template void execute_relation(::benchmark: }; using ClaimedEvaluations = typename Flavor::ClaimedEvaluations; - using RelationValues = typename Relation::RelationValues; + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; // 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; + // Define the appropriate TupleOfValuesOverSubrelations type for this relation and initialize to zero + TupleOfValuesOverSubrelations accumulator; // Evaluate each constraint in the relation and check that each is satisfied for (auto _ : state) { diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index 7cceb23abba..e40054a64e3 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 TupleOfTupleOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfTupleOfValues = decltype(create_relation_values_container()); private: /** diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 006bba75d6e..863adb330a0 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 TupleOfTupleOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfTupleOfValues = 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; 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..9db9ea9680c 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 TupleOfTupleOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfTupleOfValues = decltype(create_relation_values_container()); private: template diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 2e1ca263dfe..ee1b7a2d632 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 TupleOfTupleOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfTupleOfValues = 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; diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp index 979aaceed7b..d7ad82d8ded 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 TupleOfTupleOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfTupleOfValues = 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; diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 5168265cc08..b0d242f04ef 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 TupleOfTupleOfUnivariates = decltype(create_relation_univariates_container()); + using TupleOfTupleOfValues = decltype(create_relation_values_container()); private: template 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 15c23deda33..e98575db3c5 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/relation_correctness.test.cpp @@ -42,9 +42,9 @@ template void check_relation(auto circuit_s ++poly_idx; } - // Define the appropriate RelationValues type for this relation and initialize to zero - using RelationValues = typename Relation::RelationValues; - RelationValues result; + // Define the appropriate TupleOfValuesOverSubrelations type for this relation and initialize to zero + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; + TupleOfValuesOverSubrelations result; for (auto& element : result) { element = 0; } diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 26851ea5c19..cea3806182b 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -54,7 +54,7 @@ namespace proof_system::honk::sumcheck { template class SumcheckProverRound { using Relations = typename Flavor::Relations; - using RelationUnivariates = typename Flavor::RelationUnivariates; + using TupleOfTupleOfUnivariates = typename Flavor::TupleOfTupleOfUnivariates; public: using FF = typename Flavor::FF; @@ -67,7 +67,7 @@ template class SumcheckProverRound { 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; + TupleOfTupleOfUnivariates univariate_accumulators; // TODO(#224)(Cody): this should go away barretenberg::BarycentricData barycentric_2_to_max; @@ -146,7 +146,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); } @@ -203,7 +203,7 @@ template class SumcheckProverRound { * appropriate scaling factors, produces S_l. */ template - void accumulate_relation_univariates(RelationUnivariates& univariate_accumulators, + void accumulate_relation_univariates(TupleOfTupleOfUnivariates& univariate_accumulators, const auto& extended_edges, const proof_system::RelationParameters& relation_parameters, const FF& scaling_factor) @@ -220,9 +220,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 TupleOfTupleOfUnivariates 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 */ @@ -368,7 +367,7 @@ template class SumcheckProverRound { template class SumcheckVerifierRound { using Relations = typename Flavor::Relations; - using RelationEvaluations = typename Flavor::RelationValues; + using TupleOfTupleOfValues = typename Flavor::TupleOfTupleOfValues; public: using FF = typename Flavor::FF; @@ -381,7 +380,7 @@ template class SumcheckVerifierRound { FF target_total_sum = 0; - RelationEvaluations relation_evaluations; + TupleOfTupleOfValues relation_evaluations; // Verifier constructor explicit SumcheckVerifierRound() { zero_elements(relation_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 b78d669178a..80299a57195 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 @@ -513,7 +513,7 @@ template class ECCVMCircuitBuilder { rows.z_perm_shift = typename Flavor::Polynomial(rows.z_perm.shifted()); const auto evaluate_relation = [&](const std::string& relation_name) { - typename Relation::RelationValues result; + typename Relation::TupleOfValuesOverSubrelations result; for (auto& r : result) { r = 0; } @@ -553,7 +553,7 @@ template class ECCVMCircuitBuilder { result && evaluate_relation.template operator()>("ECCVMSetRelation"); using LookupRelation = honk::sumcheck::ECCVMLookupRelation; - typename honk::sumcheck::ECCVMLookupRelation::RelationValues lookup_result; + typename honk::sumcheck::ECCVMLookupRelation::TupleOfValuesOverSubrelations lookup_result; for (auto& r : lookup_result) { r = 0; } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 093f5ab8123..5e8452653c2 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,7 +243,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 ValuesArray = typename std::tuple_element_t::RelationValues; + using ValuesArray = typename std::tuple_element_t::TupleOfValuesOverSubrelations; return std::tuple_cat(std::tuple{}, create_relation_values_container()); } } diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp index e1b86012973..f1e17fe20e8 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -104,8 +104,8 @@ template class Relation : public RelationImpl { using ValueAccumulatorsAndViews = typename RelationImpl::template GetAccumulatorTypes; - using RelationUnivariates = typename UnivariateAccumulatorsAndViews::Accumulators; - using RelationValues = typename ValueAccumulatorsAndViews::Accumulators; + using TupleOfUnivariatesOverSubrelations = typename UnivariateAccumulatorsAndViews::Accumulators; + using TupleOfValuesOverSubrelations = typename ValueAccumulatorsAndViews::Accumulators; static constexpr size_t RELATION_LENGTH = RelationImpl::RELATION_LENGTH; /** diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp index 14f1aeaa00c..e2e4fa46668 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_relation_consistency.test.cpp @@ -99,7 +99,7 @@ class UltraRelationConsistency : public testing::Test { const InputElements& input_elements, const auto& parameters) { - typename Relation::RelationValues accumulator; + typename Relation::TupleOfValuesOverSubrelations accumulator; std::fill(accumulator.begin(), accumulator.end(), FF(0)); Relation::template accumulate( accumulator, input_elements, parameters, 1); @@ -111,7 +111,7 @@ TEST_F(UltraRelationConsistency, UltraArithmeticRelation) { const auto run_test = [](bool random_inputs) { using Relation = UltraArithmeticRelation; - using RelationValues = typename Relation::RelationValues; + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); const auto& w_1 = input_elements.w_l; @@ -128,7 +128,7 @@ TEST_F(UltraRelationConsistency, UltraArithmeticRelation) const auto& q_c = input_elements.q_c; const auto& q_arith = input_elements.q_arith; - RelationValues expected_values; + TupleOfValuesOverSubrelations expected_values; static const FF neg_half = FF(-2).invert(); // Contribution 1 @@ -155,7 +155,7 @@ TEST_F(UltraRelationConsistency, UltraPermutationRelation) { const auto run_test = [](bool random_inputs) { using Relation = UltraPermutationRelation; - using RelationValues = typename Relation::RelationValues; + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); const auto& w_1 = input_elements.w_l; @@ -175,7 +175,7 @@ TEST_F(UltraRelationConsistency, UltraPermutationRelation) const auto& lagrange_first = input_elements.lagrange_first; const auto& lagrange_last = input_elements.lagrange_last; - RelationValues expected_values; + TupleOfValuesOverSubrelations expected_values; const auto parameters = RelationParameters::get_random(); const auto& beta = parameters.beta; @@ -204,7 +204,7 @@ TEST_F(UltraRelationConsistency, LookupRelation) { const auto run_test = [](bool random_inputs) { using Relation = LookupRelation; - using RelationValues = typename Relation::RelationValues; + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); const auto& w_1 = input_elements.w_l; @@ -239,7 +239,7 @@ TEST_F(UltraRelationConsistency, LookupRelation) const auto& lagrange_first = input_elements.lagrange_first; const auto& lagrange_last = input_elements.lagrange_last; - RelationValues expected_values; + TupleOfValuesOverSubrelations expected_values; const auto parameters = RelationParameters::get_random(); @@ -282,7 +282,7 @@ TEST_F(UltraRelationConsistency, GenPermSortRelation) { const auto run_test = [](bool random_inputs) { using Relation = GenPermSortRelation; - using RelationValues = typename Relation::RelationValues; + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); const auto& w_1 = input_elements.w_l; @@ -302,7 +302,7 @@ TEST_F(UltraRelationConsistency, GenPermSortRelation) auto contribution_3 = delta_3 * (delta_3 - 1) * (delta_3 - 2) * (delta_3 - 3); auto contribution_4 = delta_4 * (delta_4 - 1) * (delta_4 - 2) * (delta_4 - 3); - RelationValues expected_values; + TupleOfValuesOverSubrelations expected_values; expected_values[0] = contribution_1 * q_sort; expected_values[1] = contribution_2 * q_sort; @@ -321,7 +321,7 @@ TEST_F(UltraRelationConsistency, EllipticRelation) { const auto run_test = [](bool random_inputs) { using Relation = EllipticRelation; - using RelationValues = typename Relation::RelationValues; + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); const auto& x_1 = input_elements.w_r; @@ -337,7 +337,7 @@ TEST_F(UltraRelationConsistency, EllipticRelation) const auto& q_beta_sqr = input_elements.q_4; const auto& q_elliptic = input_elements.q_elliptic; - RelationValues expected_values; + TupleOfValuesOverSubrelations expected_values; // Compute x/y coordinate identities // Contribution 1 @@ -366,7 +366,7 @@ TEST_F(UltraRelationConsistency, AuxiliaryRelation) { const auto run_test = [](bool random_inputs) { using Relation = AuxiliaryRelation; - using RelationValues = typename Relation::RelationValues; + using TupleOfValuesOverSubrelations = typename Relation::TupleOfValuesOverSubrelations; const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); const auto& w_1 = input_elements.w_l; @@ -396,7 +396,7 @@ TEST_F(UltraRelationConsistency, AuxiliaryRelation) const auto parameters = RelationParameters::get_random(); const auto& eta = parameters.eta; - RelationValues expected_values; + TupleOfValuesOverSubrelations expected_values; /** * Non native field arithmetic gate 2 * From 02e304a2d9b690b29906226137b97884bc1961f4 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 28 Sep 2023 20:06:18 +0000 Subject: [PATCH 03/45] Step: Containers from arrays. --- .../relations/auxiliary_relation.hpp | 9 ++++ .../relations/ecc_op_queue_relation.hpp | 11 +++++ .../relations/ecc_vm/ecc_lookup_relation.hpp | 5 +++ .../relations/ecc_vm/ecc_msm_relation.hpp | 41 ++++++++++++++++++- .../ecc_vm/ecc_point_table_relation.hpp | 10 ++++- .../relations/ecc_vm/ecc_set_relation.hpp | 5 +++ .../ecc_vm/ecc_transcript_relation.hpp | 38 +++++++++++++++++ .../relations/ecc_vm/ecc_wnaf_relation.hpp | 25 +++++++++++ .../relations/elliptic_relation.hpp | 5 +++ .../relations/gen_perm_sort_relation.hpp | 7 ++++ .../relations/lookup_relation.hpp | 5 +++ .../relations/nested_containers.hpp | 35 ++++++++++++++++ .../relations/permutation_relation.hpp | 5 +++ .../proof_system/relations/relation_types.hpp | 7 ++-- .../relations/ultra_arithmetic_relation.hpp | 5 +++ 15 files changed, 208 insertions(+), 5 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/proof_system/relations/nested_containers.hpp 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..6b17afa1798 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -12,6 +12,15 @@ template class AuxiliaryRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 6; + static constexpr std::array LENGTHS{ + 6, // auxiliary sub-relation + 6, // ROM consistency sub-relation 1 + 6, // ROM consistency sub-relation 2 + 6, // RAM consistency sub-relation 1 + 6, // RAM consistency sub-relation 2 + 6 // RAM consistency sub-relation 3 + }; + 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 diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp index 0dc0fcd3ab6..676c5150d2a 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_op_queue_relation.hpp @@ -10,6 +10,17 @@ template class EccOpQueueRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 3; // degree(q * (w - w_op_queue)) = 2 + static constexpr std::array LENGTHS{ + 3, // wire - op-queue-wire consistency sub-relation 1 + 3, // wire - op-queue-wire consistency sub-relation 2 + 3, // wire - op-queue-wire consistency sub-relation 3 + 3, // wire - op-queue-wire consistency sub-relation 4 + 3, // op-queue-wire vanishes sub-relation 1 + 3, // op-queue-wire vanishes sub-relation 2 + 3, // op-queue-wire vanishes sub-relation 3 + 3 // op-queue-wire vanishes sub-relation 4 + }; + static constexpr size_t LEN_1 = 3; // wire - op-queue-wire consistency sub-relation 1 static constexpr size_t LEN_2 = 3; // wire - op-queue-wire consistency sub-relation 2 static constexpr size_t LEN_3 = 3; // wire - op-queue-wire consistency sub-relation 3 diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.hpp index d982f85d8dd..aacc7b34b98 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.hpp @@ -18,6 +18,11 @@ template class ECCVMLookupRelationBase { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = READ_TERMS + WRITE_TERMS + 3; // 9 + static constexpr std::array LENGTHS{ + RELATION_LENGTH, // grand product construction sub-relation + RELATION_LENGTH // left-shiftable polynomial sub-relation + }; + static constexpr size_t LEN_1 = RELATION_LENGTH; // grand product construction sub-relation static constexpr size_t LEN_2 = RELATION_LENGTH; // left-shiftable polynomial sub-relation template