From a1c95c55044b8d06b1e98ec15c0cd98c33c9a841 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 19 Oct 2023 18:40:20 +0000 Subject: [PATCH 01/32] Uniformize relations in prep for refactor. --- .../relations_bench/relations.bench.cpp | 1 + .../src/barretenberg/honk/flavor/ecc_vm.hpp | 1 + .../honk/sumcheck/sumcheck_round.hpp | 8 +-- .../relations/auxiliary_relation.hpp | 7 +- .../relations/decomposition_relation.hpp | 5 +- .../relations/ecc_op_queue_relation.hpp | 11 ++-- .../relations/ecc_vm/ecc_lookup_relation.cpp | 9 ++- .../relations/ecc_vm/ecc_lookup_relation.hpp | 65 +++++++++---------- .../relations/ecc_vm/ecc_msm_relation.cpp | 5 +- .../relations/ecc_vm/ecc_msm_relation.hpp | 4 +- .../ecc_vm/ecc_point_table_relation.cpp | 5 +- .../ecc_vm/ecc_point_table_relation.hpp | 4 +- .../relations/ecc_vm/ecc_set_relation.cpp | 37 +++++------ .../relations/ecc_vm/ecc_set_relation.hpp | 15 ++--- .../ecc_vm/ecc_transcript_relation.cpp | 7 +- .../ecc_vm/ecc_transcript_relation.hpp | 4 +- .../relations/ecc_vm/ecc_wnaf_relation.cpp | 5 +- .../relations/ecc_vm/ecc_wnaf_relation.hpp | 4 +- .../relations/elliptic_relation.hpp | 12 ++-- .../relations/extra_relations.hpp | 29 ++++----- .../relations/gen_perm_sort_relation.hpp | 15 ++--- ...n_translator_relation_consistency.test.cpp | 2 +- .../relations/lookup_relation.hpp | 37 +++++------ .../relations/non_native_field_relation.hpp | 61 +++++++++-------- .../relations/permutation_relation.hpp | 52 +++++++-------- .../proof_system/relations/relation_types.hpp | 1 - .../relations/ultra_arithmetic_relation.hpp | 11 ++-- .../ultra_relation_consistency.test.cpp | 1 + .../proof_system/relations/utils.hpp | 8 +-- 29 files changed, 199 insertions(+), 227 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 9e68ad32c60..20a99af6a4a 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -6,6 +6,7 @@ #include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" #include "barretenberg/proof_system/relations/lookup_relation.hpp" #include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index 100f5f4b983..60d2124301e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -13,6 +13,7 @@ #include "barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp" #include "barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp" #include "barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/proof_system/relations/relation_types.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index c03d0968129..5cb37a7a6cd 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -153,10 +153,10 @@ template class SumcheckProverRound { // Compute the i-th edge's univariate contribution, // scale it by the pow polynomial's constant and zeta power "c_l ⋅ ζ_{l+1}ⁱ" // and add it to the accumulators for Sˡ(Xₗ) - accumulate_relation_univariates<>(thread_univariate_accumulators[thread_idx], - extended_edges[thread_idx], - relation_parameters, - pow_challenge); + accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], + extended_edges[thread_idx], + relation_parameters, + pow_challenge); } }); 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 a9b66cfa450..158b9ec4b1c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -52,13 +51,13 @@ template class AuxiliaryRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template + template inline static void accumulate(ContainerOverSubrelations& accumulators, const AllEntities& in, - const RelationParameters& relation_parameters, + const Parameters& params, const FF& scaling_factor) { - const auto& eta = relation_parameters.eta; + const auto& eta = params.eta; // All subrelations have the same length so we use the same length view for all calculations using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/decomposition_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/decomposition_relation.hpp index d295dd0a46d..edb385a9a0d 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/decomposition_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/decomposition_relation.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -79,10 +78,10 @@ template class GoblinTranslatorDecompositionRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template + template inline static void accumulate(ContainerOverSubrelations& accumulators, const AllEntities& in, - const RelationParameters&, + const Parameters&, const FF& scaling_factor) { static constexpr size_t NUM_LIMB_BITS = 68; // Number of bits in a standard limb used for bigfield operations 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 6c65b045f79..8b7de7b2a08 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 @@ -1,5 +1,4 @@ #pragma once -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -38,11 +37,11 @@ template class EccOpQueueRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - void static accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const RelationParameters&, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.cpp index 41103bb1b0d..d577f9f328c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_lookup_relation.cpp @@ -1,6 +1,5 @@ #include "barretenberg/honk/flavor/ecc_vm.hpp" #include "barretenberg/honk/sumcheck/relation_definitions_fwd.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "ecc_msm_relation.hpp" namespace proof_system::honk::sumcheck { @@ -19,10 +18,10 @@ namespace proof_system::honk::sumcheck { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template -template +template void ECCVMLookupRelationBase::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& relation_params, + const Parameters& params, [[maybe_unused]] const FF& scaling_factor) { using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; @@ -41,9 +40,9 @@ void ECCVMLookupRelationBase::accumulate(ContainerOverSubrelations& accumula // i.e. (1 / read_term[i]) = lookup_inverse * \prod_{j /ne i} (read_term[j]) * \prod_k (write_term[k]) // (1 / write_term[i]) = lookup_inverse * \prod_j (read_term[j]) * \prod_{k ne i} (write_term[k]) barretenberg::constexpr_for<0, READ_TERMS, 1>( - [&]() { lookup_terms[i] = compute_read_term(in, relation_params); }); + [&]() { lookup_terms[i] = compute_read_term(in, params); }); barretenberg::constexpr_for<0, WRITE_TERMS, 1>( - [&]() { lookup_terms[i + READ_TERMS] = compute_write_term(in, relation_params); }); + [&]() { lookup_terms[i + READ_TERMS] = compute_write_term(in, params); }); barretenberg::constexpr_for<0, NUM_TOTAL_TERMS, 1>( [&]() { denominator_accumulator[i] = lookup_terms[i]; }); 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 c7ae8d5ef1e..6da47089b2c 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 @@ -5,7 +5,6 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system::honk::sumcheck { @@ -31,46 +30,46 @@ template class ECCVMLookupRelationBase { return (row.msm_add == 1) || (row.msm_skew == 1) || (row.precompute_select == 1); } - template - static Accumulator0 compute_read_term_predicate(const AllEntities& in) + template + static Accumulator compute_read_term_predicate(const AllEntities& in) { - using View = typename Accumulator0::View; + using View = typename Accumulator::View; if constexpr (read_index == 0) { - return Accumulator0(View(in.msm_add1)); + return Accumulator(View(in.msm_add1)); } if constexpr (read_index == 1) { - return Accumulator0(View(in.msm_add2)); + return Accumulator(View(in.msm_add2)); } if constexpr (read_index == 2) { - return Accumulator0(View(in.msm_add3)); + return Accumulator(View(in.msm_add3)); } if constexpr (read_index == 3) { - return Accumulator0(View(in.msm_add4)); + return Accumulator(View(in.msm_add4)); } - return Accumulator0(1); + return Accumulator(1); } - template - static Accumulator0 compute_write_term_predicate(const AllEntities& in) + template + static Accumulator compute_write_term_predicate(const AllEntities& in) { - using View = typename Accumulator0::View; + using View = typename Accumulator::View; if constexpr (write_index == 0) { - return Accumulator0(View(in.precompute_select)); + return Accumulator(View(in.precompute_select)); } if constexpr (write_index == 1) { // TODO(https://github.com/AztecProtocol/barretenberg/issues/750) Is this a bug? - return Accumulator0(View(in.precompute_select)); + return Accumulator(View(in.precompute_select)); } - return Accumulator0(1); + return Accumulator(1); } - template - static Accumulator0 compute_write_term(const AllEntities& in, const RelationParameters& relation_params) + template + static Accumulator compute_write_term(const AllEntities& in, const Parameters& params) { - using View = typename Accumulator0::View; + using View = typename Accumulator::View; static_assert(write_index < WRITE_TERMS); @@ -95,10 +94,10 @@ template class ECCVMLookupRelationBase { const auto& tx = View(in.precompute_tx); const auto& ty = View(in.precompute_ty); const auto& precompute_round = View(in.precompute_round); - const auto& gamma = relation_params.gamma; - const auto& beta = relation_params.beta; - const auto& beta_sqr = relation_params.beta_sqr; - const auto& beta_cube = relation_params.beta_cube; + const auto& gamma = params.gamma; + const auto& beta = params.beta; + const auto& beta_sqr = params.beta_sqr; + const auto& beta_cube = params.beta_cube; // slice value : (wnaf value) : lookup term // 0 : -15 : 0 @@ -135,21 +134,21 @@ template class ECCVMLookupRelationBase { if constexpr (write_index == 1) { return negative_term; // degree 1 } - return Accumulator0(1); + return Accumulator(1); } - template - static Accumulator0 compute_read_term(const AllEntities& in, const RelationParameters& relation_params) + template + static Accumulator compute_read_term(const AllEntities& in, const Parameters& params) { - using View = typename Accumulator0::View; + using View = typename Accumulator::View; // read term: // pc, slice, x, y static_assert(read_index < READ_TERMS); - const auto& gamma = relation_params.gamma; - const auto& beta = relation_params.beta; - const auto& beta_sqr = relation_params.beta_sqr; - const auto& beta_cube = relation_params.beta_cube; + const auto& gamma = params.gamma; + const auto& beta = params.beta; + const auto& beta_sqr = params.beta_sqr; + const auto& beta_cube = params.beta_cube; const auto& msm_pc = View(in.msm_pc); const auto& msm_count = View(in.msm_count); const auto& msm_slice1 = View(in.msm_slice1); @@ -190,7 +189,7 @@ template class ECCVMLookupRelationBase { if constexpr (read_index == 3) { return read_term4; // degree 1 } - return Accumulator0(1); + return Accumulator(1); } /** @@ -206,10 +205,10 @@ template class ECCVMLookupRelationBase { * @param relation_params contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template + template static void accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& relation_params, + const Parameters& params, const FF& /*unused*/); }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.cpp index a0bead44501..23851ae5959 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.cpp @@ -1,7 +1,6 @@ #include "ecc_msm_relation.hpp" #include "barretenberg/honk/flavor/ecc_vm.hpp" #include "barretenberg/honk/sumcheck/relation_definitions_fwd.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" namespace proof_system::honk::sumcheck { @@ -37,10 +36,10 @@ namespace proof_system::honk::sumcheck { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template -template +template void ECCVMMSMRelationBase::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& /*unused*/, + const Parameters& /*unused*/, const FF& scaling_factor) { using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp index cd7c43aa1db..ce3fc6f72a1 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp @@ -41,10 +41,10 @@ template class ECCVMMSMRelationBase { static constexpr std::array SUBRELATION_LENGTHS{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; - template + template static void accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& /* unused */, + const Parameters& /* unused */, const FF& scaling_factor); }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.cpp index 0656e8c492f..fbe6a299d36 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.cpp @@ -1,7 +1,6 @@ #include "ecc_point_table_relation.hpp" #include "barretenberg/honk/flavor/ecc_vm.hpp" #include "barretenberg/honk/sumcheck/relation_definitions_fwd.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" namespace proof_system::honk::sumcheck { @@ -18,10 +17,10 @@ namespace proof_system::honk::sumcheck { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template -template +template void ECCVMPointTableRelationBase::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& /*unused*/, + const Parameters& /*unused*/, const FF& scaling_factor) { using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp index 40457041709..b67f2824f3c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp @@ -21,10 +21,10 @@ template class ECCVMPointTableRelationBase { static constexpr std::array SUBRELATION_LENGTHS{ 6, 6, 6, 6, 6, 6 }; - template + template static void accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& /* unused */, + const Parameters& /* unused */, const FF& scaling_factor); }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.cpp index 4e6e0680db9..3663c61087f 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.cpp @@ -1,6 +1,5 @@ #include "barretenberg/honk/flavor/ecc_vm.hpp" #include "barretenberg/honk/sumcheck/relation_definitions_fwd.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "ecc_msm_relation.hpp" namespace proof_system::honk::sumcheck { @@ -34,9 +33,8 @@ namespace proof_system::honk::sumcheck { * @return ECCVMSetRelationBase::template Accumulator */ template -template -Accumulator ECCVMSetRelationBase::compute_permutation_numerator(const AllEntities& in, - const RelationParameters& relation_params) +template +Accumulator ECCVMSetRelationBase::compute_permutation_numerator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; @@ -44,10 +42,10 @@ Accumulator ECCVMSetRelationBase::compute_permutation_numerator(const AllEnt const auto precompute_round2 = precompute_round + precompute_round; const auto precompute_round4 = precompute_round2 + precompute_round2; - const auto& gamma = relation_params.gamma; - const auto& beta = relation_params.beta; - const auto& beta_sqr = relation_params.beta_sqr; - const auto& beta_cube = relation_params.beta_cube; + const auto& gamma = params.gamma; + const auto& beta = params.beta; + const auto& beta_sqr = params.beta_sqr; + const auto& beta_cube = params.beta_cube; const auto& precompute_pc = View(in.precompute_pc); const auto& precompute_select = View(in.precompute_select); @@ -115,7 +113,7 @@ Accumulator ECCVMSetRelationBase::compute_permutation_numerator(const AllEnt numerator *= skew_input; // degree-5 } { - const auto& eccvm_set_permutation_delta = relation_params.eccvm_set_permutation_delta; + const auto& eccvm_set_permutation_delta = params.eccvm_set_permutation_delta; numerator *= precompute_select * (-eccvm_set_permutation_delta + 1) + eccvm_set_permutation_delta; // degree-7 } @@ -228,18 +226,17 @@ Accumulator ECCVMSetRelationBase::compute_permutation_numerator(const AllEnt } template -template -Accumulator ECCVMSetRelationBase::compute_permutation_denominator(const AllEntities& in, - const RelationParameters& relation_params) +template +Accumulator ECCVMSetRelationBase::compute_permutation_denominator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; // TODO(@zac-williamson). The degree of this contribution is 17! makes overall relation degree 19. // Can optimise by refining the algebra, once we have a stable base to iterate off of. - const auto& gamma = relation_params.gamma; - const auto& beta = relation_params.beta; - const auto& beta_sqr = relation_params.beta_sqr; - const auto& beta_cube = relation_params.beta_cube; + const auto& gamma = params.gamma; + const auto& beta = params.beta; + const auto& beta_sqr = params.beta_sqr; + const auto& beta_cube = params.beta_cube; const auto& msm_pc = View(in.msm_pc); const auto& msm_count = View(in.msm_count); const auto& msm_round = View(in.msm_round); @@ -366,20 +363,20 @@ Accumulator ECCVMSetRelationBase::compute_permutation_denominator(const AllE * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template -template +template void ECCVMSetRelationBase::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& relation_params, + const Parameters& params, const FF& scaling_factor) { using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; // degree-11 - Accumulator numerator_evaluation = compute_permutation_numerator(in, relation_params); + Accumulator numerator_evaluation = compute_permutation_numerator(in, params); // degree-17 - Accumulator denominator_evaluation = compute_permutation_denominator(in, relation_params); + Accumulator denominator_evaluation = compute_permutation_denominator(in, params); const auto& lagrange_first = View(in.lagrange_first); const auto& lagrange_last = View(in.lagrange_last); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp index de75aaf67b6..f2c9c9ecea6 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp @@ -5,7 +5,6 @@ #include "barretenberg/common/constexpr_utils.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/univariate.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system::honk::sumcheck { @@ -32,18 +31,16 @@ template class ECCVMSetRelationBase { inline static auto& get_grand_product_polynomial(auto& input) { return input.z_perm; } inline static auto& get_shifted_grand_product_polynomial(auto& input) { return input.z_perm_shift; } - template - static Accumulator compute_permutation_numerator(const AllEntities& in, - const RelationParameters& relation_params); + template + static Accumulator compute_permutation_numerator(const AllEntities& in, const Parameters& params); - template - static Accumulator compute_permutation_denominator(const AllEntities& in, - const RelationParameters& relation_params); + template + static Accumulator compute_permutation_denominator(const AllEntities& in, const Parameters& params); - template + template static void accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& relation_params, + const Parameters& params, const FF& scaling_factor); }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.cpp index 53a5b1c22f4..028fe269f40 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.cpp @@ -4,7 +4,6 @@ #include "./ecc_transcript_relation.hpp" #include "barretenberg/honk/flavor/ecc_vm.hpp" #include "barretenberg/honk/sumcheck/relation_definitions_fwd.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" namespace proof_system::honk::sumcheck { @@ -31,10 +30,10 @@ namespace proof_system::honk::sumcheck { * @tparam PolynomialTypes */ template -template +template void ECCVMTranscriptRelationBase::accumulate(ContainerOverSubrelations& accumulator, - const PolynomialTypes& in, - const RelationParameters& /*unused*/, + const AllEntities& in, + const Parameters& /*unused*/, const FF& scaling_factor) { using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp index 58c4ca6c57a..a6b8f42cee5 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp @@ -34,10 +34,10 @@ template class ECCVMTranscriptRelationBase { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, }; - template + template static void accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& /* unused */, + const Parameters& /* unused */, const FF& scaling_factor); // TODO(@zac-williamson #2609 find more generic way of doing this) diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.cpp index c294bceaca8..ec8412b7111 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.cpp @@ -1,7 +1,6 @@ #include "ecc_wnaf_relation.hpp" #include "barretenberg/honk/flavor/ecc_vm.hpp" #include "barretenberg/honk/sumcheck/relation_definitions_fwd.hpp" -#include "barretenberg/proof_system/relations/relation_parameters.hpp" namespace proof_system::honk::sumcheck { @@ -36,10 +35,10 @@ namespace proof_system::honk::sumcheck { * @tparam AccumulatorTypes */ template -template +template void ECCVMWnafRelationBase::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& /*unused*/, + const Parameters& /*unused*/, const FF& scaling_factor) { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp index 7567b1be70f..24d753a4c4b 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp @@ -39,10 +39,10 @@ template class ECCVMWnafRelationBase { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, }; - template + template static void accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, - const RelationParameters& /* unused */, + const Parameters& /* unused */, const FF& scaling_factor); }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp index 6b13f01f84e..f467d945829 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp @@ -1,8 +1,6 @@ #pragma once #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" - -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -38,11 +36,11 @@ template class EllipticRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const RelationParameters&, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) { // TODO(@zac - williamson #2608 when Pedersen refactor is completed, // replace old addition relations with these ones and diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/extra_relations.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/extra_relations.hpp index edd78f45377..4d3276032c3 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/extra_relations.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/extra_relations.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -26,11 +25,11 @@ template class GoblinTranslatorOpcodeConstraintRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - void static accumulate(ContainerOverSubrelations& accumulators, - const AllEntitites& in, - const RelationParameters&, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; @@ -89,11 +88,11 @@ template class GoblinTranslatorAccumulatorTransferRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - void static accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; @@ -159,22 +158,22 @@ template class GoblinTranslatorAccumulatorTransferRelationImpl { // Contribution (9) (9-12 ensure the output is as stated, we basically use this to get the result out of the // proof) - auto tmp_9 = (accumulators_binary_limbs_0 - relation_parameters.accumulated_result[0]) * lagrange_second; + auto tmp_9 = (accumulators_binary_limbs_0 - params.accumulated_result[0]) * lagrange_second; tmp_9 *= scaling_factor; std::get<8>(accumulators) += tmp_9; // Contribution (10) - auto tmp_10 = (accumulators_binary_limbs_1 - relation_parameters.accumulated_result[1]) * lagrange_second; + auto tmp_10 = (accumulators_binary_limbs_1 - params.accumulated_result[1]) * lagrange_second; tmp_10 *= scaling_factor; std::get<9>(accumulators) += tmp_10; // Contribution (11) - auto tmp_11 = (accumulators_binary_limbs_2 - relation_parameters.accumulated_result[2]) * lagrange_second; + auto tmp_11 = (accumulators_binary_limbs_2 - params.accumulated_result[2]) * lagrange_second; tmp_11 *= scaling_factor; std::get<10>(accumulators) += tmp_11; // Contribution (12) - auto tmp_12 = (accumulators_binary_limbs_3 - relation_parameters.accumulated_result[3]) * lagrange_second; + auto tmp_12 = (accumulators_binary_limbs_3 - params.accumulated_result[3]) * lagrange_second; tmp_12 *= scaling_factor; std::get<11>(accumulators) += tmp_12; }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp index ac25d184d23..22c95bf82bb 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp @@ -1,5 +1,4 @@ #pragma once -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -30,11 +29,11 @@ template class GenPermSortRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - void static accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const RelationParameters&, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; @@ -126,10 +125,10 @@ template class GoblinTranslatorGenPermSortRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template + template inline static void accumulate(ContainerOverSubrelations& accumulators, const AllEntities& in, - const RelationParameters&, + const Parameters&, const FF& scaling_factor) { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/goblin_translator_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/goblin_translator_relation_consistency.test.cpp index 59e242fa167..51e88d92b30 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/goblin_translator_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/goblin_translator_relation_consistency.test.cpp @@ -17,7 +17,7 @@ #include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" #include "barretenberg/proof_system/relations/non_native_field_relation.hpp" #include "barretenberg/proof_system/relations/permutation_relation.hpp" -#include "decomposition_relation.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "extra_relations.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index 493d6f3d977..dd5d9e30846 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -1,5 +1,4 @@ #pragma once -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -55,13 +54,12 @@ template class LookupRelationImpl { * @param relation_parameters * @param index If calling this method over vector inputs, index >= 0 */ - template - inline static Accumulator compute_grand_product_numerator(const AllEntities& in, - const RelationParameters& relation_parameters) + template + inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) { - const auto& beta = relation_parameters.beta; - const auto& gamma = relation_parameters.gamma; - const auto& eta = relation_parameters.eta; + const auto& beta = params.beta; + const auto& gamma = params.gamma; + const auto& eta = params.eta; const auto eta_sqr = eta * eta; const auto eta_cube = eta_sqr * eta; @@ -119,13 +117,12 @@ template class LookupRelationImpl { * @param relation_parameters * @param index */ - template - inline static Accumulator compute_grand_product_denominator(const AllEntities& in, - const RelationParameters& relation_parameters) + template + inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) { - const auto& beta = relation_parameters.beta; - const auto& gamma = relation_parameters.gamma; + const auto& beta = params.beta; + const auto& gamma = params.gamma; const auto one_plus_beta = FF(1) + beta; const auto gamma_by_one_plus_beta = gamma * one_plus_beta; @@ -158,13 +155,13 @@ template class LookupRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - void static accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) { - const auto& grand_product_delta = relation_parameters.lookup_grand_product_delta; + const auto& grand_product_delta = params.lookup_grand_product_delta; { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; @@ -176,8 +173,8 @@ template class LookupRelationImpl { auto lagrange_first = View(in.lagrange_first); auto lagrange_last = View(in.lagrange_last); - const auto lhs = compute_grand_product_numerator(in, relation_parameters); - const auto rhs = compute_grand_product_denominator(in, relation_parameters); + const auto lhs = compute_grand_product_numerator(in, params); + const auto rhs = compute_grand_product_denominator(in, params); const auto tmp = lhs * (z_lookup + lagrange_first) - rhs * (z_lookup_shift + lagrange_last * grand_product_delta); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/non_native_field_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/non_native_field_relation.hpp index 92ed2f2d3d5..9c6029e6cf2 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/non_native_field_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/non_native_field_relation.hpp @@ -1,7 +1,6 @@ #pragma once #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/numeric/uintx/uintx.hpp" -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -79,11 +78,11 @@ template class GoblinTranslatorNonNativeFieldRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - void static accumulate(ContainerOverSubrelations& accumulators, - const AllEntitites& in, - const RelationParameters& relation_parameters, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; @@ -104,33 +103,33 @@ template class GoblinTranslatorNonNativeFieldRelationImpl { -FF(curve::BN254::BaseField::modulus) }; - const auto& evaluation_input_x_0 = relation_parameters.evaluation_input_x[0]; - const auto& evaluation_input_x_1 = relation_parameters.evaluation_input_x[1]; - const auto& evaluation_input_x_2 = relation_parameters.evaluation_input_x[2]; - const auto& evaluation_input_x_3 = relation_parameters.evaluation_input_x[3]; - const auto& evaluation_input_x_4 = relation_parameters.evaluation_input_x[4]; + const auto& evaluation_input_x_0 = params.evaluation_input_x[0]; + const auto& evaluation_input_x_1 = params.evaluation_input_x[1]; + const auto& evaluation_input_x_2 = params.evaluation_input_x[2]; + const auto& evaluation_input_x_3 = params.evaluation_input_x[3]; + const auto& evaluation_input_x_4 = params.evaluation_input_x[4]; // for j < 4, v_i_j is the j-th limb of v^{1+i} // v_i_4 is v^{1+i} in the native field - const auto& v_0_0 = relation_parameters.batching_challenge_v[0][0]; - const auto& v_0_1 = relation_parameters.batching_challenge_v[0][1]; - const auto& v_0_2 = relation_parameters.batching_challenge_v[0][2]; - const auto& v_0_3 = relation_parameters.batching_challenge_v[0][3]; - const auto& v_0_4 = relation_parameters.batching_challenge_v[0][4]; - const auto& v_1_0 = relation_parameters.batching_challenge_v[1][0]; - const auto& v_1_1 = relation_parameters.batching_challenge_v[1][1]; - const auto& v_1_2 = relation_parameters.batching_challenge_v[1][2]; - const auto& v_1_3 = relation_parameters.batching_challenge_v[1][3]; - const auto& v_1_4 = relation_parameters.batching_challenge_v[1][4]; - const auto& v_2_0 = relation_parameters.batching_challenge_v[2][0]; - const auto& v_2_1 = relation_parameters.batching_challenge_v[2][1]; - const auto& v_2_2 = relation_parameters.batching_challenge_v[2][2]; - const auto& v_2_3 = relation_parameters.batching_challenge_v[2][3]; - const auto& v_2_4 = relation_parameters.batching_challenge_v[2][4]; - const auto& v_3_0 = relation_parameters.batching_challenge_v[3][0]; - const auto& v_3_1 = relation_parameters.batching_challenge_v[3][1]; - const auto& v_3_2 = relation_parameters.batching_challenge_v[3][2]; - const auto& v_3_3 = relation_parameters.batching_challenge_v[3][3]; - const auto& v_3_4 = relation_parameters.batching_challenge_v[3][4]; + const auto& v_0_0 = params.batching_challenge_v[0][0]; + const auto& v_0_1 = params.batching_challenge_v[0][1]; + const auto& v_0_2 = params.batching_challenge_v[0][2]; + const auto& v_0_3 = params.batching_challenge_v[0][3]; + const auto& v_0_4 = params.batching_challenge_v[0][4]; + const auto& v_1_0 = params.batching_challenge_v[1][0]; + const auto& v_1_1 = params.batching_challenge_v[1][1]; + const auto& v_1_2 = params.batching_challenge_v[1][2]; + const auto& v_1_3 = params.batching_challenge_v[1][3]; + const auto& v_1_4 = params.batching_challenge_v[1][4]; + const auto& v_2_0 = params.batching_challenge_v[2][0]; + const auto& v_2_1 = params.batching_challenge_v[2][1]; + const auto& v_2_2 = params.batching_challenge_v[2][2]; + const auto& v_2_3 = params.batching_challenge_v[2][3]; + const auto& v_2_4 = params.batching_challenge_v[2][4]; + const auto& v_3_0 = params.batching_challenge_v[3][0]; + const auto& v_3_1 = params.batching_challenge_v[3][1]; + const auto& v_3_2 = params.batching_challenge_v[3][2]; + const auto& v_3_3 = params.batching_challenge_v[3][3]; + const auto& v_3_4 = params.batching_challenge_v[3][4]; const auto& op = View(in.op); const auto& p_x_low_limbs = View(in.p_x_low_limbs); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index c542000c127..036c9c578e3 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -1,5 +1,4 @@ #pragma once -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -16,9 +15,8 @@ template class UltraPermutationRelationImpl { inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } inline static auto& get_shifted_grand_product_polynomial(auto& in) { return in.z_perm_shift; } - template - inline static Accumulator compute_grand_product_numerator(const AllEntities& in, - const RelationParameters& relation_parameters) + template + inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; @@ -31,16 +29,15 @@ template class UltraPermutationRelationImpl { auto id_3 = View(in.id_3); auto id_4 = View(in.id_4); - const auto& beta = relation_parameters.beta; - const auto& gamma = relation_parameters.gamma; + const auto& beta = params.beta; + const auto& gamma = params.gamma; return (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * (w_3 + id_3 * beta + gamma) * (w_4 + id_4 * beta + gamma); } - template - inline static Accumulator compute_grand_product_denominator(const AllEntities& in, - const RelationParameters& relation_parameters) + template + inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; @@ -54,8 +51,8 @@ template class UltraPermutationRelationImpl { auto sigma_3 = View(in.sigma_3); auto sigma_4 = View(in.sigma_4); - const auto& beta = relation_parameters.beta; - const auto& gamma = relation_parameters.gamma; + const auto& beta = params.beta; + const auto& gamma = params.gamma; return (w_1 + sigma_1 * beta + gamma) * (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma) * (w_4 + sigma_4 * beta + gamma); @@ -72,13 +69,13 @@ template class UltraPermutationRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template + template inline static void accumulate(ContainerOverSubrelations& accumulators, const AllEntities& in, - const RelationParameters& relation_parameters, + const Parameters& params, const FF& scaling_factor) { - const auto& public_input_delta = relation_parameters.public_input_delta; + const auto& public_input_delta = params.public_input_delta; // Contribution (1) { @@ -91,9 +88,9 @@ template class UltraPermutationRelationImpl { // Contribution (1) std::get<0>(accumulators) += - (((z_perm + lagrange_first) * compute_grand_product_numerator(in, relation_parameters)) - + (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - ((z_perm_shift + lagrange_last * public_input_delta) * - compute_grand_product_denominator(in, relation_parameters))) * + compute_grand_product_denominator(in, params))) * scaling_factor; } // Contribution (2) @@ -122,9 +119,8 @@ template class GoblinTranslatorPermutationRelationImpl { inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } inline static auto& get_shifted_grand_product_polynomial(auto& in) { return in.z_perm_shift; } - template - inline static Accumulator compute_grand_product_numerator(const AllEntities& in, - const RelationParameters& relation_parameters) + template + inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; @@ -135,15 +131,14 @@ template class GoblinTranslatorPermutationRelationImpl { auto ordered_extra_range_constraints_numerator = View(in.ordered_extra_range_constraints_numerator); - const auto& gamma = relation_parameters.gamma; + const auto& gamma = params.gamma; return (concatenated_range_constraints_0 + gamma) * (concatenated_range_constraints_1 + gamma) * (concatenated_range_constraints_2 + gamma) * (concatenated_range_constraints_3 + gamma) * (ordered_extra_range_constraints_numerator + gamma); } - template - inline static Accumulator compute_grand_product_denominator(const AllEntities& in, - const RelationParameters& relation_parameters) + template + inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; @@ -153,7 +148,7 @@ template class GoblinTranslatorPermutationRelationImpl { auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); - const auto& gamma = relation_parameters.gamma; + const auto& gamma = params.gamma; return (ordered_range_constraints_0 + gamma) * (ordered_range_constraints_1 + gamma) * (ordered_range_constraints_2 + gamma) * (ordered_range_constraints_3 + gamma) * @@ -180,10 +175,10 @@ template class GoblinTranslatorPermutationRelationImpl { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template + template inline static void accumulate(ContainerOverSubrelations& accumulators, const AllEntities& in, - const RelationParameters& relation_parameters, + const Parameters& params, const FF& scaling_factor) { [&]() { @@ -197,9 +192,8 @@ template class GoblinTranslatorPermutationRelationImpl { // Contribution (1) std::get<0>(accumulators) += - (((z_perm + lagrange_first) * compute_grand_product_numerator(in, relation_parameters)) - - ((z_perm_shift + lagrange_last) * - compute_grand_product_denominator(in, relation_parameters))) * + (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - + ((z_perm_shift + lagrange_last) * compute_grand_product_denominator(in, params))) * scaling_factor; }(); 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 4fc4f7673bd..7e8fb7542bd 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -1,6 +1,5 @@ #pragma once #include "nested_containers.hpp" -#include "relation_parameters.hpp" #include namespace barretenberg { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp index 9ac92c227f9..c0137000f25 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp @@ -1,5 +1,4 @@ #pragma once -#include "relation_parameters.hpp" #include "relation_types.hpp" namespace proof_system { @@ -64,11 +63,11 @@ template class UltraArithmeticRelationImpl { * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ - template - void static accumulate(ContainerOverSubrelations& evals, - const AllEntities& in, - const RelationParameters&, - const FF& scaling_factor) + template + inline static void accumulate(ContainerOverSubrelations& evals, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) { { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; 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 acec6116c83..6cd80499c4d 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 @@ -18,6 +18,7 @@ #include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" #include "barretenberg/proof_system/relations/lookup_relation.hpp" #include "barretenberg/proof_system/relations/permutation_relation.hpp" +#include "barretenberg/proof_system/relations/relation_parameters.hpp" #include "barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp index eb4fb3a56af..ff224c3b747 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp @@ -177,10 +177,10 @@ template class RelationUtils { */ template // TODO(#224)(Cody): Input should be an array? - static void accumulate_relation_evaluations(PolynomialEvaluations evaluations, - RelationEvaluations& relation_evaluations, - const proof_system::RelationParameters& relation_parameters, - const FF& partial_evaluation_constant) + inline static void accumulate_relation_evaluations(PolynomialEvaluations evaluations, + RelationEvaluations& relation_evaluations, + const proof_system::RelationParameters& relation_parameters, + const FF& partial_evaluation_constant) { using Relation = std::tuple_element_t; Relation::accumulate(std::get(relation_evaluations), From bee3ca2280e7947cf9f871534846e88da277d4e7 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 19 Oct 2023 20:07:12 +0000 Subject: [PATCH 02/32] Move translator relations to subfolder --- .../relations/auxiliary_relation.hpp | 2 +- .../relations/ecc_op_queue_relation.hpp | 2 +- .../relations/elliptic_relation.hpp | 2 +- .../relations/gen_perm_sort_relation.hpp | 133 +---------------- .../relations/lookup_relation.hpp | 2 +- .../relations/permutation_relation.hpp | 109 +------------- ...n_translator_relation_consistency.test.cpp | 11 +- .../translator_decomposition_relation.hpp} | 2 +- .../translator_extra_relations.hpp} | 2 +- .../translator_gen_perm_sort_relation.hpp | 138 ++++++++++++++++++ .../translator_non_native_field_relation.hpp} | 2 +- .../translator_permutation_relation.hpp | 114 +++++++++++++++ .../relations/ultra_arithmetic_relation.hpp | 2 +- 13 files changed, 267 insertions(+), 254 deletions(-) rename barretenberg/cpp/src/barretenberg/proof_system/relations/{ => translator_vm}/goblin_translator_relation_consistency.test.cpp (99%) rename barretenberg/cpp/src/barretenberg/proof_system/relations/{decomposition_relation.hpp => translator_vm/translator_decomposition_relation.hpp} (99%) rename barretenberg/cpp/src/barretenberg/proof_system/relations/{extra_relations.hpp => translator_vm/translator_extra_relations.hpp} (99%) create mode 100644 barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp rename barretenberg/cpp/src/barretenberg/proof_system/relations/{non_native_field_relation.hpp => translator_vm/translator_non_native_field_relation.hpp} (99%) create mode 100644 barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.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 158b9ec4b1c..fb02ce8cce6 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { 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 8b7de7b2a08..5f7c9cb878f 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 @@ -1,5 +1,5 @@ #pragma once -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp index f467d945829..7f780986b6a 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp index 22c95bf82bb..b5704f48a53 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp @@ -1,5 +1,5 @@ #pragma once -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { @@ -92,137 +92,6 @@ template class GenPermSortRelationImpl { }; }; -template class GoblinTranslatorGenPermSortRelationImpl { - public: - using FF = FF_; - - // 1 + polynomial degree of this relation - static constexpr size_t RELATION_LENGTH = 6; // degree((lagrange_last-1) * D(D - 1)(D - 2)(D - 3)) = 5 - - static constexpr std::array SUBRELATION_LENGTHS{ - 6, // ordered_range_constraints_0 step in {0,1,2,3} subrelation - 6, // ordered_range_constraints_1 step in {0,1,2,3} subrelation - 6, // ordered_range_constraints_2 step in {0,1,2,3} subrelation - 6, // ordered_range_constraints_3 step in {0,1,2,3} subrelation - 6, // ordered_range_constraints_4 step in {0,1,2,3} subrelation - 3, // ordered_range_constraints_0 ends with defined maximum value subrelation - 3, // ordered_range_constraints_1 ends with defined maximum value subrelation - 3, // ordered_range_constraints_2 ends with defined maximum value subrelation - 3, // ordered_range_constraints_3 ends with defined maximum value subrelation - 3 // ordered_range_constraints_4 ends with defined maximum value subrelation - - }; - - /** - * @brief Expression for the generalized permutation sort relation - * - * @details The relation enforces 2 constraints on each of the ordered_range_constraints wires: - * 1) 2 sequential values are non-descending and have a difference of at most 3, except for the value at last index - * 2) The value at last index is 2¹⁴ - 1 - * - * @param evals transformed to `evals + C(in(X)...)*scaling_factor` - * @param in an std::array containing the fully extended Univariate edges. - * @param parameters contains beta, gamma, and public_input_delta, .... - * @param scaling_factor optional term to scale the evaluation before adding to evals. - */ - template - inline static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const Parameters&, - const FF& scaling_factor) - { - using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; - using View = typename Accumulator::View; - auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0); - auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1); - auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2); - auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); - auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); - auto ordered_range_constraints_0_shift = View(in.ordered_range_constraints_0_shift); - auto ordered_range_constraints_1_shift = View(in.ordered_range_constraints_1_shift); - auto ordered_range_constraints_2_shift = View(in.ordered_range_constraints_2_shift); - auto ordered_range_constraints_3_shift = View(in.ordered_range_constraints_3_shift); - auto ordered_range_constraints_4_shift = View(in.ordered_range_constraints_4_shift); - auto lagrange_last = View(in.lagrange_last); - - static const FF minus_one = FF(-1); - static const FF minus_two = FF(-2); - static const FF minus_three = FF(-3); - static const size_t micro_limb_bits = 14; - static const auto maximum_sort_value = -FF((1 << micro_limb_bits) - 1); - // Compute wire differences - auto delta_1 = ordered_range_constraints_0_shift - ordered_range_constraints_0; - auto delta_2 = ordered_range_constraints_1_shift - ordered_range_constraints_1; - auto delta_3 = ordered_range_constraints_2_shift - ordered_range_constraints_2; - auto delta_4 = ordered_range_constraints_3_shift - ordered_range_constraints_3; - auto delta_5 = ordered_range_constraints_4_shift - ordered_range_constraints_4; - - // Contribution (1) (contributions 1-5 ensure that the sequential values have a difference of {0,1,2,3}) - auto tmp_1 = delta_1; - tmp_1 *= (delta_1 + minus_one); - tmp_1 *= (delta_1 + minus_two); - tmp_1 *= (delta_1 + minus_three); - tmp_1 *= (lagrange_last + minus_one); - tmp_1 *= scaling_factor; - std::get<0>(accumulators) += tmp_1; - - // Contribution (2) - auto tmp_2 = delta_2; - tmp_2 *= (delta_2 + minus_one); - tmp_2 *= (delta_2 + minus_two); - tmp_2 *= (delta_2 + minus_three); - tmp_2 *= (lagrange_last + minus_one); - tmp_2 *= scaling_factor; - - std::get<1>(accumulators) += tmp_2; - - // Contribution (3) - auto tmp_3 = delta_3; - tmp_3 *= (delta_3 + minus_one); - tmp_3 *= (delta_3 + minus_two); - tmp_3 *= (delta_3 + minus_three); - tmp_3 *= (lagrange_last + minus_one); - tmp_3 *= scaling_factor; - std::get<2>(accumulators) += tmp_3; - - // Contribution (4) - auto tmp_4 = delta_4; - tmp_4 *= (delta_4 + minus_one); - tmp_4 *= (delta_4 + minus_two); - tmp_4 *= (delta_4 + minus_three); - tmp_4 *= (lagrange_last + minus_one); - tmp_4 *= scaling_factor; - std::get<3>(accumulators) += tmp_4; - - // Contribution (5) - auto tmp_5 = delta_5; - tmp_5 *= (delta_5 + minus_one); - tmp_5 *= (delta_5 + minus_two); - tmp_5 *= (delta_5 + minus_three); - tmp_5 *= (lagrange_last + minus_one); - tmp_5 *= scaling_factor; - std::get<4>(accumulators) += tmp_5; - - // Contribution (6) (Contributions 6-10 ensure that the last value is the designated maximum value. We don't - // need to constrain the first value to be 0, because the shift mechanic does this for us) - std::get<5>(accumulators) += - lagrange_last * (ordered_range_constraints_0 + maximum_sort_value) * scaling_factor; - // Contribution (7) - std::get<6>(accumulators) += - lagrange_last * (ordered_range_constraints_1 + maximum_sort_value) * scaling_factor; - // Contribution (8) - std::get<7>(accumulators) += - lagrange_last * (ordered_range_constraints_2 + maximum_sort_value) * scaling_factor; - // Contribution (9) - std::get<8>(accumulators) += - lagrange_last * (ordered_range_constraints_3 + maximum_sort_value) * scaling_factor; - // Contribution (10) - std::get<9>(accumulators) += - lagrange_last * (ordered_range_constraints_4 + maximum_sort_value) * scaling_factor; - }; -}; template using GenPermSortRelation = Relation>; -template -using GoblinTranslatorGenPermSortRelation = Relation>; } // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index dd5d9e30846..2d9613c7417 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -1,5 +1,5 @@ #pragma once -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index 036c9c578e3..2769a5e8ab5 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -1,5 +1,5 @@ #pragma once -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { @@ -105,113 +105,6 @@ template class UltraPermutationRelationImpl { }; }; -template class GoblinTranslatorPermutationRelationImpl { - public: - using FF = FF_; - // 1 + polynomial degree of this relation - static constexpr size_t RELATION_LENGTH = 7; - - static constexpr std::array SUBRELATION_LENGTHS{ - 7, // grand product construction sub-relation - 3 // left-shiftable polynomial sub-relation - }; - - inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } - inline static auto& get_shifted_grand_product_polynomial(auto& in) { return in.z_perm_shift; } - - template - inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) - { - using View = typename Accumulator::View; - - auto concatenated_range_constraints_0 = View(in.concatenated_range_constraints_0); - auto concatenated_range_constraints_1 = View(in.concatenated_range_constraints_1); - auto concatenated_range_constraints_2 = View(in.concatenated_range_constraints_2); - auto concatenated_range_constraints_3 = View(in.concatenated_range_constraints_3); - - auto ordered_extra_range_constraints_numerator = View(in.ordered_extra_range_constraints_numerator); - - const auto& gamma = params.gamma; - return (concatenated_range_constraints_0 + gamma) * (concatenated_range_constraints_1 + gamma) * - (concatenated_range_constraints_2 + gamma) * (concatenated_range_constraints_3 + gamma) * - (ordered_extra_range_constraints_numerator + gamma); - } - - template - inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) - { - using View = typename Accumulator::View; - - auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0); - auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1); - auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2); - auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); - auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); - - const auto& gamma = params.gamma; - - return (ordered_range_constraints_0 + gamma) * (ordered_range_constraints_1 + gamma) * - (ordered_range_constraints_2 + gamma) * (ordered_range_constraints_3 + gamma) * - (ordered_range_constraints_4 + gamma); - } - /** - * @brief Compute contribution of the goblin translator permutation relation for a given edge (internal function) - * - * @details There are 2 relations associated with enforcing the set permutation relation - * This file handles the relation that confirms faithful calculation of the grand - * product polynomial Z_perm. - * - * C(in(X)...) = - * ( z_perm(X) + lagrange_first(X) )*P(X) - * - ( z_perm_shift(X) + lagrange_last(X))*Q(X), - * where P(X) = Prod_{i=0:4} numerator_polynomial_i(X) + γ - * Q(X) = Prod_{i=0:4} ordered_range_constraint_i(X) + γ - * the first 4 numerator polynomials are concatenated range constraint polynomials and the last one is the constant - * extra numerator - * - * @param evals transformed to `evals + C(in(X)...)*scaling_factor` - * @param in an std::array containing the fully extended Univariate edges. - * @param parameters contains beta, gamma, and public_input_delta, .... - * @param scaling_factor optional term to scale the evaluation before adding to evals. - */ - - template - inline static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const Parameters& params, - const FF& scaling_factor) - { - [&]() { - using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; - using View = typename Accumulator::View; - - auto z_perm = View(in.z_perm); - auto z_perm_shift = View(in.z_perm_shift); - auto lagrange_first = View(in.lagrange_first); - auto lagrange_last = View(in.lagrange_last); - - // Contribution (1) - std::get<0>(accumulators) += - (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - - ((z_perm_shift + lagrange_last) * compute_grand_product_denominator(in, params))) * - scaling_factor; - }(); - - [&]() { - using Accumulator = std::tuple_element_t<1, ContainerOverSubrelations>; - using View = typename Accumulator::View; - - auto z_perm_shift = View(in.z_perm_shift); - auto lagrange_last = View(in.lagrange_last); - - // Contribution (2) - std::get<1>(accumulators) += (lagrange_last * z_perm_shift) * scaling_factor; - }(); - }; -}; - template using UltraPermutationRelation = Relation>; -template -using GoblinTranslatorPermutationRelation = Relation>; } // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/goblin_translator_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/goblin_translator_relation_consistency.test.cpp similarity index 99% rename from barretenberg/cpp/src/barretenberg/proof_system/relations/goblin_translator_relation_consistency.test.cpp rename to barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/goblin_translator_relation_consistency.test.cpp index 51e88d92b30..e2a25b2778d 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/goblin_translator_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/goblin_translator_relation_consistency.test.cpp @@ -12,13 +12,12 @@ * */ #include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/proof_system/relations/decomposition_relation.hpp" -#include "barretenberg/proof_system/relations/extra_relations.hpp" -#include "barretenberg/proof_system/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/proof_system/relations/non_native_field_relation.hpp" -#include "barretenberg/proof_system/relations/permutation_relation.hpp" #include "barretenberg/proof_system/relations/relation_parameters.hpp" -#include "extra_relations.hpp" +#include "barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp" +#include "barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp" +#include "barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp" +#include "barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp" +#include "barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp" #include using namespace proof_system; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/decomposition_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp similarity index 99% rename from barretenberg/cpp/src/barretenberg/proof_system/relations/decomposition_relation.hpp rename to barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp index edb385a9a0d..40d273b4128 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/decomposition_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/extra_relations.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp similarity index 99% rename from barretenberg/cpp/src/barretenberg/proof_system/relations/extra_relations.hpp rename to barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp index 4d3276032c3..0dfad9224d6 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/extra_relations.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/numeric/uint256/uint256.hpp" -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp new file mode 100644 index 00000000000..7bfc1b00bd3 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp @@ -0,0 +1,138 @@ +#pragma once +#include "barretenberg/proof_system/relations/relation_types.hpp" + +namespace proof_system { + +template class GoblinTranslatorGenPermSortRelationImpl { + public: + using FF = FF_; + + // 1 + polynomial degree of this relation + static constexpr size_t RELATION_LENGTH = 6; // degree((lagrange_last-1) * D(D - 1)(D - 2)(D - 3)) = 5 + + static constexpr std::array SUBRELATION_LENGTHS{ + 6, // ordered_range_constraints_0 step in {0,1,2,3} subrelation + 6, // ordered_range_constraints_1 step in {0,1,2,3} subrelation + 6, // ordered_range_constraints_2 step in {0,1,2,3} subrelation + 6, // ordered_range_constraints_3 step in {0,1,2,3} subrelation + 6, // ordered_range_constraints_4 step in {0,1,2,3} subrelation + 3, // ordered_range_constraints_0 ends with defined maximum value subrelation + 3, // ordered_range_constraints_1 ends with defined maximum value subrelation + 3, // ordered_range_constraints_2 ends with defined maximum value subrelation + 3, // ordered_range_constraints_3 ends with defined maximum value subrelation + 3 // ordered_range_constraints_4 ends with defined maximum value subrelation + + }; + + /** + * @brief Expression for the generalized permutation sort relation + * + * @details The relation enforces 2 constraints on each of the ordered_range_constraints wires: + * 1) 2 sequential values are non-descending and have a difference of at most 3, except for the value at last index + * 2) The value at last index is 2¹⁴ - 1 + * + * @param evals transformed to `evals + C(in(X)...)*scaling_factor` + * @param in an std::array containing the fully extended Univariate edges. + * @param parameters contains beta, gamma, and public_input_delta, .... + * @param scaling_factor optional term to scale the evaluation before adding to evals. + */ + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) + { + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0); + auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1); + auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2); + auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); + auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); + auto ordered_range_constraints_0_shift = View(in.ordered_range_constraints_0_shift); + auto ordered_range_constraints_1_shift = View(in.ordered_range_constraints_1_shift); + auto ordered_range_constraints_2_shift = View(in.ordered_range_constraints_2_shift); + auto ordered_range_constraints_3_shift = View(in.ordered_range_constraints_3_shift); + auto ordered_range_constraints_4_shift = View(in.ordered_range_constraints_4_shift); + auto lagrange_last = View(in.lagrange_last); + + static const FF minus_one = FF(-1); + static const FF minus_two = FF(-2); + static const FF minus_three = FF(-3); + static const size_t micro_limb_bits = 14; + static const auto maximum_sort_value = -FF((1 << micro_limb_bits) - 1); + // Compute wire differences + auto delta_1 = ordered_range_constraints_0_shift - ordered_range_constraints_0; + auto delta_2 = ordered_range_constraints_1_shift - ordered_range_constraints_1; + auto delta_3 = ordered_range_constraints_2_shift - ordered_range_constraints_2; + auto delta_4 = ordered_range_constraints_3_shift - ordered_range_constraints_3; + auto delta_5 = ordered_range_constraints_4_shift - ordered_range_constraints_4; + + // Contribution (1) (contributions 1-5 ensure that the sequential values have a difference of {0,1,2,3}) + auto tmp_1 = delta_1; + tmp_1 *= (delta_1 + minus_one); + tmp_1 *= (delta_1 + minus_two); + tmp_1 *= (delta_1 + minus_three); + tmp_1 *= (lagrange_last + minus_one); + tmp_1 *= scaling_factor; + std::get<0>(accumulators) += tmp_1; + + // Contribution (2) + auto tmp_2 = delta_2; + tmp_2 *= (delta_2 + minus_one); + tmp_2 *= (delta_2 + minus_two); + tmp_2 *= (delta_2 + minus_three); + tmp_2 *= (lagrange_last + minus_one); + tmp_2 *= scaling_factor; + + std::get<1>(accumulators) += tmp_2; + + // Contribution (3) + auto tmp_3 = delta_3; + tmp_3 *= (delta_3 + minus_one); + tmp_3 *= (delta_3 + minus_two); + tmp_3 *= (delta_3 + minus_three); + tmp_3 *= (lagrange_last + minus_one); + tmp_3 *= scaling_factor; + std::get<2>(accumulators) += tmp_3; + + // Contribution (4) + auto tmp_4 = delta_4; + tmp_4 *= (delta_4 + minus_one); + tmp_4 *= (delta_4 + minus_two); + tmp_4 *= (delta_4 + minus_three); + tmp_4 *= (lagrange_last + minus_one); + tmp_4 *= scaling_factor; + std::get<3>(accumulators) += tmp_4; + + // Contribution (5) + auto tmp_5 = delta_5; + tmp_5 *= (delta_5 + minus_one); + tmp_5 *= (delta_5 + minus_two); + tmp_5 *= (delta_5 + minus_three); + tmp_5 *= (lagrange_last + minus_one); + tmp_5 *= scaling_factor; + std::get<4>(accumulators) += tmp_5; + + // Contribution (6) (Contributions 6-10 ensure that the last value is the designated maximum value. We don't + // need to constrain the first value to be 0, because the shift mechanic does this for us) + std::get<5>(accumulators) += + lagrange_last * (ordered_range_constraints_0 + maximum_sort_value) * scaling_factor; + // Contribution (7) + std::get<6>(accumulators) += + lagrange_last * (ordered_range_constraints_1 + maximum_sort_value) * scaling_factor; + // Contribution (8) + std::get<7>(accumulators) += + lagrange_last * (ordered_range_constraints_2 + maximum_sort_value) * scaling_factor; + // Contribution (9) + std::get<8>(accumulators) += + lagrange_last * (ordered_range_constraints_3 + maximum_sort_value) * scaling_factor; + // Contribution (10) + std::get<9>(accumulators) += + lagrange_last * (ordered_range_constraints_4 + maximum_sort_value) * scaling_factor; + }; +}; +template +using GoblinTranslatorGenPermSortRelation = Relation>; + +} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/non_native_field_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp similarity index 99% rename from barretenberg/cpp/src/barretenberg/proof_system/relations/non_native_field_relation.hpp rename to barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp index 9c6029e6cf2..5d33224afcb 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/non_native_field_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/ecc/curves/bn254/bn254.hpp" #include "barretenberg/numeric/uintx/uintx.hpp" -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp new file mode 100644 index 00000000000..bf46ff39880 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp @@ -0,0 +1,114 @@ +#pragma once +#include "barretenberg/proof_system/relations/relation_types.hpp" + +namespace proof_system { + +template class GoblinTranslatorPermutationRelationImpl { + public: + using FF = FF_; + // 1 + polynomial degree of this relation + static constexpr size_t RELATION_LENGTH = 7; + + static constexpr std::array SUBRELATION_LENGTHS{ + 7, // grand product construction sub-relation + 3 // left-shiftable polynomial sub-relation + }; + + inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } + inline static auto& get_shifted_grand_product_polynomial(auto& in) { return in.z_perm_shift; } + + template + inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) + { + using View = typename Accumulator::View; + + auto concatenated_range_constraints_0 = View(in.concatenated_range_constraints_0); + auto concatenated_range_constraints_1 = View(in.concatenated_range_constraints_1); + auto concatenated_range_constraints_2 = View(in.concatenated_range_constraints_2); + auto concatenated_range_constraints_3 = View(in.concatenated_range_constraints_3); + + auto ordered_extra_range_constraints_numerator = View(in.ordered_extra_range_constraints_numerator); + + const auto& gamma = params.gamma; + return (concatenated_range_constraints_0 + gamma) * (concatenated_range_constraints_1 + gamma) * + (concatenated_range_constraints_2 + gamma) * (concatenated_range_constraints_3 + gamma) * + (ordered_extra_range_constraints_numerator + gamma); + } + + template + inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) + { + using View = typename Accumulator::View; + + auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0); + auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1); + auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2); + auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); + auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); + + const auto& gamma = params.gamma; + + return (ordered_range_constraints_0 + gamma) * (ordered_range_constraints_1 + gamma) * + (ordered_range_constraints_2 + gamma) * (ordered_range_constraints_3 + gamma) * + (ordered_range_constraints_4 + gamma); + } + /** + * @brief Compute contribution of the goblin translator permutation relation for a given edge (internal function) + * + * @details There are 2 relations associated with enforcing the set permutation relation + * This file handles the relation that confirms faithful calculation of the grand + * product polynomial Z_perm. + * + * C(in(X)...) = + * ( z_perm(X) + lagrange_first(X) )*P(X) + * - ( z_perm_shift(X) + lagrange_last(X))*Q(X), + * where P(X) = Prod_{i=0:4} numerator_polynomial_i(X) + γ + * Q(X) = Prod_{i=0:4} ordered_range_constraint_i(X) + γ + * the first 4 numerator polynomials are concatenated range constraint polynomials and the last one is the constant + * extra numerator + * + * @param evals transformed to `evals + C(in(X)...)*scaling_factor` + * @param in an std::array containing the fully extended Univariate edges. + * @param parameters contains beta, gamma, and public_input_delta, .... + * @param scaling_factor optional term to scale the evaluation before adding to evals. + */ + + template + inline static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) + { + [&]() { + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + auto z_perm = View(in.z_perm); + auto z_perm_shift = View(in.z_perm_shift); + auto lagrange_first = View(in.lagrange_first); + auto lagrange_last = View(in.lagrange_last); + + // Contribution (1) + std::get<0>(accumulators) += + (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - + ((z_perm_shift + lagrange_last) * compute_grand_product_denominator(in, params))) * + scaling_factor; + }(); + + [&]() { + using Accumulator = std::tuple_element_t<1, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + auto z_perm_shift = View(in.z_perm_shift); + auto lagrange_last = View(in.lagrange_last); + + // Contribution (2) + std::get<1>(accumulators) += (lagrange_last * z_perm_shift) * scaling_factor; + }(); + }; +}; + +template +using GoblinTranslatorPermutationRelation = Relation>; + +} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp index c0137000f25..17a736ac936 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp @@ -1,5 +1,5 @@ #pragma once -#include "relation_types.hpp" +#include "barretenberg/proof_system/relations/relation_types.hpp" namespace proof_system { From 6e77bce205290c4c16499d7ff993dbb33a766dd9 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 20 Oct 2023 19:16:10 +0000 Subject: [PATCH 03/32] Stalled experiment --- .../honk/proof_system/combiner.test.cpp | 4 + .../honk/proof_system/protogalaxy_prover.hpp | 14 +++- .../barretenberg/polynomials/univariate.hpp | 2 + .../relations/lookup_relation.hpp | 4 +- .../relations/permutation_relation.hpp | 18 ++-- .../relations/relation_parameters.hpp | 83 ++++++++----------- .../proof_system/relations/utils.hpp | 6 +- 7 files changed, 67 insertions(+), 64 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp index 328045b335f..f8f42069b5e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp @@ -12,6 +12,10 @@ using Polynomial = typename Flavor::Polynomial; using FF = typename Flavor::FF; using RelationParameters = proof_system::RelationParameters; +// WORKTODO +// using MyUnivariate = Univariate; +// using RelationParameters = proof_system::RelationParameters; + TEST(Protogalaxy, CombinerOn2Instances) { constexpr size_t NUM_INSTANCES = 2; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index a5ae4cd5506..3a1c96b6cf0 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -31,6 +31,9 @@ template class ProtoGalaxyProver_ { typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; using RelationEvaluations = typename Flavor::TupleOfArraysOfValues; + // WORKTODO + // using MyUnivariate = Univariate; + ProverInstances instances; ProverTranscript transcript; @@ -193,10 +196,12 @@ template class ProtoGalaxyProver_ { } template - void accumulate_relation_univariates(TupleOfTuplesOfUnivariates& univariate_accumulators, - const ExtendedUnivariates& extended_univariates, - const proof_system::RelationParameters& relation_parameters, - const FF& scaling_factor) + void accumulate_relation_univariates( + TupleOfTuplesOfUnivariates& univariate_accumulators, + const ExtendedUnivariates& extended_univariates, + const proof_system::RelationParameters& relation_parameters, + // const proof_system::RelationParameters& relation_parameters, // WORKTODO + const FF& scaling_factor) { using Relation = std::tuple_element_t; Relation::accumulate( @@ -217,6 +222,7 @@ template class ProtoGalaxyProver_ { RandomExtendedUnivariate compute_combiner( const ProverInstances& instances, const proof_system::RelationParameters& relation_parameters, + // const proof_system::RelationParameters& relation_parameters, // WORKTODO const PowUnivariate& pow_univariate, const typename Flavor::FF alpha) { diff --git a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index ca3701f9b9f..6cd154ba0ed 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -78,6 +78,8 @@ template class Univariate { return output; }; + static Univariate random_element() { return get_random(); }; + // Operations between Univariate and other Univariate bool operator==(const Univariate& other) const = default; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index 2d9613c7417..233d5c99239 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -63,7 +63,7 @@ template class LookupRelationImpl { const auto eta_sqr = eta * eta; const auto eta_cube = eta_sqr * eta; - const auto one_plus_beta = FF(1) + beta; + const auto one_plus_beta = beta + FF(1); const auto gamma_by_one_plus_beta = gamma * one_plus_beta; using View = typename Accumulator::View; @@ -124,7 +124,7 @@ template class LookupRelationImpl { const auto& beta = params.beta; const auto& gamma = params.gamma; - const auto one_plus_beta = FF(1) + beta; + const auto one_plus_beta = beta + FF(1); const auto gamma_by_one_plus_beta = gamma * one_plus_beta; using View = typename Accumulator::View; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index 2769a5e8ab5..4e2bb9c20a5 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -75,33 +75,35 @@ template class UltraPermutationRelationImpl { const Parameters& params, const FF& scaling_factor) { - const auto& public_input_delta = params.public_input_delta; - // Contribution (1) - { + [&]() { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; - auto z_perm = View(in.z_perm); + const auto& public_input_delta = params.public_input_delta; + // WORKTODO + // using ParameterView = typename Parameters::ParameterView; + // auto public_input_delta = ParameterView(params.public_input_delta); + auto z_perm = View(in.z_perm); // WORKTODO: these should all be const auto auto z_perm_shift = View(in.z_perm_shift); auto lagrange_first = View(in.lagrange_first); auto lagrange_last = View(in.lagrange_last); - // Contribution (1) std::get<0>(accumulators) += (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - ((z_perm_shift + lagrange_last * public_input_delta) * compute_grand_product_denominator(in, params))) * scaling_factor; - } + }(); + // Contribution (2) - { + [&]() { using Accumulator = std::tuple_element_t<1, ContainerOverSubrelations>; using View = typename Accumulator::View; auto z_perm_shift = View(in.z_perm_shift); auto lagrange_last = View(in.lagrange_last); std::get<1>(accumulators) += (lagrange_last * z_perm_shift) * scaling_factor; - } + }(); }; }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp index 59e76b613c4..53dd283333c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp @@ -5,76 +5,65 @@ namespace proof_system { /** * @brief Container for parameters used by the grand product (permutation, lookup) Honk relations * - * @tparam FF + * @tparam T, either a native field type or a Univariate. */ -template struct RelationParameters { +template struct RelationParameters { + using ParameterView = typename T::View; static constexpr int NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR = 4; static constexpr int NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR = 1; static constexpr int NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR = 4; - FF eta = FF(0); // Lookup - FF beta = FF(0); // Permutation + Lookup - FF gamma = FF(0); // Permutation + Lookup - FF public_input_delta = FF(0); // Permutation - FF lookup_grand_product_delta = FF(0); // Lookup - FF beta_sqr = 0; - FF beta_cube = 0; + T eta = T(0); // Lookup + T beta = T(0); // Permutation + Lookup + T gamma = T(0); // Permutation + Lookup + T public_input_delta = T(0); // Permutation + T lookup_grand_product_delta = T(0); // Lookup + T beta_sqr = T(0); + T beta_cube = T(0); // eccvm_set_permutation_delta is used in the set membership gadget in eccvm/ecc_set_relation.hpp // We can remove this by modifying the relation, but increases complexity - FF eccvm_set_permutation_delta = 0; - std::array accumulated_result = { - FF(0), FF(0), FF(0), FF(0) + T eccvm_set_permutation_delta = T(0); + std::array accumulated_result = { + T(0), T(0), T(0), T(0) }; // Goblin Translator - std::array evaluation_input_x = { - FF(0), FF(0), FF(0), FF(0), FF(0) + std::array evaluation_input_x = { + T(0), T(0), T(0), T(0), T(0) }; // Goblin Translator - std::array, + std::array, NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR> - batching_challenge_v = { { { FF(0), FF(0), FF(0), FF(0), FF(0) }, - { FF(0), FF(0), FF(0), FF(0), FF(0) }, - { FF(0), FF(0), FF(0), FF(0), FF(0) }, - { FF(0), FF(0), FF(0), FF(0), FF(0) } } }; + batching_challenge_v = { { { T(0), T(0), T(0), T(0), T(0) }, + { T(0), T(0), T(0), T(0), T(0) }, + { T(0), T(0), T(0), T(0), T(0) }, + { T(0), T(0), T(0), T(0), T(0) } } }; static RelationParameters get_random() { RelationParameters result; - result.eta = FF::random_element(); - result.beta_sqr = result.beta.sqr(); + result.eta = T::random_element(); + result.beta_sqr = result.beta * result.beta; result.beta_cube = result.beta_sqr * result.beta; - result.beta = FF::random_element(); - result.gamma = FF::random_element(); - result.public_input_delta = FF::random_element(); - result.lookup_grand_product_delta = FF::random_element(); + result.beta = T::random_element(); + result.gamma = T::random_element(); + result.public_input_delta = T::random_element(); + result.lookup_grand_product_delta = T::random_element(); result.eccvm_set_permutation_delta = result.gamma * (result.gamma + result.beta_sqr) * (result.gamma + result.beta_sqr + result.beta_sqr) * (result.gamma + result.beta_sqr + result.beta_sqr + result.beta_sqr); result.accumulated_result = { - FF::random_element(), FF::random_element(), FF::random_element(), FF::random_element() + T::random_element(), T::random_element(), T::random_element(), T::random_element() }; result.evaluation_input_x = { - FF::random_element(), FF::random_element(), FF::random_element(), FF::random_element(), FF::random_element() + T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element() }; result.batching_challenge_v = { - std::array{ FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element() }, - { FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element() }, - { FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element() }, - { FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element(), - FF::random_element() }, + std::array{ T::random_element(), + T::random_element(), + T::random_element(), + T::random_element(), + T::random_element() }, + { T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element() }, + { T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element() }, + { T::random_element(), T::random_element(), T::random_element(), T::random_element(), T::random_element() }, }; return result; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp index ff224c3b747..d818d1b3ccf 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp @@ -175,11 +175,11 @@ template class RelationUtils { * together, with appropriate scaling factors, produces the expected value of the full Honk relation. This value is * checked against the final value of the target total sum (called sigma_0 in the thesis). */ - template + template // TODO(#224)(Cody): Input should be an array? inline static void accumulate_relation_evaluations(PolynomialEvaluations evaluations, RelationEvaluations& relation_evaluations, - const proof_system::RelationParameters& relation_parameters, + const Parameters& relation_parameters, const FF& partial_evaluation_constant) { using Relation = std::tuple_element_t; @@ -190,7 +190,7 @@ template class RelationUtils { // Repeat for the next relation. if constexpr (relation_idx + 1 < NUM_RELATIONS) { - accumulate_relation_evaluations( + accumulate_relation_evaluations( evaluations, relation_evaluations, relation_parameters, partial_evaluation_constant); } } From 98aec2a0912af1771185f8e0f419596ab92884bb Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 20 Oct 2023 19:26:28 +0000 Subject: [PATCH 04/32] Add tmp proxy to sumcheck prover prove --- .../cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 81af019be73..78b01e9fcb3 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -1,6 +1,7 @@ #pragma once #include "barretenberg/common/serialize.hpp" #include "barretenberg/common/throw_or_abort.hpp" +#include "barretenberg/honk/instance/prover_instance.hpp" #include "barretenberg/honk/sumcheck/sumcheck_output.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/honk/utils/grand_product_delta.hpp" @@ -17,6 +18,7 @@ template class SumcheckProver { using ProverPolynomials = typename Flavor::ProverPolynomials; using PartiallyEvaluatedMultivariates = typename Flavor::PartiallyEvaluatedMultivariates; using ClaimedEvaluations = typename Flavor::AllValues; + using Instance = ProverInstance_; ProverTranscript& transcript; const size_t multivariate_n; @@ -119,6 +121,17 @@ template class SumcheckProver { return { multivariate_challenge, multivariate_evaluations }; }; + /** + * @brief Compute univariate restriction place in transcript, generate challenge, partially evaluate,... repeat + * until final round, then compute multivariate evaluations and place in transcript. + * + * @details + */ + SumcheckOutput prove(std::shared_ptr instance) + { + return prove(instance->prover_polynomials, instance->relation_parameters); + }; + /** * @brief Evaluate at the round challenge and prepare class for next round. * Illustration of layout in example of first round when d==3 (showing just one Honk polynomial, From d3bde61cbd16e53140254a835026754950196027 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 20 Oct 2023 19:32:05 +0000 Subject: [PATCH 05/32] Change compute_combiner interface --- .../barretenberg/honk/proof_system/combiner.test.cpp | 9 +++------ .../honk/proof_system/protogalaxy_prover.hpp | 11 ++++------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp index f8f42069b5e..039ecbad38d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp @@ -38,7 +38,6 @@ TEST(Protogalaxy, CombinerOn2Instances) if (is_random_input) { std::vector> instance_data(NUM_INSTANCES); std::array, NUM_INSTANCES> storage_arrays; - auto relation_parameters = RelationParameters::get_random(); ProtoGalaxyProver prover; auto pow_univariate = PowUnivariate(/*zeta_pow=*/2); auto alpha = FF(0); // focus on the arithmetic relation only @@ -55,7 +54,7 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; - auto result = prover.compute_combiner(instances, relation_parameters, pow_univariate, alpha); + auto result = prover.compute_combiner(instances, pow_univariate, alpha); auto expected_result = barretenberg::Univariate(std::array{ 87706, 27289140, @@ -69,7 +68,6 @@ TEST(Protogalaxy, CombinerOn2Instances) } else { std::vector> instance_data(NUM_INSTANCES); std::array, NUM_INSTANCES> storage_arrays; - auto relation_parameters = RelationParameters::get_random(); ProtoGalaxyProver prover; auto pow_univariate = PowUnivariate(/*zeta_pow=*/2); auto alpha = FF(0); // focus on the arithmetic relation only @@ -130,7 +128,7 @@ TEST(Protogalaxy, CombinerOn2Instances) relation value: 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ - auto result = prover.compute_combiner(instances, relation_parameters, pow_univariate, alpha); + auto result = prover.compute_combiner(instances, pow_univariate, alpha); auto expected_result = barretenberg::Univariate(std::array{ 0, 0, 36, 144, 360, 720, 1260 }); EXPECT_EQ(result, expected_result); } @@ -160,7 +158,6 @@ TEST(Protogalaxy, CombinerOn4Instances) auto run_test = [&]() { std::vector> instance_data(NUM_INSTANCES); std::array, NUM_INSTANCES> storage_arrays; - auto relation_parameters = RelationParameters::get_random(); ProtoGalaxyProver prover; auto pow_univariate = PowUnivariate(/*zeta_pow=*/2); auto alpha = FF(0); // focus on the arithmetic relation only @@ -181,7 +178,7 @@ TEST(Protogalaxy, CombinerOn4Instances) zero_all_selectors(instances[2]->prover_polynomials); zero_all_selectors(instances[3]->prover_polynomials); - auto result = prover.compute_combiner(instances, relation_parameters, pow_univariate, alpha); + auto result = prover.compute_combiner(instances, pow_univariate, alpha); std::array zeroes; std::fill(zeroes.begin(), zeroes.end(), 0); auto expected_result = barretenberg::Univariate(zeroes); diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 3a1c96b6cf0..d172dcf505d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -219,12 +219,9 @@ template class ProtoGalaxyProver_ { * * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/754) Provide the right challenge to here */ - RandomExtendedUnivariate compute_combiner( - const ProverInstances& instances, - const proof_system::RelationParameters& relation_parameters, - // const proof_system::RelationParameters& relation_parameters, // WORKTODO - const PowUnivariate& pow_univariate, - const typename Flavor::FF alpha) + RandomExtendedUnivariate compute_combiner(const ProverInstances& instances, + const PowUnivariate& pow_univariate, + const typename Flavor::FF alpha) { size_t common_circuit_size = instances[0]->prover_polynomials._data[0].size(); // Precompute the vector of required powers of zeta @@ -270,7 +267,7 @@ template class ProtoGalaxyProver_ { // Accumulate the i-th row's univariate contribution accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], extended_univariates[thread_idx], - relation_parameters, + instances[0]->relation_parameters, // WORKTODO pow_challenge); } }); From b6df92e1ddce338d73d544111089b1dec3dbae1a Mon Sep 17 00:00:00 2001 From: codygunton Date: Sat, 21 Oct 2023 00:30:32 +0000 Subject: [PATCH 06/32] Quick and dirty. IOU test --- .../barretenberg/honk/instance/instances.hpp | 22 ++++++++++++++++-- .../honk/proof_system/protogalaxy_prover.cpp | 1 + .../honk/proof_system/protogalaxy_prover.hpp | 16 ++++++------- .../relations/auxiliary_relation.hpp | 4 +++- .../relations/lookup_relation.hpp | 23 +++++++++++-------- .../relations/permutation_relation.hpp | 16 ++++++------- .../relations/relation_parameters.hpp | 12 +++++++++- 7 files changed, 64 insertions(+), 30 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index 280920b4796..b4fce7a4de6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -4,14 +4,19 @@ namespace proof_system::honk { template struct ProverInstances_ { + public: using Flavor = Flavor_; using FF = typename Flavor::FF; + static constexpr size_t NUM = NUM_; using Instance = ProverInstance_; + using ArrayType = std::array, NUM_>; + static constexpr size_t EXTENDED_LENGTH = Flavor::MAX_RELATION_LENGTH * NUM; + using RelationParameters = RelationParameters>; // WORKTODO - public: - static constexpr size_t NUM = NUM_; ArrayType _data; + RelationParameters relation_parameters; + std::shared_ptr const& operator[](size_t idx) const { return _data[idx]; } typename ArrayType::iterator begin() { return _data.begin(); }; typename ArrayType::iterator end() { return _data.end(); }; @@ -24,6 +29,19 @@ template struct ProverInstances_ { } }; + void parameters_to_univariates() + { + auto params_to_fold = relation_parameters.to_fold; + for (size_t param_idx = 0; param_idx < params_to_fold.size(); param_idx++) { + auto& univariate_param = *params_to_fold[param_idx]; + Univariate tmp(0); + for (size_t instance_idx = 0; instance_idx < NUM; instance_idx++) { + tmp.value_at(instance_idx) = *((*_data[instance_idx]).relation_parameters.to_fold[param_idx]); + } + univariate_param = tmp.template extend_to(); + } + } + /** * @brief For a prover polynomial label and a fixed row index, construct a uninvariate from the corresponding value * from each instance. diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp index 913b4868d73..40a2302c935 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp @@ -31,6 +31,7 @@ template void ProtoGalaxyProver_::prepa instance->compute_sorted_accumulator_polynomials(eta); instance->compute_grand_product_polynomials(beta, gamma); } + instances.parameters_to_univariates(); } // TODO(#https://github.com/AztecProtocol/barretenberg/issues/689): finalise implementation this function diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index d172dcf505d..f4184212600 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -195,13 +195,11 @@ template class ProtoGalaxyProver_ { } } - template - void accumulate_relation_univariates( - TupleOfTuplesOfUnivariates& univariate_accumulators, - const ExtendedUnivariates& extended_univariates, - const proof_system::RelationParameters& relation_parameters, - // const proof_system::RelationParameters& relation_parameters, // WORKTODO - const FF& scaling_factor) + template + void accumulate_relation_univariates(TupleOfTuplesOfUnivariates& univariate_accumulators, + const ExtendedUnivariates& extended_univariates, + const Parameters& relation_parameters, + const FF& scaling_factor) { using Relation = std::tuple_element_t; Relation::accumulate( @@ -209,7 +207,7 @@ template class ProtoGalaxyProver_ { // Repeat for the next relation. if constexpr (relation_idx + 1 < Flavor::NUM_RELATIONS) { - accumulate_relation_univariates( + accumulate_relation_univariates( univariate_accumulators, extended_univariates, relation_parameters, scaling_factor); } } @@ -267,7 +265,7 @@ template class ProtoGalaxyProver_ { // Accumulate the i-th row's univariate contribution accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], extended_univariates[thread_idx], - instances[0]->relation_parameters, // WORKTODO + instances.relation_parameters, pow_challenge); } }); 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 fb02ce8cce6..38e970b08ed 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -57,11 +57,13 @@ template class AuxiliaryRelationImpl { const Parameters& params, const FF& scaling_factor) { - const auto& eta = params.eta; // All subrelations have the same length so we use the same length view for all calculations using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; + using ParameterView = typename Parameters::template ParameterView; + + const auto& eta = ParameterView(params.eta); auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index 233d5c99239..3e3de8315f2 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -57,16 +57,18 @@ template class LookupRelationImpl { template inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) { - const auto& beta = params.beta; - const auto& gamma = params.gamma; - const auto& eta = params.eta; + using View = typename Accumulator::View; + using ParameterView = typename Parameters::template ParameterView; + + const auto& beta = ParameterView(params.beta); + const auto& gamma = ParameterView(params.gamma); + const auto& eta = ParameterView(params.eta); const auto eta_sqr = eta * eta; const auto eta_cube = eta_sqr * eta; const auto one_plus_beta = beta + FF(1); const auto gamma_by_one_plus_beta = gamma * one_plus_beta; - using View = typename Accumulator::View; auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); auto w_3 = View(in.w_o); @@ -121,14 +123,15 @@ template class LookupRelationImpl { inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) { - const auto& beta = params.beta; - const auto& gamma = params.gamma; + using View = typename Accumulator::View; + using ParameterView = typename Parameters::template ParameterView; + + const auto& beta = ParameterView(params.beta); + const auto& gamma = ParameterView(params.gamma); const auto one_plus_beta = beta + FF(1); const auto gamma_by_one_plus_beta = gamma * one_plus_beta; - using View = typename Accumulator::View; - // Contribution (1) auto s_accum = View(in.sorted_accum); auto s_accum_shift = View(in.sorted_accum_shift); @@ -161,11 +164,13 @@ template class LookupRelationImpl { const Parameters& params, const FF& scaling_factor) { - const auto& grand_product_delta = params.lookup_grand_product_delta; { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; + using ParameterView = typename Parameters::template ParameterView; + + const auto& grand_product_delta = ParameterView(params.lookup_grand_product_delta); auto z_lookup = View(in.z_lookup); auto z_lookup_shift = View(in.z_lookup_shift); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index 4e2bb9c20a5..c09675196e2 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -19,6 +19,7 @@ template class UltraPermutationRelationImpl { inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; + using ParameterView = typename Parameters::template ParameterView; auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); @@ -29,8 +30,8 @@ template class UltraPermutationRelationImpl { auto id_3 = View(in.id_3); auto id_4 = View(in.id_4); - const auto& beta = params.beta; - const auto& gamma = params.gamma; + const auto& beta = ParameterView(params.beta); + const auto& gamma = ParameterView(params.gamma); return (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * (w_3 + id_3 * beta + gamma) * (w_4 + id_4 * beta + gamma); @@ -40,6 +41,7 @@ template class UltraPermutationRelationImpl { inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; + using ParameterView = typename Parameters::template ParameterView; auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); @@ -51,8 +53,8 @@ template class UltraPermutationRelationImpl { auto sigma_3 = View(in.sigma_3); auto sigma_4 = View(in.sigma_4); - const auto& beta = params.beta; - const auto& gamma = params.gamma; + const auto& beta = ParameterView(params.beta); + const auto& gamma = ParameterView(params.gamma); return (w_1 + sigma_1 * beta + gamma) * (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma) * (w_4 + sigma_4 * beta + gamma); @@ -79,10 +81,8 @@ template class UltraPermutationRelationImpl { [&]() { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; - const auto& public_input_delta = params.public_input_delta; - // WORKTODO - // using ParameterView = typename Parameters::ParameterView; - // auto public_input_delta = ParameterView(params.public_input_delta); + using ParameterView = typename Parameters::template ParameterView; + auto public_input_delta = ParameterView(params.public_input_delta); auto z_perm = View(in.z_perm); // WORKTODO: these should all be const auto auto z_perm_shift = View(in.z_perm_shift); auto lagrange_first = View(in.lagrange_first); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp index 53dd283333c..41af99bd559 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp @@ -1,5 +1,12 @@ #pragma once +#include "barretenberg/ecc/curves/bn254/fr.hpp" #include + +template +concept IsAnyOf = (std::same_as || ...); +template +concept IsField = IsAnyOf; + namespace proof_system { /** @@ -8,7 +15,7 @@ namespace proof_system { * @tparam T, either a native field type or a Univariate. */ template struct RelationParameters { - using ParameterView = typename T::View; + template using ParameterView = std::conditional_t, T, U>; static constexpr int NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR = 4; static constexpr int NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR = 1; static constexpr int NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR = 4; @@ -35,6 +42,9 @@ template struct RelationParameters { { T(0), T(0), T(0), T(0), T(0) }, { T(0), T(0), T(0), T(0), T(0) } } }; + static constexpr int NUM_TO_FOLD = 5; + std::array to_fold = { &eta, &beta, &gamma, &public_input_delta, &lookup_grand_product_delta }; + static RelationParameters get_random() { RelationParameters result; From 12b25b0f69002d2c8f533afd14b2f5e9300be9c1 Mon Sep 17 00:00:00 2001 From: codygunton Date: Sat, 21 Oct 2023 00:34:07 +0000 Subject: [PATCH 07/32] WORKTODO tweaks --- .../cpp/src/barretenberg/honk/instance/instances.hpp | 3 ++- .../barretenberg/honk/proof_system/combiner.test.cpp | 4 ---- .../honk/proof_system/protogalaxy_prover.hpp | 3 --- .../proof_system/relations/permutation_relation.hpp | 10 +++++----- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index b4fce7a4de6..21e12882049 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -11,8 +11,9 @@ template struct ProverInstances_ { using Instance = ProverInstance_; using ArrayType = std::array, NUM_>; + // WORKTODO set this correctly or extract it static constexpr size_t EXTENDED_LENGTH = Flavor::MAX_RELATION_LENGTH * NUM; - using RelationParameters = RelationParameters>; // WORKTODO + using RelationParameters = RelationParameters>; ArrayType _data; RelationParameters relation_parameters; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp index 039ecbad38d..fedd7757925 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp @@ -12,10 +12,6 @@ using Polynomial = typename Flavor::Polynomial; using FF = typename Flavor::FF; using RelationParameters = proof_system::RelationParameters; -// WORKTODO -// using MyUnivariate = Univariate; -// using RelationParameters = proof_system::RelationParameters; - TEST(Protogalaxy, CombinerOn2Instances) { constexpr size_t NUM_INSTANCES = 2; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index f4184212600..aefbfa271c4 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -31,9 +31,6 @@ template class ProtoGalaxyProver_ { typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; using RelationEvaluations = typename Flavor::TupleOfArraysOfValues; - // WORKTODO - // using MyUnivariate = Univariate; - ProverInstances instances; ProverTranscript transcript; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index c09675196e2..ebdc308f5bf 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -82,11 +82,11 @@ template class UltraPermutationRelationImpl { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; using ParameterView = typename Parameters::template ParameterView; - auto public_input_delta = ParameterView(params.public_input_delta); - auto z_perm = View(in.z_perm); // WORKTODO: these should all be const auto - auto z_perm_shift = View(in.z_perm_shift); - auto lagrange_first = View(in.lagrange_first); - auto lagrange_last = View(in.lagrange_last); + const auto public_input_delta = ParameterView(params.public_input_delta); + const auto z_perm = View(in.z_perm); + const auto z_perm_shift = View(in.z_perm_shift); + const auto lagrange_first = View(in.lagrange_first); + const auto lagrange_last = View(in.lagrange_last); std::get<0>(accumulators) += (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - From ffaf07b399ef425b245379719532c37a423e6314 Mon Sep 17 00:00:00 2001 From: codygunton Date: Sat, 21 Oct 2023 00:47:23 +0000 Subject: [PATCH 08/32] Fix? --- barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index 21e12882049..e92b3ff69ad 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -13,7 +13,7 @@ template struct ProverInstances_ { using ArrayType = std::array, NUM_>; // WORKTODO set this correctly or extract it static constexpr size_t EXTENDED_LENGTH = Flavor::MAX_RELATION_LENGTH * NUM; - using RelationParameters = RelationParameters>; + using RelationParameters = proof_system::RelationParameters>; ArrayType _data; RelationParameters relation_parameters; From ddeaba3ef83074c73f540cb3ed1fd27d9a95ba13 Mon Sep 17 00:00:00 2001 From: codygunton Date: Sat, 21 Oct 2023 19:51:30 +0000 Subject: [PATCH 09/32] Move ParameterView gettinger --- .../relations/auxiliary_relation.hpp | 2 +- .../relations/lookup_relation.hpp | 6 +++--- .../relations/permutation_relation.hpp | 6 +++--- .../relations/relation_parameters.hpp | 7 +------ .../proof_system/relations/relation_types.hpp | 19 +++++++++++++++---- 5 files changed, 23 insertions(+), 17 deletions(-) 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 38e970b08ed..3fff2f2e45e 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -61,7 +61,7 @@ template class AuxiliaryRelationImpl { // All subrelations have the same length so we use the same length view for all calculations using Accumulator = typename std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; - using ParameterView = typename Parameters::template ParameterView; + using ParameterView = GetParameterView; const auto& eta = ParameterView(params.eta); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index 3e3de8315f2..267a8b430a0 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -58,7 +58,7 @@ template class LookupRelationImpl { inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; - using ParameterView = typename Parameters::template ParameterView; + using ParameterView = GetParameterView; const auto& beta = ParameterView(params.beta); const auto& gamma = ParameterView(params.gamma); @@ -124,7 +124,7 @@ template class LookupRelationImpl { { using View = typename Accumulator::View; - using ParameterView = typename Parameters::template ParameterView; + using ParameterView = GetParameterView; const auto& beta = ParameterView(params.beta); const auto& gamma = ParameterView(params.gamma); @@ -168,7 +168,7 @@ template class LookupRelationImpl { { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; - using ParameterView = typename Parameters::template ParameterView; + using ParameterView = GetParameterView; const auto& grand_product_delta = ParameterView(params.lookup_grand_product_delta); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index ebdc308f5bf..58e7e3c29a6 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -19,7 +19,7 @@ template class UltraPermutationRelationImpl { inline static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; - using ParameterView = typename Parameters::template ParameterView; + using ParameterView = GetParameterView; auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); @@ -41,7 +41,7 @@ template class UltraPermutationRelationImpl { inline static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; - using ParameterView = typename Parameters::template ParameterView; + using ParameterView = GetParameterView; auto w_1 = View(in.w_l); auto w_2 = View(in.w_r); @@ -81,7 +81,7 @@ template class UltraPermutationRelationImpl { [&]() { using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; using View = typename Accumulator::View; - using ParameterView = typename Parameters::template ParameterView; + using ParameterView = GetParameterView; const auto public_input_delta = ParameterView(params.public_input_delta); const auto z_perm = View(in.z_perm); const auto z_perm_shift = View(in.z_perm_shift); diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp index 41af99bd559..f9d5ca63a15 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp @@ -2,11 +2,6 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include -template -concept IsAnyOf = (std::same_as || ...); -template -concept IsField = IsAnyOf; - namespace proof_system { /** @@ -15,7 +10,7 @@ namespace proof_system { * @tparam T, either a native field type or a Univariate. */ template struct RelationParameters { - template using ParameterView = std::conditional_t, T, U>; + using DataType = T; static constexpr int NUM_BINARY_LIMBS_IN_GOBLIN_TRANSLATOR = 4; static constexpr int NUM_NATIVE_LIMBS_IN_GOBLIN_TRANSLATOR = 1; static constexpr int NUM_CHALLENGE_POWERS_IN_GOBLIN_TRANSLATOR = 4; 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 7e8fb7542bd..92b25e2eaad 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -1,13 +1,24 @@ #pragma once +#include "barretenberg/ecc/curves/bn254/fr.hpp" #include "nested_containers.hpp" #include -namespace barretenberg { -template class Polynomial; -} +template +concept IsField = std::same_as /* || std::same_as */; + namespace proof_system { -// forward-declare Polynomial so we can use in a concept +/** + * @brief A type to optionally extract a view of a relation parameter in a relation. + * + * @details In sumcheck, challenges in relations are always field elements, but in folding we need univariate + * challenges. This template inspecting the underlying type of a RelationParameters instance. When this type is a field + * type, do nothing, otherwise apply the provided view type. + * @tparam Params + * @tparam View + */ +template +using GetParameterView = std::conditional_t, typename Params::DataType, View>; template concept HasSubrelationLinearlyIndependentMember = requires(T) { From bd8e812b8b6c4e762ec50da3f44a35441190927f Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 23 Oct 2023 00:23:24 +0000 Subject: [PATCH 10/32] Compute full degrees where needed --- .../relations/auxiliary_relation.hpp | 86 ++++++++++++------- .../relations/lookup_relation.hpp | 25 ++++-- .../relations/permutation_relation.hpp | 9 ++ .../proof_system/relations/relation_types.hpp | 1 + 4 files changed, 83 insertions(+), 38 deletions(-) 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 3fff2f2e45e..93d66a08a52 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -9,12 +9,21 @@ template class AuxiliaryRelationImpl { using FF = FF_; static constexpr std::array SUBRELATION_LENGTHS{ + 6, // could be 5 // auxiliary sub-relation; + 6, // could be 6 // ROM consistency sub-relation 1 + 6, // could be 6 // ROM consistency sub-relation 2 + 6, // could be 6 // RAM consistency sub-relation 1 + 6, // could be 5 // RAM consistency sub-relation 2 + 6 // could be 5 // RAM consistency sub-relation 3 + }; + + static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ 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 + 0, // ROM consistency sub-relation 1 + 0, // ROM consistency sub-relation 2 + 3, // RAM consistency sub-relation 1 + 0, // RAM consistency sub-relation 2 + 2 // RAM consistency sub-relation 3 }; /** @@ -88,6 +97,7 @@ template class AuxiliaryRelationImpl { /** * Non native field arithmetic gate 2 + * deg 4 * * _ _ * / _ _ _ 14 \ @@ -116,6 +126,8 @@ template class AuxiliaryRelationImpl { auto non_native_field_identity = non_native_field_gate_1 + non_native_field_gate_2 + non_native_field_gate_3; non_native_field_identity *= q_2; + // ((((w2' * 2^14 + w1') * 2^14 + w3) * 2^14 + w2) * 2^14 + w1 - w4) * qm + // deg 2 auto limb_accumulator_1 = w_2_shift * SUBLIMB_SHIFT; limb_accumulator_1 += w_1_shift; limb_accumulator_1 *= SUBLIMB_SHIFT; @@ -127,6 +139,8 @@ template class AuxiliaryRelationImpl { limb_accumulator_1 -= w_4; limb_accumulator_1 *= q_4; + // ((((w3' * 2^14 + w2') * 2^14 + w1') * 2^14 + w4) * 2^14 + w3 - w4') * qm + // deg 2 auto limb_accumulator_2 = w_3_shift * SUBLIMB_SHIFT; limb_accumulator_2 += w_2_shift; limb_accumulator_2 *= SUBLIMB_SHIFT; @@ -139,7 +153,7 @@ template class AuxiliaryRelationImpl { limb_accumulator_2 *= q_m; auto limb_accumulator_identity = limb_accumulator_1 + limb_accumulator_2; - limb_accumulator_identity *= q_3; + limb_accumulator_identity *= q_3; // deg 3 /** * MEMORY @@ -172,6 +186,11 @@ template class AuxiliaryRelationImpl { /** * Memory Record Check + * Partial degree: 1 + * Full degree: 4 + * WORKTODO: Full degree reducible using not powers of eta + * WORKTODO: this could (hence should?) be defined lower? + * * * A ROM/ROM access gate can be evaluated with the identity: * @@ -185,11 +204,13 @@ template class AuxiliaryRelationImpl { memory_record_check += w_1; memory_record_check *= eta; memory_record_check += q_c; - auto partial_record_check = memory_record_check; // used in RAM consistency check + auto partial_record_check = memory_record_check; // used in RAM consistency check; deg 1 or 4 memory_record_check = memory_record_check - w_4; /** * ROM Consistency Check + * Partial degree: 1 + * Full degree: 4 * * For every ROM read, a set equivalence check is applied between the record witnesses, and a second set of * records that are sorted. @@ -204,14 +225,14 @@ template class AuxiliaryRelationImpl { auto index_delta = w_1_shift - w_1; auto record_delta = w_4_shift - w_4; - auto index_is_monotonically_increasing = index_delta * index_delta - index_delta; + auto index_is_monotonically_increasing = index_delta * index_delta - index_delta; // 2 - auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta; + auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta; // 2 std::get<1>(accumulators) += - adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2) * (q_aux * scaling_factor); - std::get<2>(accumulators) += index_is_monotonically_increasing * (q_1 * q_2) * (q_aux * scaling_factor); - auto ROM_consistency_check_identity = memory_record_check * (q_1 * q_2); + adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2) * (q_aux * scaling_factor); // 5 + std::get<2>(accumulators) += index_is_monotonically_increasing * (q_1 * q_2) * (q_aux * scaling_factor); // 5 + auto ROM_consistency_check_identity = memory_record_check * (q_1 * q_2); // 3 or 7 /** * RAM Consistency Check @@ -231,10 +252,13 @@ template class AuxiliaryRelationImpl { * N.B. it is the responsibility of the circuit writer to ensure that every RAM cell is initialized * with a WRITE operation. */ - auto access_type = (w_4 - partial_record_check); // will be 0 or 1 for honest Prover - auto access_check = access_type * access_type - access_type; // check value is 0 or 1 + auto access_type = (w_4 - partial_record_check); // will be 0 or 1 for honest Prover; deg 1 or 4 + auto access_check = access_type * access_type - access_type; // check value is 0 or 1; deg 2 or 8 + // WORKTODO: make issue // TODO: oof nasty compute here. If we sorted in reverse order we could re-use `partial_record_check` + // 1 - ((w3' * eta + w2') * eta + w1') * eta + // deg 1 or 4 auto next_gate_access_type = w_3_shift * eta; next_gate_access_type += w_2_shift; next_gate_access_type *= eta; @@ -244,22 +268,23 @@ template class AuxiliaryRelationImpl { auto value_delta = w_3_shift - w_3; auto adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation = - (index_delta * FF(-1) + FF(1)) * value_delta * (next_gate_access_type * FF(-1) + FF(1)); + (index_delta * FF(-1) + FF(1)) * value_delta * (next_gate_access_type * FF(-1) + FF(1)); // deg 3 or 6 // We can't apply the RAM consistency check identity on the final entry in the sorted list (the wires in the - // next gate would make the identity fail). - // We need to validate that its 'access type' bool is correct. Can't do - // with an arithmetic gate because of the `eta` factors. We need to check that the *next* gate's access type is - // correct, to cover this edge case + // next gate would make the identity fail). We need to validate that its 'access type' bool is correct. Can't + // do with an arithmetic gate because of the `eta` factors. We need to check that the *next* gate's access + // type is correct, to cover this edge case + // deg 2 or 4 auto next_gate_access_type_is_boolean = next_gate_access_type * next_gate_access_type - next_gate_access_type; // Putting it all together... std::get<3>(accumulators) += adjacent_values_match_if_adjacent_indices_match_and_next_access_is_a_read_operation * (q_arith) * - (q_aux * scaling_factor); - std::get<4>(accumulators) += index_is_monotonically_increasing * (q_arith) * (q_aux * scaling_factor); - std::get<5>(accumulators) += next_gate_access_type_is_boolean * (q_arith) * (q_aux * scaling_factor); - auto RAM_consistency_check_identity = access_check * (q_arith); + (q_aux * scaling_factor); // deg 5 or 8 + std::get<4>(accumulators) += index_is_monotonically_increasing * (q_arith) * (q_aux * scaling_factor); // deg 4 + std::get<5>(accumulators) += + next_gate_access_type_is_boolean * (q_arith) * (q_aux * scaling_factor); // deg 4 or 6 + auto RAM_consistency_check_identity = access_check * (q_arith); // deg 3 or 9 /** * RAM Timestamp Consistency Check @@ -273,19 +298,20 @@ template class AuxiliaryRelationImpl { * Else timestamp_check = 0 */ auto timestamp_delta = w_2_shift - w_2; - auto RAM_timestamp_check_identity = (index_delta * FF(-1) + FF(1)) * timestamp_delta - w_3; + auto RAM_timestamp_check_identity = (index_delta * FF(-1) + FF(1)) * timestamp_delta - w_3; // deg 3 /** * The complete RAM/ROM memory identity - * + * Partial degree: */ - auto memory_identity = ROM_consistency_check_identity; - memory_identity += RAM_timestamp_check_identity * (q_4 * q_1); - memory_identity += memory_record_check * (q_m * q_1); - memory_identity += RAM_consistency_check_identity; + auto memory_identity = ROM_consistency_check_identity; // 3 or 6 + memory_identity += RAM_timestamp_check_identity * (q_4 * q_1); // 4 + memory_identity += memory_record_check * (q_m * q_1); // 3 or 6 + memory_identity += RAM_consistency_check_identity; // 3 or 9 + // (deg 3 or 9) + (deg 4) + (deg 3) auto auxiliary_identity = memory_identity + non_native_field_identity + limb_accumulator_identity; - auxiliary_identity *= (q_aux * scaling_factor); + auxiliary_identity *= (q_aux * scaling_factor); // deg 4 or 10 std::get<0>(accumulators) += auxiliary_identity; }; }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index 267a8b430a0..5ad60d94a4d 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -27,6 +27,10 @@ template class LookupRelationImpl { 3 // left-shiftable polynomial sub-relation }; + static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ + 6, // grand product construction sub-relation + 0 // left-shiftable polynomial sub-relation + }; /** * @brief Get the grand product polynomial object (either from the proving key or AllEntities depending on context) * @@ -94,19 +98,23 @@ template class LookupRelationImpl { auto q_lookup = View(in.q_lookup); // (w_1 + q_2*w_1_shift) + η(w_2 + q_m*w_2_shift) + η²(w_3 + q_c*w_3_shift) + η³q_index. + // deg 2 or 4 auto wire_accum = (w_1 + column_1_step_size * w_1_shift) + (w_2 + column_2_step_size * w_2_shift) * eta + (w_3 + column_3_step_size * w_3_shift) * eta_sqr + table_index * eta_cube; // t_1 + ηt_2 + η²t_3 + η³t_4 + // deg 1 or 4 auto table_accum = table_1 + table_2 * eta + table_3 * eta_sqr + table_4 * eta_cube; + // t_1_shift + ηt_2_shift + η²t_3_shift + η³t_4_shift + // deg 4 auto table_accum_shift = table_1_shift + table_2_shift * eta + table_3_shift * eta_sqr + table_4_shift * eta_cube; - auto tmp = (q_lookup * wire_accum + gamma); - tmp *= (table_accum + table_accum_shift * beta + gamma_by_one_plus_beta); - tmp *= one_plus_beta; - return tmp; + auto tmp = (q_lookup * wire_accum + gamma); // deg 2 or 4 + tmp *= (table_accum + table_accum_shift * beta + gamma_by_one_plus_beta); // 1 or 5 + tmp *= one_plus_beta; // deg 1 + return tmp; // deg 4 or 10 } /** @@ -130,13 +138,13 @@ template class LookupRelationImpl { const auto& gamma = ParameterView(params.gamma); const auto one_plus_beta = beta + FF(1); - const auto gamma_by_one_plus_beta = gamma * one_plus_beta; + const auto gamma_by_one_plus_beta = gamma * one_plus_beta; // deg 0 or 2 // Contribution (1) auto s_accum = View(in.sorted_accum); auto s_accum_shift = View(in.sorted_accum_shift); - auto tmp = (s_accum + s_accum_shift * beta + gamma_by_one_plus_beta); + auto tmp = (s_accum + s_accum_shift * beta + gamma_by_one_plus_beta); // 1 or 2 return tmp; } @@ -178,9 +186,10 @@ template class LookupRelationImpl { auto lagrange_first = View(in.lagrange_first); auto lagrange_last = View(in.lagrange_last); - const auto lhs = compute_grand_product_numerator(in, params); - const auto rhs = compute_grand_product_denominator(in, params); + const auto lhs = compute_grand_product_numerator(in, params); // deg 4 or 10 + const auto rhs = compute_grand_product_denominator(in, params); // deg 1 or 2 + // (deg 5 or 11) - (deg 3 or 5) const auto tmp = lhs * (z_lookup + lagrange_first) - rhs * (z_lookup_shift + lagrange_last * grand_product_delta); std::get<0>(accumulators) += tmp * scaling_factor; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index 58e7e3c29a6..dc873ee0f83 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -12,6 +12,11 @@ template class UltraPermutationRelationImpl { 3 // left-shiftable polynomial sub-relation }; + static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ + 5, // grand product construction sub-relation + 0 // left-shiftable polynomial sub-relation + }; + inline static auto& get_grand_product_polynomial(auto& in) { return in.z_perm; } inline static auto& get_shifted_grand_product_polynomial(auto& in) { return in.z_perm_shift; } @@ -33,6 +38,7 @@ template class UltraPermutationRelationImpl { const auto& beta = ParameterView(params.beta); const auto& gamma = ParameterView(params.gamma); + // witness degree 4; fully degree 8 return (w_1 + id_1 * beta + gamma) * (w_2 + id_2 * beta + gamma) * (w_3 + id_3 * beta + gamma) * (w_4 + id_4 * beta + gamma); } @@ -56,6 +62,7 @@ template class UltraPermutationRelationImpl { const auto& beta = ParameterView(params.beta); const auto& gamma = ParameterView(params.gamma); + // witness degree 4; fully degree 8 return (w_1 + sigma_1 * beta + gamma) * (w_2 + sigma_2 * beta + gamma) * (w_3 + sigma_3 * beta + gamma) * (w_4 + sigma_4 * beta + gamma); } @@ -88,6 +95,8 @@ template class UltraPermutationRelationImpl { const auto lagrange_first = View(in.lagrange_first); const auto lagrange_last = View(in.lagrange_last); + // witness degree: deg 5 - deg 5 = deg 5 + // total degree: deg 9 - deg 10 = deg 10 std::get<0>(accumulators) += (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - ((z_perm_shift + lagrange_last * public_input_delta) * 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 92b25e2eaad..a924f9b296d 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -16,6 +16,7 @@ namespace proof_system { * type, do nothing, otherwise apply the provided view type. * @tparam Params * @tparam View + * @todo WORKTODO: make sure this is zero-cost in the IsField case. */ template using GetParameterView = std::conditional_t, typename Params::DataType, View>; From ee83443ffc4e61a7985a79355a6cf8600382d57f Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 00:07:17 +0000 Subject: [PATCH 11/32] Compile with full degrees; IOU tests --- .../barretenberg/honk/flavor/goblin_ultra.hpp | 4 +- .../src/barretenberg/honk/flavor/ultra.hpp | 4 +- .../honk/proof_system/combiner.test.cpp | 38 +++++----- .../honk/proof_system/protogalaxy_prover.hpp | 6 +- .../proof_system/flavor/flavor.hpp | 15 ++++ .../relations/auxiliary_relation.hpp | 64 +++++++++++------ .../proof_system/relations/relation_types.hpp | 72 +++++++++++++------ 7 files changed, 137 insertions(+), 66 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index ccdf63b7915..7b5ce59196a 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -52,11 +52,13 @@ class GoblinUltra { proof_system::EccOpQueueRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t MAX_FULL_RELATION_LENGTH = get_max_full_relation_length(); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1; - static constexpr size_t NUM_RELATIONS = std::tuple_size::value; + static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_FULL_RELATION_LENGTH + 1; + static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template using ProtogalaxyTupleOfTuplesOfUnivariates = diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 3330929fa8f..c5e457a6780 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -54,11 +54,13 @@ class Ultra { proof_system::AuxiliaryRelation>; static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t MAX_FULL_RELATION_LENGTH = get_max_full_relation_length(); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1; - static constexpr size_t NUM_RELATIONS = std::tuple_size::value; + static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_FULL_RELATION_LENGTH + 1; + static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template using ProtogalaxyTupleOfTuplesOfUnivariates = diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp index fedd7757925..426dfdf223b 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp @@ -50,17 +50,17 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; - auto result = prover.compute_combiner(instances, pow_univariate, alpha); - auto expected_result = - barretenberg::Univariate(std::array{ 87706, - 27289140, - 229355214, - 905031784, - static_cast(2504059650), - static_cast(5627174556), - static_cast(11026107190) }); - - EXPECT_EQ(result, expected_result); + [[maybe_unused]] auto result = prover.compute_combiner(instances, pow_univariate, alpha); + // auto expected_result = + // barretenberg::Univariate(std::array{ 87706, + // 27289140, + // 229355214, + // 905031784, + // static_cast(2504059650), + // static_cast(5627174556), + // static_cast(11026107190) }); + + // EXPECT_EQ(result, expected_result); } else { std::vector> instance_data(NUM_INSTANCES); std::array, NUM_INSTANCES> storage_arrays; @@ -124,9 +124,9 @@ TEST(Protogalaxy, CombinerOn2Instances) relation value: 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ - auto result = prover.compute_combiner(instances, pow_univariate, alpha); - auto expected_result = barretenberg::Univariate(std::array{ 0, 0, 36, 144, 360, 720, 1260 }); - EXPECT_EQ(result, expected_result); + [[maybe_unused]] auto result = prover.compute_combiner(instances, pow_univariate, alpha); + // auto expected_result = barretenberg::Univariate(std::array{ 0, 0, 36, 144, 360, 720, 1260 + // }); EXPECT_EQ(result, expected_result); } }; run_test(true); @@ -174,11 +174,11 @@ TEST(Protogalaxy, CombinerOn4Instances) zero_all_selectors(instances[2]->prover_polynomials); zero_all_selectors(instances[3]->prover_polynomials); - auto result = prover.compute_combiner(instances, pow_univariate, alpha); - std::array zeroes; - std::fill(zeroes.begin(), zeroes.end(), 0); - auto expected_result = barretenberg::Univariate(zeroes); - EXPECT_EQ(result, expected_result); + [[maybe_unused]] auto result = prover.compute_combiner(instances, pow_univariate, alpha); + // std::array zeroes; + // std::fill(zeroes.begin(), zeroes.end(), 0); + // auto expected_result = barretenberg::Univariate(zeroes); + // EXPECT_EQ(result, expected_result); }; run_test(); }; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index aefbfa271c4..14da51fadee 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -22,11 +22,13 @@ template class ProtoGalaxyProver_ { using RowEvaluations = typename Flavor::AllValues; using ProverPolynomials = typename Flavor::ProverPolynomials; using Relations = typename Flavor::Relations; + using BaseUnivariate = Univariate; - using ExtendedUnivariate = Univariate; + using ExtendedUnivariate = Univariate; using RandomExtendedUnivariate = - Univariate; + Univariate; using ExtendedUnivariates = typename Flavor::template ProverUnivariates; + using TupleOfTuplesOfUnivariates = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; using RelationEvaluations = typename Flavor::TupleOfArraysOfValues; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 9db88b2c41f..2b2b11fad08 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -216,6 +216,21 @@ template static constexpr size_t get_max } } +/** + * @brief Recursive utility function to find max RELATION_LENGTH over tuple of Relations + * + */ +template static constexpr size_t get_max_full_relation_length() +{ + if constexpr (Index >= std::tuple_size::value) { + return 0; // Return 0 when reach end of the tuple + } else { + constexpr size_t current_length = std::tuple_element::type::FULL_RELATION_LENGTH; + constexpr size_t next_length = get_max_full_relation_length(); + return (current_length > next_length) ? current_length : next_length; + } +} + /** * @brief Recursive utility function to construct a container for the subrelation accumulators of Protogalaxy folding. * @details The size of the outer tuple is equal to the number of relations. Each relation contributes an inner tuple of 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 93d66a08a52..075686f572b 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -7,23 +7,46 @@ namespace proof_system { template class AuxiliaryRelationImpl { public: using FF = FF_; + /* + * TODO(https://github.com/AztecProtocol/barretenberg/issues/757): Investigate optimizations. + * It seems that we could have: + * static constexpr std::array SUBRELATION_LENGTHS{ + * 5 // auxiliary sub-relation; + * 6 // ROM consistency sub-relation 1 + * 6 // ROM consistency sub-relation 2 + * 6 // RAM consistency sub-relation 1 + * 5 // RAM consistency sub-relation 2 + * 5 // RAM consistency sub-relation 3 + * }; + * + * and + * + * static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ + * 6, // auxiliary sub-relation + * 0, // ROM consistency sub-relation 1 + * 0, // ROM consistency sub-relation 2 + * 3, // RAM consistency sub-relation 1 + * 0, // RAM consistency sub-relation 2 + * 1 // RAM consistency sub-relation 3 + * }; + */ static constexpr std::array SUBRELATION_LENGTHS{ - 6, // could be 5 // auxiliary sub-relation; - 6, // could be 6 // ROM consistency sub-relation 1 - 6, // could be 6 // ROM consistency sub-relation 2 - 6, // could be 6 // RAM consistency sub-relation 1 - 6, // could be 5 // RAM consistency sub-relation 2 - 6 // could be 5 // RAM consistency sub-relation 3 + 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 std::array PARAMETER_LENGTH_ADJUSTMENTS{ 6, // auxiliary sub-relation - 0, // ROM consistency sub-relation 1 - 0, // ROM consistency sub-relation 2 - 3, // RAM consistency sub-relation 1 - 0, // RAM consistency sub-relation 2 - 2 // RAM consistency sub-relation 3 + 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 }; /** @@ -225,14 +248,15 @@ template class AuxiliaryRelationImpl { auto index_delta = w_1_shift - w_1; auto record_delta = w_4_shift - w_4; - auto index_is_monotonically_increasing = index_delta * index_delta - index_delta; // 2 + auto index_is_monotonically_increasing = index_delta * index_delta - index_delta; // deg 2 - auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta; // 2 + auto adjacent_values_match_if_adjacent_indices_match = (index_delta * FF(-1) + FF(1)) * record_delta; // deg 2 std::get<1>(accumulators) += - adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2) * (q_aux * scaling_factor); // 5 - std::get<2>(accumulators) += index_is_monotonically_increasing * (q_1 * q_2) * (q_aux * scaling_factor); // 5 - auto ROM_consistency_check_identity = memory_record_check * (q_1 * q_2); // 3 or 7 + adjacent_values_match_if_adjacent_indices_match * (q_1 * q_2) * (q_aux * scaling_factor); // deg 5 + std::get<2>(accumulators) += + index_is_monotonically_increasing * (q_1 * q_2) * (q_aux * scaling_factor); // deg 5 + auto ROM_consistency_check_identity = memory_record_check * (q_1 * q_2); // deg 3 or 7 /** * RAM Consistency Check @@ -304,10 +328,10 @@ template class AuxiliaryRelationImpl { * The complete RAM/ROM memory identity * Partial degree: */ - auto memory_identity = ROM_consistency_check_identity; // 3 or 6 - memory_identity += RAM_timestamp_check_identity * (q_4 * q_1); // 4 - memory_identity += memory_record_check * (q_m * q_1); // 3 or 6 - memory_identity += RAM_consistency_check_identity; // 3 or 9 + auto memory_identity = ROM_consistency_check_identity; // deg 3 or 6 + memory_identity += RAM_timestamp_check_identity * (q_4 * q_1); // deg 4 + memory_identity += memory_record_check * (q_m * q_1); // deg 3 or 6 + memory_identity += RAM_consistency_check_identity; // deg 3 or 9 // (deg 3 or 9) + (deg 4) + (deg 3) auto auxiliary_identity = memory_identity + non_native_field_identity + limb_accumulator_identity; 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 a924f9b296d..11423a4cde9 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -28,13 +28,16 @@ concept HasSubrelationLinearlyIndependentMember = requires(T) { } -> std::convertible_to; }; +template +concept HasParameterLengthAdjustmentsMember = requires { T::PARAMETER_LENGTH_ADJUSTMENTS; }; + /** * @brief Check whether a given subrelation is linearly independent from the other subrelations. * - * @details More often than not, we want multiply each subrelation contribution by a power of the relation separator - * challenge. In cases where we wish to define a subrelation that merges into another, we encode this in a boolean array - * `SUBRELATION_LINEARLY_INDEPENDENT` in the relation. If no such array is defined, then the default case where all - * subrelations are independent is engaged. + * @details More often than not, we want multiply each subrelation contribution by a power of the relation + * separator challenge. In cases where we wish to define a subrelation that merges into another, we encode this + * in a boolean array `SUBRELATION_LINEARLY_INDEPENDENT` in the relation. If no such array is defined, then the + * default case where all subrelations are independent is engaged. */ template constexpr bool subrelation_is_linearly_independent() { @@ -45,19 +48,34 @@ template constexpr bool subrelatio } } +template +consteval std::array compute_full_subrelation_lengths() +{ + if constexpr (HasParameterLengthAdjustmentsMember) { + constexpr size_t NUM_SUBRELATIONS = RelationImpl::SUBRELATION_LENGTHS.size(); + std::array result; + for (size_t idx = 0; idx < NUM_SUBRELATIONS; idx++) { + result[idx] = RelationImpl::SUBRELATION_LENGTHS[idx] + RelationImpl::PARAMETER_LENGTH_ADJUSTMENTS[idx]; + } + return result; + } else { + return RelationImpl::SUBRELATION_LENGTHS; + } +}; + /** * @brief Get the subrelation accumulators for the Protogalaxy combiner calculation. - * @details A subrelation of degree D, when evaluated on polynomials of degree N, gives a polynomial of degree D * - * N. In the context of Protogalaxy, N = NUM_INSTANCES-1. Hence, given a subrelation of length x, its evaluation on - * such polynomials will have degree (x-1) * (NUM_INSTANCES-1), and the length of this evaluation will be one - * greater than this. + * @details A subrelation of degree D, when evaluated on polynomials of degree N, gives a polynomial of degree D + * * N. In the context of Protogalaxy, N = NUM_INSTANCES-1. Hence, given a subrelation of length x, its + * evaluation on such polynomials will have degree (x-1) * (NUM_INSTANCES-1), and the length of this evaluation + * will be one greater than this. * @tparam NUM_INSTANCES * @tparam NUM_SUBRELATIONS * @param subrelation_lengths The array of subrelation lengths supplied by a relation. * @return The transformed subrelation lenths */ template -consteval std::array get_composed_subrelation_lengths( +consteval std::array compute_composed_subrelation_lengths( std::array subrelation_lengths) { std::transform(subrelation_lengths.begin(), @@ -68,26 +86,28 @@ consteval std::array get_composed_subrelation_lengths( }; /** - * @brief The templates defined herein facilitate sharing the relation arithmetic between the prover and the verifier. + * @brief The templates defined herein facilitate sharing the relation arithmetic between the prover and the + * verifier. * - * The sumcheck prover and verifier accumulate the contributions from each relation (really, each sub-relation) into, - * respectively, Univariates and individual field elements. When performing relation arithmetic on Univariates, we - * introduce UnivariateViews to reduce full length Univariates to the minimum required length and to avoid unnecessary - * copies. + * The sumcheck prover and verifier accumulate the contributions from each relation (really, each sub-relation) + * into, respectively, Univariates and individual field elements. When performing relation arithmetic on + * Univariates, we introduce UnivariateViews to reduce full length Univariates to the minimum required length + * and to avoid unnecessary copies. * * To share the relation arithmetic, we introduce simple structs that specify two types: Accumulators and - * AccumulatorViews. For the prover, who accumulates Univariates, these are respectively std::tuple and - * std::tuple. For the verifier, who accumulates FFs, both types are simply aliases for std::array - * (since no "view" type is necessary). The containers std::tuple and std::array are needed to accommodate multiple - * sub-relations within each relation, where, for efficiency, each sub-relation has its own specified degree. + * AccumulatorViews. For the prover, who accumulates Univariates, these are respectively std::tuple + * and std::tuple. For the verifier, who accumulates FFs, both types are simply aliases for + * std::array (since no "view" type is necessary). The containers std::tuple and std::array are needed to + * accommodate multiple sub-relations within each relation, where, for efficiency, each sub-relation has its own + * specified degree. * * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/720) * */ /** - * @brief A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribution of - * a given relation to the corresponding accumulator. + * @brief A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the + * contribution of a given relation to the corresponding accumulator. * * @tparam FF * @tparam RelationImpl Base class that implements the arithmetic for a given relation (or set of sub-relations) @@ -96,18 +116,24 @@ template class Relation : public RelationImpl { public: using FF = typename RelationImpl::FF; + static constexpr std::array FULL_SUBRELATION_LENGTHS = + compute_full_subrelation_lengths(); + static constexpr size_t RELATION_LENGTH = *std::max_element(RelationImpl::SUBRELATION_LENGTHS.begin(), RelationImpl::SUBRELATION_LENGTHS.end()); + static constexpr size_t FULL_RELATION_LENGTH = + *std::max_element(FULL_SUBRELATION_LENGTHS.begin(), FULL_SUBRELATION_LENGTHS.end()); + template using ProtogalaxyTupleOfUnivariatesOverSubrelations = - TupleOfUnivariates(RelationImpl::SUBRELATION_LENGTHS)>; + TupleOfUnivariates(FULL_SUBRELATION_LENGTHS)>; using SumcheckTupleOfUnivariatesOverSubrelations = TupleOfUnivariates; using SumcheckArrayOfValuesOverSubrelations = ArrayOfValues; - // These are commonly needed, most importantly, for explicitly instantiating compute_foo_numerator/denomintor. + // These are commonly needed, most importantly, for explicitly instantiating + // compute_foo_numerator/denomintor. using UnivariateAccumulator0 = std::tuple_element_t<0, SumcheckTupleOfUnivariatesOverSubrelations>; using ValueAccumulator0 = std::tuple_element_t<0, SumcheckArrayOfValuesOverSubrelations>; }; - } // namespace proof_system From f08793696482a4c127f500a6f8cede10ba3aefdd Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 00:18:33 +0000 Subject: [PATCH 12/32] Update two tests. --- .../src/barretenberg/honk/flavor/ultra.hpp | 2 ++ .../honk/proof_system/combiner.test.cpp | 35 +++++++++++-------- .../honk/proof_system/combiner_example_gen.py | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index c5e457a6780..6ee6ab06d30 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -55,6 +55,8 @@ class Ultra { static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); static constexpr size_t MAX_FULL_RELATION_LENGTH = get_max_full_relation_length(); + static_assert(MAX_RELATION_LENGTH == 6); + static_assert(MAX_FULL_RELATION_LENGTH == 12); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp index 426dfdf223b..a5f9b2f19a3 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp @@ -51,16 +51,21 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; [[maybe_unused]] auto result = prover.compute_combiner(instances, pow_univariate, alpha); - // auto expected_result = - // barretenberg::Univariate(std::array{ 87706, - // 27289140, - // 229355214, - // 905031784, - // static_cast(2504059650), - // static_cast(5627174556), - // static_cast(11026107190) }); - - // EXPECT_EQ(result, expected_result); + auto expected_result = + barretenberg::Univariate(std::array{ 87706, + 27289140, + 229355214, + 905031784, + static_cast(2504059650), + static_cast(5627174556), + static_cast(11026107190), + static_cast(19603583184), + static_cast(32413323114), + static_cast(50660042500), + static_cast(75699451806), + static_cast(109038256440), + static_cast(152334156754) }); + EXPECT_EQ(result, expected_result); } else { std::vector> instance_data(NUM_INSTANCES); std::array, NUM_INSTANCES> storage_arrays; @@ -174,11 +179,11 @@ TEST(Protogalaxy, CombinerOn4Instances) zero_all_selectors(instances[2]->prover_polynomials); zero_all_selectors(instances[3]->prover_polynomials); - [[maybe_unused]] auto result = prover.compute_combiner(instances, pow_univariate, alpha); - // std::array zeroes; - // std::fill(zeroes.begin(), zeroes.end(), 0); - // auto expected_result = barretenberg::Univariate(zeroes); - // EXPECT_EQ(result, expected_result); + auto result = prover.compute_combiner(instances, pow_univariate, alpha); + std::array zeroes; + std::fill(zeroes.begin(), zeroes.end(), 0); + auto expected_result = barretenberg::Univariate(zeroes); + EXPECT_EQ(result, expected_result); }; run_test(); }; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py index 2c37304ae97..9ca59ccfa44 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py @@ -3,7 +3,7 @@ # np.set_printoptions(formatter={'int': hex}) -EXTENDED_RELATION_LENGTH = 7 +EXTENDED_RELATION_LENGTH = 13 class Row: def __init__(self, start): From 709259381c6e67cbbcbc02201426424e64a843ab Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 00:26:56 +0000 Subject: [PATCH 13/32] Update final test. --- .../honk/proof_system/combiner.test.cpp | 7 ++-- .../honk/proof_system/combiner_example_gen.py | 33 ++++++++++--------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp index a5f9b2f19a3..7e6417949f2 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp @@ -129,9 +129,10 @@ TEST(Protogalaxy, CombinerOn2Instances) relation value: 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ - [[maybe_unused]] auto result = prover.compute_combiner(instances, pow_univariate, alpha); - // auto expected_result = barretenberg::Univariate(std::array{ 0, 0, 36, 144, 360, 720, 1260 - // }); EXPECT_EQ(result, expected_result); + auto result = prover.compute_combiner(instances, pow_univariate, alpha); + auto expected_result = barretenberg::Univariate( + std::array{ 0, 0, 36, 144, 360, 720, 1260, 2016, 3024, 4320, 5940, 7920, 10296 }); + EXPECT_EQ(result, expected_result); } }; run_test(true); diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py index 9ca59ccfa44..33b4329a301 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py @@ -110,25 +110,26 @@ def compute_first_example(): def compute_second_example(): result = 0 - w_l = np.array([ 1, 3, 5, 7, 9, 11, 13]) - w_r = np.array([ 2, 4, 6, 8, 10, 12, 14]) - w_o = np.array([ 3, 7, 11, 15, 19, 23, 27]) - q_m = np.array([ 0, 0, 0, 0, 0, 0, 0]) - q_l = np.array([ 1, 1, 1, 1, 1, 1, 1]) - q_r = np.array([ 1, 1, 1, 1, 1, 1, 1]) - q_o = np.array([-1, -1, -1, -1, -1, -1, -1]) - q_c = np.array([ 0, 0, 0, 0, 0, 0, 0]) + # 0 1 2 3 4 5 6 7 8 9 10 11 12 + w_l = np.array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) + w_r = np.array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]) + w_o = np.array([ 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51]) + q_m = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) + q_l = np.array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) + q_r = np.array([ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) + q_o = np.array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) + q_c = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) # contribution is zero, but why not? result += rel(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c) - w_l = np.array([ 0, 1, 2, 3, 4, 5, 6]) - w_r = np.array([ 4, 4, 4, 4, 4, 4, 4]) - w_o = np.array([ 4, 4, 4, 4, 4, 4, 4]) - q_m = np.array([ 0, 1, 2, 3, 4, 5, 6]) - q_l = np.array([ 1, 0, -1, -2, -3, -4, -5]) - q_r = np.array([ 1, 0, -1, -2, -3, -4, -5]) - q_o = np.array([-1, -1, -1, -1, -1, -1, -1]) - q_c = np.array([ 0, 0, 0, 0, 0, 0, 0]) + w_l = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) + w_r = np.array([ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) + w_o = np.array([ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]) + q_m = np.array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) + q_l = np.array([ 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9,-10,-11]) + q_r = np.array([ 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9,-10,-11]) + q_o = np.array([-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]) + q_c = np.array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) result += rel(w_l, w_r, w_o, q_m, q_l, q_r, q_o, q_c) result *= 2 From 093255fdcc193bc256ba08c477a8bddda9946bd4 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 05:46:39 +0000 Subject: [PATCH 14/32] Rename MAX_RELATION_LENGTH --- barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp | 6 +++--- .../cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp | 6 +++--- .../barretenberg/honk/flavor/goblin_ultra_recursive.hpp | 4 ++-- barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp | 8 ++++---- .../cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp | 4 ++-- .../cpp/src/barretenberg/honk/instance/instances.hpp | 2 +- .../cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp | 4 ++-- .../src/barretenberg/honk/transcript/transcript.test.cpp | 4 ++-- .../cpp/src/barretenberg/proof_system/flavor/flavor.hpp | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index 60d2124301e..cfb2618ee66 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -66,11 +66,11 @@ template class ECCVMBa sumcheck::ECCVMLookupRelation>; using LookupRelation = sumcheck::ECCVMLookupRelation; - static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1; + static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // Instantiate the BarycentricData needed to extend each Relation Univariate @@ -722,7 +722,7 @@ template class ECCVMBa /** * @brief A container for univariates produced during the hot loop in sumcheck. */ - using ExtendedEdges = ProverUnivariates; + using ExtendedEdges = ProverUnivariates; /** * @brief A container for the prover polynomials handles; only stores spans. diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 7b5ce59196a..ebd1937889d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -51,12 +51,12 @@ class GoblinUltra { proof_system::AuxiliaryRelation, proof_system::EccOpQueueRelation>; - static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); static constexpr size_t MAX_FULL_RELATION_LENGTH = get_max_full_relation_length(); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1; + static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_FULL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size_v; @@ -332,7 +332,7 @@ class GoblinUltra { /** * @brief A container for univariates produced during the hot loop in sumcheck. */ - using ExtendedEdges = ProverUnivariates; + using ExtendedEdges = ProverUnivariates; /** * @brief A field element for each entity of the flavor. These entities represent the prover polynomials evaluated 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 10f6202552f..d86c6f1de3d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp @@ -77,11 +77,11 @@ template class GoblinUltraRecursive_ { proof_system::AuxiliaryRelation, proof_system::EccOpQueueRelation>; - static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1; + static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 6ee6ab06d30..9c4fabd37a1 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -53,14 +53,14 @@ class Ultra { proof_system::EllipticRelation, proof_system::AuxiliaryRelation>; - static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); static constexpr size_t MAX_FULL_RELATION_LENGTH = get_max_full_relation_length(); - static_assert(MAX_RELATION_LENGTH == 6); + static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); static_assert(MAX_FULL_RELATION_LENGTH == 12); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1; + static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_FULL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size_v; @@ -331,7 +331,7 @@ class Ultra { /** * @brief A container for univariates produced during the hot loop in sumcheck. */ - using ExtendedEdges = ProverUnivariates; + using ExtendedEdges = ProverUnivariates; /** * @brief A container for commitment labels. diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 1343254525d..1e172b3f552 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -76,11 +76,11 @@ template class UltraRecursive_ { proof_system::EllipticRelation, proof_system::AuxiliaryRelation>; - static constexpr size_t MAX_RELATION_LENGTH = get_max_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_RELATION_LENGTH + 1; + static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index e92b3ff69ad..c8ac7594671 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -12,7 +12,7 @@ template struct ProverInstances_ { using ArrayType = std::array, NUM_>; // WORKTODO set this correctly or extract it - static constexpr size_t EXTENDED_LENGTH = Flavor::MAX_RELATION_LENGTH * NUM; + static constexpr size_t EXTENDED_LENGTH = Flavor::MAX_PARTIAL_RELATION_LENGTH * NUM; using RelationParameters = proof_system::RelationParameters>; ArrayType _data; diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 5cb37a7a6cd..3fdebc1f892 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -65,7 +65,7 @@ template class SumcheckProverRound { size_t round_size; // a power of 2 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_PARTIAL_RELATION_LENGTH = Flavor::MAX_PARTIAL_RELATION_LENGTH; static constexpr size_t MAX_RANDOM_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; SumcheckTupleOfTuplesOfUnivariates univariate_accumulators; @@ -93,7 +93,7 @@ template class SumcheckProverRound { size_t univariate_idx = 0; // TODO(https://github.com/AztecProtocol/barretenberg/issues/391) zip for (auto& poly : multivariates) { auto edge = barretenberg::Univariate({ poly[edge_idx], poly[edge_idx + 1] }); - extended_edges[univariate_idx] = edge.template extend_to(); + extended_edges[univariate_idx] = edge.template extend_to(); ++univariate_idx; } } diff --git a/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp index 3a0271bdd8d..84cecb61cf0 100644 --- a/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp @@ -32,10 +32,10 @@ class UltraTranscriptTests : public ::testing::Test { auto log_n = numeric::get_msb(circuit_size); - size_t max_relation_length = Flavor::MAX_RANDOM_RELATION_LENGTH; + size_t MAX_PARTIAL_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; size_t size_FF = sizeof(FF); size_t size_G = 2 * size_FF; - size_t size_uni = max_relation_length * size_FF; + size_t size_uni = MAX_PARTIAL_RELATION_LENGTH * size_FF; size_t size_evals = (Flavor::NUM_ALL_ENTITIES)*size_FF; size_t size_uint32 = 4; size_t size_uint64 = 8; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 2b2b11fad08..c9ef0f866f9 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -205,13 +205,13 @@ class AllEntities_ : public Entities_ { * @brief Recursive utility function to find max RELATION_LENGTH over tuple of Relations * */ -template static constexpr size_t get_max_relation_length() +template static constexpr size_t get_max_partial_relation_length() { if constexpr (Index >= std::tuple_size::value) { return 0; // Return 0 when reach end of the tuple } else { constexpr size_t current_length = std::tuple_element::type::RELATION_LENGTH; - constexpr size_t next_length = get_max_relation_length(); + constexpr size_t next_length = get_max_partial_relation_length(); return (current_length > next_length) ? current_length : next_length; } } From 83de9420cf4afe9dde6667b700f4bc7cd510a6e5 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 06:13:57 +0000 Subject: [PATCH 15/32] Stop detecting submodules! --- barretenberg/barretenberg.code-workspace | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/barretenberg.code-workspace b/barretenberg/barretenberg.code-workspace index 0995a1c0c9f..8cf62e8ae40 100644 --- a/barretenberg/barretenberg.code-workspace +++ b/barretenberg/barretenberg.code-workspace @@ -156,6 +156,7 @@ "-g" ], "cmake.useCMakePresets": "auto", - "editor.inlayHints.enabled": "offUnlessPressed" + "editor.inlayHints.enabled": "offUnlessPressed", + "git.detectSubmodules": false }, } \ No newline at end of file From dc775016bf37c4cf6afb58beabe7f9d55af7c4d7 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 06:43:49 +0000 Subject: [PATCH 16/32] Rename FULL to TOTAL --- .../cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp | 4 ++-- .../cpp/src/barretenberg/honk/flavor/ultra.hpp | 11 +++++------ .../honk/proof_system/protogalaxy_prover.hpp | 2 +- .../src/barretenberg/proof_system/flavor/flavor.hpp | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index ebd1937889d..048e4b8d22e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -52,12 +52,12 @@ class GoblinUltra { proof_system::EccOpQueueRelation>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - static constexpr size_t MAX_FULL_RELATION_LENGTH = get_max_full_relation_length(); + static constexpr size_t MAX_TOTAL_RELATION_LENGTH = get_max_total_relation_length(); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; - static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_FULL_RELATION_LENGTH + 1; + static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 9c4fabd37a1..aca75eeeaec 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -1,12 +1,11 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" -#include "barretenberg/polynomials/barycentric.hpp" -#include "barretenberg/polynomials/univariate.hpp" - #include "barretenberg/honk/transcript/transcript.hpp" +#include "barretenberg/polynomials/barycentric.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp" #include "barretenberg/proof_system/flavor/flavor.hpp" #include "barretenberg/proof_system/relations/auxiliary_relation.hpp" @@ -54,14 +53,14 @@ class Ultra { proof_system::AuxiliaryRelation>; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - static constexpr size_t MAX_FULL_RELATION_LENGTH = get_max_full_relation_length(); + static constexpr size_t MAX_TOTAL_RELATION_LENGTH = get_max_total_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); - static_assert(MAX_FULL_RELATION_LENGTH == 12); + static_assert(MAX_TOTAL_RELATION_LENGTH == 12); // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; - static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_FULL_RELATION_LENGTH + 1; + static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 14da51fadee..cb62353975e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -24,7 +24,7 @@ template class ProtoGalaxyProver_ { using Relations = typename Flavor::Relations; using BaseUnivariate = Univariate; - using ExtendedUnivariate = Univariate; + using ExtendedUnivariate = Univariate; using RandomExtendedUnivariate = Univariate; using ExtendedUnivariates = typename Flavor::template ProverUnivariates; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index c9ef0f866f9..291b8fda748 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -220,13 +220,13 @@ template static constexpr size_t get_max * @brief Recursive utility function to find max RELATION_LENGTH over tuple of Relations * */ -template static constexpr size_t get_max_full_relation_length() +template static constexpr size_t get_max_total_relation_length() { if constexpr (Index >= std::tuple_size::value) { return 0; // Return 0 when reach end of the tuple } else { constexpr size_t current_length = std::tuple_element::type::FULL_RELATION_LENGTH; - constexpr size_t next_length = get_max_full_relation_length(); + constexpr size_t next_length = get_max_total_relation_length(); return (current_length > next_length) ? current_length : next_length; } } From 0dac01d3b1305c32c0f9861b43329a4a5e262a0c Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 06:46:15 +0000 Subject: [PATCH 17/32] RANDOM to BATCHED --- .../cpp/src/barretenberg/honk/flavor/ecc_vm.hpp | 9 +++++---- .../src/barretenberg/honk/flavor/goblin_ultra.hpp | 9 +++++---- .../honk/flavor/goblin_ultra_recursive.hpp | 7 ++++--- .../cpp/src/barretenberg/honk/flavor/ultra.hpp | 9 +++++---- .../src/barretenberg/honk/flavor/ultra_recursive.hpp | 7 ++++--- .../honk/proof_system/protogalaxy_prover.hpp | 2 +- .../cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp | 4 ++-- .../barretenberg/honk/sumcheck/sumcheck_round.hpp | 12 ++++++------ .../barretenberg/honk/transcript/transcript.test.cpp | 2 +- 9 files changed, 33 insertions(+), 28 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index cfb2618ee66..8f792d86030 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -68,13 +68,14 @@ template class ECCVMBa using LookupRelation = sumcheck::ECCVMLookupRelation; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random - // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // Instantiate the BarycentricData needed to extend each Relation Univariate - // static_assert(instantiate_barycentric_utils()); + // static_assert(instantiate_barycentric_utils()); // define the containers for storing the contributions from each relation in Sumcheck using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 048e4b8d22e..869349bb945 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -54,10 +54,11 @@ class GoblinUltra { static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); static constexpr size_t MAX_TOTAL_RELATION_LENGTH = get_max_total_relation_length(); - // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random - // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; - static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1; + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + static constexpr size_t BATCHED_RELATION_TOTAL_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template 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 d86c6f1de3d..eff7f585829 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp @@ -79,9 +79,10 @@ template class GoblinUltraRecursive_ { static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random - // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index aca75eeeaec..c0e444e734c 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -57,10 +57,11 @@ class Ultra { static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); static_assert(MAX_TOTAL_RELATION_LENGTH == 12); - // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random - // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; - static constexpr size_t MAX_FULL_RANDOM_RELATION_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1; + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + static constexpr size_t BATCHED_RELATION_TOTAL_LENGTH = MAX_TOTAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 1e172b3f552..2a65d9df922 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -78,9 +78,10 @@ template class UltraRecursive_ { static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - // MAX_RANDOM_RELATION_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` random - // polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation length = 3 - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // define the container for storing the univariate contribution from each relation in Sumcheck diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index cb62353975e..781485bf2fd 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -26,7 +26,7 @@ template class ProtoGalaxyProver_ { using BaseUnivariate = Univariate; using ExtendedUnivariate = Univariate; using RandomExtendedUnivariate = - Univariate; + Univariate; using ExtendedUnivariates = typename Flavor::template ProverUnivariates; using TupleOfTuplesOfUnivariates = diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 78b01e9fcb3..c0e6e73eefd 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -168,7 +168,7 @@ template class SumcheckVerifier { using FF = typename Flavor::FF; using ClaimedEvaluations = typename Flavor::AllValues; - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH; static constexpr size_t NUM_POLYNOMIALS = Flavor::NUM_ALL_ENTITIES; const size_t multivariate_d; @@ -209,7 +209,7 @@ template class SumcheckVerifier { // Obtain the round univariate from the transcript std::string round_univariate_label = "Sumcheck:univariate_" + std::to_string(round_idx); auto round_univariate = - transcript.template receive_from_prover>( + transcript.template receive_from_prover>( round_univariate_label); bool checked = round.check_sum(round_univariate); diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp index 3fdebc1f892..e048c48fcbc 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck_round.hpp @@ -66,7 +66,7 @@ template class SumcheckProverRound { static constexpr size_t NUM_RELATIONS = Flavor::NUM_RELATIONS; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = Flavor::MAX_PARTIAL_RELATION_LENGTH; - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH; SumcheckTupleOfTuplesOfUnivariates univariate_accumulators; @@ -104,7 +104,7 @@ template class SumcheckProverRound { * univariate accumulators to be zero. */ template - barretenberg::Univariate compute_univariate( + barretenberg::Univariate compute_univariate( ProverPolynomialsOrPartiallyEvaluatedMultivariates& polynomials, const proof_system::RelationParameters& relation_parameters, const barretenberg::PowUnivariate& pow_univariate, @@ -165,7 +165,7 @@ template class SumcheckProverRound { Utils::add_nested_tuples(univariate_accumulators, accumulators); } // Batch the univariate contributions from each sub-relation to obtain the round univariate - return Utils::template batch_over_relations>( + return Utils::template batch_over_relations>( univariate_accumulators, alpha, pow_univariate); } @@ -215,7 +215,7 @@ template class SumcheckVerifierRound { bool round_failed = false; static constexpr size_t NUM_RELATIONS = Flavor::NUM_RELATIONS; - static constexpr size_t MAX_RANDOM_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH; FF target_total_sum = 0; @@ -224,7 +224,7 @@ template class SumcheckVerifierRound { // Verifier constructor explicit SumcheckVerifierRound() { Utils::zero_elements(relation_evaluations); }; - bool check_sum(barretenberg::Univariate& univariate) + bool check_sum(barretenberg::Univariate& univariate) { // S^{l}(0) = ( (1−0) + 0⋅ζ^{ 2^l } ) ⋅ T^{l}(0) = T^{l}(0) // S^{l}(1) = ( (1−1) + 1⋅ζ^{ 2^l } ) ⋅ T^{l}(1) = ζ^{ 2^l } ⋅ T^{l}(1) @@ -252,7 +252,7 @@ template class SumcheckVerifierRound { * @param round_challenge u_l * @return FF sigma_{l+1} = S^l(u_l) */ - FF compute_next_target_sum(barretenberg::Univariate& univariate, + FF compute_next_target_sum(barretenberg::Univariate& univariate, FF& round_challenge) { // Evaluate T^{l}(u_{l}) diff --git a/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp index 84cecb61cf0..246e11e92e1 100644 --- a/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/transcript/transcript.test.cpp @@ -32,7 +32,7 @@ class UltraTranscriptTests : public ::testing::Test { auto log_n = numeric::get_msb(circuit_size); - size_t MAX_PARTIAL_RELATION_LENGTH = Flavor::MAX_RANDOM_RELATION_LENGTH; + size_t MAX_PARTIAL_RELATION_LENGTH = Flavor::BATCHED_RELATION_PARTIAL_LENGTH; size_t size_FF = sizeof(FF); size_t size_G = 2 * size_FF; size_t size_uni = MAX_PARTIAL_RELATION_LENGTH * size_FF; From dacacf9f61bd8caf7fe6588342dfbc3f3555ca9b Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 21:18:07 +0000 Subject: [PATCH 18/32] Cleanup Pass --- .../cpp/src/barretenberg/honk/flavor/ecc_vm.hpp | 1 - .../cpp/src/barretenberg/honk/instance/instances.hpp | 6 +++++- .../barretenberg/honk/proof_system/combiner.test.cpp | 2 +- .../honk/proof_system/protogalaxy_prover.cpp | 1 + .../honk/proof_system/protogalaxy_prover.hpp | 10 +++++----- .../cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp | 2 +- .../src/barretenberg/proof_system/flavor/flavor.hpp | 4 ++-- .../proof_system/relations/auxiliary_relation.hpp | 3 --- .../proof_system/relations/lookup_relation.hpp | 2 ++ .../proof_system/relations/relation_types.hpp | 6 +++++- .../src/barretenberg/proof_system/relations/utils.hpp | 4 ++-- 11 files changed, 24 insertions(+), 17 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index 8f792d86030..caebccdbafa 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -75,7 +75,6 @@ template class ECCVMBa static constexpr size_t NUM_RELATIONS = std::tuple_size::value; // Instantiate the BarycentricData needed to extend each Relation Univariate - // static_assert(instantiate_barycentric_utils()); // define the containers for storing the contributions from each relation in Sumcheck using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index c8ac7594671..47799f16811 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -12,7 +12,7 @@ template struct ProverInstances_ { using ArrayType = std::array, NUM_>; // WORKTODO set this correctly or extract it - static constexpr size_t EXTENDED_LENGTH = Flavor::MAX_PARTIAL_RELATION_LENGTH * NUM; + static constexpr size_t EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1) * (NUM - 1) + 1; using RelationParameters = proof_system::RelationParameters>; ArrayType _data; @@ -30,6 +30,10 @@ template struct ProverInstances_ { } }; + /** + * @brief Create folded (univariate) relation parameters + * + */ void parameters_to_univariates() { auto params_to_fold = relation_parameters.to_fold; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp index 7e6417949f2..f469ec8863f 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner.test.cpp @@ -50,7 +50,7 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; - [[maybe_unused]] auto result = prover.compute_combiner(instances, pow_univariate, alpha); + auto result = prover.compute_combiner(instances, pow_univariate, alpha); auto expected_result = barretenberg::Univariate(std::array{ 87706, 27289140, diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp index 40a2302c935..bb7b90690f8 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp @@ -31,6 +31,7 @@ template void ProtoGalaxyProver_::prepa instance->compute_sorted_accumulator_polynomials(eta); instance->compute_grand_product_polynomials(beta, gamma); } + instances.parameters_to_univariates(); } diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 781485bf2fd..9c685a1c68e 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -25,7 +25,7 @@ template class ProtoGalaxyProver_ { using BaseUnivariate = Univariate; using ExtendedUnivariate = Univariate; - using RandomExtendedUnivariate = + using ExtendedUnivariateWithRandomization = Univariate; using ExtendedUnivariates = typename Flavor::template ProverUnivariates; @@ -216,9 +216,9 @@ template class ProtoGalaxyProver_ { * * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/754) Provide the right challenge to here */ - RandomExtendedUnivariate compute_combiner(const ProverInstances& instances, - const PowUnivariate& pow_univariate, - const typename Flavor::FF alpha) + ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances& instances, + const PowUnivariate& pow_univariate, + const typename Flavor::FF alpha) { size_t common_circuit_size = instances[0]->prover_polynomials._data[0].size(); // Precompute the vector of required powers of zeta @@ -274,7 +274,7 @@ template class ProtoGalaxyProver_ { Utils::add_nested_tuples(univariate_accumulators, accumulators); } // Batch the univariate contributions from each sub-relation to obtain the round univariate - return Utils::template batch_over_relations( + return Utils::template batch_over_relations( univariate_accumulators, alpha, pow_univariate); } }; diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index c0e6e73eefd..6774ac1c7bc 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -125,7 +125,7 @@ template class SumcheckProver { * @brief Compute univariate restriction place in transcript, generate challenge, partially evaluate,... repeat * until final round, then compute multivariate evaluations and place in transcript. * - * @details + * WORKTODO */ SumcheckOutput prove(std::shared_ptr instance) { diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 291b8fda748..3d4edab6165 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -217,7 +217,7 @@ template static constexpr size_t get_max } /** - * @brief Recursive utility function to find max RELATION_LENGTH over tuple of Relations + * @brief Recursive utility function to find max TOTAL_RELATION_LENGTH over tuple of Relations * */ template static constexpr size_t get_max_total_relation_length() @@ -225,7 +225,7 @@ template static constexpr size_t get_max if constexpr (Index >= std::tuple_size::value) { return 0; // Return 0 when reach end of the tuple } else { - constexpr size_t current_length = std::tuple_element::type::FULL_RELATION_LENGTH; + constexpr size_t current_length = std::tuple_element::type::TOTAL_RELATION_LENGTH; constexpr size_t next_length = get_max_total_relation_length(); return (current_length > next_length) ? current_length : next_length; } 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 075686f572b..e1d7b6f395e 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -211,9 +211,6 @@ template class AuxiliaryRelationImpl { * Memory Record Check * Partial degree: 1 * Full degree: 4 - * WORKTODO: Full degree reducible using not powers of eta - * WORKTODO: this could (hence should?) be defined lower? - * * * A ROM/ROM access gate can be evaluated with the identity: * diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index 5ad60d94a4d..a81ae5d06a1 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -22,11 +22,13 @@ template class LookupRelationImpl { public: using FF = FF_; + // WORKTODO: rename SUBRELATION_LENGTHS static constexpr std::array SUBRELATION_LENGTHS{ 6, // grand product construction sub-relation 3 // left-shiftable polynomial sub-relation }; + // WORKTODO: better name static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ 6, // grand product construction sub-relation 0 // left-shiftable polynomial sub-relation 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 11423a4cde9..16122c1d363 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -48,6 +48,10 @@ template constexpr bool subrelatio } } +/** + * @brief WORKTODO check Compute the full subrelation lenghths, i.e., the lengths when regarding the challenges as + * variables. + */ template consteval std::array compute_full_subrelation_lengths() { @@ -122,7 +126,7 @@ template class Relation : public RelationImpl { static constexpr size_t RELATION_LENGTH = *std::max_element(RelationImpl::SUBRELATION_LENGTHS.begin(), RelationImpl::SUBRELATION_LENGTHS.end()); - static constexpr size_t FULL_RELATION_LENGTH = + static constexpr size_t TOTAL_RELATION_LENGTH = *std::max_element(FULL_SUBRELATION_LENGTHS.begin(), FULL_SUBRELATION_LENGTHS.end()); template diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp index d818d1b3ccf..d4a0a9f5e4c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/utils.hpp @@ -121,8 +121,8 @@ template class RelationUtils { * @param tuple A tuple of tuples of Univariates * @param result A Univariate of length extended_size */ - template - static void extend_and_batch_univariates(const OfTuplesOfUnivariates& tuple, + template + static void extend_and_batch_univariates(const TupleOfTuplesOfUnivariates& tuple, const PowUnivariate& pow_univariate, ExtendedUnivariate& result) { From 2bbac89551ca03ed4d73032c989694111afff568 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 21:54:35 +0000 Subject: [PATCH 19/32] More smaller cleanup --- .../barretenberg/honk/instance/instances.hpp | 1 - .../honk/proof_system/combiner_example_gen.py | 2 +- .../relations/auxiliary_relation.hpp | 13 +++-- .../relations/ecc_op_queue_relation.hpp | 2 +- .../relations/ecc_vm/ecc_lookup_relation.hpp | 2 +- .../relations/ecc_vm/ecc_msm_relation.hpp | 5 +- .../ecc_vm/ecc_point_table_relation.hpp | 2 +- .../relations/ecc_vm/ecc_set_relation.hpp | 2 +- .../ecc_vm/ecc_transcript_relation.hpp | 2 +- .../relations/ecc_vm/ecc_wnaf_relation.hpp | 2 +- .../relations/elliptic_relation.hpp | 2 +- .../relations/gen_perm_sort_relation.hpp | 2 +- .../relations/lookup_relation.hpp | 6 +-- .../relations/permutation_relation.hpp | 4 +- .../proof_system/relations/relation_types.hpp | 53 ++++++++++--------- .../translator_decomposition_relation.hpp | 2 +- .../translator_extra_relations.hpp | 4 +- .../translator_gen_perm_sort_relation.hpp | 2 +- .../translator_non_native_field_relation.hpp | 2 +- .../translator_permutation_relation.hpp | 2 +- .../relations/ultra_arithmetic_relation.hpp | 2 +- 21 files changed, 58 insertions(+), 56 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index 47799f16811..89eceb075ec 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -11,7 +11,6 @@ template struct ProverInstances_ { using Instance = ProverInstance_; using ArrayType = std::array, NUM_>; - // WORKTODO set this correctly or extract it static constexpr size_t EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1) * (NUM - 1) + 1; using RelationParameters = proof_system::RelationParameters>; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py index 33b4329a301..352422cab19 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py @@ -1,4 +1,4 @@ -# WORKTODO: delete this +# TODO: delete this import numpy as np # np.set_printoptions(formatter={'int': hex}) 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 e1d7b6f395e..cdcc007a8ae 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -10,7 +10,7 @@ template class AuxiliaryRelationImpl { /* * TODO(https://github.com/AztecProtocol/barretenberg/issues/757): Investigate optimizations. * It seems that we could have: - * static constexpr std::array SUBRELATION_LENGTHS{ + * static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ * 5 // auxiliary sub-relation; * 6 // ROM consistency sub-relation 1 * 6 // ROM consistency sub-relation 2 @@ -21,7 +21,7 @@ template class AuxiliaryRelationImpl { * * and * - * static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ + * static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ * 6, // auxiliary sub-relation * 0, // ROM consistency sub-relation 1 * 0, // ROM consistency sub-relation 2 @@ -31,7 +31,7 @@ template class AuxiliaryRelationImpl { * }; */ - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, // auxiliary sub-relation; 6, // ROM consistency sub-relation 1 6, // ROM consistency sub-relation 2 @@ -40,7 +40,7 @@ template class AuxiliaryRelationImpl { 6 // RAM consistency sub-relation 3 }; - static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ + static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ 6, // auxiliary sub-relation 6, // ROM consistency sub-relation 1 6, // ROM consistency sub-relation 2 @@ -276,9 +276,8 @@ template class AuxiliaryRelationImpl { auto access_type = (w_4 - partial_record_check); // will be 0 or 1 for honest Prover; deg 1 or 4 auto access_check = access_type * access_type - access_type; // check value is 0 or 1; deg 2 or 8 - // WORKTODO: make issue - // TODO: oof nasty compute here. If we sorted in reverse order we could re-use `partial_record_check` - // 1 - ((w3' * eta + w2') * eta + w1') * eta + // TODO(https://github.com/AztecProtocol/barretenberg/issues/757): If we sorted in + // reverse order we could re-use `partial_record_check` 1 - ((w3' * eta + w2') * eta + w1') * eta // deg 1 or 4 auto next_gate_access_type = w_3_shift * eta; next_gate_access_type += w_2_shift; 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 5f7c9cb878f..ac6af95edaf 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 @@ -7,7 +7,7 @@ template class EccOpQueueRelationImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_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 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 6da47089b2c..a59d82936a3 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 @@ -17,7 +17,7 @@ template class ECCVMLookupRelationBase { // 1 + polynomial degree of this relation static constexpr size_t LENGTH = READ_TERMS + WRITE_TERMS + 3; // 9 - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ LENGTH, // grand product construction sub-relation LENGTH // left-shiftable polynomial sub-relation }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp index ce3fc6f72a1..93cd28d6de2 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_msm_relation.hpp @@ -38,8 +38,9 @@ template class ECCVMMSMRelationBase { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; template static void accumulate(ContainerOverSubrelations& accumulator, diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp index b67f2824f3c..ffef181cc71 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_point_table_relation.hpp @@ -19,7 +19,7 @@ template class ECCVMPointTableRelationBase { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ 6, 6, 6, 6, 6, 6 }; + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, 6, 6, 6, 6, 6 }; template static void accumulate(ContainerOverSubrelations& accumulator, diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp index f2c9c9ecea6..efa01b6e177 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_set_relation.hpp @@ -13,7 +13,7 @@ template class ECCVMSetRelationBase { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 19, // grand product construction sub-relation 19 // left-shiftable polynomial sub-relation }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp index a6b8f42cee5..2bee205554f 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_transcript_relation.hpp @@ -30,7 +30,7 @@ template class ECCVMTranscriptRelationBase { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp index 24d753a4c4b..73b3f08e814 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ecc_vm/ecc_wnaf_relation.hpp @@ -35,7 +35,7 @@ template class ECCVMWnafRelationBase { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp index 7f780986b6a..87d84c1330c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/elliptic_relation.hpp @@ -9,7 +9,7 @@ template class EllipticRelationImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, // x-coordinate sub-relation 6, // y-coordinate sub-relation }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp index b5704f48a53..c61dda3e2be 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/gen_perm_sort_relation.hpp @@ -7,7 +7,7 @@ template class GenPermSortRelationImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, // range constrain sub-relation 1 6, // range constrain sub-relation 2 6, // range constrain sub-relation 3 diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp index a81ae5d06a1..bd825b75d88 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/lookup_relation.hpp @@ -22,14 +22,12 @@ template class LookupRelationImpl { public: using FF = FF_; - // WORKTODO: rename SUBRELATION_LENGTHS - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, // grand product construction sub-relation 3 // left-shiftable polynomial sub-relation }; - // WORKTODO: better name - static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ + static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ 6, // grand product construction sub-relation 0 // left-shiftable polynomial sub-relation }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp index dc873ee0f83..8e4cdf1c107 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/permutation_relation.hpp @@ -7,12 +7,12 @@ template class UltraPermutationRelationImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, // grand product construction sub-relation 3 // left-shiftable polynomial sub-relation }; - static constexpr std::array PARAMETER_LENGTH_ADJUSTMENTS{ + static constexpr std::array TOTAL_LENGTH_ADJUSTMENTS{ 5, // grand product construction sub-relation 0 // left-shiftable polynomial sub-relation }; 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 16122c1d363..dfeb08b60c6 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -16,7 +16,7 @@ namespace proof_system { * type, do nothing, otherwise apply the provided view type. * @tparam Params * @tparam View - * @todo WORKTODO: make sure this is zero-cost in the IsField case. + * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/759): Optimize */ template using GetParameterView = std::conditional_t, typename Params::DataType, View>; @@ -29,7 +29,7 @@ concept HasSubrelationLinearlyIndependentMember = requires(T) { }; template -concept HasParameterLengthAdjustmentsMember = requires { T::PARAMETER_LENGTH_ADJUSTMENTS; }; +concept HasParameterLengthAdjustmentsMember = requires { T::TOTAL_LENGTH_ADJUSTMENTS; }; /** * @brief Check whether a given subrelation is linearly independent from the other subrelations. @@ -49,21 +49,21 @@ template constexpr bool subrelatio } /** - * @brief WORKTODO check Compute the full subrelation lenghths, i.e., the lengths when regarding the challenges as + * @brief Compute the full subrelation lenghhs, i.e., the lengths when regarding the challenges as * variables. */ template -consteval std::array compute_full_subrelation_lengths() +consteval std::array compute_full_subrelation_lengths() { if constexpr (HasParameterLengthAdjustmentsMember) { - constexpr size_t NUM_SUBRELATIONS = RelationImpl::SUBRELATION_LENGTHS.size(); + constexpr size_t NUM_SUBRELATIONS = RelationImpl::SUBRELATION_PARTIAL_LENGTHS.size(); std::array result; for (size_t idx = 0; idx < NUM_SUBRELATIONS; idx++) { - result[idx] = RelationImpl::SUBRELATION_LENGTHS[idx] + RelationImpl::PARAMETER_LENGTH_ADJUSTMENTS[idx]; + result[idx] = RelationImpl::SUBRELATION_PARTIAL_LENGTHS[idx] + RelationImpl::TOTAL_LENGTH_ADJUSTMENTS[idx]; } return result; } else { - return RelationImpl::SUBRELATION_LENGTHS; + return RelationImpl::SUBRELATION_PARTIAL_LENGTHS; } }; @@ -75,25 +75,25 @@ consteval std::array compute_f * will be one greater than this. * @tparam NUM_INSTANCES * @tparam NUM_SUBRELATIONS - * @param subrelation_lengths The array of subrelation lengths supplied by a relation. + * @param SUBRELATION_PARTIAL_LENGTHS The array of subrelation lengths supplied by a relation. * @return The transformed subrelation lenths */ template -consteval std::array compute_composed_subrelation_lengths( - std::array subrelation_lengths) +consteval std::array compute_composed_SUBRELATION_PARTIAL_LENGTHS( + std::array SUBRELATION_PARTIAL_LENGTHS) { - std::transform(subrelation_lengths.begin(), - subrelation_lengths.end(), - subrelation_lengths.begin(), + std::transform(SUBRELATION_PARTIAL_LENGTHS.begin(), + SUBRELATION_PARTIAL_LENGTHS.end(), + SUBRELATION_PARTIAL_LENGTHS.begin(), [](const size_t x) { return (x - 1) * (NUM_INSTANCES - 1) + 1; }); - return subrelation_lengths; + return SUBRELATION_PARTIAL_LENGTHS; }; /** * @brief The templates defined herein facilitate sharing the relation arithmetic between the prover and the * verifier. * - * The sumcheck prover and verifier accumulate the contributions from each relation (really, each sub-relation) + * @details The sumcheck prover and verifier accumulate the contributions from each relation (really, each sub-relation) * into, respectively, Univariates and individual field elements. When performing relation arithmetic on * Univariates, we introduce UnivariateViews to reduce full length Univariates to the minimum required length * and to avoid unnecessary copies. @@ -105,7 +105,9 @@ consteval std::array compute_composed_subrelation_leng * accommodate multiple sub-relations within each relation, where, for efficiency, each sub-relation has its own * specified degree. * - * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/720) + * @note We use some funny terminology: we use the term "length" for 1 + the degree of a relation. When the relation is + * regarded as a polynomial in all of its arguments, we refer refer to this length as the "total length", and when we + * hold the relation parameters constant we refer to it as a "partial length." * */ @@ -120,20 +122,23 @@ template class Relation : public RelationImpl { public: using FF = typename RelationImpl::FF; - static constexpr std::array FULL_SUBRELATION_LENGTHS = - compute_full_subrelation_lengths(); + static constexpr std::array + FULL_SUBRELATION_PARTIAL_LENGTHS = compute_full_subrelation_lengths(); - static constexpr size_t RELATION_LENGTH = - *std::max_element(RelationImpl::SUBRELATION_LENGTHS.begin(), RelationImpl::SUBRELATION_LENGTHS.end()); + static constexpr size_t RELATION_LENGTH = *std::max_element(RelationImpl::SUBRELATION_PARTIAL_LENGTHS.begin(), + RelationImpl::SUBRELATION_PARTIAL_LENGTHS.end()); static constexpr size_t TOTAL_RELATION_LENGTH = - *std::max_element(FULL_SUBRELATION_LENGTHS.begin(), FULL_SUBRELATION_LENGTHS.end()); + *std::max_element(FULL_SUBRELATION_PARTIAL_LENGTHS.begin(), FULL_SUBRELATION_PARTIAL_LENGTHS.end()); template using ProtogalaxyTupleOfUnivariatesOverSubrelations = - TupleOfUnivariates(FULL_SUBRELATION_LENGTHS)>; - using SumcheckTupleOfUnivariatesOverSubrelations = TupleOfUnivariates; - using SumcheckArrayOfValuesOverSubrelations = ArrayOfValues; + TupleOfUnivariates( + FULL_SUBRELATION_PARTIAL_LENGTHS)>; + using SumcheckTupleOfUnivariatesOverSubrelations = + TupleOfUnivariates; + using SumcheckArrayOfValuesOverSubrelations = ArrayOfValues; // These are commonly needed, most importantly, for explicitly instantiating // compute_foo_numerator/denomintor. diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp index 40d273b4128..856f12265a5 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_decomposition_relation.hpp @@ -10,7 +10,7 @@ template class GoblinTranslatorDecompositionRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 3; // degree(lagrange_odd(a - a_0 - a_1*2¹⁴ ... - a_l⋅2¹⁴ˡ )) = 2 - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 3, // decomposition of P.x limb 0 into microlimbs subrelation 3, // decomposition of P.x limb 1 into microlimbs subrelation 3, // decomposition of P.x limb 2 into microlimbs subrelation diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp index 0dfad9224d6..cc88e997f2c 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_extra_relations.hpp @@ -10,7 +10,7 @@ template class GoblinTranslatorOpcodeConstraintRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 7; // degree(op(op - 1)(op - 2)(op - 3)(op - 4)(op - 8)) = 6 - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 7 // opcode constraint relation }; @@ -59,7 +59,7 @@ template class GoblinTranslatorAccumulatorTransferRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 3; // degree((SOME_LAGRANGE)(A-B)) = 2 - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 3, // transfer accumulator limb 0 at even index subrelation 3, // transfer accumulator limb 1 at even index subrelation 3, // transfer accumulator limb 2 at even index subrelation diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp index 7bfc1b00bd3..365c6044c36 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_gen_perm_sort_relation.hpp @@ -10,7 +10,7 @@ template class GoblinTranslatorGenPermSortRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 6; // degree((lagrange_last-1) * D(D - 1)(D - 2)(D - 3)) = 5 - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, // ordered_range_constraints_0 step in {0,1,2,3} subrelation 6, // ordered_range_constraints_1 step in {0,1,2,3} subrelation 6, // ordered_range_constraints_2 step in {0,1,2,3} subrelation diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp index 5d33224afcb..b25fea06492 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_non_native_field_relation.hpp @@ -10,7 +10,7 @@ template class GoblinTranslatorNonNativeFieldRelationImpl { using FF = FF_; // 1 + polynomial degree of this relation - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 3, // Lower wide limb subrelation (checks result is 0 mod 2¹³⁶) 3, // Higher wide limb subrelation (checks result is 0 in higher mod 2¹³⁶), 3 // Prime subrelation (checks result in native field) diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp index bf46ff39880..448b9cc5b33 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/translator_vm/translator_permutation_relation.hpp @@ -9,7 +9,7 @@ template class GoblinTranslatorPermutationRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 7; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 7, // grand product construction sub-relation 3 // left-shiftable polynomial sub-relation }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp index 17a736ac936..957b6baaa36 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/ultra_arithmetic_relation.hpp @@ -7,7 +7,7 @@ template class UltraArithmeticRelationImpl { public: using FF = FF_; - static constexpr std::array SUBRELATION_LENGTHS{ + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 6, // primary arithmetic sub-relation 5 // secondary arithmetic sub-relation }; From 4c207eef34bd7cb7cdd1ba586b0e92e759e309fe Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 22:22:53 +0000 Subject: [PATCH 20/32] Use instance interface. --- .../cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp | 2 +- barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) 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 fbfc5d5fc11..224fa64ab20 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp @@ -107,7 +107,7 @@ template void UltraProver_::execute_relation_check_ auto sumcheck = Sumcheck(instance->proving_key->circuit_size, transcript); - sumcheck_output = sumcheck.prove(instance->prover_polynomials, instance->relation_parameters); + sumcheck_output = sumcheck.prove(instance); } /** diff --git a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 6774ac1c7bc..033401f6361 100644 --- a/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -124,8 +124,6 @@ template class SumcheckProver { /** * @brief Compute univariate restriction place in transcript, generate challenge, partially evaluate,... repeat * until final round, then compute multivariate evaluations and place in transcript. - * - * WORKTODO */ SumcheckOutput prove(std::shared_ptr instance) { From f3caefa12086704c50c6f276ee3a1373935c60ea Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 23:17:07 +0000 Subject: [PATCH 21/32] Add comments --- .../cpp/src/barretenberg/honk/instance/instances.hpp | 7 +++++-- .../barretenberg/honk/proof_system/combiner_example_gen.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index 89eceb075ec..17febb8a1e6 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -11,6 +11,7 @@ template struct ProverInstances_ { using Instance = ProverInstance_; using ArrayType = std::array, NUM_>; + // The extended length here is the length of a composition of polynomials. static constexpr size_t EXTENDED_LENGTH = (Flavor::MAX_TOTAL_RELATION_LENGTH - 1) * (NUM - 1) + 1; using RelationParameters = proof_system::RelationParameters>; @@ -30,8 +31,10 @@ template struct ProverInstances_ { }; /** - * @brief Create folded (univariate) relation parameters - * + * @brief Create folded (univariate) relation parameters. + * @details For a given relation parameter type, extract that parameter from each instance, place the values in a + * univariate (i.e., sum them against an appropriate Lagrange basis) and then extended as needed during the + * constuction of the combiner. */ void parameters_to_univariates() { diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py index 352422cab19..e222d8e9033 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/combiner_example_gen.py @@ -1,4 +1,4 @@ -# TODO: delete this +# TODO(https://github.com/AztecProtocol/barretenberg/issues/760): Delete this? import numpy as np # np.set_printoptions(formatter={'int': hex}) From a5c985c3d42b00feebd53570987fc7e93366c8c8 Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 24 Oct 2023 23:47:44 +0000 Subject: [PATCH 22/32] Test parameters_to_univariates --- .../honk/instance/instances.test.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp new file mode 100644 index 00000000000..dbf4a9e3ecb --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp @@ -0,0 +1,46 @@ + +#include "instances.hpp" +#include "barretenberg/ecc/curves/bn254/bn254.hpp" +#include "barretenberg/honk/proof_system/grand_product_library.hpp" +#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/srs/factories/file_crs_factory.hpp" +#include + +namespace proof_system::honk::instance_tests { + +template class InstancesTests : public testing::Test { + using FF = typename Flavor::FF; + using Builder = typename Flavor::CircuitBuilder; + + public: + static void test_parameters_to_univariates() + { + using Instances = ProverInstances_; + using Instance = typename Instances::Instance; + + Builder builder1; + auto instance1 = std::make_shared(builder1); + instance1->relation_parameters.eta = 1; + + Builder builder2; + builder2.add_variable(3); + auto instance2 = std::make_shared(builder2); + instance2->relation_parameters.eta = 3; + + Instances instances{ { instance1, instance2 } }; + instances.parameters_to_univariates(); + + Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 } }; + EXPECT_EQ(instances.relation_parameters.eta, expected_eta); + }; +}; + +using FlavorTypes = testing::Types; +TYPED_TEST_SUITE(InstancesTests, FlavorTypes); + +TYPED_TEST(InstancesTests, ParametersToUnivariates) +{ + TestFixture::test_parameters_to_univariates(); +} + +} // namespace proof_system::honk::instance_tests \ No newline at end of file From c0a611420d603f49306e346a6e217b23141a9991 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 26 Oct 2023 21:31:39 +0000 Subject: [PATCH 23/32] Partial response to review. --- barretenberg/barretenberg.code-workspace | 2 +- .../src/barretenberg/honk/flavor/ecc_vm.hpp | 2 +- .../honk/flavor/goblin_translator.hpp | 4 +- .../barretenberg/honk/flavor/goblin_ultra.hpp | 4 +- .../honk/flavor/goblin_ultra_recursive.hpp | 2 +- .../src/barretenberg/honk/flavor/ultra.hpp | 4 +- .../honk/flavor/ultra_recursive.hpp | 2 +- .../barretenberg/honk/instance/instances.hpp | 19 ------- .../honk/instance/instances.test.cpp | 46 ---------------- .../honk/proof_system/protogalaxy.test.cpp | 53 +++++++++++++++++++ .../honk/proof_system/protogalaxy_prover.cpp | 2 +- .../honk/proof_system/protogalaxy_prover.hpp | 19 +++++++ .../proof_system/flavor/flavor.hpp | 16 +++--- 13 files changed, 93 insertions(+), 82 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp diff --git a/barretenberg/barretenberg.code-workspace b/barretenberg/barretenberg.code-workspace index 8cf62e8ae40..24c8a186612 100644 --- a/barretenberg/barretenberg.code-workspace +++ b/barretenberg/barretenberg.code-workspace @@ -83,7 +83,7 @@ // Clangd. Note that this setting may be overridden by user settings // to the default value "clangd". // - "clangd.path": "clangd-15", + "clangd.path": "clangd-16", // We should disable automatic inclusion of headers unless we decide to follow "WhyIWYU". "clangd.arguments": [ "-header-insertion=never" diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index caebccdbafa..74585c9136a 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -66,7 +66,7 @@ template class ECCVMBa sumcheck::ECCVMLookupRelation>; using LookupRelation = sumcheck::ECCVMLookupRelation; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp index ce1d895e426..865ee8c52aa 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp @@ -316,8 +316,8 @@ template class GoblinTranslator_ { GoblinTranslatorDecompositionRelation, GoblinTranslatorNonNativeFieldRelation>; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - static constexpr size_t MAX_TOTAL_RELATION_LENGTH = get_max_total_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); + static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 869349bb945..31fcf7f0429 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -51,8 +51,8 @@ class GoblinUltra { proof_system::AuxiliaryRelation, proof_system::EccOpQueueRelation>; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - static constexpr size_t MAX_TOTAL_RELATION_LENGTH = get_max_total_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); + static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation 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 eff7f585829..d41dec60599 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp @@ -77,7 +77,7 @@ template class GoblinUltraRecursive_ { proof_system::AuxiliaryRelation, proof_system::EccOpQueueRelation>; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index c0e444e734c..14abec49a73 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -52,8 +52,8 @@ class Ultra { proof_system::EllipticRelation, proof_system::AuxiliaryRelation>; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); - static constexpr size_t MAX_TOTAL_RELATION_LENGTH = get_max_total_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); + static constexpr size_t MAX_TOTAL_RELATION_LENGTH = compute_max_total_relation_length(); static_assert(MAX_PARTIAL_RELATION_LENGTH == 6); static_assert(MAX_TOTAL_RELATION_LENGTH == 12); diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp index 2a65d9df922..534b22c5157 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -76,7 +76,7 @@ template class UltraRecursive_ { proof_system::EllipticRelation, proof_system::AuxiliaryRelation>; - static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = get_max_partial_relation_length(); + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` // random polynomial e.g. For \sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp index 17febb8a1e6..02219aa0e73 100644 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/instance/instances.hpp @@ -30,25 +30,6 @@ template struct ProverInstances_ { } }; - /** - * @brief Create folded (univariate) relation parameters. - * @details For a given relation parameter type, extract that parameter from each instance, place the values in a - * univariate (i.e., sum them against an appropriate Lagrange basis) and then extended as needed during the - * constuction of the combiner. - */ - void parameters_to_univariates() - { - auto params_to_fold = relation_parameters.to_fold; - for (size_t param_idx = 0; param_idx < params_to_fold.size(); param_idx++) { - auto& univariate_param = *params_to_fold[param_idx]; - Univariate tmp(0); - for (size_t instance_idx = 0; instance_idx < NUM; instance_idx++) { - tmp.value_at(instance_idx) = *((*_data[instance_idx]).relation_parameters.to_fold[param_idx]); - } - univariate_param = tmp.template extend_to(); - } - } - /** * @brief For a prover polynomial label and a fixed row index, construct a uninvariate from the corresponding value * from each instance. diff --git a/barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp b/barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp deleted file mode 100644 index dbf4a9e3ecb..00000000000 --- a/barretenberg/cpp/src/barretenberg/honk/instance/instances.test.cpp +++ /dev/null @@ -1,46 +0,0 @@ - -#include "instances.hpp" -#include "barretenberg/ecc/curves/bn254/bn254.hpp" -#include "barretenberg/honk/proof_system/grand_product_library.hpp" -#include "barretenberg/polynomials/polynomial.hpp" -#include "barretenberg/srs/factories/file_crs_factory.hpp" -#include - -namespace proof_system::honk::instance_tests { - -template class InstancesTests : public testing::Test { - using FF = typename Flavor::FF; - using Builder = typename Flavor::CircuitBuilder; - - public: - static void test_parameters_to_univariates() - { - using Instances = ProverInstances_; - using Instance = typename Instances::Instance; - - Builder builder1; - auto instance1 = std::make_shared(builder1); - instance1->relation_parameters.eta = 1; - - Builder builder2; - builder2.add_variable(3); - auto instance2 = std::make_shared(builder2); - instance2->relation_parameters.eta = 3; - - Instances instances{ { instance1, instance2 } }; - instances.parameters_to_univariates(); - - Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 } }; - EXPECT_EQ(instances.relation_parameters.eta, expected_eta); - }; -}; - -using FlavorTypes = testing::Types; -TYPED_TEST_SUITE(InstancesTests, FlavorTypes); - -TYPED_TEST(InstancesTests, ParametersToUnivariates) -{ - TestFixture::test_parameters_to_univariates(); -} - -} // namespace proof_system::honk::instance_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy.test.cpp index 8c35ce4d40b..5115e0a8192 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy.test.cpp @@ -1,7 +1,16 @@ // Note these tests are a bit hacky + +// #include "instances.hpp" +// #include "barretenberg/ecc/curves/bn254/bn254.hpp" +// #include "barretenberg/honk/proof_system/grand_product_library.hpp" +// #include "barretenberg/polynomials/polynomial.hpp" +// #include "barretenberg/srs/factories/file_crs_factory.hpp" +// #include #include "barretenberg/honk/composer/ultra_composer.hpp" #include "protogalaxy_prover.hpp" #include + +using namespace barretenberg; using namespace proof_system::honk; using Flavor = flavor::Ultra; @@ -178,4 +187,48 @@ TEST_F(ProtoGalaxyTests, PowPerturbatorPolynomial) // Ensure the constant coefficient of the perturbator is equal to the target sum as indicated by the paper EXPECT_EQ(perturbator[0], target_sum); } + +TEST_F(ProtoGalaxyTests, FoldChallenges) +{ + using Instances = ProverInstances_; + using Instance = typename Instances::Instance; + + Builder builder1; + auto instance1 = std::make_shared(builder1); + instance1->relation_parameters.eta = 1; + + Builder builder2; + builder2.add_variable(3); + auto instance2 = std::make_shared(builder2); + instance2->relation_parameters.eta = 3; + + Instances instances{ { instance1, instance2 } }; + ProtoGalaxyProver::fold_parameters(instances); + + Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23 } }; + EXPECT_EQ(instances.relation_parameters.eta, expected_eta); +} + +// namespace proof_system::honk::instance_tests { + +// template class InstancesTests : public testing::Test { +// using FF = typename Flavor::FF; +// using Builder = typename Flavor::CircuitBuilder; + +// public: +// static void test_parameters_to_univariates() +// { + +// }; +// }; + +// using FlavorTypes = testing::Types; +// TYPED_TEST_SUITE(InstancesTests, FlavorTypes); + +// TYPED_TEST(InstancesTests, ParametersToUnivariates) +// { +// TestFixture::test_parameters_to_univariates(); +// } + +// } // namespace proof_system::honk::instance_tests } // namespace protogalaxy_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp index bb7b90690f8..ef64c21c924 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.cpp @@ -32,7 +32,7 @@ template void ProtoGalaxyProver_::prepa instance->compute_grand_product_polynomials(beta, gamma); } - instances.parameters_to_univariates(); + fold_parameters(instances); } // TODO(#https://github.com/AztecProtocol/barretenberg/issues/689): finalise implementation this function diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 9c685a1c68e..bc6a6046209 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -277,6 +277,25 @@ template class ProtoGalaxyProver_ { return Utils::template batch_over_relations( univariate_accumulators, alpha, pow_univariate); } + + /** + * @brief Create folded (univariate) relation parameters. + * @details For a given relation parameter type, extract that parameter from each instance, place the values in a + * univariate (i.e., sum them against an appropriate univariate Lagrange basis) and then extended as needed during + * the constuction of the combiner. + */ + static void fold_parameters(ProverInstances& instances) + { + auto params_to_fold = instances.relation_parameters.to_fold; + for (size_t param_idx = 0; param_idx < params_to_fold.size(); param_idx++) { + auto& univariate_param = *params_to_fold[param_idx]; + Univariate tmp(0); + for (size_t instance_idx = 0; instance_idx < ProverInstances::NUM; instance_idx++) { + tmp.value_at(instance_idx) = *((*instances._data[instance_idx]).relation_parameters.to_fold[param_idx]); + } + univariate_param = tmp.template extend_to(); + } + } }; extern template class ProtoGalaxyProver_>; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 3d4edab6165..8ce1bb0c789 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -202,31 +202,35 @@ class AllEntities_ : public Entities_ { }; /** - * @brief Recursive utility function to find max RELATION_LENGTH over tuple of Relations + * @brief Recursive utility function to find max PARTIAL_RELATION_LENGTH tuples of Relations. + * @details The "partial length" of a relation is 1 + the degree of the relation, where any challenges used in the + * relation are as constants, not as variables.. * */ -template static constexpr size_t get_max_partial_relation_length() +template static constexpr size_t compute_max_partial_relation_length() { if constexpr (Index >= std::tuple_size::value) { return 0; // Return 0 when reach end of the tuple } else { constexpr size_t current_length = std::tuple_element::type::RELATION_LENGTH; - constexpr size_t next_length = get_max_partial_relation_length(); + constexpr size_t next_length = compute_max_partial_relation_length(); return (current_length > next_length) ? current_length : next_length; } } /** - * @brief Recursive utility function to find max TOTAL_RELATION_LENGTH over tuple of Relations + * @brief Recursive utility function to find max TOTAL_RELATION_LENGTH among tuples of Relations. + * @details The "total length" of a relation is 1 + the degree of the relation, where any challenges used in the + * relation are regarded as variables. * */ -template static constexpr size_t get_max_total_relation_length() +template static constexpr size_t compute_max_total_relation_length() { if constexpr (Index >= std::tuple_size::value) { return 0; // Return 0 when reach end of the tuple } else { constexpr size_t current_length = std::tuple_element::type::TOTAL_RELATION_LENGTH; - constexpr size_t next_length = get_max_total_relation_length(); + constexpr size_t next_length = compute_max_total_relation_length(); return (current_length > next_length) ? current_length : next_length; } } From cd644d086fdf91c94c9c49d72b0fbef2a782434f Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 26 Oct 2023 21:59:06 +0000 Subject: [PATCH 24/32] More response --- .../barretenberg/honk/proof_system/protogalaxy_prover.hpp | 2 ++ .../proof_system/relations/auxiliary_relation.hpp | 6 +++--- .../barretenberg/proof_system/relations/relation_types.hpp | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index bc6a6046209..40eec574130 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -24,6 +24,8 @@ template class ProtoGalaxyProver_ { using Relations = typename Flavor::Relations; using BaseUnivariate = Univariate; + // The length of ExtendedUnivariate is the largest length (==degree + 1) of a univariate polynomial obtained by + // composing a relation with folded instance + challenge data. using ExtendedUnivariate = Univariate; using ExtendedUnivariateWithRandomization = Univariate; 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 cdcc007a8ae..1974006c6fe 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/auxiliary_relation.hpp @@ -79,7 +79,7 @@ template class AuxiliaryRelationImpl { * N.B.2 The q_c selector is used to store circuit-specific values in the RAM/ROM access gate * * @param evals transformed to `evals + C(in(X)...)*scaling_factor` - * @param in an std::array containing the fully extended Univariate edges. + * @param in an std::array containing the Totaly extended Univariate edges. * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ @@ -210,7 +210,7 @@ template class AuxiliaryRelationImpl { /** * Memory Record Check * Partial degree: 1 - * Full degree: 4 + * Total degree: 4 * * A ROM/ROM access gate can be evaluated with the identity: * @@ -230,7 +230,7 @@ template class AuxiliaryRelationImpl { /** * ROM Consistency Check * Partial degree: 1 - * Full degree: 4 + * Total degree: 4 * * For every ROM read, a set equivalence check is applied between the record witnesses, and a second set of * records that are sorted. 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 dfeb08b60c6..bd8348f2abb 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -49,11 +49,11 @@ template constexpr bool subrelatio } /** - * @brief Compute the full subrelation lenghhs, i.e., the lengths when regarding the challenges as + * @brief Compute the full subrelation lengths, i.e., the lengths when regarding the challenges as * variables. */ template -consteval std::array compute_full_subrelation_lengths() +consteval std::array compute_total_subrelation_lengths() { if constexpr (HasParameterLengthAdjustmentsMember) { constexpr size_t NUM_SUBRELATIONS = RelationImpl::SUBRELATION_PARTIAL_LENGTHS.size(); @@ -123,7 +123,7 @@ template class Relation : public RelationImpl { using FF = typename RelationImpl::FF; static constexpr std::array - FULL_SUBRELATION_PARTIAL_LENGTHS = compute_full_subrelation_lengths(); + FULL_SUBRELATION_PARTIAL_LENGTHS = compute_total_subrelation_lengths(); static constexpr size_t RELATION_LENGTH = *std::max_element(RelationImpl::SUBRELATION_PARTIAL_LENGTHS.begin(), RelationImpl::SUBRELATION_PARTIAL_LENGTHS.end()); From 248d4e0f00cbf4976c66feeed6c48a1fb08f890b Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 26 Oct 2023 22:36:22 +0000 Subject: [PATCH 25/32] Double dereferencing improvement. --- .../barretenberg/honk/proof_system/protogalaxy_prover.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 40eec574130..2dd8fa35caf 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -292,8 +292,11 @@ template class ProtoGalaxyProver_ { for (size_t param_idx = 0; param_idx < params_to_fold.size(); param_idx++) { auto& univariate_param = *params_to_fold[param_idx]; Univariate tmp(0); - for (size_t instance_idx = 0; instance_idx < ProverInstances::NUM; instance_idx++) { - tmp.value_at(instance_idx) = *((*instances._data[instance_idx]).relation_parameters.to_fold[param_idx]); + size_t instance_idx = 0; + for (auto& instance : instances) { + auto parameter_to_fold = instance->relation_parameters.to_fold[param_idx]; + tmp.value_at(instance_idx) = *(parameter_to_fold); + instance_idx++; } univariate_param = tmp.template extend_to(); } From 5e9c3b51d2fe2bc6a681c78b40b304fe2bb99b73 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 26 Oct 2023 22:55:01 +0000 Subject: [PATCH 26/32] Clean up `fold_parameters` --- .../honk/proof_system/protogalaxy_prover.hpp | 13 +++++++------ .../proof_system/relations/relation_parameters.hpp | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 2dd8fa35caf..aa54980ac5c 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -288,17 +288,18 @@ template class ProtoGalaxyProver_ { */ static void fold_parameters(ProverInstances& instances) { - auto params_to_fold = instances.relation_parameters.to_fold; - for (size_t param_idx = 0; param_idx < params_to_fold.size(); param_idx++) { - auto& univariate_param = *params_to_fold[param_idx]; + // array of parameters to be computed + auto& folded_parameters = instances.relation_parameters.to_fold; + size_t param_idx = 0; + for (auto& folded_parameter : folded_parameters) { Univariate tmp(0); size_t instance_idx = 0; for (auto& instance : instances) { - auto parameter_to_fold = instance->relation_parameters.to_fold[param_idx]; - tmp.value_at(instance_idx) = *(parameter_to_fold); + tmp.value_at(instance_idx) = instance->relation_parameters.to_fold[param_idx]; instance_idx++; } - univariate_param = tmp.template extend_to(); + folded_parameter.get() = tmp.template extend_to(); + param_idx++; } } }; diff --git a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp index f9d5ca63a15..096f5b79603 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_parameters.hpp @@ -38,7 +38,9 @@ template struct RelationParameters { { T(0), T(0), T(0), T(0), T(0) } } }; static constexpr int NUM_TO_FOLD = 5; - std::array to_fold = { &eta, &beta, &gamma, &public_input_delta, &lookup_grand_product_delta }; + std::array, NUM_TO_FOLD> to_fold = { + eta, beta, gamma, public_input_delta, lookup_grand_product_delta + }; static RelationParameters get_random() { From 1ffdb98cc481bc3267b07db0b19912fed2868fb5 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 26 Oct 2023 23:00:32 +0000 Subject: [PATCH 27/32] Last bit of cleanup. --- .../barretenberg/proof_system/relations/relation_types.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 bd8348f2abb..e3568bf7d93 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -79,7 +79,7 @@ consteval std::array c * @return The transformed subrelation lenths */ template -consteval std::array compute_composed_SUBRELATION_PARTIAL_LENGTHS( +consteval std::array compute_composed_subrelation_partial_lengths( std::array SUBRELATION_PARTIAL_LENGTHS) { std::transform(SUBRELATION_PARTIAL_LENGTHS.begin(), @@ -106,7 +106,7 @@ consteval std::array compute_composed_SUBRELATION_PART * specified degree. * * @note We use some funny terminology: we use the term "length" for 1 + the degree of a relation. When the relation is - * regarded as a polynomial in all of its arguments, we refer refer to this length as the "total length", and when we + * regarded as a polynomial in all of its arguments, we refer to this length as the "total length", and when we * hold the relation parameters constant we refer to it as a "partial length." * */ @@ -134,7 +134,7 @@ template class Relation : public RelationImpl { template using ProtogalaxyTupleOfUnivariatesOverSubrelations = TupleOfUnivariates( + compute_composed_subrelation_partial_lengths( FULL_SUBRELATION_PARTIAL_LENGTHS)>; using SumcheckTupleOfUnivariatesOverSubrelations = TupleOfUnivariates; From 22a6ee3fbe310f0a5fa437d86fbda863e360befb Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 27 Oct 2023 11:44:11 +0000 Subject: [PATCH 28/32] fix comments --- .../src/barretenberg/honk/proof_system/protogalaxy_prover.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index aa54980ac5c..88af23023be 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -263,7 +263,8 @@ template class ProtoGalaxyProver_ { FF pow_challenge = pow_challenges[idx]; - // Accumulate the i-th row's univariate contribution + // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to this + // function have already been folded accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], extended_univariates[thread_idx], instances.relation_parameters, From d0deb59fda90f547678bb33ee4a739aaf327d77b Mon Sep 17 00:00:00 2001 From: maramihali Date: Fri, 27 Oct 2023 13:01:45 +0000 Subject: [PATCH 29/32] another comment fix --- .../src/barretenberg/proof_system/relations/relation_types.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e3568bf7d93..3d737112f89 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -49,7 +49,7 @@ template constexpr bool subrelatio } /** - * @brief Compute the full subrelation lengths, i.e., the lengths when regarding the challenges as + * @brief Compute the total subrelation lengths, i.e., the lengths when regarding the challenges as * variables. */ template From 869b83072a76316e1ae77ae13c7078f6363b0d8e Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 27 Oct 2023 15:27:34 +0000 Subject: [PATCH 30/32] Fix bad naming. --- .../proof_system/relations/relation_types.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 3d737112f89..b53d154cbfe 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/relations/relation_types.hpp @@ -122,20 +122,18 @@ template class Relation : public RelationImpl { public: using FF = typename RelationImpl::FF; - static constexpr std::array - FULL_SUBRELATION_PARTIAL_LENGTHS = compute_total_subrelation_lengths(); + static constexpr std::array SUBRELATION_TOTAL_LENGTHS = + compute_total_subrelation_lengths(); static constexpr size_t RELATION_LENGTH = *std::max_element(RelationImpl::SUBRELATION_PARTIAL_LENGTHS.begin(), RelationImpl::SUBRELATION_PARTIAL_LENGTHS.end()); static constexpr size_t TOTAL_RELATION_LENGTH = - *std::max_element(FULL_SUBRELATION_PARTIAL_LENGTHS.begin(), FULL_SUBRELATION_PARTIAL_LENGTHS.end()); + *std::max_element(SUBRELATION_TOTAL_LENGTHS.begin(), SUBRELATION_TOTAL_LENGTHS.end()); template using ProtogalaxyTupleOfUnivariatesOverSubrelations = - TupleOfUnivariates( - FULL_SUBRELATION_PARTIAL_LENGTHS)>; + TupleOfUnivariates(SUBRELATION_TOTAL_LENGTHS)>; using SumcheckTupleOfUnivariatesOverSubrelations = TupleOfUnivariates; using SumcheckArrayOfValuesOverSubrelations = ArrayOfValues; From b9bd1b4b0998749747bbff9d31f64b385b50fac3 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 27 Oct 2023 15:37:26 +0000 Subject: [PATCH 31/32] Add a comment. --- .../honk/proof_system/protogalaxy_prover.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp index 88af23023be..c4a87be54b7 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/protogalaxy_prover.hpp @@ -265,10 +265,11 @@ template class ProtoGalaxyProver_ { // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to this // function have already been folded - accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], - extended_univariates[thread_idx], - instances.relation_parameters, - pow_challenge); + accumulate_relation_univariates( + thread_univariate_accumulators[thread_idx], + extended_univariates[thread_idx], + instances.relation_parameters, // these parameters have already been folded + pow_challenge); } }); From e4097c378e35865f08e9a5de5b5bfeb77640c3b2 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 27 Oct 2023 15:44:42 +0000 Subject: [PATCH 32/32] Remove bad ref to sumcheck --- barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp | 2 +- .../cpp/src/barretenberg/honk/flavor/goblin_translator.hpp | 2 +- .../cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp | 2 +- .../src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp | 2 +- barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp | 2 +- .../cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp | 2 +- .../cpp/src/barretenberg/proof_system/flavor/flavor.hpp | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp index 74585c9136a..3e966d8c833 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ecc_vm.hpp @@ -78,7 +78,7 @@ template class ECCVMBa // define the containers for storing the contributions from each relation in Sumcheck using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); private: /** diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp index 865ee8c52aa..f68a3ff54eb 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_translator.hpp @@ -328,7 +328,7 @@ template class GoblinTranslator_ { // define the containers for storing the contributions from each relation in Sumcheck using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); private: template diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 31fcf7f0429..faf55851306 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -65,7 +65,7 @@ class GoblinUltra { using ProtogalaxyTupleOfTuplesOfUnivariates = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); // 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 d41dec60599..e4affda825a 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra_recursive.hpp @@ -87,7 +87,7 @@ template class GoblinUltraRecursive_ { // define the container for storing the univariate contribution from each relation in Sumcheck using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); private: template diff --git a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index 14abec49a73..13540b04056 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -68,7 +68,7 @@ class Ultra { using ProtogalaxyTupleOfTuplesOfUnivariates = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); // 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 534b22c5157..316dff3c1ba 100644 --- a/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_recursive.hpp @@ -86,7 +86,7 @@ template class UltraRecursive_ { // define the container for storing the univariate contribution from each relation in Sumcheck using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); - using TupleOfArraysOfValues = decltype(create_sumcheck_tuple_of_arrays_of_values()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); private: template diff --git a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 8ce1bb0c789..7b8bc126206 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -277,13 +277,13 @@ template static constexpr auto create_su * @details Container for storing value of each identity in each relation. Each Relation contributes an array of * length num-identities. */ -template static constexpr auto create_sumcheck_tuple_of_arrays_of_values() +template static constexpr auto create_tuple_of_arrays_of_values() { if constexpr (Index >= std::tuple_size::value) { return std::tuple<>{}; // Return empty when reach end of the tuple } else { using Values = typename std::tuple_element_t::SumcheckArrayOfValuesOverSubrelations; - return std::tuple_cat(std::tuple{}, create_sumcheck_tuple_of_arrays_of_values()); + return std::tuple_cat(std::tuple{}, create_tuple_of_arrays_of_values()); } }