From 14c560d386f93b305967c87402e481f9882b0a71 Mon Sep 17 00:00:00 2001 From: codygunton Date: Sun, 25 Aug 2024 22:46:37 +0000 Subject: [PATCH 01/36] Add notes to state --- .../protogalaxy/protogalaxy_prover.hpp | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index c1c49cf7f51..7840e434a80 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -23,17 +23,19 @@ template class ProtoGalaxyProver_ { std::array, Flavor::NUM_SUBRELATIONS - 1>; std::shared_ptr accumulator; - LegacyPolynomial perturbator; - std::vector gate_challenges; - std::vector deltas; - CombinerQuotient combiner_quotient; - FF compressed_perturbator; - RelationParameters relation_parameters; - CombinedRelationSeparator alphas; // a univariate interpolation of challenges for each subrelation - OptimisedRelationParameters optimised_relation_parameters; - OptimisedTupleOfTuplesOfUnivariates optimised_univariate_accumulators; - TupleOfTuplesOfUnivariates univariate_accumulators; - FoldingResult result; + LegacyPolynomial perturbator; // computed then evaluated at a challenge + std::vector gate_challenges; // use to compute pow_polynomial + // WORKTODO: move into accumulator + std::vector deltas; // used to compute perturbator; used to update gate challenge + CombinerQuotient combiner_quotient; // computed then evaluated in computation of next target sum + FF perturbator_evaluation; // computed then evaluated in computation of next target sum + RelationParameters relation_parameters; // used for combiner; folded + // WORKTODO: deprecated + OptimisedRelationParameters optimised_relation_parameters; // used for combiner; folded + CombinedRelationSeparator alphas; // used for combiner; folded + TupleOfTuplesOfUnivariates univariate_accumulators; // WORKTODO: delete + OptimisedTupleOfTuplesOfUnivariates optimised_univariate_accumulators; // WORKTODO: delete + FoldingResult result; // WORKTODO: move out }; using ProverInstances = ProverInstances_; @@ -95,7 +97,7 @@ template class ProtoGalaxyProver_ { * @param instances * @param combiner_quotient polynomial K in the paper * @param challenge - * @param compressed_perturbator + * @param perturbator_evaluation * * TODO(https://github.com/AztecProtocol/barretenberg/issues/796): optimise the construction of the new * accumulator @@ -104,7 +106,7 @@ template class ProtoGalaxyProver_ { State::CombinerQuotient&, State::OptimisedRelationParameters&, FF& challenge, - const FF& compressed_perturbator); + const FF& perturbator_evaluation); /** * @brief Finalise the prover instances that will be folded: complete computation of all the witness polynomials From 80e27c6d646de4c88408ce312d49ecda364e1444 Mon Sep 17 00:00:00 2001 From: codygunton Date: Sun, 25 Aug 2024 22:46:56 +0000 Subject: [PATCH 02/36] Rename compressed_perturbator --- .../protogalaxy/protogalaxy.test.cpp | 24 +++++++++---------- .../protogalaxy/protogalaxy_prover_impl.hpp | 12 +++++----- .../protogalaxy_prover_internal.hpp | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 1319d4aea7e..a3621764cdf 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -232,23 +232,23 @@ template class ProtoGalaxyTests : public testing::Test { */ static void test_combiner_quotient() { - auto compressed_perturbator = FF(2); // F(\alpha) in the paper + auto perturbator_evaluation = FF(2); // F(\alpha) in the paper auto combiner = bb::Univariate(std::array{ 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); - auto combiner_quotient = Fun::compute_combiner_quotient(compressed_perturbator, combiner); + auto combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); // K(i) = (G(i) - ( L_0(i) * F(\alpha)) / Z(i), i = {2,.., 13} for ProverInstances::NUM = 2 // K(i) = (G(i) - (1 - i) * F(\alpha)) / i * (i - 1) auto expected_evals = bb::Univariate(std::array{ - (FF(22) - (FF(1) - FF(2)) * compressed_perturbator) / (FF(2) * FF(2 - 1)), - (FF(23) - (FF(1) - FF(3)) * compressed_perturbator) / (FF(3) * FF(3 - 1)), - (FF(24) - (FF(1) - FF(4)) * compressed_perturbator) / (FF(4) * FF(4 - 1)), - (FF(25) - (FF(1) - FF(5)) * compressed_perturbator) / (FF(5) * FF(5 - 1)), - (FF(26) - (FF(1) - FF(6)) * compressed_perturbator) / (FF(6) * FF(6 - 1)), - (FF(27) - (FF(1) - FF(7)) * compressed_perturbator) / (FF(7) * FF(7 - 1)), - (FF(28) - (FF(1) - FF(8)) * compressed_perturbator) / (FF(8) * FF(8 - 1)), - (FF(29) - (FF(1) - FF(9)) * compressed_perturbator) / (FF(9) * FF(9 - 1)), - (FF(30) - (FF(1) - FF(10)) * compressed_perturbator) / (FF(10) * FF(10 - 1)), - (FF(31) - (FF(1) - FF(11)) * compressed_perturbator) / (FF(11) * FF(11 - 1)), + (FF(22) - (FF(1) - FF(2)) * perturbator_evaluation) / (FF(2) * FF(2 - 1)), + (FF(23) - (FF(1) - FF(3)) * perturbator_evaluation) / (FF(3) * FF(3 - 1)), + (FF(24) - (FF(1) - FF(4)) * perturbator_evaluation) / (FF(4) * FF(4 - 1)), + (FF(25) - (FF(1) - FF(5)) * perturbator_evaluation) / (FF(5) * FF(5 - 1)), + (FF(26) - (FF(1) - FF(6)) * perturbator_evaluation) / (FF(6) * FF(6 - 1)), + (FF(27) - (FF(1) - FF(7)) * perturbator_evaluation) / (FF(7) * FF(7 - 1)), + (FF(28) - (FF(1) - FF(8)) * perturbator_evaluation) / (FF(8) * FF(8 - 1)), + (FF(29) - (FF(1) - FF(9)) * perturbator_evaluation) / (FF(9) * FF(9 - 1)), + (FF(30) - (FF(1) - FF(10)) * perturbator_evaluation) / (FF(10) * FF(10 - 1)), + (FF(31) - (FF(1) - FF(11)) * perturbator_evaluation) / (FF(11) * FF(11 - 1)), }); for (size_t idx = 2; idx < 7; idx++) { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 07c8251479e..af9fd9254d3 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -48,7 +48,7 @@ std::shared_ptr ProtoGalaxyProver_; @@ -61,9 +61,9 @@ std::shared_ptr ProtoGalaxyProver_target_sum = next_target_sum; + next_accumulator->target_sum = next_target_sum; // WORKTODO: move out next_accumulator->gate_challenges = state.gate_challenges; // Initialize accumulator proving key polynomials @@ -144,8 +144,8 @@ template void ProtoGalaxyProver_::combi state.alphas, state.optimised_univariate_accumulators); - state.compressed_perturbator = state.perturbator.evaluate(perturbator_challenge); - state.combiner_quotient = Fun::compute_combiner_quotient(state.compressed_perturbator, combiner); + state.perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); + state.combiner_quotient = Fun::compute_combiner_quotient(state.perturbator_evaluation, combiner); for (size_t idx = ProverInstances::NUM; idx < ProverInstances::BATCHED_EXTENDED_LENGTH; idx++) { transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), state.combiner_quotient.value_at(idx)); @@ -160,7 +160,7 @@ template void ProtoGalaxyProver_::accum state.combiner_quotient, state.optimised_relation_parameters, combiner_challenge, - state.compressed_perturbator); + state.perturbator_evaluation); state.result.proof = transcript->proof_data; state.result.accumulator = next_accumulator; }; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 733b18197ea..3170bb2abae 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -415,7 +415,7 @@ template class ProtogalaxyProverInternal { * */ static Univariate compute_combiner_quotient( - FF compressed_perturbator, ExtendedUnivariateWithRandomization combiner) + FF perturbator_evaluation, ExtendedUnivariateWithRandomization combiner) { std::array combiner_quotient_evals = {}; @@ -438,7 +438,7 @@ template class ProtogalaxyProverInternal { static_assert(ProverInstances::NUM < 5); combiner_quotient_evals[idx] = - (combiner.value_at(point) - compressed_perturbator * lagrange_0) * vanishing_polynomial.invert(); + (combiner.value_at(point) - perturbator_evaluation * lagrange_0) * vanishing_polynomial.invert(); } Univariate combiner_quotient( From fbd4872dbb298cc61c1dd80b9246535249eb87ac Mon Sep 17 00:00:00 2001 From: codygunton Date: Sun, 25 Aug 2024 23:08:46 +0000 Subject: [PATCH 03/36] Outline IO of rounds --- .../protogalaxy/protogalaxy_prover_impl.hpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index af9fd9254d3..abba484b758 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -22,6 +22,7 @@ template void ProtoGalaxyProver_::prepa auto idx = 0; auto instance = instances[0]; auto domain_separator = std::to_string(idx); + // WORKTODO: just do this on a longer if (!instance->is_accumulator) { finalise_and_send_instance(instance, domain_separator); instance->target_sum = 0; @@ -98,7 +99,7 @@ std::shared_ptr ProtoGalaxyProver_ void ProtoGalaxyProver_::preparation_round() +template void ProtoGalaxyProver_::preparation_round() // WORKTODO: { BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::preparation_round"); prepare_for_folding(); @@ -115,6 +116,7 @@ template void ProtoGalaxyProver_::pertu state.perturbator = LegacyPolynomial(state.accumulator->proving_key.log_circuit_size + 1); // initialize to all zeros // compute perturbator only if this is not the first round and has an accumulator + // WORKTODO: just check if accumulator is null if (state.accumulator->is_accumulator) { state.perturbator = Fun::compute_perturbator(state.accumulator, state.deltas); // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of @@ -179,10 +181,16 @@ FoldingResult ProtoGalaxyProver_ Date: Sun, 25 Aug 2024 23:22:22 +0000 Subject: [PATCH 04/36] Link rounds to Pg interation steps. --- .../protogalaxy/protogalaxy_prover.hpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 7840e434a80..749c6395245 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -59,7 +59,8 @@ template class ProtoGalaxyProver_ { , commitment_key(instances[1]->proving_key.commitment_key){}; /** - * @brief Prior to folding, we need to finalize the given instances and add all their public data ϕ to the + * @brief Create inputs to folding protocol (an Oink interaction). + * @details Prior to folding, we need to finalize the given instances and add all their public data ϕ to the * transcript, labelled by their corresponding instance index for domain separation. */ void prepare_for_folding(); @@ -109,27 +110,31 @@ template class ProtoGalaxyProver_ { const FF& perturbator_evaluation); /** - * @brief Finalise the prover instances that will be folded: complete computation of all the witness polynomials + * @brief Create inputs to folding protocol (an Oink interaction). + * @details Finalise the prover instances that will be folded: complete computation of all the witness polynomials * and compute commitments. Send commitments to the verifier and retrieve challenges. * */ void preparation_round(); /** - * @brief Compute perturbator (F polynomial in paper). Send all but the constant coefficient to verifier. + * @brief Steps 2 - 5 of the paper. + * @details Compute perturbator (F polynomial in paper). Send all but the constant coefficient to verifier. * */ void perturbator_round(); /** - * @brief Compute combiner (G polynomial in the paper) and then its quotient (K polynomial), whose coefficient + * @brief Steps 6 - 11 of the paper. + * @details Compute combiner (G polynomial in the paper) and then its quotient (K polynomial), whose coefficient * will be sent to the verifier. * */ void combiner_quotient_round(); /** - * @brief Compute the next prover accumulator (ω* in the paper), encapsulated in a ProverInstance with folding + * @brief Steps 12 - 13 of the paper plus the prover folding work. + * @details Compute the next prover accumulator (ω* in the paper), encapsulated in a ProverInstance with folding * parameters set. * */ From 72ac9d603f5ee034903a24b32cd81ab8379d1144 Mon Sep 17 00:00:00 2001 From: codygunton Date: Sun, 25 Aug 2024 23:34:09 +0000 Subject: [PATCH 05/36] Remove pass-through round and rename rounds --- .../cpp/scripts/analyze_client_ivc_bench.py | 6 +-- .../cpp/scripts/analyze_protogalaxy_bench.py | 8 +-- .../protogalaxy_rounds.bench.cpp | 8 +-- .../protogalaxy/protogalaxy_prover.hpp | 11 +--- .../protogalaxy/protogalaxy_prover_impl.hpp | 52 +++++++++---------- 5 files changed, 37 insertions(+), 48 deletions(-) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index 32dc147724c..c2464204ea4 100644 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -69,7 +69,7 @@ "ProtoGalaxyProver_::preparation_round(t)", "ProtoGalaxyProver_::perturbator_round(t)", "ProtoGalaxyProver_::combiner_quotient_round(t)", - "ProtoGalaxyProver_::accumulator_update_round(t)" + "ProtoGalaxyProver_::update_target_sum_and_fold(t)" ] max_label_length = max(len(label) for label in protogalaxy_round_labels) for key in protogalaxy_round_labels: @@ -80,7 +80,7 @@ total_time_ms = bench["ProtogalaxyProver::prove(t)"]/1e6 print(f"{key:<{max_label_length}}{time_ms:>8.0f} {time_ms/total_time_ms:>8.2%}") -# Extract a set of components from the benchmark data and display timings and relative percentages +# Extract a set of components from the benchmark data and display timings and relative percentages def print_contributions(prefix, ivc_bench_json, bench_name, components): # Read JSON file and extract benchmark @@ -93,7 +93,7 @@ def print_contributions(prefix, ivc_bench_json, bench_name, components): except FileNotFoundError: print(f"File not found: {prefix / ivc_bench_json}") return - + # Filter and sum up kept times bench_components = {key: bench[key] for key in components if key in bench} sum_of_kept_times_ms = sum(float(time) for time in bench_components.values()) / 1e6 diff --git a/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py b/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py index b518e3a8df5..56be71fec2e 100755 --- a/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py +++ b/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py @@ -47,10 +47,10 @@ print('\nBreakdown of ProtogalaxyProver::prove:') protogalaxy_round_labels = [ - "ProtoGalaxyProver_::preparation_round(t)", - "ProtoGalaxyProver_::perturbator_round(t)", - "ProtoGalaxyProver_::combiner_quotient_round(t)", - "ProtoGalaxyProver_::accumulator_update_round(t)" + "ProtoGalaxyProver_::preparation_round(t)", + "ProtoGalaxyProver_::perturbator_round(t)", + "ProtoGalaxyProver_::combiner_quotient_round(t)", + "ProtoGalaxyProver_::update_target_sum_and_fold(t)" ] max_label_length = max(len(label) for label in protogalaxy_round_labels) for key in protogalaxy_round_labels: diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index 5faafc83037..9d51cbe78d8 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -39,7 +39,7 @@ void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_(state, F); } -BENCHMARK_CAPTURE(bench_round_mega, preparation, [](auto& prover) { prover.preparation_round(); }) -> DenseRange(14, 20) - -> Unit(kMillisecond); +BENCHMARK_CAPTURE(bench_round_mega, preparation, [](auto& prover) { prover.run_oink_prover_on_each_instance(); }) + -> DenseRange(14, 20) -> Unit(kMillisecond); BENCHMARK_CAPTURE(bench_round_mega, perturbator, [](auto& prover) { prover.perturbator_round(); }) -> DenseRange(14, 20) -> Unit(kMillisecond); BENCHMARK_CAPTURE(bench_round_mega, combiner_quotient, [](auto& prover) { prover.combiner_quotient_round(); }) -> DenseRange(14, 20) -> Unit(kMillisecond); -BENCHMARK_CAPTURE(bench_round_mega, accumulator_update, [](auto& prover) { prover.accumulator_update_round(); }) +BENCHMARK_CAPTURE(bench_round_mega, accumulator_update, [](auto& prover) { prover.update_target_sum_and_fold(); }) -> DenseRange(14, 20) -> Unit(kMillisecond); } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 749c6395245..7f492d7bfaa 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -58,13 +58,6 @@ template class ProtoGalaxyProver_ { // TODO(https://github.com/AztecProtocol/barretenberg/issues/878) , commitment_key(instances[1]->proving_key.commitment_key){}; - /** - * @brief Create inputs to folding protocol (an Oink interaction). - * @details Prior to folding, we need to finalize the given instances and add all their public data ϕ to the - * transcript, labelled by their corresponding instance index for domain separation. - */ - void prepare_for_folding(); - /** * @brief For each instance produced by a circuit, prior to folding, we need to complete the computation of its * prover polynomials, commit to witnesses and generate the relation parameters as well as send the public data ϕ of @@ -115,7 +108,7 @@ template class ProtoGalaxyProver_ { * and compute commitments. Send commitments to the verifier and retrieve challenges. * */ - void preparation_round(); + void run_oink_prover_on_each_instance(); /** * @brief Steps 2 - 5 of the paper. @@ -138,6 +131,6 @@ template class ProtoGalaxyProver_ { * parameters set. * */ - void accumulator_update_round(); + void update_target_sum_and_fold(); }; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index abba484b758..4283dda98a0 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -17,27 +17,6 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared oink_prover.prove(); } -template void ProtoGalaxyProver_::prepare_for_folding() -{ - auto idx = 0; - auto instance = instances[0]; - auto domain_separator = std::to_string(idx); - // WORKTODO: just do this on a longer - if (!instance->is_accumulator) { - finalise_and_send_instance(instance, domain_separator); - instance->target_sum = 0; - instance->gate_challenges = std::vector(instance->proving_key.log_circuit_size, 0); - } - - idx++; - - for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) { - auto instance = *it; - auto domain_separator = std::to_string(idx); - finalise_and_send_instance(instance, domain_separator); - } -} - /** * @brief Given the challenge \gamma, compute Z(\gamma) and {L_0(\gamma),L_1(\gamma)} * TODO(https://github.com/AztecProtocol/barretenberg/issues/764): Generalize the vanishing polynomial formula @@ -99,10 +78,27 @@ std::shared_ptr ProtoGalaxyProver_ void ProtoGalaxyProver_::preparation_round() // WORKTODO: +template void ProtoGalaxyProver_::run_oink_prover_on_each_instance() { - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::preparation_round"); - prepare_for_folding(); + BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::run_oink_prover_on_each_instance"); + auto idx = 0; + auto instance = instances[0]; + auto domain_separator = std::to_string(idx); + + // WORKTODO: just do this on a longer + if (!instance->is_accumulator) { + finalise_and_send_instance(instance, domain_separator); + instance->target_sum = 0; + instance->gate_challenges = std::vector(instance->proving_key.log_circuit_size, 0); + } + + idx++; + + for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) { + auto instance = *it; + auto domain_separator = std::to_string(idx); + finalise_and_send_instance(instance, domain_separator); + } }; template void ProtoGalaxyProver_::perturbator_round() @@ -154,9 +150,9 @@ template void ProtoGalaxyProver_::combi } }; -template void ProtoGalaxyProver_::accumulator_update_round() +template void ProtoGalaxyProver_::update_target_sum_and_fold() { - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::accumulator_update_round"); + BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::update_target_sum_and_fold"); FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); std::shared_ptr next_accumulator = compute_next_accumulator(instances, state.combiner_quotient, @@ -181,7 +177,7 @@ FoldingResult ProtoGalaxyProver_ ProtoGalaxyProver_ Date: Mon, 26 Aug 2024 16:02:48 +0000 Subject: [PATCH 06/36] Perturbator round is a pure function --- .../protogalaxy_rounds.bench.cpp | 5 +-- .../protogalaxy/protogalaxy_prover.hpp | 5 ++- .../protogalaxy/protogalaxy_prover_impl.hpp | 34 +++++++++++-------- .../protogalaxy_prover_internal.hpp | 2 +- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index 9d51cbe78d8..f962835fedc 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -53,8 +53,9 @@ void bench_round_mega(::benchmark::State& state, void (*F)(ProtoGalaxyProver_ DenseRange(14, 20) -> Unit(kMillisecond); -BENCHMARK_CAPTURE(bench_round_mega, perturbator, [](auto& prover) { prover.perturbator_round(); }) -> DenseRange(14, 20) - -> Unit(kMillisecond); +BENCHMARK_CAPTURE(bench_round_mega, perturbator, [](auto& prover) { + prover.perturbator_round(prover.state.accumulator); +}) -> DenseRange(14, 20) -> Unit(kMillisecond); BENCHMARK_CAPTURE(bench_round_mega, combiner_quotient, [](auto& prover) { prover.combiner_quotient_round(); }) -> DenseRange(14, 20) -> Unit(kMillisecond); BENCHMARK_CAPTURE(bench_round_mega, accumulator_update, [](auto& prover) { prover.update_target_sum_and_fold(); }) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 7f492d7bfaa..872f79bde3b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -114,8 +114,11 @@ template class ProtoGalaxyProver_ { * @brief Steps 2 - 5 of the paper. * @details Compute perturbator (F polynomial in paper). Send all but the constant coefficient to verifier. * + * @param accumulator + * @return std::tuple, LegacyPolynomial> deltas, perturbator */ - void perturbator_round(); + std::tuple, LegacyPolynomial> perturbator_round( + const std::shared_ptr& accumulator); /** * @brief Steps 6 - 11 of the paper. diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 4283dda98a0..663f5892476 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -99,28 +99,34 @@ template void ProtoGalaxyProver_::run_o auto domain_separator = std::to_string(idx); finalise_and_send_instance(instance, domain_separator); } + + state.accumulator = instances[0]; }; -template void ProtoGalaxyProver_::perturbator_round() +template +std::tuple, LegacyPolynomial> +ProtoGalaxyProver_::perturbator_round( + const std::shared_ptr& accumulator) { BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::perturbator_round"); using Fun = ProtogalaxyProverInternal; - state.accumulator = get_accumulator(); + FF delta = transcript->template get_challenge("delta"); - state.deltas = compute_round_challenge_pows(state.accumulator->proving_key.log_circuit_size, delta); - state.perturbator = - LegacyPolynomial(state.accumulator->proving_key.log_circuit_size + 1); // initialize to all zeros - // compute perturbator only if this is not the first round and has an accumulator - // WORKTODO: just check if accumulator is null - if (state.accumulator->is_accumulator) { - state.perturbator = Fun::compute_perturbator(state.accumulator, state.deltas); - // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of - // the accumulator which the folding verifier has from the previous iteration. - for (size_t idx = 1; idx <= state.accumulator->proving_key.log_circuit_size; idx++) { - transcript->send_to_verifier("perturbator_" + std::to_string(idx), state.perturbator[idx]); + std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); + // An honest prover with valid initial instances computes that the perturbator is 0 in the first round + LegacyPolynomial perturbator = accumulator->is_accumulator + ? Fun::compute_perturbator(accumulator, deltas) + : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); + // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of + // the accumulator which the folding verifier has from the previous iteration. + if (accumulator->is_accumulator) { // WORKTODO: differing amount of work in the verifier + for (size_t idx = 1; idx <= accumulator->proving_key.log_circuit_size; idx++) { + transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); } } + + return std::make_tuple(std::move(deltas), std::move(perturbator)); }; template void ProtoGalaxyProver_::combiner_quotient_round() @@ -179,7 +185,7 @@ FoldingResult ProtoGalaxyProver_ class ProtogalaxyProverInternal { * * */ - static LegacyPolynomial compute_perturbator(std::shared_ptr accumulator, + static LegacyPolynomial compute_perturbator(const std::shared_ptr& accumulator, const std::vector& deltas) { BB_OP_COUNT_TIME(); From 61c0df03f10347daf3aef004695f00399a37f89d Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Aug 2024 19:58:17 +0000 Subject: [PATCH 07/36] Combiner quotient round is a pure function --- .../protogalaxy_rounds.bench.cpp | 5 +- .../protogalaxy/protogalaxy.test.cpp | 6 +- .../protogalaxy/protogalaxy_prover.hpp | 57 ++++++++--------- .../protogalaxy/protogalaxy_prover_impl.hpp | 62 ++++++++++++------- 4 files changed, 72 insertions(+), 58 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index f962835fedc..b77e7db2bb2 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -56,8 +56,9 @@ BENCHMARK_CAPTURE(bench_round_mega, preparation, [](auto& prover) { prover.run_o BENCHMARK_CAPTURE(bench_round_mega, perturbator, [](auto& prover) { prover.perturbator_round(prover.state.accumulator); }) -> DenseRange(14, 20) -> Unit(kMillisecond); -BENCHMARK_CAPTURE(bench_round_mega, combiner_quotient, [](auto& prover) { prover.combiner_quotient_round(); }) - -> DenseRange(14, 20) -> Unit(kMillisecond); +BENCHMARK_CAPTURE(bench_round_mega, combiner_quotient, [](auto& prover) { + prover.combiner_quotient_round(prover.state.accumulator->gate_challenges, prover.state.deltas, prover.instances); +}) -> DenseRange(14, 20) -> Unit(kMillisecond); BENCHMARK_CAPTURE(bench_round_mega, accumulator_update, [](auto& prover) { prover.update_target_sum_and_fold(); }) -> DenseRange(14, 20) -> Unit(kMillisecond); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index a3621764cdf..5d694355f53 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -274,10 +274,10 @@ template class ProtoGalaxyTests : public testing::Test { ProverInstances instances{ { instance1, instance2 } }; auto relation_parameters = - Fun::template compute_extended_relation_parameters( + Fun::template compute_extended_relation_parameters(instances); + auto optimised_relation_parameters = + Fun::template compute_extended_relation_parameters( instances); - auto optimised_relation_parameters = Fun::template compute_extended_relation_parameters< - typename FoldingProver::State::OptimisedRelationParameters>(instances); bb::Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } }; EXPECT_EQ(relation_parameters.eta, expected_eta); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 872f79bde3b..4d0683e12b7 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -6,22 +6,21 @@ namespace bb { template class ProtoGalaxyProver_ { public: - struct State { - using FF = typename ProverInstances_::FF; - using ProverInstance = typename ProverInstances_::Instance; - using Flavor = typename ProverInstances_::Flavor; - static constexpr size_t NUM_INSTANCES = ProverInstances_::NUM; - using CombinerQuotient = Univariate; - using TupleOfTuplesOfUnivariates = - typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; - using OptimisedTupleOfTuplesOfUnivariates = - typename Flavor::template OptimisedProtogalaxyTupleOfTuplesOfUnivariates; - using RelationParameters = bb::RelationParameters>; - using OptimisedRelationParameters = bb::RelationParameters< - Univariate>; - using CombinedRelationSeparator = - std::array, Flavor::NUM_SUBRELATIONS - 1>; + using ProverInstance = typename ProverInstances_::Instance; + using Flavor = typename ProverInstances_::Flavor; + using FF = typename ProverInstances_::Flavor::FF; + static constexpr size_t NUM_INSTANCES = ProverInstances_::NUM; + using CombinerQuotient = Univariate; + using TupleOfTuplesOfUnivariates = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; + using OptimisedTupleOfTuplesOfUnivariates = + typename Flavor::template OptimisedProtogalaxyTupleOfTuplesOfUnivariates; + using RelationParameters = bb::RelationParameters>; + using OptimisedRelationParameters = + bb::RelationParameters>; + using CombinedRelationSeparator = + std::array, Flavor::NUM_SUBRELATIONS - 1>; + struct State { std::shared_ptr accumulator; LegacyPolynomial perturbator; // computed then evaluated at a challenge std::vector gate_challenges; // use to compute pow_polynomial @@ -37,24 +36,21 @@ template class ProtoGalaxyProver_ { OptimisedTupleOfTuplesOfUnivariates optimised_univariate_accumulators; // WORKTODO: delete FoldingResult result; // WORKTODO: move out }; - - using ProverInstances = ProverInstances_; - using Flavor = typename ProverInstances::Flavor; using Transcript = typename Flavor::Transcript; - using FF = typename Flavor::FF; - using Instance = typename ProverInstances::Instance; + using Instance = typename ProverInstances_::Instance; using CommitmentKey = typename Flavor::CommitmentKey; + using ProverInstances = ProverInstances_; - static constexpr size_t NUM_SUBRELATIONS = ProverInstances::NUM_SUBRELATIONS; + static constexpr size_t NUM_SUBRELATIONS = ProverInstances_::NUM_SUBRELATIONS; - ProverInstances instances; + ProverInstances_ instances; std::shared_ptr transcript = std::make_shared(); std::shared_ptr commitment_key; State state; ProtoGalaxyProver_() = default; ProtoGalaxyProver_(const std::vector>& insts) - : instances(ProverInstances(insts)) + : instances(ProverInstances_(insts)) // TODO(https://github.com/AztecProtocol/barretenberg/issues/878) , commitment_key(instances[1]->proving_key.commitment_key){}; @@ -96,9 +92,9 @@ template class ProtoGalaxyProver_ { * TODO(https://github.com/AztecProtocol/barretenberg/issues/796): optimise the construction of the new * accumulator */ - std::shared_ptr compute_next_accumulator(ProverInstances&, - State::CombinerQuotient&, - State::OptimisedRelationParameters&, + std::shared_ptr compute_next_accumulator(ProverInstances_&, + CombinerQuotient&, + OptimisedRelationParameters&, FF& challenge, const FF& perturbator_evaluation); @@ -106,7 +102,6 @@ template class ProtoGalaxyProver_ { * @brief Create inputs to folding protocol (an Oink interaction). * @details Finalise the prover instances that will be folded: complete computation of all the witness polynomials * and compute commitments. Send commitments to the verifier and retrieve challenges. - * */ void run_oink_prover_on_each_instance(); @@ -124,15 +119,17 @@ template class ProtoGalaxyProver_ { * @brief Steps 6 - 11 of the paper. * @details Compute combiner (G polynomial in the paper) and then its quotient (K polynomial), whose coefficient * will be sent to the verifier. - * */ - void combiner_quotient_round(); + /*gate_challenges, alphas, optimised_relation_parameters, perturbator_evaluation, combiner_quotient */ + std::tuple, CombinedRelationSeparator, OptimisedRelationParameters, FF, CombinerQuotient> + combiner_quotient_round(const std::vector& gate_challenges, + const std::vector& deltas, + const ProverInstances_& instances); /** * @brief Steps 12 - 13 of the paper plus the prover folding work. * @details Compute the next prover accumulator (ω* in the paper), encapsulated in a ProverInstance with folding * parameters set. - * */ void update_target_sum_and_fold(); }; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 663f5892476..2395ae9b9c4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -25,8 +25,8 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared template std::shared_ptr ProtoGalaxyProver_::compute_next_accumulator( ProverInstances& instances, - State::CombinerQuotient& combiner_quotient, - State::OptimisedRelationParameters& univariate_relation_parameters, + CombinerQuotient& combiner_quotient, + OptimisedRelationParameters& univariate_relation_parameters, FF& challenge, const FF& perturbator_evaluation) { @@ -129,32 +129,45 @@ ProtoGalaxyProver_::perturbator_round( return std::make_tuple(std::move(deltas), std::move(perturbator)); }; -template void ProtoGalaxyProver_::combiner_quotient_round() +template +std::tuple, + typename ProtoGalaxyProver_::CombinedRelationSeparator, + typename ProtoGalaxyProver_::OptimisedRelationParameters, + typename ProverInstances::Flavor::FF, + typename ProtoGalaxyProver_::CombinerQuotient> +ProtoGalaxyProver_::combiner_quotient_round(const std::vector& gate_challenges, + const std::vector& deltas, + const ProverInstances& instances) { BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::combiner_quotient_round"); using Fun = ProtogalaxyProverInternal; - auto perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); - state.gate_challenges = - update_gate_challenges(perturbator_challenge, state.accumulator->gate_challenges, state.deltas); - state.alphas = Fun::compute_and_extend_alphas(instances); - PowPolynomial pow_polynomial{ state.gate_challenges, instances[0]->proving_key.log_circuit_size }; - state.optimised_relation_parameters = - Fun::template compute_extended_relation_parameters(instances); - auto combiner = Fun::compute_combiner(instances, - pow_polynomial, - state.optimised_relation_parameters, - state.alphas, - state.optimised_univariate_accumulators); - - state.perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); - state.combiner_quotient = Fun::compute_combiner_quotient(state.perturbator_evaluation, combiner); + FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); + + std::vector updated_gate_challenges = update_gate_challenges(perturbator_challenge, gate_challenges, deltas); + CombinedRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); + PowPolynomial pow_polynomial{ updated_gate_challenges, instances[0]->proving_key.log_circuit_size }; + OptimisedRelationParameters optimised_relation_parameters = + Fun::template compute_extended_relation_parameters(instances); + + OptimisedTupleOfTuplesOfUnivariates accumulators; + auto combiner = + Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, alphas, accumulators); + + FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); + CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); for (size_t idx = ProverInstances::NUM; idx < ProverInstances::BATCHED_EXTENDED_LENGTH; idx++) { - transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), state.combiner_quotient.value_at(idx)); + transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), combiner_quotient.value_at(idx)); } -}; + + return std::make_tuple(std::move(updated_gate_challenges), + std::move(alphas), + std::move(optimised_relation_parameters), + std::move(perturbator_evaluation), + std::move(combiner_quotient)); +} template void ProtoGalaxyProver_::update_target_sum_and_fold() { @@ -187,9 +200,12 @@ FoldingResult ProtoGalaxyProver_gate_challenges, state.deltas, instances); /* result = */ update_target_sum_and_fold( /* instances, combiner_quotient, optimised_relation_parameters, perturbator_evaluation */); From c49abd8c8ff71e8f8ad20f20aed6e1962f20b1cc Mon Sep 17 00:00:00 2001 From: codygunton Date: Mon, 26 Aug 2024 22:21:34 +0000 Subject: [PATCH 08/36] Big refactor of final round, incl brittle folding loops --- .../protogalaxy_rounds.bench.cpp | 12 ++- .../barretenberg/polynomials/univariate.hpp | 2 +- .../protogalaxy/protogalaxy_prover.hpp | 31 ++---- .../protogalaxy/protogalaxy_prover_impl.hpp | 97 ++++++++----------- 4 files changed, 59 insertions(+), 83 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index b77e7db2bb2..05acdfef5fc 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -51,7 +51,7 @@ void bench_round_mega(::benchmark::State& state, void (*F)(ProtoGalaxyProver_(state, F); } -BENCHMARK_CAPTURE(bench_round_mega, preparation, [](auto& prover) { prover.run_oink_prover_on_each_instance(); }) +BENCHMARK_CAPTURE(bench_round_mega, oink, [](auto& prover) { prover.run_oink_prover_on_each_instance(); }) -> DenseRange(14, 20) -> Unit(kMillisecond); BENCHMARK_CAPTURE(bench_round_mega, perturbator, [](auto& prover) { prover.perturbator_round(prover.state.accumulator); @@ -59,8 +59,14 @@ BENCHMARK_CAPTURE(bench_round_mega, perturbator, [](auto& prover) { BENCHMARK_CAPTURE(bench_round_mega, combiner_quotient, [](auto& prover) { prover.combiner_quotient_round(prover.state.accumulator->gate_challenges, prover.state.deltas, prover.instances); }) -> DenseRange(14, 20) -> Unit(kMillisecond); -BENCHMARK_CAPTURE(bench_round_mega, accumulator_update, [](auto& prover) { prover.update_target_sum_and_fold(); }) - -> DenseRange(14, 20) -> Unit(kMillisecond); +BENCHMARK_CAPTURE(bench_round_mega, fold, [](auto& prover) { + prover.update_target_sum_and_fold(prover.instances, + prover.state.combiner_quotient, + prover.state.gate_challenges, + prover.state.alphas, + prover.state.optimised_relation_parameters, + prover.state.perturbator_evaluation); +}) -> DenseRange(14, 20) -> Unit(kMillisecond); } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp index 65c5fad4d4e..18af318f912 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/univariate.hpp @@ -473,7 +473,7 @@ template ; Fr full_numerator_value = 1; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 4d0683e12b7..79953062846 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -34,7 +34,7 @@ template class ProtoGalaxyProver_ { CombinedRelationSeparator alphas; // used for combiner; folded TupleOfTuplesOfUnivariates univariate_accumulators; // WORKTODO: delete OptimisedTupleOfTuplesOfUnivariates optimised_univariate_accumulators; // WORKTODO: delete - FoldingResult result; // WORKTODO: move out + FoldingResult result; // WORKTODO: move out }; using Transcript = typename Flavor::Transcript; using Instance = typename ProverInstances_::Instance; @@ -77,27 +77,6 @@ template class ProtoGalaxyProver_ { // FoldingParameters set and be the result of a previous round of folding. std::shared_ptr get_accumulator() { return instances[0]; } - /** - * @brief Compute the next accumulator (ϕ*, ω*, \vec{\beta*}, e*), send the public data ϕ* and the folding - * parameters - * (\vec{\beta*}, e*) to the verifier and return the complete accumulator - * - * @details At this stage, we assume that the instances have the same size and the same number of public - * parameter.s - * @param instances - * @param combiner_quotient polynomial K in the paper - * @param challenge - * @param perturbator_evaluation - * - * TODO(https://github.com/AztecProtocol/barretenberg/issues/796): optimise the construction of the new - * accumulator - */ - std::shared_ptr compute_next_accumulator(ProverInstances_&, - CombinerQuotient&, - OptimisedRelationParameters&, - FF& challenge, - const FF& perturbator_evaluation); - /** * @brief Create inputs to folding protocol (an Oink interaction). * @details Finalise the prover instances that will be folded: complete computation of all the witness polynomials @@ -131,6 +110,12 @@ template class ProtoGalaxyProver_ { * @details Compute the next prover accumulator (ω* in the paper), encapsulated in a ProverInstance with folding * parameters set. */ - void update_target_sum_and_fold(); + FoldingResult update_target_sum_and_fold( + const ProverInstances_& instances, + const CombinerQuotient& combiner_quotient, + const std::vector& gate_challenges, + const CombinedRelationSeparator& alphas, + /* WORKTOO */ OptimisedRelationParameters& univariate_relation_parameters, + const FF& perturbator_evaluation); }; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 2395ae9b9c4..0edb84238d6 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -23,59 +23,56 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared * and the computation of Lagrange basis for k instances */ template -std::shared_ptr ProtoGalaxyProver_::compute_next_accumulator( - ProverInstances& instances, - CombinerQuotient& combiner_quotient, +FoldingResult ProtoGalaxyProver_::update_target_sum_and_fold( + const ProverInstances& instances, + const CombinerQuotient& combiner_quotient, + const std::vector& gate_challenges, + const CombinedRelationSeparator& alphas, OptimisedRelationParameters& univariate_relation_parameters, - FF& challenge, const FF& perturbator_evaluation) { + BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::update_target_sum_and_fold"); using Fun = ProtogalaxyProverInternal; - auto combiner_quotient_at_challenge = combiner_quotient.evaluate(challenge); - auto [vanishing_polynomial_at_challenge, lagranges] = Fun::compute_vanishing_polynomial_and_lagranges(challenge); + FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); - // TODO(https://github.com/AztecProtocol/barretenberg/issues/881): bad pattern - auto next_accumulator = std::move(instances[0]); - next_accumulator->is_accumulator = true; + FoldingResult result{ .accumulator = instances[0], .proof = std::move(transcript->proof_data) }; - // Compute the next target sum and send the next folding parameters to the verifier - FF next_target_sum = - perturbator_evaluation * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient_at_challenge; + // TODO(https://github.com/AztecProtocol/barretenberg/issues/881): bad pattern + result.accumulator->is_accumulator = true; - next_accumulator->target_sum = next_target_sum; // WORKTODO: move out - next_accumulator->gate_challenges = state.gate_challenges; + // Compute the next target sum + auto [vanishing_polynomial_at_challenge, lagranges] = + Fun::compute_vanishing_polynomial_and_lagranges(combiner_challenge); + result.accumulator->target_sum = perturbator_evaluation * lagranges[0] + + vanishing_polynomial_at_challenge * combiner_quotient.evaluate(combiner_challenge); - // Initialize accumulator proving key polynomials - auto accumulator_polys = next_accumulator->proving_key.polynomials.get_all(); - for (size_t poly_idx = 0; poly_idx < Flavor::NUM_FOLDED_ENTITIES; poly_idx++) { - accumulator_polys[poly_idx] *= lagranges[0]; - } + result.accumulator->gate_challenges = gate_challenges; // Fold the proving key polynomials + for (auto& poly : result.accumulator->proving_key.polynomials.get_unshifted()) { + poly *= lagranges[0]; + } for (size_t inst_idx = 1; inst_idx < ProverInstances::NUM; inst_idx++) { - auto input_polys = instances[inst_idx]->proving_key.polynomials.get_all(); - for (size_t poly_idx = 0; poly_idx < Flavor::NUM_FOLDED_ENTITIES; poly_idx++) { - accumulator_polys[poly_idx].add_scaled(input_polys[poly_idx], lagranges[inst_idx]); + for (auto [acc_poly, inst_poly] : zip_view(result.accumulator->proving_key.polynomials.get_unshifted(), + instances[inst_idx]->proving_key.polynomials.get_unshifted())) { + acc_poly.add_scaled(inst_poly, lagranges[inst_idx]); } } // Evaluate the combined batching α_i univariate at challenge to obtain next α_i and send it to the // verifier, where i ∈ {0,...,NUM_SUBRELATIONS - 1} - auto& folded_alphas = next_accumulator->alphas; - for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) { - folded_alphas[idx] = state.alphas[idx].evaluate(challenge); + for (auto [folded_alpha, inst_alpha] : zip_view(result.accumulator->alphas, alphas)) { + folded_alpha = inst_alpha.evaluate(combiner_challenge); } - // Evaluate each relation parameter univariate at challenge to obtain the folded relation parameters and send to - // the verifier. We could reuse the univariate relation parameters comuted before, but the computation is tiny and - // we do this now to avoid passing that state through the ProverInstances. - for (auto [univariate, value] : - zip_view(univariate_relation_parameters.get_to_fold(), next_accumulator->relation_parameters.get_to_fold())) { - value = univariate.evaluate(challenge); + // Evaluate each relation parameter univariate at challenge to obtain the folded relation parameters. + for (auto [univariate, value] : zip_view(univariate_relation_parameters.get_to_fold(), + result.accumulator->relation_parameters.get_to_fold())) { + value = univariate.evaluate(combiner_challenge); } - next_accumulator->proving_key = std::move(instances[0]->proving_key); - return next_accumulator; + + return result; } template void ProtoGalaxyProver_::run_oink_prover_on_each_instance() @@ -100,7 +97,7 @@ template void ProtoGalaxyProver_::run_o finalise_and_send_instance(instance, domain_separator); } - state.accumulator = instances[0]; + state.accumulator = instances[0]; // WORKTODO: use this }; template @@ -126,7 +123,7 @@ ProtoGalaxyProver_::perturbator_round( } } - return std::make_tuple(std::move(deltas), std::move(perturbator)); + return std::make_tuple(deltas, perturbator); }; template @@ -162,26 +159,10 @@ ProtoGalaxyProver_::combiner_quotient_round(const std::vectorsend_to_verifier("combiner_quotient_" + std::to_string(idx), combiner_quotient.value_at(idx)); } - return std::make_tuple(std::move(updated_gate_challenges), - std::move(alphas), - std::move(optimised_relation_parameters), - std::move(perturbator_evaluation), - std::move(combiner_quotient)); + return std::make_tuple( + updated_gate_challenges, alphas, optimised_relation_parameters, perturbator_evaluation, combiner_quotient); } -template void ProtoGalaxyProver_::update_target_sum_and_fold() -{ - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::update_target_sum_and_fold"); - FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); - std::shared_ptr next_accumulator = compute_next_accumulator(instances, - state.combiner_quotient, - state.optimised_relation_parameters, - combiner_challenge, - state.perturbator_evaluation); - state.result.proof = transcript->proof_data; - state.result.accumulator = next_accumulator; -}; - template FoldingResult ProtoGalaxyProver_::prove() { @@ -207,9 +188,13 @@ FoldingResult ProtoGalaxyProver_gate_challenges, state.deltas, instances); - /* result = */ update_target_sum_and_fold( - /* instances, combiner_quotient, optimised_relation_parameters, perturbator_evaluation */); + FoldingResult result = update_target_sum_and_fold(instances, + state.combiner_quotient, + state.gate_challenges, + state.alphas, + state.optimised_relation_parameters, + state.perturbator_evaluation); - return state.result; + return result; } } // namespace bb \ No newline at end of file From 64ed8160d51c3061c723a51162d5497d2ce7780f Mon Sep 17 00:00:00 2001 From: codygunton Date: Tue, 27 Aug 2024 00:06:41 +0000 Subject: [PATCH 09/36] Delete accumulators from state --- .../protogalaxy/combiner.test.cpp | 49 ++++++------------- .../protogalaxy/protogalaxy_prover.hpp | 7 +-- .../protogalaxy_prover_internal.hpp | 21 ++++++++ 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index 47b77b3b8c4..2742cb724ae 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -56,11 +56,8 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; prover.state.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - auto result = Fun::compute_combiner(instances, - pow_polynomial, - prover.state.relation_parameters, - prover.state.alphas, - prover.state.univariate_accumulators); + auto result = Fun::compute_combiner_no_skip_zero_computations( + instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); // The expected_result values are computed by running the python script combiner_example_gen.py auto expected_result = Univariate(std::array{ 9704UL, 13245288UL, @@ -138,16 +135,10 @@ TEST(Protogalaxy, CombinerOn2Instances) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - auto result = Fun::compute_combiner(instances, - pow_polynomial, - prover.state.relation_parameters, - prover.state.alphas, - prover.state.univariate_accumulators); - auto optimised_result = Fun::compute_combiner(instances, - pow_polynomial, - prover.state.optimised_relation_parameters, - prover.state.alphas, - prover.state.optimised_univariate_accumulators); + auto result = Fun::compute_combiner_no_skip_zero_computations( + instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); + auto optimised_result = Fun::compute_combiner( + instances, pow_polynomial, prover.state.optimised_relation_parameters, prover.state.alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); @@ -264,16 +255,10 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) precomputed_result[idx] = std::get<0>(accumulator)[0]; } auto expected_result = Univariate(precomputed_result); - auto result = Fun::compute_combiner(instances, - pow_polynomial, - prover.state.relation_parameters, - prover.state.alphas, - prover.state.univariate_accumulators); - auto optimised_result = Fun::compute_combiner(instances, - pow_polynomial, - prover.state.optimised_relation_parameters, - prover.state.alphas, - prover.state.optimised_univariate_accumulators); + auto result = Fun::compute_combiner_no_skip_zero_computations( + instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); + auto optimised_result = Fun::compute_combiner( + instances, pow_polynomial, prover.state.optimised_relation_parameters, prover.state.alphas); EXPECT_EQ(result, expected_result); EXPECT_EQ(optimised_result, expected_result); @@ -340,16 +325,10 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - auto result = Fun::compute_combiner(instances, - pow_polynomial, - prover.state.relation_parameters, - prover.state.alphas, - prover.state.univariate_accumulators); - auto optimised_result = Fun::compute_combiner(instances, - pow_polynomial, - prover.state.optimised_relation_parameters, - prover.state.alphas, - prover.state.optimised_univariate_accumulators); + auto result = Fun::compute_combiner_no_skip_zero_computations( + instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); + auto optimised_result = Fun::compute_combiner( + instances, pow_polynomial, prover.state.optimised_relation_parameters, prover.state.alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 79953062846..b946af6b6ec 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -30,11 +30,8 @@ template class ProtoGalaxyProver_ { FF perturbator_evaluation; // computed then evaluated in computation of next target sum RelationParameters relation_parameters; // used for combiner; folded // WORKTODO: deprecated - OptimisedRelationParameters optimised_relation_parameters; // used for combiner; folded - CombinedRelationSeparator alphas; // used for combiner; folded - TupleOfTuplesOfUnivariates univariate_accumulators; // WORKTODO: delete - OptimisedTupleOfTuplesOfUnivariates optimised_univariate_accumulators; // WORKTODO: delete - FoldingResult result; // WORKTODO: move out + OptimisedRelationParameters optimised_relation_parameters; // used for combiner; folded + CombinedRelationSeparator alphas; // used for combiner; folded }; using Transcript = typename Flavor::Transcript; using Instance = typename ProverInstances_::Instance; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 0a8de5b96f2..2f8ad17299d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -332,6 +332,27 @@ template class ProtogalaxyProverInternal { return batch_over_relations(deoptimized_univariates, alphas); } + template + static ExtendedUnivariateWithRandomization compute_combiner_no_skip_zero_computations( + const ProverInstances& instances, + const PowPolynomial& pow_betas, + const Parameters& relation_parameters, + const CombinedRelationSeparator& alphas) + { + TupleOfTuplesOfUnivariates accumulators; + return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); + } + + template + static ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances& instances, + const PowPolynomial& pow_betas, + const Parameters& relation_parameters, + const CombinedRelationSeparator& alphas) + { + OptimisedTupleOfTuplesOfUnivariates accumulators; + return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); + } + /** * @brief Convert univariates from optimised form to regular * From 2aa89d154841142e0bc9cdb878eaea6a6bcd5d7c Mon Sep 17 00:00:00 2001 From: codygunton Date: Wed, 28 Aug 2024 21:25:24 +0000 Subject: [PATCH 10/36] Remove non-optimised parameters from state --- .../protogalaxy/combiner.test.cpp | 29 ++++++++++++------- .../protogalaxy/protogalaxy_prover.hpp | 14 ++++----- .../protogalaxy/protogalaxy_prover_impl.hpp | 2 +- .../protogalaxy_prover_internal.hpp | 17 ++++++----- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index 2742cb724ae..21253c50d4c 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -56,8 +56,9 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; prover.state.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - auto result = Fun::compute_combiner_no_skip_zero_computations( - instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); + ProtoGalaxyProver::RelationParameters relation_parameters; + auto result = Fun::compute_combiner_no_skip_zero_computations + instances, pow_polynomial, relation_parameters, prover.state.alphas); // The expected_result values are computed by running the python script combiner_example_gen.py auto expected_result = Univariate(std::array{ 9704UL, 13245288UL, @@ -135,10 +136,12 @@ TEST(Protogalaxy, CombinerOn2Instances) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); + ProtoGalaxyProver::RelationParameters relation_parameters; + ProtoGalaxyProver::OptimisedRelationParameters optimised_relation_parameters; auto result = Fun::compute_combiner_no_skip_zero_computations( - instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); - auto optimised_result = Fun::compute_combiner( - instances, pow_polynomial, prover.state.optimised_relation_parameters, prover.state.alphas); + instances, pow_polynomial, relation_parameters, prover.state.alphas); + auto optimised_result = + Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, prover.state.alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); @@ -255,10 +258,12 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) precomputed_result[idx] = std::get<0>(accumulator)[0]; } auto expected_result = Univariate(precomputed_result); + ProtoGalaxyProver::RelationParameters relation_parameters; + ProtoGalaxyProver::OptimisedRelationParameters optimised_relation_parameters; auto result = Fun::compute_combiner_no_skip_zero_computations( - instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); - auto optimised_result = Fun::compute_combiner( - instances, pow_polynomial, prover.state.optimised_relation_parameters, prover.state.alphas); + instances, pow_polynomial, relation_parameters, prover.state.alphas); + auto optimised_result = + Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, prover.state.alphas); EXPECT_EQ(result, expected_result); EXPECT_EQ(optimised_result, expected_result); @@ -325,10 +330,12 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); + ProtoGalaxyProver::RelationParameters relation_parameters; + ProtoGalaxyProver::OptimisedRelationParameters optimised_relation_parameters; auto result = Fun::compute_combiner_no_skip_zero_computations( - instances, pow_polynomial, prover.state.relation_parameters, prover.state.alphas); - auto optimised_result = Fun::compute_combiner( - instances, pow_polynomial, prover.state.optimised_relation_parameters, prover.state.alphas); + instances, pow_polynomial, relation_parameters, prover.state.alphas); + auto optimised_result = + Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, prover.state.alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index b946af6b6ec..a4027a21bd9 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -22,14 +22,12 @@ template class ProtoGalaxyProver_ { struct State { std::shared_ptr accumulator; - LegacyPolynomial perturbator; // computed then evaluated at a challenge - std::vector gate_challenges; // use to compute pow_polynomial - // WORKTODO: move into accumulator - std::vector deltas; // used to compute perturbator; used to update gate challenge - CombinerQuotient combiner_quotient; // computed then evaluated in computation of next target sum - FF perturbator_evaluation; // computed then evaluated in computation of next target sum - RelationParameters relation_parameters; // used for combiner; folded - // WORKTODO: deprecated + LegacyPolynomial perturbator; // computed then evaluated at a challenge + std::vector gate_challenges; // use to compute pow_polynomial + // WORKTODO: move into accumulator + std::vector deltas; // used to compute perturbator; used to update gate challenge + CombinerQuotient combiner_quotient; // computed then evaluated in computation of next target sum + FF perturbator_evaluation; // computed then evaluated in computation of next target sum OptimisedRelationParameters optimised_relation_parameters; // used for combiner; folded CombinedRelationSeparator alphas; // used for combiner; folded }; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 0edb84238d6..72459e833f2 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -177,7 +177,7 @@ FoldingResult ProtoGalaxyProver_ class ProtogalaxyProverInternal { using ProverPolynomials = typename Flavor::ProverPolynomials; using Relations = typename Flavor::Relations; using RelationSeparator = typename Flavor::RelationSeparator; + static constexpr size_t NUM_INSTANCES = ProverInstances_::NUM; + using UnivariateRelationParameters = bb::RelationParameters>; + using OptimisedUnivariateRelationParameters = + bb::RelationParameters>; using CombinedRelationSeparator = std::array, Flavor::NUM_SUBRELATIONS - 1>; @@ -332,22 +336,21 @@ template class ProtogalaxyProverInternal { return batch_over_relations(deoptimized_univariates, alphas); } - template static ExtendedUnivariateWithRandomization compute_combiner_no_skip_zero_computations( const ProverInstances& instances, const PowPolynomial& pow_betas, - const Parameters& relation_parameters, + const UnivariateRelationParameters& relation_parameters, const CombinedRelationSeparator& alphas) { TupleOfTuplesOfUnivariates accumulators; return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); } - template - static ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances& instances, - const PowPolynomial& pow_betas, - const Parameters& relation_parameters, - const CombinedRelationSeparator& alphas) + static ExtendedUnivariateWithRandomization compute_combiner( + const ProverInstances& instances, + const PowPolynomial& pow_betas, + const OptimisedUnivariateRelationParameters& relation_parameters, + const CombinedRelationSeparator& alphas) { OptimisedTupleOfTuplesOfUnivariates accumulators; return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); From a6d0b0856288d769d8083f2013e8a07653cc0c9a Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 11:09:56 +0000 Subject: [PATCH 11/36] No Prover in combiner test --- .../protogalaxy/combiner.test.cpp | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index 21253c50d4c..ce1c10f2f9f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -1,5 +1,4 @@ #include "barretenberg/honk/utils/testing.hpp" -#include "barretenberg/protogalaxy/protogalaxy_prover.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover_internal.hpp" #include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include "barretenberg/stdlib_circuit_builders/ultra_flavor.hpp" @@ -19,7 +18,6 @@ TEST(Protogalaxy, CombinerOn2Instances) constexpr size_t NUM_INSTANCES = 2; using ProverInstance = ProverInstance_; using ProverInstances = ProverInstances_; - using ProtoGalaxyProver = ProtoGalaxyProver_; using Fun = ProtogalaxyProverInternal; const auto restrict_to_standard_arithmetic_relation = [](auto& polys) { @@ -40,7 +38,6 @@ TEST(Protogalaxy, CombinerOn2Instances) // relation. if (is_random_input) { std::vector> instance_data(NUM_INSTANCES); - ProtoGalaxyProver prover; for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { auto instance = std::make_shared(); @@ -54,11 +51,12 @@ TEST(Protogalaxy, CombinerOn2Instances) } ProverInstances instances{ instance_data }; - prover.state.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only + Fun::CombinedRelationSeparator alphas; + alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - ProtoGalaxyProver::RelationParameters relation_parameters; - auto result = Fun::compute_combiner_no_skip_zero_computations - instances, pow_polynomial, relation_parameters, prover.state.alphas); + Fun::UnivariateRelationParameters univariate_relation_parameters; + auto result = Fun::compute_combiner_no_skip_zero_computations( + instances, pow_polynomial, univariate_relation_parameters, alphas); // The expected_result values are computed by running the python script combiner_example_gen.py auto expected_result = Univariate(std::array{ 9704UL, 13245288UL, @@ -75,7 +73,6 @@ TEST(Protogalaxy, CombinerOn2Instances) EXPECT_EQ(result, expected_result); } else { std::vector> instance_data(NUM_INSTANCES); - ProtoGalaxyProver prover; for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { auto instance = std::make_shared(); @@ -89,7 +86,8 @@ TEST(Protogalaxy, CombinerOn2Instances) } ProverInstances instances{ instance_data }; - prover.state.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only + Fun::CombinedRelationSeparator alphas; + alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only const auto create_add_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) { polys.w_l[idx] = w_l; @@ -136,12 +134,12 @@ TEST(Protogalaxy, CombinerOn2Instances) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - ProtoGalaxyProver::RelationParameters relation_parameters; - ProtoGalaxyProver::OptimisedRelationParameters optimised_relation_parameters; + Fun::UnivariateRelationParameters univariate_relation_parameters; + Fun::OptimisedUnivariateRelationParameters optimised_univariate_relation_parameters; auto result = Fun::compute_combiner_no_skip_zero_computations( - instances, pow_polynomial, relation_parameters, prover.state.alphas); + instances, pow_polynomial, univariate_relation_parameters, alphas); auto optimised_result = - Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, prover.state.alphas); + Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); @@ -159,7 +157,6 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) constexpr size_t NUM_INSTANCES = 2; using ProverInstance = ProverInstance_; using ProverInstances = ProverInstances_; - using ProtoGalaxyProver = ProtoGalaxyProver_; using Fun = ProtogalaxyProverInternal; using UltraArithmeticRelation = UltraArithmeticRelation; @@ -181,7 +178,6 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) if (is_random_input) { std::vector> instance_data(NUM_INSTANCES); ASSERT(NUM_INSTANCES == 2); // Don't want to handle more here - ProtoGalaxyProver prover; for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { auto instance = std::make_shared(); @@ -195,8 +191,8 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) } ProverInstances instances{ instance_data }; - prover.state.alphas.fill( - bb::Univariate(FF(0))); // focus on the arithmetic relation only + Fun::CombinedRelationSeparator alphas; + alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); // Relation parameters are all zeroes @@ -258,18 +254,17 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) precomputed_result[idx] = std::get<0>(accumulator)[0]; } auto expected_result = Univariate(precomputed_result); - ProtoGalaxyProver::RelationParameters relation_parameters; - ProtoGalaxyProver::OptimisedRelationParameters optimised_relation_parameters; + Fun::UnivariateRelationParameters univariate_relation_parameters; + Fun::OptimisedUnivariateRelationParameters optimised_univariate_relation_parameters; auto result = Fun::compute_combiner_no_skip_zero_computations( - instances, pow_polynomial, relation_parameters, prover.state.alphas); + instances, pow_polynomial, univariate_relation_parameters, alphas); auto optimised_result = - Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, prover.state.alphas); + Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); EXPECT_EQ(result, expected_result); EXPECT_EQ(optimised_result, expected_result); } else { std::vector> instance_data(NUM_INSTANCES); - ProtoGalaxyProver prover; for (size_t idx = 0; idx < NUM_INSTANCES; idx++) { auto instance = std::make_shared(); @@ -283,7 +278,8 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) } ProverInstances instances{ instance_data }; - prover.state.alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only + Fun::CombinedRelationSeparator alphas; + alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only const auto create_add_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) { polys.w_l[idx] = w_l; @@ -330,12 +326,12 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - ProtoGalaxyProver::RelationParameters relation_parameters; - ProtoGalaxyProver::OptimisedRelationParameters optimised_relation_parameters; + Fun::UnivariateRelationParameters univariate_relation_parameters; + Fun::OptimisedUnivariateRelationParameters optimised_univariate_relation_parameters; auto result = Fun::compute_combiner_no_skip_zero_computations( - instances, pow_polynomial, relation_parameters, prover.state.alphas); + instances, pow_polynomial, univariate_relation_parameters, alphas); auto optimised_result = - Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, prover.state.alphas); + Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); From 301522a0ba90f17d4bd73d1c1d1e8cc4ee9aac82 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 11:33:42 +0000 Subject: [PATCH 12/36] Move gate challenges out of state --- .../protogalaxy_rounds.bench.cpp | 2 +- .../barretenberg/protogalaxy/protogalaxy_prover.hpp | 3 --- .../protogalaxy/protogalaxy_prover_impl.hpp | 10 +++------- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index 05acdfef5fc..4080aaad1ff 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -62,7 +62,7 @@ BENCHMARK_CAPTURE(bench_round_mega, combiner_quotient, [](auto& prover) { BENCHMARK_CAPTURE(bench_round_mega, fold, [](auto& prover) { prover.update_target_sum_and_fold(prover.instances, prover.state.combiner_quotient, - prover.state.gate_challenges, + prover.state.accumulator->gate_challenges, prover.state.alphas, prover.state.optimised_relation_parameters, prover.state.perturbator_evaluation); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index a4027a21bd9..d0c47b525a1 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -23,8 +23,6 @@ template class ProtoGalaxyProver_ { struct State { std::shared_ptr accumulator; LegacyPolynomial perturbator; // computed then evaluated at a challenge - std::vector gate_challenges; // use to compute pow_polynomial - // WORKTODO: move into accumulator std::vector deltas; // used to compute perturbator; used to update gate challenge CombinerQuotient combiner_quotient; // computed then evaluated in computation of next target sum FF perturbator_evaluation; // computed then evaluated in computation of next target sum @@ -108,7 +106,6 @@ template class ProtoGalaxyProver_ { FoldingResult update_target_sum_and_fold( const ProverInstances_& instances, const CombinerQuotient& combiner_quotient, - const std::vector& gate_challenges, const CombinedRelationSeparator& alphas, /* WORKTOO */ OptimisedRelationParameters& univariate_relation_parameters, const FF& perturbator_evaluation); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 72459e833f2..5567fbb5b39 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -26,7 +26,6 @@ template FoldingResult ProtoGalaxyProver_::update_target_sum_and_fold( const ProverInstances& instances, const CombinerQuotient& combiner_quotient, - const std::vector& gate_challenges, const CombinedRelationSeparator& alphas, OptimisedRelationParameters& univariate_relation_parameters, const FF& perturbator_evaluation) @@ -47,8 +46,6 @@ FoldingResult ProtoGalaxyProver_target_sum = perturbator_evaluation * lagranges[0] + vanishing_polynomial_at_challenge * combiner_quotient.evaluate(combiner_challenge); - result.accumulator->gate_challenges = gate_challenges; - // Fold the proving key polynomials for (auto& poly : result.accumulator->proving_key.polynomials.get_unshifted()) { poly *= lagranges[0]; @@ -82,7 +79,6 @@ template void ProtoGalaxyProver_::run_o auto instance = instances[0]; auto domain_separator = std::to_string(idx); - // WORKTODO: just do this on a longer if (!instance->is_accumulator) { finalise_and_send_instance(instance, domain_separator); instance->target_sum = 0; @@ -117,7 +113,8 @@ ProtoGalaxyProver_::perturbator_round( : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of // the accumulator which the folding verifier has from the previous iteration. - if (accumulator->is_accumulator) { // WORKTODO: differing amount of work in the verifier + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is different + if (accumulator->is_accumulator) { for (size_t idx = 1; idx <= accumulator->proving_key.log_circuit_size; idx++) { transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); } @@ -181,7 +178,7 @@ FoldingResult ProtoGalaxyProver_gate_challenges, state.alphas, state.optimised_relation_parameters, state.perturbator_evaluation, @@ -190,7 +187,6 @@ FoldingResult ProtoGalaxyProver_ result = update_target_sum_and_fold(instances, state.combiner_quotient, - state.gate_challenges, state.alphas, state.optimised_relation_parameters, state.perturbator_evaluation); From 49efd457f1ffed972429fda2446de9dcb3dacd1a Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 11:45:15 +0000 Subject: [PATCH 13/36] Final TODO is bigger --- .../src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 5567fbb5b39..f8e1d1ae005 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -93,7 +93,7 @@ template void ProtoGalaxyProver_::run_o finalise_and_send_instance(instance, domain_separator); } - state.accumulator = instances[0]; // WORKTODO: use this + state.accumulator = instances[0]; }; template From c55dea365cb9ef958de4da188f88d231857037a8 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 13:20:53 +0000 Subject: [PATCH 14/36] Rename optimised, combined --- .../protogalaxy_rounds.bench.cpp | 3 +- .../protogalaxy/combiner.test.cpp | 30 ++++++++-------- .../protogalaxy/protogalaxy.test.cpp | 10 +++--- .../protogalaxy/protogalaxy_prover.hpp | 23 ++++++------- .../protogalaxy/protogalaxy_prover_impl.hpp | 28 +++++++-------- .../protogalaxy_prover_internal.hpp | 34 +++++++++++-------- 6 files changed, 63 insertions(+), 65 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index 4080aaad1ff..414a89b908b 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -62,9 +62,8 @@ BENCHMARK_CAPTURE(bench_round_mega, combiner_quotient, [](auto& prover) { BENCHMARK_CAPTURE(bench_round_mega, fold, [](auto& prover) { prover.update_target_sum_and_fold(prover.instances, prover.state.combiner_quotient, - prover.state.accumulator->gate_challenges, prover.state.alphas, - prover.state.optimised_relation_parameters, + prover.state.relation_parameters, prover.state.perturbator_evaluation); }) -> DenseRange(14, 20) -> Unit(kMillisecond); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index ce1c10f2f9f..c57e08a905d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -51,11 +51,11 @@ TEST(Protogalaxy, CombinerOn2Instances) } ProverInstances instances{ instance_data }; - Fun::CombinedRelationSeparator alphas; + Fun::UnivariateRelationSeparator alphas; alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - Fun::UnivariateRelationParameters univariate_relation_parameters; - auto result = Fun::compute_combiner_no_skip_zero_computations( + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; + auto result = Fun::compute_combiner_no_optimistic_skipping( instances, pow_polynomial, univariate_relation_parameters, alphas); // The expected_result values are computed by running the python script combiner_example_gen.py auto expected_result = Univariate(std::array{ 9704UL, @@ -86,7 +86,7 @@ TEST(Protogalaxy, CombinerOn2Instances) } ProverInstances instances{ instance_data }; - Fun::CombinedRelationSeparator alphas; + Fun::UnivariateRelationSeparator alphas; alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only const auto create_add_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) { @@ -134,9 +134,9 @@ TEST(Protogalaxy, CombinerOn2Instances) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - Fun::UnivariateRelationParameters univariate_relation_parameters; - Fun::OptimisedUnivariateRelationParameters optimised_univariate_relation_parameters; - auto result = Fun::compute_combiner_no_skip_zero_computations( + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; + Fun::UnivariateRelationParameters optimised_univariate_relation_parameters; + auto result = Fun::compute_combiner_no_optimistic_skipping( instances, pow_polynomial, univariate_relation_parameters, alphas); auto optimised_result = Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); @@ -191,7 +191,7 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) } ProverInstances instances{ instance_data }; - Fun::CombinedRelationSeparator alphas; + Fun::UnivariateRelationSeparator alphas; alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); @@ -254,9 +254,9 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) precomputed_result[idx] = std::get<0>(accumulator)[0]; } auto expected_result = Univariate(precomputed_result); - Fun::UnivariateRelationParameters univariate_relation_parameters; - Fun::OptimisedUnivariateRelationParameters optimised_univariate_relation_parameters; - auto result = Fun::compute_combiner_no_skip_zero_computations( + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; + Fun::UnivariateRelationParameters optimised_univariate_relation_parameters; + auto result = Fun::compute_combiner_no_optimistic_skipping( instances, pow_polynomial, univariate_relation_parameters, alphas); auto optimised_result = Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); @@ -278,7 +278,7 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) } ProverInstances instances{ instance_data }; - Fun::CombinedRelationSeparator alphas; + Fun::UnivariateRelationSeparator alphas; alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only const auto create_add_gate = [](auto& polys, const size_t idx, FF w_l, FF w_r) { @@ -326,9 +326,9 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - Fun::UnivariateRelationParameters univariate_relation_parameters; - Fun::OptimisedUnivariateRelationParameters optimised_univariate_relation_parameters; - auto result = Fun::compute_combiner_no_skip_zero_computations( + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; + Fun::UnivariateRelationParameters optimised_univariate_relation_parameters; + auto result = Fun::compute_combiner_no_optimistic_skipping( instances, pow_polynomial, univariate_relation_parameters, alphas); auto optimised_result = Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 5d694355f53..56f09ffe349 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -273,18 +273,18 @@ template class ProtoGalaxyTests : public testing::Test { instance2->relation_parameters.eta = 3; ProverInstances instances{ { instance1, instance2 } }; + auto relation_parameters_no_optimistic_skipping = Fun::template compute_extended_relation_parameters< + typename Fun::UnivariateRelationParametersNoOptimisticSkipping>(instances); auto relation_parameters = - Fun::template compute_extended_relation_parameters(instances); - auto optimised_relation_parameters = - Fun::template compute_extended_relation_parameters( + Fun::template compute_extended_relation_parameters( instances); bb::Univariate expected_eta{ { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 } }; - EXPECT_EQ(relation_parameters.eta, expected_eta); + EXPECT_EQ(relation_parameters_no_optimistic_skipping.eta, expected_eta); // Optimised relation parameters are the same, we just don't compute any values for non-used indices when // deriving values from them for (size_t i = 0; i < 11; i++) { - EXPECT_EQ(optimised_relation_parameters.eta.evaluations[i], expected_eta.evaluations[i]); + EXPECT_EQ(relation_parameters.eta.evaluations[i], expected_eta.evaluations[i]); } } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index d0c47b525a1..80632cc995a 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -14,20 +14,19 @@ template class ProtoGalaxyProver_ { using TupleOfTuplesOfUnivariates = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; using OptimisedTupleOfTuplesOfUnivariates = typename Flavor::template OptimisedProtogalaxyTupleOfTuplesOfUnivariates; - using RelationParameters = bb::RelationParameters>; - using OptimisedRelationParameters = + using UnivariateRelationParameters = bb::RelationParameters>; - using CombinedRelationSeparator = + using UnivariateRelationSeparator = std::array, Flavor::NUM_SUBRELATIONS - 1>; struct State { std::shared_ptr accumulator; - LegacyPolynomial perturbator; // computed then evaluated at a challenge - std::vector deltas; // used to compute perturbator; used to update gate challenge - CombinerQuotient combiner_quotient; // computed then evaluated in computation of next target sum - FF perturbator_evaluation; // computed then evaluated in computation of next target sum - OptimisedRelationParameters optimised_relation_parameters; // used for combiner; folded - CombinedRelationSeparator alphas; // used for combiner; folded + LegacyPolynomial perturbator; + std::vector deltas; + CombinerQuotient combiner_quotient; + FF perturbator_evaluation; + UnivariateRelationParameters relation_parameters; + UnivariateRelationSeparator alphas; }; using Transcript = typename Flavor::Transcript; using Instance = typename ProverInstances_::Instance; @@ -93,7 +92,7 @@ template class ProtoGalaxyProver_ { * will be sent to the verifier. */ /*gate_challenges, alphas, optimised_relation_parameters, perturbator_evaluation, combiner_quotient */ - std::tuple, CombinedRelationSeparator, OptimisedRelationParameters, FF, CombinerQuotient> + std::tuple, UnivariateRelationSeparator, UnivariateRelationParameters, FF, CombinerQuotient> combiner_quotient_round(const std::vector& gate_challenges, const std::vector& deltas, const ProverInstances_& instances); @@ -106,8 +105,8 @@ template class ProtoGalaxyProver_ { FoldingResult update_target_sum_and_fold( const ProverInstances_& instances, const CombinerQuotient& combiner_quotient, - const CombinedRelationSeparator& alphas, - /* WORKTOO */ OptimisedRelationParameters& univariate_relation_parameters, + const UnivariateRelationSeparator& alphas, + /* WORKTODO */ UnivariateRelationParameters& univariate_relation_parameters, const FF& perturbator_evaluation); }; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index f8e1d1ae005..71ead667c9f 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -26,8 +26,8 @@ template FoldingResult ProtoGalaxyProver_::update_target_sum_and_fold( const ProverInstances& instances, const CombinerQuotient& combiner_quotient, - const CombinedRelationSeparator& alphas, - OptimisedRelationParameters& univariate_relation_parameters, + const UnivariateRelationSeparator& alphas, + UnivariateRelationParameters& univariate_relation_parameters, // WORKTODO: const const FF& perturbator_evaluation) { BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::update_target_sum_and_fold"); @@ -125,8 +125,8 @@ ProtoGalaxyProver_::perturbator_round( template std::tuple, - typename ProtoGalaxyProver_::CombinedRelationSeparator, - typename ProtoGalaxyProver_::OptimisedRelationParameters, + typename ProtoGalaxyProver_::UnivariateRelationSeparator, + typename ProtoGalaxyProver_::UnivariateRelationParameters, typename ProverInstances::Flavor::FF, typename ProtoGalaxyProver_::CombinerQuotient> ProtoGalaxyProver_::combiner_quotient_round(const std::vector& gate_challenges, @@ -140,14 +140,13 @@ ProtoGalaxyProver_::combiner_quotient_round(const std::vectortemplate get_challenge("perturbator_challenge"); std::vector updated_gate_challenges = update_gate_challenges(perturbator_challenge, gate_challenges, deltas); - CombinedRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); + UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); PowPolynomial pow_polynomial{ updated_gate_challenges, instances[0]->proving_key.log_circuit_size }; - OptimisedRelationParameters optimised_relation_parameters = - Fun::template compute_extended_relation_parameters(instances); + UnivariateRelationParameters relation_parameters = + Fun::template compute_extended_relation_parameters(instances); OptimisedTupleOfTuplesOfUnivariates accumulators; - auto combiner = - Fun::compute_combiner(instances, pow_polynomial, optimised_relation_parameters, alphas, accumulators); + auto combiner = Fun::compute_combiner(instances, pow_polynomial, relation_parameters, alphas, accumulators); FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); @@ -157,7 +156,7 @@ ProtoGalaxyProver_::combiner_quotient_round(const std::vector @@ -180,16 +179,13 @@ FoldingResult ProtoGalaxyProver_gate_challenges, state.alphas, - state.optimised_relation_parameters, + state.relation_parameters, state.perturbator_evaluation, state.combiner_quotient) = combiner_quotient_round(state.accumulator->gate_challenges, state.deltas, instances); - FoldingResult result = update_target_sum_and_fold(instances, - state.combiner_quotient, - state.alphas, - state.optimised_relation_parameters, - state.perturbator_evaluation); + FoldingResult result = update_target_sum_and_fold( + instances, state.combiner_quotient, state.alphas, state.relation_parameters, state.perturbator_evaluation); return result; } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 0b747100bc1..45e64fb5c82 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -26,10 +26,11 @@ template class ProtogalaxyProverInternal { using Relations = typename Flavor::Relations; using RelationSeparator = typename Flavor::RelationSeparator; static constexpr size_t NUM_INSTANCES = ProverInstances_::NUM; - using UnivariateRelationParameters = bb::RelationParameters>; - using OptimisedUnivariateRelationParameters = + using UnivariateRelationParametersNoOptimisticSkipping = + bb::RelationParameters>; + using UnivariateRelationParameters = bb::RelationParameters>; - using CombinedRelationSeparator = + using UnivariateRelationSeparator = std::array, Flavor::NUM_SUBRELATIONS - 1>; // The length of ExtendedUnivariate is the largest length (==max_relation_degree + 1) of a univariate polynomial @@ -263,7 +264,7 @@ template class ProtogalaxyProverInternal { static ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances& instances, const PowPolynomial& pow_betas, const Parameters& relation_parameters, - const CombinedRelationSeparator& alphas, + const UnivariateRelationSeparator& alphas, TupleOfTuples& univariate_accumulators) { BB_OP_COUNT_TIME(); @@ -336,21 +337,24 @@ template class ProtogalaxyProverInternal { return batch_over_relations(deoptimized_univariates, alphas); } - static ExtendedUnivariateWithRandomization compute_combiner_no_skip_zero_computations( + /** + * @brief Compute combiner using univariates that do not avoid zero computation in case of valid incoming indices. + * @details This is only used for testing the combiner calculation. + */ + static ExtendedUnivariateWithRandomization compute_combiner_no_optimistic_skipping( const ProverInstances& instances, const PowPolynomial& pow_betas, - const UnivariateRelationParameters& relation_parameters, - const CombinedRelationSeparator& alphas) + const UnivariateRelationParametersNoOptimisticSkipping& relation_parameters, + const UnivariateRelationSeparator& alphas) { TupleOfTuplesOfUnivariates accumulators; return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); } - static ExtendedUnivariateWithRandomization compute_combiner( - const ProverInstances& instances, - const PowPolynomial& pow_betas, - const OptimisedUnivariateRelationParameters& relation_parameters, - const CombinedRelationSeparator& alphas) + static ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances& instances, + const PowPolynomial& pow_betas, + const UnivariateRelationParameters& relation_parameters, + const UnivariateRelationSeparator& alphas) { OptimisedTupleOfTuplesOfUnivariates accumulators; return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); @@ -384,7 +388,7 @@ template class ProtogalaxyProverInternal { } static ExtendedUnivariateWithRandomization batch_over_relations(TupleOfTuplesOfUnivariates& univariate_accumulators, - const CombinedRelationSeparator& alpha) + const UnivariateRelationSeparator& alpha) { auto result = std::get<0>(std::get<0>(univariate_accumulators)) .template extend_to(); @@ -497,9 +501,9 @@ template class ProtogalaxyProverInternal { * @brief Combine the relation batching parameters (alphas) from each instance into a univariate, used in the * computation of combiner. */ - static CombinedRelationSeparator compute_and_extend_alphas(const ProverInstances& instances) + static UnivariateRelationSeparator compute_and_extend_alphas(const ProverInstances& instances) { - CombinedRelationSeparator result; + UnivariateRelationSeparator result; size_t alpha_idx = 0; for (auto& alpha : result) { Univariate tmp; From 4d943c77c9bc2728ba0162e5713347f3e8e86544 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 13:32:13 +0000 Subject: [PATCH 15/36] Parameters are const --- .../barretenberg/protogalaxy/protogalaxy_prover.hpp | 11 +++++------ .../protogalaxy/protogalaxy_prover_impl.hpp | 2 +- .../barretenberg/relations/relation_parameters.hpp | 5 +++++ 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 80632cc995a..54b6722f466 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -102,11 +102,10 @@ template class ProtoGalaxyProver_ { * @details Compute the next prover accumulator (ω* in the paper), encapsulated in a ProverInstance with folding * parameters set. */ - FoldingResult update_target_sum_and_fold( - const ProverInstances_& instances, - const CombinerQuotient& combiner_quotient, - const UnivariateRelationSeparator& alphas, - /* WORKTODO */ UnivariateRelationParameters& univariate_relation_parameters, - const FF& perturbator_evaluation); + FoldingResult update_target_sum_and_fold(const ProverInstances_& instances, + const CombinerQuotient& combiner_quotient, + const UnivariateRelationSeparator& alphas, + const UnivariateRelationParameters& univariate_relation_parameters, + const FF& perturbator_evaluation); }; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 71ead667c9f..03a70be05f6 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -27,7 +27,7 @@ FoldingResult ProtoGalaxyProver_ struct RelationParameters { return RefArray{ eta, eta_two, eta_three, beta, gamma, public_input_delta, lookup_grand_product_delta }; } + RefArray get_to_fold() const + { + return RefArray{ eta, eta_two, eta_three, beta, gamma, public_input_delta, lookup_grand_product_delta }; + } + static RelationParameters get_random() { RelationParameters result; From c11a029da6a62aee5d0e1d458a740aa423a49947 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 13:45:47 +0000 Subject: [PATCH 16/36] Use const more --- .../protogalaxy/protogalaxy_prover_impl.hpp | 31 +++++++-------- .../protogalaxy_prover_internal.hpp | 38 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 03a70be05f6..1986ff73dce 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -33,7 +33,7 @@ FoldingResult ProtoGalaxyProver_; - FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); + const FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); FoldingResult result{ .accumulator = instances[0], .proof = std::move(transcript->proof_data) }; @@ -76,7 +76,7 @@ template void ProtoGalaxyProver_::run_o { BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::run_oink_prover_on_each_instance"); auto idx = 0; - auto instance = instances[0]; + auto& instance = instances[0]; auto domain_separator = std::to_string(idx); if (!instance->is_accumulator) { @@ -105,12 +105,12 @@ ProtoGalaxyProver_::perturbator_round( using Fun = ProtogalaxyProverInternal; - FF delta = transcript->template get_challenge("delta"); - std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); + const FF delta = transcript->template get_challenge("delta"); + const std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); // An honest prover with valid initial instances computes that the perturbator is 0 in the first round - LegacyPolynomial perturbator = accumulator->is_accumulator - ? Fun::compute_perturbator(accumulator, deltas) - : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); + const LegacyPolynomial perturbator = accumulator->is_accumulator + ? Fun::compute_perturbator(accumulator, deltas) + : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of // the accumulator which the folding verifier has from the previous iteration. // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is different @@ -137,19 +137,20 @@ ProtoGalaxyProver_::combiner_quotient_round(const std::vector; - FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); + const FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); - std::vector updated_gate_challenges = update_gate_challenges(perturbator_challenge, gate_challenges, deltas); - UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); - PowPolynomial pow_polynomial{ updated_gate_challenges, instances[0]->proving_key.log_circuit_size }; - UnivariateRelationParameters relation_parameters = + const std::vector updated_gate_challenges = + update_gate_challenges(perturbator_challenge, gate_challenges, deltas); + const UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); + const PowPolynomial pow_polynomial{ updated_gate_challenges, instances[0]->proving_key.log_circuit_size }; + const UnivariateRelationParameters relation_parameters = Fun::template compute_extended_relation_parameters(instances); OptimisedTupleOfTuplesOfUnivariates accumulators; auto combiner = Fun::compute_combiner(instances, pow_polynomial, relation_parameters, alphas, accumulators); - FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); - CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); + const FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); + const CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); for (size_t idx = ProverInstances::NUM; idx < ProverInstances::BATCHED_EXTENDED_LENGTH; idx++) { transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), combiner_quotient.value_at(idx)); @@ -184,7 +185,7 @@ FoldingResult ProtoGalaxyProver_gate_challenges, state.deltas, instances); - FoldingResult result = update_target_sum_and_fold( + const FoldingResult result = update_target_sum_and_fold( instances, state.combiner_quotient, state.alphas, state.relation_parameters, state.perturbator_evaluation); return result; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 45e64fb5c82..133c194eb86 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -74,7 +74,7 @@ template class ProtogalaxyProverInternal { BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::compute_full_honk_evaluations"); auto instance_size = instance_polynomials.get_polynomial_size(); std::vector full_honk_evaluations(instance_size); - std::vector linearly_dependent_contribution_accumulators = parallel_for_heuristic( + const std::vector linearly_dependent_contribution_accumulators = parallel_for_heuristic( instance_size, /*accumulator default*/ FF(0), [&](size_t row, FF& linearly_dependent_contribution_accumulator) { @@ -172,9 +172,8 @@ template class ProtogalaxyProverInternal { auto full_honk_evaluations = compute_full_honk_evaluations( accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); const auto betas = accumulator->gate_challenges; - assert(betas.size() == deltas.size()); - auto coeffs = construct_perturbator_coefficients(betas, deltas, full_honk_evaluations); - return LegacyPolynomial(coeffs); + ASSERT(betas.size() == deltas.size()); + return LegacyPolynomial(construct_perturbator_coefficients(betas, deltas, full_honk_evaluations)); } /** @@ -192,7 +191,7 @@ template class ProtogalaxyProverInternal { const ProverInstances& instances, const size_t row_idx) { - auto base_univariates = instances.template row_to_univariates(row_idx); + const auto base_univariates = instances.template row_to_univariates(row_idx); for (auto [extended_univariate, base_univariate] : zip_view(extended_univariates.get_all(), base_univariates)) { extended_univariate = base_univariate.template extend_to(); } @@ -272,18 +271,19 @@ template class ProtogalaxyProverInternal { // Whether to use univariates whose operators ignore some values which an honest prover would compute to be zero constexpr bool skip_zero_computations = std::same_as; - size_t common_instance_size = instances[0]->proving_key.circuit_size; + const size_t common_instance_size = instances[0]->proving_key.circuit_size; // Determine number of threads for multithreading. // Note: Multithreading is "on" for every round but we reduce the number of threads from the max available based // on a specified minimum number of iterations per thread. This eventually leads to the use of a // single thread. For now we use a power of 2 number of threads simply to ensure the round size is evenly // divided. - size_t max_num_threads = get_num_cpus_pow2(); // number of available threads (power of 2) - size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread - size_t desired_num_threads = common_instance_size / min_iterations_per_thread; - size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified - num_threads = num_threads > 0 ? num_threads : 1; // ensure num threads is >= 1 - size_t iterations_per_thread = common_instance_size / num_threads; // actual iterations per thread + const size_t max_num_threads = get_num_cpus_pow2(); // number of available threads (power of 2) + const size_t min_iterations_per_thread = + 1 << 6; // min number of iterations for which we'll spin up a unique thread + const size_t desired_num_threads = common_instance_size / min_iterations_per_thread; + size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified + num_threads = num_threads > 0 ? num_threads : 1; // ensure num threads is >= 1 + const size_t iterations_per_thread = common_instance_size / num_threads; // actual iterations per thread // Univariates are optimised for usual PG, but we need the unoptimised version for tests (it's a version that // doesn't skip computation), so we need to define types depending on the template instantiation @@ -304,8 +304,8 @@ template class ProtogalaxyProverInternal { // Accumulate the contribution from each sub-relation parallel_for(num_threads, [&](size_t thread_idx) { - size_t start = thread_idx * iterations_per_thread; - size_t end = (thread_idx + 1) * iterations_per_thread; + const size_t start = thread_idx * iterations_per_thread; + const size_t end = (thread_idx + 1) * iterations_per_thread; for (size_t idx = start; idx < end; idx++) { // Instantiate univariates, possibly with skipping toto ignore computation in those indices (they are @@ -314,7 +314,7 @@ template class ProtogalaxyProverInternal { constexpr size_t skip_count = skip_zero_computations ? ProverInstances::NUM - 1 : 0; extend_univariates(extended_univariates[thread_idx], instances, idx); - FF pow_challenge = pow_betas[idx]; + const FF pow_challenge = pow_betas[idx]; // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to // this function have already been folded. Moreover, linear-dependent relations that act over the @@ -377,7 +377,7 @@ template class ProtogalaxyProverInternal { return tup; } - auto deoptimise = [&](auto& element) { + const auto deoptimise = [&](auto& element) { auto& optimised_element = std::get(std::get(tup)); element = optimised_element.convert(); }; @@ -393,7 +393,7 @@ template class ProtogalaxyProverInternal { auto result = std::get<0>(std::get<0>(univariate_accumulators)) .template extend_to(); size_t idx = 0; - auto scale_and_sum = [&](auto& element) { + const auto scale_and_sum = [&](auto& element) { auto extended = element.template extend_to(); extended *= alpha[idx]; result += extended; @@ -469,9 +469,7 @@ template class ProtogalaxyProverInternal { (combiner.value_at(point) - perturbator_evaluation * lagrange_0) * vanishing_polynomial.invert(); } - Univariate combiner_quotient( - combiner_quotient_evals); - return combiner_quotient; + return Univariate(combiner_quotient_evals); } /** From 96085faea4ad9af0f8ab2e3a131b957fd72e0cc4 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 14:14:32 +0000 Subject: [PATCH 17/36] Rename PgTupOfUnivOberSubs --- .../relations_bench/relations.bench.cpp | 3 ++- .../cpp/src/barretenberg/flavor/flavor.hpp | 20 +++++++++---------- .../barretenberg/relations/relation_types.hpp | 4 ++-- 3 files changed, 14 insertions(+), 13 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 b6545d90245..6d1f656d41f 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -55,7 +55,8 @@ template void execute_relation_for_pg_univa { using ProverInstances = ProverInstances_; using Input = ProtogalaxyProverInternal::ExtendedUnivariates; - using Accumulator = typename Relation::template ProtogalaxyTupleOfUnivariatesOverSubrelations; + using Accumulator = typename Relation::template ProtogalaxyTupleOfUnivariatesOverSubrelationsNoOptimisticSkipping< + ProverInstances::NUM>; execute_relation(state); } diff --git a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp index 69a3a9dabb4..5fdac3c3afa 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/flavor.hpp @@ -328,13 +328,13 @@ constexpr auto create_protogalaxy_tuple_of_tuples_of_univariates() constexpr auto seq = std::make_index_sequence>(); return [](std::index_sequence) { if constexpr (optimised) { - return std::make_tuple( - typename std::tuple_element_t:: - template OptimisedProtogalaxyTupleOfUnivariatesOverSubrelations{}...); - } else { return std::make_tuple( typename std::tuple_element_t::template ProtogalaxyTupleOfUnivariatesOverSubrelations< NUM_INSTANCES>{}...); + } else { + return std::make_tuple( + typename std::tuple_element_t:: + template ProtogalaxyTupleOfUnivariatesOverSubrelationsNoOptimisticSkipping{}...); } }(seq); } @@ -410,13 +410,13 @@ concept IsPlonkFlavor = IsAnyOf concept IsUltraPlonkFlavor = IsAnyOf; -template +template concept IsUltraPlonkOrHonk = IsAnyOf; -template +template concept IsHonkFlavor = IsAnyOf; -template +template concept IsUltraFlavor = IsAnyOf; template @@ -448,9 +448,9 @@ template concept IsFoldingFlavor = IsAnyOf, - UltraRecursiveFlavor_, + MegaFlavor, + UltraRecursiveFlavor_, + UltraRecursiveFlavor_, UltraRecursiveFlavor_, MegaRecursiveFlavor_, MegaRecursiveFlavor_, MegaRecursiveFlavor_>; diff --git a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp index 81da1f4df79..d8be6c87e71 100644 --- a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp @@ -178,10 +178,10 @@ template class Relation : public RelationImpl { *std::max_element(ZK_PARTIAL_LENGTHS.begin(), ZK_PARTIAL_LENGTHS.end()); template - using ProtogalaxyTupleOfUnivariatesOverSubrelations = + using ProtogalaxyTupleOfUnivariatesOverSubrelationsNoOptimisticSkipping = TupleOfUnivariates(SUBRELATION_TOTAL_LENGTHS)>; template - using OptimisedProtogalaxyTupleOfUnivariatesOverSubrelations = + using ProtogalaxyTupleOfUnivariatesOverSubrelations = OptimisedTupleOfUnivariates( SUBRELATION_TOTAL_LENGTHS), From 7f5f0524e04ec8daedfba68627ac4a907a3846ca Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 14:24:36 +0000 Subject: [PATCH 18/36] Rename some OptimisedTupleOf... --- .../protogalaxy/protogalaxy_prover.hpp | 5 ++-- .../protogalaxy/protogalaxy_prover_impl.hpp | 2 +- .../protogalaxy_prover_internal.hpp | 28 +++++++++++-------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 54b6722f466..c17f5431120 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -11,8 +11,9 @@ template class ProtoGalaxyProver_ { using FF = typename ProverInstances_::Flavor::FF; static constexpr size_t NUM_INSTANCES = ProverInstances_::NUM; using CombinerQuotient = Univariate; - using TupleOfTuplesOfUnivariates = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; - using OptimisedTupleOfTuplesOfUnivariates = + using TupleOfTuplesOfUnivariatesNoOptimisticSkipping = + typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; + using TupleOfTuplesOfUnivariates = typename Flavor::template OptimisedProtogalaxyTupleOfTuplesOfUnivariates; using UnivariateRelationParameters = bb::RelationParameters>; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 1986ff73dce..dbb0c2af051 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -146,7 +146,7 @@ ProtoGalaxyProver_::combiner_quotient_round(const std::vector(instances); - OptimisedTupleOfTuplesOfUnivariates accumulators; + TupleOfTuplesOfUnivariates accumulators; auto combiner = Fun::compute_combiner(instances, pow_polynomial, relation_parameters, alphas, accumulators); const FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 133c194eb86..aa6c5b22cc4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -46,9 +46,9 @@ template class ProtogalaxyProverInternal { typename Flavor::template OptimisedProverUnivariates; - using TupleOfTuplesOfUnivariates = + using TupleOfTuplesOfUnivariatesNoOptimisticSkipping = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; - using OptimisedTupleOfTuplesOfUnivariates = + using TupleOfTuplesOfUnivariates = typename Flavor::template OptimisedProtogalaxyTupleOfTuplesOfUnivariates; using RelationEvaluations = typename Flavor::TupleOfArraysOfValues; @@ -269,7 +269,7 @@ template class ProtogalaxyProverInternal { BB_OP_COUNT_TIME(); // Whether to use univariates whose operators ignore some values which an honest prover would compute to be zero - constexpr bool skip_zero_computations = std::same_as; + constexpr bool skip_zero_computations = std::same_as; const size_t common_instance_size = instances[0]->proving_key.circuit_size; // Determine number of threads for multithreading. @@ -332,7 +332,8 @@ template class ProtogalaxyProverInternal { RelationUtils::add_nested_tuples(univariate_accumulators, accumulators); } // This does nothing if TupleOfTuples is TupleOfTuplesOfUnivariates - TupleOfTuplesOfUnivariates deoptimized_univariates = deoptimise_univariates(univariate_accumulators); + TupleOfTuplesOfUnivariatesNoOptimisticSkipping deoptimized_univariates = + deoptimise_univariates(univariate_accumulators); // Batch the univariate contributions from each sub-relation to obtain the round univariate return batch_over_relations(deoptimized_univariates, alphas); } @@ -347,7 +348,7 @@ template class ProtogalaxyProverInternal { const UnivariateRelationParametersNoOptimisticSkipping& relation_parameters, const UnivariateRelationSeparator& alphas) { - TupleOfTuplesOfUnivariates accumulators; + TupleOfTuplesOfUnivariatesNoOptimisticSkipping accumulators; return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); } @@ -356,7 +357,7 @@ template class ProtogalaxyProverInternal { const UnivariateRelationParameters& relation_parameters, const UnivariateRelationSeparator& alphas) { - OptimisedTupleOfTuplesOfUnivariates accumulators; + TupleOfTuplesOfUnivariates accumulators; return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); } @@ -369,11 +370,13 @@ template class ProtogalaxyProverInternal { * @param optimised_univariate_accumulators * @param new_univariate_accumulators */ - template - static TupleOfTuplesOfUnivariates deoptimise_univariates(const PossiblyOptimisedTupleOfTuplesOfUnivariates& tup) + template + static TupleOfTuplesOfUnivariatesNoOptimisticSkipping deoptimise_univariates( + const TupleOfTuplesOfUnivariatePossiblyOptimistic& tup) { // If input does not have optimized operators, return the input - if constexpr (std::same_as) { + if constexpr (std::same_as) { return tup; } @@ -382,13 +385,14 @@ template class ProtogalaxyProverInternal { element = optimised_element.convert(); }; - TupleOfTuplesOfUnivariates result; + TupleOfTuplesOfUnivariatesNoOptimisticSkipping result; RelationUtils::template apply_to_tuple_of_tuples<0, 0>(result, deoptimise); return result; } - static ExtendedUnivariateWithRandomization batch_over_relations(TupleOfTuplesOfUnivariates& univariate_accumulators, - const UnivariateRelationSeparator& alpha) + static ExtendedUnivariateWithRandomization batch_over_relations( + TupleOfTuplesOfUnivariatesNoOptimisticSkipping& univariate_accumulators, + const UnivariateRelationSeparator& alpha) { auto result = std::get<0>(std::get<0>(univariate_accumulators)) .template extend_to(); From 84b1b8146124aa68846735918cdab58387a90ddc Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 14:53:34 +0000 Subject: [PATCH 19/36] Rename base method --- .../cpp/src/barretenberg/relations/nested_containers.hpp | 2 +- .../cpp/src/barretenberg/relations/relation_types.hpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/nested_containers.hpp b/barretenberg/cpp/src/barretenberg/relations/nested_containers.hpp index 36a522eb161..719aa770ed3 100644 --- a/barretenberg/cpp/src/barretenberg/relations/nested_containers.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/nested_containers.hpp @@ -44,7 +44,7 @@ using TupleOfUnivariates = typename TupleOfContainersOverArray -using OptimisedTupleOfUnivariates = +using TupleOfUnivariatesWithOptimisticSkipping = typename TupleOfContainersOverArray::type; template diff --git a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp index d8be6c87e71..5ca396b2d6d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/relation_types.hpp @@ -182,10 +182,10 @@ template class Relation : public RelationImpl { TupleOfUnivariates(SUBRELATION_TOTAL_LENGTHS)>; template using ProtogalaxyTupleOfUnivariatesOverSubrelations = - OptimisedTupleOfUnivariates( - SUBRELATION_TOTAL_LENGTHS), - NUM_INSTANCES - 1>; + TupleOfUnivariatesWithOptimisticSkipping( + SUBRELATION_TOTAL_LENGTHS), + NUM_INSTANCES - 1>; using SumcheckTupleOfUnivariatesOverSubrelations = TupleOfUnivariates; // The containter constructor for sumcheck univariates corresponding to each subrelation in ZK Flavor's relations From 41fdcb8541f323312856b08cfabccec9bb228a6b Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 14:57:27 +0000 Subject: [PATCH 20/36] Rename OptimisedProverUnivariates --- .../barretenberg/protogalaxy/protogalaxy_prover_internal.hpp | 4 ++-- .../src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 2 +- .../src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp | 2 +- .../src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp | 2 +- barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp | 2 +- bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index aa6c5b22cc4..feb20f79bef 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -43,8 +43,8 @@ template class ProtogalaxyProverInternal { (Flavor::MAX_TOTAL_RELATION_LENGTH - 1 + ProverInstances::NUM - 1) * (ProverInstances::NUM - 1) + 1>; using ExtendedUnivariates = typename Flavor::template ProverUnivariates; using OptimisedExtendedUnivariates = - typename Flavor::template OptimisedProverUnivariates; + typename Flavor::template ProverUnivariatesWithOptimisticSkipping; using TupleOfTuplesOfUnivariatesNoOptimisticSkipping = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index 071bd50c675..dc24586bdb7 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -683,7 +683,7 @@ class MegaFlavor { * @details During folding and sumcheck, the prover evaluates the relations on these univariates. */ template - using OptimisedProverUnivariates = AllEntities>; + using ProverUnivariatesWithOptimisticSkipping = AllEntities>; /** * @brief A container for univariates produced during the hot loop in sumcheck. diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 1acd95d3319..4656162e587 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -571,7 +571,7 @@ class UltraFlavor { * @details During folding and sumcheck, the prover evaluates the relations on these univariates. */ template - using OptimisedProverUnivariates = AllEntities>; + using ProverUnivariatesWithOptimisticSkipping = AllEntities>; /** * @brief A container for univariates produced during the hot loop in sumcheck. diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp index 91f9017893c..a05ab176560 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp @@ -503,7 +503,7 @@ class UltraKeccakFlavor { * @details During folding and sumcheck, the prover evaluates the relations on these univariates. */ template - using OptimisedProverUnivariates = AllEntities>; + using ProverUnivariatesWithOptimisticSkipping = AllEntities>; /** * @brief A container for univariates produced during the hot loop in sumcheck. diff --git a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp index da57edf4b8d..df53e1c277f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm/generated/flavor.hpp @@ -390,7 +390,7 @@ class AvmFlavor { * @details During folding and sumcheck, the prover evaluates the relations on these univariates. */ template - using OptimisedProverUnivariates = AllEntities>; + using ProverUnivariatesWithOptimisticSkipping = AllEntities>; /** * @brief A container for univariates produced during the hot loop in sumcheck. diff --git a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs index 416257d5dcd..530f951d1cd 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs @@ -254,7 +254,7 @@ class {{name}}Flavor { * @details During folding and sumcheck, the prover evaluates the relations on these univariates. */ template - using OptimisedProverUnivariates = AllEntities>; + using ProverUnivariatesWithOptimisticSkipping = AllEntities>; /** * @brief A container for univariates produced during the hot loop in sumcheck. From a18212cecd2339626a2f0545a24a4107a8a29f2c Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 15:28:42 +0000 Subject: [PATCH 21/36] Rename PgTupleOfTuples --- .../cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp | 5 ++--- .../barretenberg/protogalaxy/protogalaxy_prover_internal.hpp | 4 ++-- .../src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp | 4 ++-- .../barretenberg/stdlib_circuit_builders/ultra_flavor.hpp | 4 ++-- .../barretenberg/stdlib_circuit_builders/ultra_keccak.hpp | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index c17f5431120..138db779eeb 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -12,9 +12,8 @@ template class ProtoGalaxyProver_ { static constexpr size_t NUM_INSTANCES = ProverInstances_::NUM; using CombinerQuotient = Univariate; using TupleOfTuplesOfUnivariatesNoOptimisticSkipping = - typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; - using TupleOfTuplesOfUnivariates = - typename Flavor::template OptimisedProtogalaxyTupleOfTuplesOfUnivariates; + typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping; + using TupleOfTuplesOfUnivariates = typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; using UnivariateRelationParameters = bb::RelationParameters>; using UnivariateRelationSeparator = diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index feb20f79bef..30ce996d45d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -47,9 +47,9 @@ template class ProtogalaxyProverInternal { /* SKIP_COUNT= */ ProverInstances::NUM - 1>; using TupleOfTuplesOfUnivariatesNoOptimisticSkipping = - typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; + typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping; using TupleOfTuplesOfUnivariates = - typename Flavor::template OptimisedProtogalaxyTupleOfTuplesOfUnivariates; + typename Flavor::template ProtogalaxyTupleOfTuplesOfUnivariates; using RelationEvaluations = typename Flavor::TupleOfArraysOfValues; static constexpr size_t NUM_SUBRELATIONS = ProverInstances::NUM_SUBRELATIONS; diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp index dc24586bdb7..bc43e48a034 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/mega_flavor.hpp @@ -86,11 +86,11 @@ class MegaFlavor { using RelationSeparator = std::array; template - using ProtogalaxyTupleOfTuplesOfUnivariates = + using ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); template - using OptimisedProtogalaxyTupleOfTuplesOfUnivariates = + using ProtogalaxyTupleOfTuplesOfUnivariates = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp index 4656162e587..0167e20f67f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_flavor.hpp @@ -85,10 +85,10 @@ class UltraFlavor { static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template - using ProtogalaxyTupleOfTuplesOfUnivariates = + using ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); template - using OptimisedProtogalaxyTupleOfTuplesOfUnivariates = + using ProtogalaxyTupleOfTuplesOfUnivariates = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); diff --git a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp index a05ab176560..a1c10071baa 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib_circuit_builders/ultra_keccak.hpp @@ -80,10 +80,10 @@ class UltraKeccakFlavor { static constexpr size_t NUM_RELATIONS = std::tuple_size_v; template - using ProtogalaxyTupleOfTuplesOfUnivariates = + using ProtogalaxyTupleOfTuplesOfUnivariatesNoOptimisticSkipping = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); template - using OptimisedProtogalaxyTupleOfTuplesOfUnivariates = + using ProtogalaxyTupleOfTuplesOfUnivariates = decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); From de21eafddbca44b3c85f0e24e5eeed5c559e49a0 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 15:32:06 +0000 Subject: [PATCH 22/36] Rename ExtendedUnivs --- .../benchmark/relations_bench/relations.bench.cpp | 2 +- .../protogalaxy/protogalaxy_prover_internal.hpp | 10 ++++++---- 2 files changed, 7 insertions(+), 5 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 6d1f656d41f..a33d912e0d9 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -54,7 +54,7 @@ template void execute_relation_for_univaria template void execute_relation_for_pg_univariates(::benchmark::State& state) { using ProverInstances = ProverInstances_; - using Input = ProtogalaxyProverInternal::ExtendedUnivariates; + using Input = ProtogalaxyProverInternal::ExtendedUnivariatesNoOptimisticSkipping; using Accumulator = typename Relation::template ProtogalaxyTupleOfUnivariatesOverSubrelationsNoOptimisticSkipping< ProverInstances::NUM>; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 30ce996d45d..b0941786ebb 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -41,8 +41,9 @@ template class ProtogalaxyProverInternal { using ExtendedUnivariateWithRandomization = Univariate; - using ExtendedUnivariates = typename Flavor::template ProverUnivariates; - using OptimisedExtendedUnivariates = + using ExtendedUnivariatesNoOptimisticSkipping = + typename Flavor::template ProverUnivariates; + using ExtendedUnivariates = typename Flavor::template ProverUnivariatesWithOptimisticSkipping; @@ -187,7 +188,8 @@ template class ProtogalaxyProverInternal { template static void extend_univariates( - std::conditional_t& extended_univariates, + std::conditional_t& + extended_univariates, const ProverInstances& instances, const size_t row_idx) { @@ -289,7 +291,7 @@ template class ProtogalaxyProverInternal { // doesn't skip computation), so we need to define types depending on the template instantiation using ThreadAccumulators = TupleOfTuples; using ExtendedUnivatiatesType = - std::conditional_t; + std::conditional_t; // Construct univariate accumulator containers; one per thread std::vector thread_univariate_accumulators(num_threads); From 0993f48316355ea334769d9e077d41ff8dc156bb Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 15:45:51 +0000 Subject: [PATCH 23/36] Change var names to reflect new types --- .../protogalaxy/combiner.test.cpp | 58 +++++++++---------- .../protogalaxy/protogalaxy_prover.hpp | 1 - .../protogalaxy_prover_internal.hpp | 8 +-- 3 files changed, 31 insertions(+), 36 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index c57e08a905d..3a1d3c2a806 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -54,9 +54,9 @@ TEST(Protogalaxy, CombinerOn2Instances) Fun::UnivariateRelationSeparator alphas; alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; - auto result = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters, alphas); + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; + auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( + instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); // The expected_result values are computed by running the python script combiner_example_gen.py auto expected_result = Univariate(std::array{ 9704UL, 13245288UL, @@ -70,7 +70,7 @@ TEST(Protogalaxy, CombinerOn2Instances) 5055956840UL, 6869630184UL, 9072095848UL }); - EXPECT_EQ(result, expected_result); + EXPECT_EQ(result_no_skipping, expected_result); } else { std::vector> instance_data(NUM_INSTANCES); @@ -134,17 +134,17 @@ TEST(Protogalaxy, CombinerOn2Instances) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; - Fun::UnivariateRelationParameters optimised_univariate_relation_parameters; - auto result = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters, alphas); - auto optimised_result = - Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; + Fun::UnivariateRelationParameters univariate_relation_parameters; + auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( + instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); + auto result_with_skipping = + Fun::compute_combiner(instances, pow_polynomial, univariate_relation_parameters, alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); - EXPECT_EQ(result, expected_result); - EXPECT_EQ(optimised_result, expected_result); + EXPECT_EQ(result_no_skipping, expected_result); + EXPECT_EQ(result_with_skipping, expected_result); } }; run_test(true); @@ -254,15 +254,15 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) precomputed_result[idx] = std::get<0>(accumulator)[0]; } auto expected_result = Univariate(precomputed_result); - Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; - Fun::UnivariateRelationParameters optimised_univariate_relation_parameters; - auto result = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters, alphas); - auto optimised_result = - Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); - - EXPECT_EQ(result, expected_result); - EXPECT_EQ(optimised_result, expected_result); + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; + Fun::UnivariateRelationParameters univariate_relation_parameters; + auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( + instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); + auto result_with_skipping = + Fun::compute_combiner(instances, pow_polynomial, univariate_relation_parameters, alphas); + + EXPECT_EQ(result_no_skipping, expected_result); + EXPECT_EQ(result_with_skipping, expected_result); } else { std::vector> instance_data(NUM_INSTANCES); @@ -326,17 +326,17 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); - Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters; - Fun::UnivariateRelationParameters optimised_univariate_relation_parameters; - auto result = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters, alphas); - auto optimised_result = - Fun::compute_combiner(instances, pow_polynomial, optimised_univariate_relation_parameters, alphas); + Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; + Fun::UnivariateRelationParameters univariate_relation_parameters; + auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( + instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); + auto result_with_skipping = + Fun::compute_combiner(instances, pow_polynomial, univariate_relation_parameters, alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); - EXPECT_EQ(result, expected_result); - EXPECT_EQ(optimised_result, expected_result); + EXPECT_EQ(result_no_skipping, expected_result); + EXPECT_EQ(result_with_skipping, expected_result); } }; run_test(true); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 138db779eeb..acc5d295ef2 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -91,7 +91,6 @@ template class ProtoGalaxyProver_ { * @details Compute combiner (G polynomial in the paper) and then its quotient (K polynomial), whose coefficient * will be sent to the verifier. */ - /*gate_challenges, alphas, optimised_relation_parameters, perturbator_evaluation, combiner_quotient */ std::tuple, UnivariateRelationSeparator, UnivariateRelationParameters, FF, CombinerQuotient> combiner_quotient_round(const std::vector& gate_challenges, const std::vector& deltas, diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index b0941786ebb..63d1b98ea33 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -365,12 +365,8 @@ template class ProtogalaxyProverInternal { /** * @brief Convert univariates from optimised form to regular - * * @details We need to convert before we batch relations, since optimised versions don't have enough information to * extend the univariates to maximum length - * - * @param optimised_univariate_accumulators - * @param new_univariate_accumulators */ template static TupleOfTuplesOfUnivariatesNoOptimisticSkipping deoptimise_univariates( @@ -383,8 +379,8 @@ template class ProtogalaxyProverInternal { } const auto deoptimise = [&](auto& element) { - auto& optimised_element = std::get(std::get(tup)); - element = optimised_element.convert(); + auto& element_with_skipping = std::get(std::get(tup)); + element = element_with_skipping.convert(); }; TupleOfTuplesOfUnivariatesNoOptimisticSkipping result; From 5648884ac4d17adc97dead562a91ce6751153892 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 16:09:30 +0000 Subject: [PATCH 24/36] Ariel said this is the real name and I like it better --- CHANGELOG.md | 2 +- barretenberg/CHANGELOG.md | 2 +- .../cpp/scripts/analyze_client_ivc_bench.py | 8 ++-- .../cpp/scripts/analyze_protogalaxy_bench.py | 8 ++-- .../src/barretenberg/aztec_ivc/aztec_ivc.hpp | 6 +-- .../barretenberg/aztec_ivc/aztec_ivc.test.cpp | 4 +- .../protogalaxy_bench/protogalaxy.bench.cpp | 4 +- .../protogalaxy_rounds.bench.cpp | 8 ++-- .../barretenberg/client_ivc/client_ivc.hpp | 6 +-- .../client_ivc/client_ivc.test.cpp | 4 +- .../cpp/src/barretenberg/polynomials/pow.hpp | 2 +- .../protogalaxy/protogalaxy.test.cpp | 42 +++++++++---------- .../protogalaxy/protogalaxy_prover.hpp | 6 +-- .../protogalaxy/protogalaxy_prover_impl.hpp | 28 ++++++------- .../protogalaxy_prover_internal.hpp | 6 +-- .../protogalaxy/protogalaxy_prover_mega.cpp | 2 +- .../protogalaxy/protogalaxy_prover_ultra.cpp | 2 +- .../protogalaxy/protogalaxy_verifier.cpp | 10 ++--- .../protogalaxy/protogalaxy_verifier.hpp | 6 +-- .../protogalaxy/prover_verifier_shared.cpp | 2 +- .../protogalaxy/prover_verifier_shared.hpp | 2 +- .../client_ivc_recursive_verifier.hpp | 2 +- .../protogalaxy_recursive_verifier.cpp | 18 ++++---- .../protogalaxy_recursive_verifier.hpp | 6 +-- .../protogalaxy_recursive_verifier.test.cpp | 22 +++++----- 25 files changed, 104 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04695b78f76..2ead5f24ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3957,7 +3957,7 @@ * **docs:** Docs deeper dive into unconstrained functions ([#4233](https://github.com/AztecProtocol/aztec-packages/issues/4233)) ([6af548e](https://github.com/AztecProtocol/aztec-packages/commit/6af548e369d5d20bcbd08d346f5c6f89b7363f39)) * Emit single functions from class registerer ([#4429](https://github.com/AztecProtocol/aztec-packages/issues/4429)) ([19e03ad](https://github.com/AztecProtocol/aztec-packages/commit/19e03adc71ab7561d33dc9d75b9bdb7c19883fc9)), closes [#4427](https://github.com/AztecProtocol/aztec-packages/issues/4427) * Extend Historical Access APIs [#4179](https://github.com/AztecProtocol/aztec-packages/issues/4179) ([#4375](https://github.com/AztecProtocol/aztec-packages/issues/4375)) ([c918d8d](https://github.com/AztecProtocol/aztec-packages/commit/c918d8d1a6ba306afd2feab97ddb8527b76d1a82)) -* Folding `GoblinUltra` instances in ProtoGalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) +* Folding `GoblinUltra` instances in Protogalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) * Hashing output of `serialize()` in noir + more tests ([#4365](https://github.com/AztecProtocol/aztec-packages/issues/4365)) ([5a71bb9](https://github.com/AztecProtocol/aztec-packages/commit/5a71bb95a57bf22189e2611035e5f1faae92426b)) * Implementation for bigint opcodes ([#4288](https://github.com/AztecProtocol/aztec-packages/issues/4288)) ([b61dace](https://github.com/AztecProtocol/aztec-packages/commit/b61dacee47f57a8fce6657f28b64e7a3128d0dba)) * Improve ivc bench ([#4242](https://github.com/AztecProtocol/aztec-packages/issues/4242)) ([9d28354](https://github.com/AztecProtocol/aztec-packages/commit/9d28354ecefc9f7db71c7d2f40da7eae30e133c5)) diff --git a/barretenberg/CHANGELOG.md b/barretenberg/CHANGELOG.md index fd3bb3bba9e..0100a467b37 100644 --- a/barretenberg/CHANGELOG.md +++ b/barretenberg/CHANGELOG.md @@ -1248,7 +1248,7 @@ - **avm:** Add command to call avm proving in bb binary ([#4369](https://github.com/AztecProtocol/aztec-packages/issues/4369)) ([4f6d607](https://github.com/AztecProtocol/aztec-packages/commit/4f6d607d7dce36819d84ba6ce69bbd57e0ad79a0)), closes [#4039](https://github.com/AztecProtocol/aztec-packages/issues/4039) - **avm:** Back in avm context with macro - refactor context ([#4438](https://github.com/AztecProtocol/aztec-packages/issues/4438)) ([ccf9b17](https://github.com/AztecProtocol/aztec-packages/commit/ccf9b17495ec46df6494fa93e1c848c87a05d071)) - **bb:** Wasmtime and remote benchmarking ([#4204](https://github.com/AztecProtocol/aztec-packages/issues/4204)) ([fd27808](https://github.com/AztecProtocol/aztec-packages/commit/fd27808721b1f32b4828db5465b502cca2f1ce6c)) -- Folding `Mega` instances in ProtoGalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) +- Folding `Mega` instances in Protogalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) - Implementation for bigint opcodes ([#4288](https://github.com/AztecProtocol/aztec-packages/issues/4288)) ([b61dace](https://github.com/AztecProtocol/aztec-packages/commit/b61dacee47f57a8fce6657f28b64e7a3128d0dba)) - Improve ivc bench ([#4242](https://github.com/AztecProtocol/aztec-packages/issues/4242)) ([9d28354](https://github.com/AztecProtocol/aztec-packages/commit/9d28354ecefc9f7db71c7d2f40da7eae30e133c5)) - Memory only brillig ([#4215](https://github.com/AztecProtocol/aztec-packages/issues/4215)) ([018177b](https://github.com/AztecProtocol/aztec-packages/commit/018177bc757cce3258c153a56f1f7a871fec681c)) diff --git a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py index c2464204ea4..43efc74fed0 100644 --- a/barretenberg/cpp/scripts/analyze_client_ivc_bench.py +++ b/barretenberg/cpp/scripts/analyze_client_ivc_bench.py @@ -66,10 +66,10 @@ print('\nBreakdown of ProtogalaxyProver::prove:') protogalaxy_round_labels = [ - "ProtoGalaxyProver_::preparation_round(t)", - "ProtoGalaxyProver_::perturbator_round(t)", - "ProtoGalaxyProver_::combiner_quotient_round(t)", - "ProtoGalaxyProver_::update_target_sum_and_fold(t)" + "ProtogalaxyProver_::preparation_round(t)", + "ProtogalaxyProver_::perturbator_round(t)", + "ProtogalaxyProver_::combiner_quotient_round(t)", + "ProtogalaxyProver_::update_target_sum_and_fold(t)" ] max_label_length = max(len(label) for label in protogalaxy_round_labels) for key in protogalaxy_round_labels: diff --git a/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py b/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py index 56be71fec2e..b5686fc351a 100755 --- a/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py +++ b/barretenberg/cpp/scripts/analyze_protogalaxy_bench.py @@ -47,10 +47,10 @@ print('\nBreakdown of ProtogalaxyProver::prove:') protogalaxy_round_labels = [ - "ProtoGalaxyProver_::preparation_round(t)", - "ProtoGalaxyProver_::perturbator_round(t)", - "ProtoGalaxyProver_::combiner_quotient_round(t)", - "ProtoGalaxyProver_::update_target_sum_and_fold(t)" + "ProtogalaxyProver_::preparation_round(t)", + "ProtogalaxyProver_::perturbator_round(t)", + "ProtogalaxyProver_::combiner_quotient_round(t)", + "ProtogalaxyProver_::update_target_sum_and_fold(t)" ] max_label_length = max(len(label) for label in protogalaxy_round_labels) for key in protogalaxy_round_labels: diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp index ead9390e54f..ac0b3a3893d 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.hpp @@ -36,9 +36,9 @@ class AztecIVC { using DeciderProver = DeciderProver_; using DeciderVerifier = DeciderVerifier_; using ProverInstances = ProverInstances_; - using FoldingProver = ProtoGalaxyProver_; + using FoldingProver = ProtogalaxyProver_; using VerifierInstances = VerifierInstances_; - using FoldingVerifier = ProtoGalaxyVerifier_; + using FoldingVerifier = ProtogalaxyVerifier_; using ECCVMVerificationKey = bb::ECCVMFlavor::VerificationKey; using TranslatorVerificationKey = bb::TranslatorFlavor::VerificationKey; @@ -47,7 +47,7 @@ class AztecIVC { using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; using RecursiveVerificationKey = RecursiveFlavor::VerificationKey; using FoldingRecursiveVerifier = - bb::stdlib::recursion::honk::ProtoGalaxyRecursiveVerifier_; + bb::stdlib::recursion::honk::ProtogalaxyRecursiveVerifier_; using OinkRecursiveVerifier = stdlib::recursion::honk::OinkRecursiveVerifier_; using DataBusDepot = stdlib::DataBusDepot; diff --git a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp index 237d8b6b7e7..84012b3cb85 100644 --- a/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/aztec_ivc/aztec_ivc.test.cpp @@ -26,9 +26,9 @@ class AztecIVCTests : public ::testing::Test { using DeciderProver = AztecIVC::DeciderProver; using DeciderVerifier = AztecIVC::DeciderVerifier; using ProverInstances = ProverInstances_; - using FoldingProver = ProtoGalaxyProver_; + using FoldingProver = ProtogalaxyProver_; using VerifierInstances = VerifierInstances_; - using FoldingVerifier = ProtoGalaxyVerifier_; + using FoldingVerifier = ProtogalaxyVerifier_; /** * @brief Construct mock circuit with arithmetic gates and goblin ops diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp index 21a4e46606a..e79f5a44b4f 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_bench/protogalaxy.bench.cpp @@ -17,7 +17,7 @@ template void fold_k(State& state) noexcept using ProverInstance = ProverInstance_; using Instance = ProverInstance; using Instances = ProverInstances_; - using ProtoGalaxyProver = ProtoGalaxyProver_; + using ProtogalaxyProver = ProtogalaxyProver_; using Builder = typename Flavor::CircuitBuilder; bb::srs::init_crs_factory("../srs_db/ignition"); @@ -35,7 +35,7 @@ template void fold_k(State& state) noexcept instances.emplace_back(construct_instance()); } - ProtoGalaxyProver folding_prover(instances); + ProtogalaxyProver folding_prover(instances); for (auto _ : state) { BB_REPORT_OP_COUNT_IN_BENCH(state); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp index 414a89b908b..ce372cf31f3 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/protogalaxy_rounds_bench/protogalaxy_rounds.bench.cpp @@ -10,12 +10,12 @@ using namespace benchmark; namespace bb { template -void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_>&)) +void _bench_round(::benchmark::State& state, void (*F)(ProtogalaxyProver_>&)) { using Builder = typename Flavor::CircuitBuilder; using ProverInstance = ProverInstance_; using Instances = ProverInstances_; - using ProtoGalaxyProver = ProtoGalaxyProver_; + using ProtogalaxyProver = ProtogalaxyProver_; bb::srs::init_crs_factory("../srs_db/ignition"); auto log2_num_gates = static_cast(state.range(0)); @@ -31,7 +31,7 @@ void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_ prover_instance_1 = construct_instance(); std::shared_ptr prover_instance_2 = construct_instance(); - ProtoGalaxyProver folding_prover({ prover_instance_1, prover_instance_2 }); + ProtogalaxyProver folding_prover({ prover_instance_1, prover_instance_2 }); // prepare the prover state folding_prover.state.accumulator = prover_instance_1; @@ -46,7 +46,7 @@ void _bench_round(::benchmark::State& state, void (*F)(ProtoGalaxyProver_>&)) +void bench_round_mega(::benchmark::State& state, void (*F)(ProtogalaxyProver_>&)) { _bench_round(state, F); } diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp index 3051b1bf433..8c7d3fd538d 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.hpp @@ -31,9 +31,9 @@ class ClientIVC { using DeciderProver = DeciderProver_; using DeciderVerifier = DeciderVerifier_; using ProverInstances = ProverInstances_; - using FoldingProver = ProtoGalaxyProver_; + using FoldingProver = ProtogalaxyProver_; using VerifierInstances = VerifierInstances_; - using FoldingVerifier = ProtoGalaxyVerifier_; + using FoldingVerifier = ProtogalaxyVerifier_; using ECCVMVerificationKey = bb::ECCVMFlavor::VerificationKey; using TranslatorVerificationKey = bb::TranslatorFlavor::VerificationKey; @@ -42,7 +42,7 @@ class ClientIVC { using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; using RecursiveVerificationKey = RecursiveVerifierInstances::VerificationKey; using FoldingRecursiveVerifier = - bb::stdlib::recursion::honk::ProtoGalaxyRecursiveVerifier_; + bb::stdlib::recursion::honk::ProtogalaxyRecursiveVerifier_; // A full proof for the IVC scheme struct Proof { diff --git a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp index 57cf6997837..77685d2717c 100644 --- a/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp +++ b/barretenberg/cpp/src/barretenberg/client_ivc/client_ivc.test.cpp @@ -26,9 +26,9 @@ class ClientIVCTests : public ::testing::Test { using DeciderProver = ClientIVC::DeciderProver; using DeciderVerifier = ClientIVC::DeciderVerifier; using ProverInstances = ProverInstances_; - using FoldingProver = ProtoGalaxyProver_; + using FoldingProver = ProtogalaxyProver_; using VerifierInstances = VerifierInstances_; - using FoldingVerifier = ProtoGalaxyVerifier_; + using FoldingVerifier = ProtogalaxyVerifier_; /** * @brief Prove and verify the IVC scheme diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp index 81bea2a0aed..e68c93da095 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp @@ -178,7 +178,7 @@ template struct PowPolynomial { }; /**< * @struct PowPolynomial - * @brief Implementation of the methods for the \f$pow_{\ell}\f$-polynomials used in ProtoGalaxy and + * @brief Implementation of the methods for the \f$pow_{\ell}\f$-polynomials used in Protogalaxy and \f$pow_{\beta}\f$-polynomials used in Sumcheck. * * @details diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 56f09ffe349..f69a14f8db9 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -16,14 +16,14 @@ namespace { auto& engine = numeric::get_debug_randomness(); -template class ProtoGalaxyTests : public testing::Test { +template class ProtogalaxyTests : public testing::Test { public: using VerificationKey = typename Flavor::VerificationKey; using ProverInstance = ProverInstance_; using ProverInstances = ProverInstances_; using VerifierInstance = VerifierInstance_; using VerifierInstances = VerifierInstances_; - using ProtoGalaxyProver = ProtoGalaxyProver_; + using ProtogalaxyProver = ProtogalaxyProver_; using FF = typename Flavor::FF; using Affine = typename Flavor::Commitment; using Projective = typename Flavor::GroupElement; @@ -36,8 +36,8 @@ template class ProtoGalaxyTests : public testing::Test { using PowPolynomial = bb::PowPolynomial; using DeciderProver = DeciderProver_; using DeciderVerifier = DeciderVerifier_; - using FoldingProver = ProtoGalaxyProver_; - using FoldingVerifier = ProtoGalaxyVerifier_; + using FoldingProver = ProtogalaxyProver_; + using FoldingVerifier = ProtogalaxyVerifier_; using Fun = ProtogalaxyProverInternal; using TupleOfInstances = @@ -550,8 +550,8 @@ template class ProtoGalaxyTests : public testing::Test { constexpr size_t total_insts = k + 1; TupleOfInstances insts = construct_instances(total_insts); - ProtoGalaxyProver_> folding_prover(get<0>(insts)); - ProtoGalaxyVerifier_> folding_verifier(get<1>(insts)); + ProtogalaxyProver_> folding_prover(get<0>(insts)); + ProtogalaxyVerifier_> folding_verifier(get<1>(insts)); auto [prover_accumulator, folding_proof] = folding_prover.prove(); auto verifier_accumulator = folding_verifier.verify_folding_proof(folding_proof); @@ -563,74 +563,74 @@ template class ProtoGalaxyTests : public testing::Test { } // namespace using FlavorTypes = testing::Types; -TYPED_TEST_SUITE(ProtoGalaxyTests, FlavorTypes); +TYPED_TEST_SUITE(ProtogalaxyTests, FlavorTypes); -TYPED_TEST(ProtoGalaxyTests, PerturbatorCoefficients) +TYPED_TEST(ProtogalaxyTests, PerturbatorCoefficients) { TestFixture::test_pertubator_coefficients(); } -TYPED_TEST(ProtoGalaxyTests, FullHonkEvaluationsValidCircuit) +TYPED_TEST(ProtogalaxyTests, FullHonkEvaluationsValidCircuit) { TestFixture::test_full_honk_evaluations_valid_circuit(); } -TYPED_TEST(ProtoGalaxyTests, PerturbatorPolynomial) +TYPED_TEST(ProtogalaxyTests, PerturbatorPolynomial) { TestFixture::test_pertubator_polynomial(); } -TYPED_TEST(ProtoGalaxyTests, CombinerQuotient) +TYPED_TEST(ProtogalaxyTests, CombinerQuotient) { TestFixture::test_combiner_quotient(); } -TYPED_TEST(ProtoGalaxyTests, CombineRelationParameters) +TYPED_TEST(ProtogalaxyTests, CombineRelationParameters) { TestFixture::test_compute_extended_relation_parameters(); } -TYPED_TEST(ProtoGalaxyTests, CombineAlphas) +TYPED_TEST(ProtogalaxyTests, CombineAlphas) { TestFixture::test_compute_and_extend_alphas(); } -TYPED_TEST(ProtoGalaxyTests, ProtogalaxyInhomogeneous) +TYPED_TEST(ProtogalaxyTests, ProtogalaxyInhomogeneous) { TestFixture::test_protogalaxy_inhomogeneous(); } -TYPED_TEST(ProtoGalaxyTests, FullProtogalaxyTest) +TYPED_TEST(ProtogalaxyTests, FullProtogalaxyTest) { TestFixture::test_full_protogalaxy(); } -TYPED_TEST(ProtoGalaxyTests, FullProtogalaxyStructuredTrace) +TYPED_TEST(ProtogalaxyTests, FullProtogalaxyStructuredTrace) { TestFixture::test_full_protogalaxy_structured_trace(); } -TYPED_TEST(ProtoGalaxyTests, FullProtogalaxyStructuredTraceInhomogeneous) +TYPED_TEST(ProtogalaxyTests, FullProtogalaxyStructuredTraceInhomogeneous) { TestFixture::test_full_protogalaxy_structured_trace_inhomogeneous_circuits(); } -TYPED_TEST(ProtoGalaxyTests, TamperedCommitment) +TYPED_TEST(ProtogalaxyTests, TamperedCommitment) { TestFixture::test_tampered_commitment(); } -TYPED_TEST(ProtoGalaxyTests, TamperedAccumulatorPolynomial) +TYPED_TEST(ProtogalaxyTests, TamperedAccumulatorPolynomial) { TestFixture::test_tampered_accumulator_polynomial(); } -TYPED_TEST(ProtoGalaxyTests, BadLookupFailure) +TYPED_TEST(ProtogalaxyTests, BadLookupFailure) { TestFixture::test_protogalaxy_bad_lookup_failure(); } // We only fold one instance currently due to significant compile time added by multiple instances -TYPED_TEST(ProtoGalaxyTests, Fold1Instance) +TYPED_TEST(ProtogalaxyTests, Fold1Instance) { TestFixture::template test_fold_k_instances<1>(); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index acc5d295ef2..4c7b36903a0 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -4,7 +4,7 @@ namespace bb { -template class ProtoGalaxyProver_ { +template class ProtogalaxyProver_ { public: using ProverInstance = typename ProverInstances_::Instance; using Flavor = typename ProverInstances_::Flavor; @@ -40,8 +40,8 @@ template class ProtoGalaxyProver_ { std::shared_ptr commitment_key; State state; - ProtoGalaxyProver_() = default; - ProtoGalaxyProver_(const std::vector>& insts) + ProtogalaxyProver_() = default; + ProtogalaxyProver_(const std::vector>& insts) : instances(ProverInstances_(insts)) // TODO(https://github.com/AztecProtocol/barretenberg/issues/878) , commitment_key(instances[1]->proving_key.commitment_key){}; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index dbb0c2af051..2185da9bf4b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -8,10 +8,10 @@ namespace bb { template -void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, +void ProtogalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, const std::string& domain_separator) { - ZoneScopedN("ProtoGalaxyProver::finalise_and_send_instance"); + ZoneScopedN("ProtogalaxyProver::finalise_and_send_instance"); OinkProver oink_prover(instance, transcript, domain_separator + '_'); oink_prover.prove(); @@ -23,14 +23,14 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared * and the computation of Lagrange basis for k instances */ template -FoldingResult ProtoGalaxyProver_::update_target_sum_and_fold( +FoldingResult ProtogalaxyProver_::update_target_sum_and_fold( const ProverInstances& instances, const CombinerQuotient& combiner_quotient, const UnivariateRelationSeparator& alphas, const UnivariateRelationParameters& univariate_relation_parameters, const FF& perturbator_evaluation) { - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::update_target_sum_and_fold"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::update_target_sum_and_fold"); using Fun = ProtogalaxyProverInternal; const FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); @@ -72,9 +72,9 @@ FoldingResult ProtoGalaxyProver_ void ProtoGalaxyProver_::run_oink_prover_on_each_instance() +template void ProtogalaxyProver_::run_oink_prover_on_each_instance() { - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::run_oink_prover_on_each_instance"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::run_oink_prover_on_each_instance"); auto idx = 0; auto& instance = instances[0]; auto domain_separator = std::to_string(idx); @@ -98,10 +98,10 @@ template void ProtoGalaxyProver_::run_o template std::tuple, LegacyPolynomial> -ProtoGalaxyProver_::perturbator_round( +ProtogalaxyProver_::perturbator_round( const std::shared_ptr& accumulator) { - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::perturbator_round"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::perturbator_round"); using Fun = ProtogalaxyProverInternal; @@ -125,15 +125,15 @@ ProtoGalaxyProver_::perturbator_round( template std::tuple, - typename ProtoGalaxyProver_::UnivariateRelationSeparator, - typename ProtoGalaxyProver_::UnivariateRelationParameters, + typename ProtogalaxyProver_::UnivariateRelationSeparator, + typename ProtogalaxyProver_::UnivariateRelationParameters, typename ProverInstances::Flavor::FF, - typename ProtoGalaxyProver_::CombinerQuotient> -ProtoGalaxyProver_::combiner_quotient_round(const std::vector& gate_challenges, + typename ProtogalaxyProver_::CombinerQuotient> +ProtogalaxyProver_::combiner_quotient_round(const std::vector& gate_challenges, const std::vector& deltas, const ProverInstances& instances) { - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::combiner_quotient_round"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::combiner_quotient_round"); using Fun = ProtogalaxyProverInternal; @@ -161,7 +161,7 @@ ProtoGalaxyProver_::combiner_quotient_round(const std::vector -FoldingResult ProtoGalaxyProver_::prove() +FoldingResult ProtogalaxyProver_::prove() { ZoneScopedN("ProtogalaxyProver::prove"); BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove"); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 63d1b98ea33..c89c368101c 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -57,9 +57,9 @@ template class ProtogalaxyProverInternal { /** * @brief Compute the values of the full Honk relation at each row in the execution trace, representing f_i(ω) in - * the ProtoGalaxy paper, given the evaluations of all the prover polynomials and \vec{α} (the batching challenges + * the Protogalaxy paper, given the evaluations of all the prover polynomials and \vec{α} (the batching challenges * that help establishing each subrelation is independently valid in Honk - from the Plonk paper, DO NOT confuse - * with α in ProtoGalaxy). + * with α in Protogalaxy). * * @details When folding Mega instances, one of the relations is linearly dependent. We define such relations * as acting on the entire execution trace and hence requiring to be accumulated separately as we iterate over each @@ -72,7 +72,7 @@ template class ProtogalaxyProverInternal { const RelationParameters& relation_parameters) { - BB_OP_COUNT_TIME_NAME("ProtoGalaxyProver_::compute_full_honk_evaluations"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::compute_full_honk_evaluations"); auto instance_size = instance_polynomials.get_polynomial_size(); std::vector full_honk_evaluations(instance_size); const std::vector linearly_dependent_contribution_accumulators = parallel_for_heuristic( diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_mega.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_mega.cpp index 2d96969cf8d..1f92af9dae1 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_mega.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_mega.cpp @@ -5,5 +5,5 @@ #include "protogalaxy_prover_impl.hpp" namespace bb { -template class ProtoGalaxyProver_>; +template class ProtogalaxyProver_>; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_ultra.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_ultra.cpp index 8cc9c4f768f..bf6ff176912 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_ultra.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_ultra.cpp @@ -4,5 +4,5 @@ // TODO(https://github.com/AztecProtocol/barretenberg/issues/1076) Remove this instantiation. namespace bb { -template class ProtoGalaxyProver_>; +template class ProtogalaxyProver_>; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index c61576cdfc0..5e9dc05515d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -6,7 +6,7 @@ namespace bb { template -void ProtoGalaxyVerifier_::receive_and_finalise_instance(const std::shared_ptr& inst, +void ProtogalaxyVerifier_::receive_and_finalise_instance(const std::shared_ptr& inst, const std::string& domain_separator) { OinkVerifier oink_verifier{ inst, transcript, domain_separator + '_' }; @@ -14,7 +14,7 @@ void ProtoGalaxyVerifier_::receive_and_finalise_instance(cons } template -void ProtoGalaxyVerifier_::prepare_for_folding(const std::vector& fold_data) +void ProtogalaxyVerifier_::prepare_for_folding(const std::vector& fold_data) { transcript = std::make_shared(fold_data); auto index = 0; @@ -35,7 +35,7 @@ void ProtoGalaxyVerifier_::prepare_for_folding(const std::vec } template -std::shared_ptr ProtoGalaxyVerifier_::verify_folding_proof( +std::shared_ptr ProtogalaxyVerifier_::verify_folding_proof( const std::vector& fold_data) { prepare_for_folding(fold_data); @@ -171,7 +171,7 @@ std::shared_ptr ProtoGalaxyVerifier_>; -template class ProtoGalaxyVerifier_>; +template class ProtogalaxyVerifier_>; +template class ProtogalaxyVerifier_>; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.hpp index 0d08141c3f7..8c96456b1e4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.hpp @@ -7,7 +7,7 @@ #include "barretenberg/transcript/transcript.hpp" namespace bb { -template class ProtoGalaxyVerifier_ { +template class ProtogalaxyVerifier_ { public: using Flavor = typename VerifierInstances::Flavor; using Transcript = typename Flavor::Transcript; @@ -27,9 +27,9 @@ template class ProtoGalaxyVerifier_ { CommitmentLabels commitment_labels; - ProtoGalaxyVerifier_(const std::vector>& insts) + ProtogalaxyVerifier_(const std::vector>& insts) : instances(VerifierInstances(insts)){}; - ~ProtoGalaxyVerifier_() = default; + ~ProtogalaxyVerifier_() = default; std::shared_ptr get_accumulator() { return instances[0]; } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.cpp index 12484eb37d6..90059bdf1e8 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.cpp @@ -15,7 +15,7 @@ std::vector update_gate_challenges(const fr& perturbator_challenge, } /** - * @brief For a new round challenge δ at each iteration of the ProtoGalaxy protocol, compute the vector + * @brief For a new round challenge δ at each iteration of the Protogalaxy protocol, compute the vector * [δ, δ^2,..., δ^t] where t = logn and n is the size of the instance. */ std::vector compute_round_challenge_pows(const size_t log_instance_size, const fr& round_challenge) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.hpp index ff21c50498b..412f5e44495 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/prover_verifier_shared.hpp @@ -12,7 +12,7 @@ std::vector update_gate_challenges(const fr& perturbator_challenge, const std::vector& init_challenges); /** - * @brief For a new round challenge δ at each iteration of the ProtoGalaxy protocol, compute the vector + * @brief For a new round challenge δ at each iteration of the Protogalaxy protocol, compute the vector * [δ, δ^2,..., δ^t] where t = logn and n is the size of the instance. */ std::vector compute_round_challenge_pows(const size_t log_instance_size, const fr& round_challenge); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp index 4f9f006a06d..b68e104615d 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/client_ivc_verifier/client_ivc_recursive_verifier.hpp @@ -11,7 +11,7 @@ class ClientIVCRecursiveVerifier { using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; using RecursiveVerificationKey = RecursiveVerifierInstances::VerificationKey; using DeciderVerifier = DeciderRecursiveVerifier_; - using FoldingVerifier = ProtoGalaxyRecursiveVerifier_; + using FoldingVerifier = ProtogalaxyRecursiveVerifier_; using GoblinVerifier = GoblinRecursiveVerifier; public: diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp index ce1428f06d7..5d0f02fdad1 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.cpp @@ -5,7 +5,7 @@ namespace bb::stdlib::recursion::honk { template -void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_instance( +void ProtogalaxyRecursiveVerifier_::receive_and_finalise_instance( const std::shared_ptr& inst, std::string& domain_separator) { domain_separator = domain_separator + "_"; @@ -15,7 +15,7 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst // TODO(https://github.com/AztecProtocol/barretenberg/issues/795): The rounds prior to actual verifying are common // between decider and folding verifier and could be somehow shared so we do not duplicate code so much. -template void ProtoGalaxyRecursiveVerifier_::prepare_for_folding() +template void ProtogalaxyRecursiveVerifier_::prepare_for_folding() { auto index = 0; auto inst = instances[0]; @@ -36,7 +36,7 @@ template void ProtoGalaxyRecursiveVerifier_ -std::shared_ptr ProtoGalaxyRecursiveVerifier_< +std::shared_ptr ProtogalaxyRecursiveVerifier_< VerifierInstances>::verify_folding_proof(const StdlibProof& proof) { using Transcript = typename Flavor::Transcript; @@ -131,13 +131,13 @@ std::shared_ptr ProtoGalaxyRecursiveVerifi return next_accumulator; } -template class ProtoGalaxyRecursiveVerifier_< +template class ProtogalaxyRecursiveVerifier_< RecursiveVerifierInstances_, 2>>; -template class ProtoGalaxyRecursiveVerifier_, 2>>; -template class ProtoGalaxyRecursiveVerifier_, 2>>; -template class ProtoGalaxyRecursiveVerifier_, 2>>; -template class ProtoGalaxyRecursiveVerifier_< +template class ProtogalaxyRecursiveVerifier_, 2>>; +template class ProtogalaxyRecursiveVerifier_, 2>>; +template class ProtogalaxyRecursiveVerifier_, 2>>; +template class ProtogalaxyRecursiveVerifier_< RecursiveVerifierInstances_, 2>>; -template class ProtoGalaxyRecursiveVerifier_< +template class ProtogalaxyRecursiveVerifier_< RecursiveVerifierInstances_, 2>>; } // namespace bb::stdlib::recursion::honk \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp index 66b79a326da..0a1d139ef57 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.hpp @@ -9,7 +9,7 @@ #include "barretenberg/stdlib_circuit_builders/ultra_recursive_flavor.hpp" namespace bb::stdlib::recursion::honk { -template class ProtoGalaxyRecursiveVerifier_ { +template class ProtogalaxyRecursiveVerifier_ { public: using Flavor = typename VerifierInstances::Flavor; using NativeFlavor = typename Flavor::NativeFlavor; @@ -43,14 +43,14 @@ template class ProtoGalaxyRecursiveVerifier_ { std::shared_ptr transcript; VerifierInstances instances; - ProtoGalaxyRecursiveVerifier_(Builder* builder, + ProtogalaxyRecursiveVerifier_(Builder* builder, const std::shared_ptr& accumulator, const std::vector>& instance_vks) : builder(builder) , instances(VerifierInstances(builder, accumulator, instance_vks)){}; /** - * @brief Given a new round challenge δ for each iteration of the full ProtoGalaxy protocol, compute the vector + * @brief Given a new round challenge δ for each iteration of the full Protogalaxy protocol, compute the vector * [δ, δ^2,..., δ^t] where t = logn and n is the size of the instance. */ static std::vector compute_round_challenge_pows(size_t log_instance_size, FF round_challenge) diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp index f64f0580f40..6a91085811f 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp @@ -15,7 +15,7 @@ #include "barretenberg/ultra_honk/ultra_verifier.hpp" namespace bb::stdlib::recursion::honk { -template class ProtoGalaxyRecursiveTests : public testing::Test { +template class ProtogalaxyRecursiveTests : public testing::Test { public: // Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified using InnerFlavor = typename RecursiveFlavor::NativeFlavor; @@ -39,14 +39,14 @@ template class ProtoGalaxyRecursiveTests : public tes using RecursiveVerifierInstances = ::bb::stdlib::recursion::honk::RecursiveVerifierInstances_; using RecursiveVerifierInstance = RecursiveVerifierInstances::Instance; using RecursiveVerificationKey = RecursiveVerifierInstances::VerificationKey; - using FoldingRecursiveVerifier = ProtoGalaxyRecursiveVerifier_; + using FoldingRecursiveVerifier = ProtogalaxyRecursiveVerifier_; using DeciderRecursiveVerifier = DeciderRecursiveVerifier_; using InnerDeciderProver = DeciderProver_; using InnerDeciderVerifier = DeciderVerifier_; using InnerVerifierInstances = VerifierInstances_; using InnerProverInstances = ProverInstances_; - using InnerFoldingVerifier = ProtoGalaxyVerifier_; - using InnerFoldingProver = ProtoGalaxyProver_; + using InnerFoldingVerifier = ProtogalaxyVerifier_; + using InnerFoldingProver = ProtogalaxyProver_; static void SetUpTestSuite() { bb::srs::init_crs_factory("../srs_db/ignition"); } /** @@ -391,35 +391,35 @@ template class ProtoGalaxyRecursiveTests : public tes using FlavorTypes = testing::Types, MegaRecursiveFlavor_>; -TYPED_TEST_SUITE(ProtoGalaxyRecursiveTests, FlavorTypes); +TYPED_TEST_SUITE(ProtogalaxyRecursiveTests, FlavorTypes); -TYPED_TEST(ProtoGalaxyRecursiveTests, InnerCircuit) +TYPED_TEST(ProtogalaxyRecursiveTests, InnerCircuit) { TestFixture::test_circuit(); } -TYPED_TEST(ProtoGalaxyRecursiveTests, NewEvaluate) +TYPED_TEST(ProtogalaxyRecursiveTests, NewEvaluate) { TestFixture::test_new_evaluate(); } -TYPED_TEST(ProtoGalaxyRecursiveTests, RecursiveFoldingTest) +TYPED_TEST(ProtogalaxyRecursiveTests, RecursiveFoldingTest) { TestFixture::test_recursive_folding(); } -TYPED_TEST(ProtoGalaxyRecursiveTests, FullProtogalaxyRecursiveTest) +TYPED_TEST(ProtogalaxyRecursiveTests, FullProtogalaxyRecursiveTest) { TestFixture::test_full_protogalaxy_recursive(); } -TYPED_TEST(ProtoGalaxyRecursiveTests, TamperedDeciderProof) +TYPED_TEST(ProtogalaxyRecursiveTests, TamperedDeciderProof) { TestFixture::test_tampered_decider_proof(); } -TYPED_TEST(ProtoGalaxyRecursiveTests, TamperedAccumulator) +TYPED_TEST(ProtogalaxyRecursiveTests, TamperedAccumulator) { TestFixture::test_tampered_accumulator(); } From 54349b3e94d1890596703de9d8a2921acef85b79 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 16:26:40 +0000 Subject: [PATCH 25/36] PowPolynomial is a misnomer --- .../barretenberg/polynomials/pow.bench.cpp | 2 +- .../cpp/src/barretenberg/polynomials/pow.hpp | 43 ++++++++++--------- .../src/barretenberg/polynomials/pow.test.cpp | 16 +++---- .../protogalaxy/combiner.test.cpp | 28 ++++++------ .../protogalaxy/protogalaxy.test.cpp | 11 ++--- .../protogalaxy/protogalaxy_prover_impl.hpp | 5 ++- .../protogalaxy_prover_internal.hpp | 14 +++--- .../src/barretenberg/sumcheck/sumcheck.hpp | 22 +++++----- .../barretenberg/sumcheck/sumcheck_round.hpp | 29 +++++++------ .../sumcheck/sumcheck_round.test.cpp | 4 +- 10 files changed, 89 insertions(+), 85 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.bench.cpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.bench.cpp index b3f1d31e55b..5a092bbcadc 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/pow.bench.cpp @@ -16,7 +16,7 @@ void compute_pow_poly(benchmark::State& state) for (auto _ : state) { int64_t num_betas = state.range(0); std::vector cur_betas(betas.begin(), betas.begin() + num_betas); - PowPolynomial pow{ cur_betas, cur_betas.size() }; + GateSeparatorPolynomial poly{ cur_betas, cur_betas.size() }; } } diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp index e68c93da095..5ef5580fcbc 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp @@ -8,7 +8,7 @@ #include namespace bb { -template struct PowPolynomial { +template struct GateSeparatorPolynomial { /** * @brief The challenges \f$(\beta_0,\ldots, \beta_{d-1}) \f$ * @@ -20,7 +20,7 @@ template struct PowPolynomial { * identified with the integers \f$\ell = 0,\ldots, 2^d-1\f$ * */ - std::vector pow_betas; + std::vector beta_products; /** * @brief In Round \f$ i\f$ of Sumcheck, it points to the \f$ i \f$-th element in \f$ \vec \beta \f$ * @@ -28,7 +28,7 @@ template struct PowPolynomial { size_t current_element_idx = 0; /** * @brief In Round \f$ i\f$ of Sumcheck, the periodicity equals to \f$ 2^{i+1}\f$ and represents the fixed interval - * at which elements not containing either of \f$ (\beta_0,\ldots ,β_i)\f$ appear in #pow_betas. + * at which elements not containing either of \f$ (\beta_0,\ldots ,β_i)\f$ appear in #beta_products. * */ size_t periodicity = 2; @@ -42,33 +42,33 @@ template struct PowPolynomial { FF partial_evaluation_result = FF(1); /** - * @brief Construct a new PowPolynomial + * @brief Construct a new GateSeparatorPolynomial * * @param betas * @param log_num_monomials */ - PowPolynomial(const std::vector& betas, const size_t log_num_monomials) + GateSeparatorPolynomial(const std::vector& betas, const size_t log_num_monomials) : betas(betas) - , pow_betas(compute_pow_betas(betas, log_num_monomials)) + , beta_products(compute_beta_products(betas, log_num_monomials)) {} /** - * @brief Construct a new PowPolynomial object without expanding to a vector of monomials - * @details The sumcheck verifier does not use pow_betas + * @brief Construct a new GateSeparatorPolynomial object without expanding to a vector of monomials + * @details The sumcheck verifier does not use beta_products * * @param betas */ - PowPolynomial(const std::vector& betas) + GateSeparatorPolynomial(const std::vector& betas) : betas(betas) {} /** - * @brief Retruns the element in #pow_betas at place #idx. + * @brief Retruns the element in #beta_products at place #idx. * * @param idx * @return FF const& */ - FF const& operator[](size_t idx) const { return pow_betas[idx]; } + FF const& operator[](size_t idx) const { return beta_products[idx]; } /** * @brief Computes the component at index #current_element_idx in #betas. * @@ -134,15 +134,16 @@ template struct PowPolynomial { * @brief Given \f$ \vec\beta = (\beta_0,...,\beta_{d-1})\f$ compute \f$ pow_{\ell}(\vec \beta) = pow_{\beta}(\vec * \ell)\f$ for \f$ \ell =0,\ldots,2^{d}-1\f$. * - * @param log_num_monomials Determines the number of beta challenges used to compute pow_betas (required because + * @param log_num_monomials Determines the number of beta challenges used to compute beta_products (required because * when we generate CONST_SIZE_PROOF_LOG_N, currently 28, challenges but the real circuit size is less than 1 << - * CONST_SIZE_PROOF_LOG_N, we should compute unnecessarily a vector of pow_betas of length 1 << 28 ) + * CONST_SIZE_PROOF_LOG_N, we should compute unnecessarily a vector of beta_products of length 1 << 28 ) */ - BB_PROFILE static std::vector compute_pow_betas(const std::vector& betas, const size_t log_num_monomials) + BB_PROFILE static std::vector compute_beta_products(const std::vector& betas, + const size_t log_num_monomials) { size_t pow_size = 1 << log_num_monomials; - std::vector pow_betas(pow_size); + std::vector beta_products(pow_size); // Determine number of threads for multithreading. // Note: Multithreading is "on" for every round but we reduce the number of threads from the max available based @@ -169,20 +170,20 @@ template struct PowPolynomial { res *= betas[beta_idx]; } } - pow_betas[i] = res; + beta_products[i] = res; } }); - return pow_betas; + return beta_products; } }; /**< - * @struct PowPolynomial + * @struct GateSeparatorPolynomial * @brief Implementation of the methods for the \f$pow_{\ell}\f$-polynomials used in Protogalaxy and \f$pow_{\beta}\f$-polynomials used in Sumcheck. * * @details - * ## PowPolynomial in Protogalaxy + * ## GateSeparatorPolynomial in Protogalaxy * * \todo Expand this while completing PG docs. * @@ -235,12 +236,12 @@ S^i_{\ell}( X_i ) * Define \f{align} T^{i}( X_i ) = \sum_{\ell = 0}^{2^{d-i-1}-1} \beta_{i+1}^{\ell_{i+1}} \cdot \ldots \cdot \beta_{d-1}^{\ell_{d-1}} \cdot S^{i}_{\ell}( X_i ) \f} then \f$ \deg_{X_i} (T^i) \leq \deg_{X_i} S^i \f$. - ### Features of PowPolynomial used by Sumcheck Prover + ### Features of GateSeparatorPolynomial used by Sumcheck Prover - The factor \f$ c_i \f$ is the #partial_evaluation_result, it is updated by \ref partially_evaluate. - The challenges \f$(\beta_0,\ldots, \beta_{d-1}) \f$ are recorded in #betas. - The consecutive evaluations \f$ pow_{\ell}(\vec \beta) = pow_{\beta}(\vec \ell) \f$ for \f$\vec \ell\f$ identified with the integers \f$\ell = 0,\ldots, 2^d-1\f$ represented in binary are pre-computed by \ref compute_values and stored -in #pow_betas. +in #beta_products. * */ diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp index 4673f792cf8..6bcaa734f3f 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp @@ -4,7 +4,7 @@ using namespace bb; -TEST(PowPolynomial, FullPowConsistency) +TEST(GateSeparatorPolynomial, FullPowConsistency) { constexpr size_t d = 5; std::vector betas(d); @@ -12,27 +12,27 @@ TEST(PowPolynomial, FullPowConsistency) beta = fr::random_element(); } - PowPolynomial pow_polynomial(betas); + GateSeparatorPolynomial poly(betas); std::array variables{}; for (auto& u_i : variables) { u_i = fr::random_element(); - pow_polynomial.partially_evaluate(u_i); + poly.partially_evaluate(u_i); } size_t beta_idx = 0; fr expected_eval = 1; for (auto& u_i : variables) { - expected_eval *= fr(1) - u_i + u_i * pow_polynomial.betas[beta_idx]; + expected_eval *= fr(1) - u_i + u_i * poly.betas[beta_idx]; beta_idx++; } - EXPECT_EQ(pow_polynomial.partial_evaluation_result, expected_eval); + EXPECT_EQ(poly.partial_evaluation_result, expected_eval); } -TEST(PowPolynomial, PowPolynomialsOnPowers) +TEST(GateSeparatorPolynomial, GateSeparatorPolynomialsOnPowers) { std::vector betas{ 2, 4, 16 }; - PowPolynomial pow(betas, betas.size()); + GateSeparatorPolynomial poly(betas, betas.size()); std::vector expected_values{ 1, 2, 4, 8, 16, 32, 64, 128 }; - EXPECT_EQ(expected_values, pow.pow_betas); + EXPECT_EQ(expected_values, poly.beta_products); } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp index 3a1d3c2a806..a9bcb68de76 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/combiner.test.cpp @@ -53,10 +53,10 @@ TEST(Protogalaxy, CombinerOn2Instances) ProverInstances instances{ instance_data }; Fun::UnivariateRelationSeparator alphas; alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only - PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); + GateSeparatorPolynomial gate_separators({ 2 }, /*log_num_monomials=*/1); Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); + instances, gate_separators, univariate_relation_parameters_no_skpping, alphas); // The expected_result values are computed by running the python script combiner_example_gen.py auto expected_result = Univariate(std::array{ 9704UL, 13245288UL, @@ -133,13 +133,13 @@ TEST(Protogalaxy, CombinerOn2Instances) relation value: 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ - PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); + GateSeparatorPolynomial gate_separators({ 2 }, /*log_num_monomials=*/1); Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; Fun::UnivariateRelationParameters univariate_relation_parameters; auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); + instances, gate_separators, univariate_relation_parameters_no_skpping, alphas); auto result_with_skipping = - Fun::compute_combiner(instances, pow_polynomial, univariate_relation_parameters, alphas); + Fun::compute_combiner(instances, gate_separators, univariate_relation_parameters, alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); @@ -193,7 +193,7 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) ProverInstances instances{ instance_data }; Fun::UnivariateRelationSeparator alphas; alphas.fill(bb::Univariate(FF(0))); // focus on the arithmetic relation only - PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); + GateSeparatorPolynomial gate_separators({ 2 }, /*log_num_monomials=*/1); // Relation parameters are all zeroes RelationParameters relation_parameters; @@ -206,7 +206,7 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) std::get<0>(temporary_accumulator), instance_data[NUM_INSTANCES - 1]->proving_key.polynomials.get_row(i), relation_parameters, - pow_polynomial[i]); + gate_separators[i]); } // Get the result of the 0th subrelation of the arithmetic relation FF instance_offset = std::get<0>(temporary_accumulator)[0]; @@ -241,14 +241,14 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) UltraArithmeticRelation::accumulate(std::get<0>(accumulator), instance_data[idx]->proving_key.polynomials.get_row(i), relation_parameters, - pow_polynomial[i]); + gate_separators[i]); } } else { for (size_t i = 0; i < 2; i++) { UltraArithmeticRelation::accumulate(std::get<0>(accumulator), extended_polynomials[idx - NUM_INSTANCES].get_row(i), relation_parameters, - pow_polynomial[i]); + gate_separators[i]); } } precomputed_result[idx] = std::get<0>(accumulator)[0]; @@ -257,9 +257,9 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; Fun::UnivariateRelationParameters univariate_relation_parameters; auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); + instances, gate_separators, univariate_relation_parameters_no_skpping, alphas); auto result_with_skipping = - Fun::compute_combiner(instances, pow_polynomial, univariate_relation_parameters, alphas); + Fun::compute_combiner(instances, gate_separators, univariate_relation_parameters, alphas); EXPECT_EQ(result_no_skipping, expected_result); EXPECT_EQ(result_with_skipping, expected_result); @@ -325,13 +325,13 @@ TEST(Protogalaxy, CombinerOptimizationConsistency) relation value: 0 0 0 0 0 0 0 0 0 6 18 36 60 90 */ - PowPolynomial pow_polynomial({ 2 }, /*log_num_monomials=*/1); + GateSeparatorPolynomial gate_separators({ 2 }, /*log_num_monomials=*/1); Fun::UnivariateRelationParametersNoOptimisticSkipping univariate_relation_parameters_no_skpping; Fun::UnivariateRelationParameters univariate_relation_parameters; auto result_no_skipping = Fun::compute_combiner_no_optimistic_skipping( - instances, pow_polynomial, univariate_relation_parameters_no_skpping, alphas); + instances, gate_separators, univariate_relation_parameters_no_skpping, alphas); auto result_with_skipping = - Fun::compute_combiner(instances, pow_polynomial, univariate_relation_parameters, alphas); + Fun::compute_combiner(instances, gate_separators, univariate_relation_parameters, alphas); auto expected_result = Univariate(std::array{ 0, 0, 12, 36, 72, 120, 180, 252, 336, 432, 540, 660 }); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index f69a14f8db9..674ed5bbb24 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -33,7 +33,7 @@ template class ProtogalaxyTests : public testing::Test { using RelationParameters = bb::RelationParameters; using WitnessCommitments = typename Flavor::WitnessCommitments; using CommitmentKey = typename Flavor::CommitmentKey; - using PowPolynomial = bb::PowPolynomial; + using GateSeparatorPolynomial = bb::GateSeparatorPolynomial; using DeciderProver = DeciderProver_; using DeciderVerifier = DeciderVerifier_; using FoldingProver = ProtogalaxyProver_; @@ -98,12 +98,13 @@ template class ProtogalaxyTests : public testing::Test { auto expected_honk_evals = Fun::compute_full_honk_evaluations( accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); // Construct pow(\vec{betas*}) as in the paper - PowPolynomial expected_pows(accumulator->gate_challenges, accumulator->gate_challenges.size()); + GateSeparatorPolynomial expected_gate_separators(accumulator->gate_challenges, + accumulator->gate_challenges.size()); // Compute the corresponding target sum and create a dummy accumulator auto expected_target_sum = FF(0); for (size_t i = 0; i < instance_size; i++) { - expected_target_sum += expected_honk_evals[i] * expected_pows[i]; + expected_target_sum += expected_honk_evals[i] * expected_gate_separators[i]; } EXPECT_EQ(accumulator->target_sum == expected_target_sum, expected_result); } @@ -203,12 +204,12 @@ template class ProtogalaxyTests : public testing::Test { } // Construct pow(\vec{betas}) as in the paper - bb::PowPolynomial pow_beta(betas, log_instance_size); + bb::GateSeparatorPolynomial gate_separators(betas, log_instance_size); // Compute the corresponding target sum and create a dummy accumulator auto target_sum = FF(0); for (size_t i = 0; i < instance_size; i++) { - target_sum += full_honk_evals[i] * pow_beta[i]; + target_sum += full_honk_evals[i] * gate_separators[i]; } auto accumulator = std::make_shared(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 2185da9bf4b..5da1b977212 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -142,12 +142,13 @@ ProtogalaxyProver_::combiner_quotient_round(const std::vector updated_gate_challenges = update_gate_challenges(perturbator_challenge, gate_challenges, deltas); const UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); - const PowPolynomial pow_polynomial{ updated_gate_challenges, instances[0]->proving_key.log_circuit_size }; + const GateSeparatorPolynomial gate_separators{ updated_gate_challenges, + instances[0]->proving_key.log_circuit_size }; const UnivariateRelationParameters relation_parameters = Fun::template compute_extended_relation_parameters(instances); TupleOfTuplesOfUnivariates accumulators; - auto combiner = Fun::compute_combiner(instances, pow_polynomial, relation_parameters, alphas, accumulators); + auto combiner = Fun::compute_combiner(instances, gate_separators, relation_parameters, alphas, accumulators); const FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); const CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index c89c368101c..8a72b3125e8 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -258,12 +258,12 @@ template class ProtogalaxyProverInternal { * * @tparam skip_zero_computations whether to use the the optimization that skips computing zero. * @param instances - * @param pow_betas + * @param gate_separators * @return ExtendedUnivariateWithRandomization */ template static ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances& instances, - const PowPolynomial& pow_betas, + const GateSeparatorPolynomial& gate_separators, const Parameters& relation_parameters, const UnivariateRelationSeparator& alphas, TupleOfTuples& univariate_accumulators) @@ -316,7 +316,7 @@ template class ProtogalaxyProverInternal { constexpr size_t skip_count = skip_zero_computations ? ProverInstances::NUM - 1 : 0; extend_univariates(extended_univariates[thread_idx], instances, idx); - const FF pow_challenge = pow_betas[idx]; + const FF pow_challenge = gate_separators[idx]; // Accumulate the i-th row's univariate contribution. Note that the relation parameters passed to // this function have already been folded. Moreover, linear-dependent relations that act over the @@ -346,21 +346,21 @@ template class ProtogalaxyProverInternal { */ static ExtendedUnivariateWithRandomization compute_combiner_no_optimistic_skipping( const ProverInstances& instances, - const PowPolynomial& pow_betas, + const GateSeparatorPolynomial& gate_separators, const UnivariateRelationParametersNoOptimisticSkipping& relation_parameters, const UnivariateRelationSeparator& alphas) { TupleOfTuplesOfUnivariatesNoOptimisticSkipping accumulators; - return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); + return compute_combiner(instances, gate_separators, relation_parameters, alphas, accumulators); } static ExtendedUnivariateWithRandomization compute_combiner(const ProverInstances& instances, - const PowPolynomial& pow_betas, + const GateSeparatorPolynomial& gate_separators, const UnivariateRelationParameters& relation_parameters, const UnivariateRelationSeparator& alphas) { TupleOfTuplesOfUnivariates accumulators; - return compute_combiner(instances, pow_betas, relation_parameters, alphas, accumulators); + return compute_combiner(instances, gate_separators, relation_parameters, alphas, accumulators); } /** diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 28ec75fdf14..47eea0c0da9 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -79,7 +79,7 @@ to the transcript. ## Round Univariates -\subsubsection SumcheckProverContributionsofPow Contributions of PowPolynomial +\subsubsection SumcheckProverContributionsofPow Contributions of GateSeparatorPolynomial * Let \f$ \vec \beta = (\beta_0,\ldots, \beta_{d-1}) \in \mathbb{F}\f$ be a vector of challenges. * @@ -91,7 +91,7 @@ is computed as follows. First, we introduce notation - \f$ S^i_{\ell} (X_i) = F \left(P_1(u_0,\ldots, u_{i-1}, X_i, \vec \ell), \ldots, P_1(u_0,\ldots, u_{i-1}, X_i, \vec \ell) \right) \f$ - As explained in \ref bb::PowPolynomial "PowPolynomial", + As explained in \ref bb::GateSeparatorPolynomial "GateSeparatorPolynomial", \f{align}{ \tilde{S}^{i}(X_i) = \sum_{ \ell = 0} ^{2^{d-i-1}-1} pow^i_\beta ( X_i, \ell_{i+1}, \ldots, \ell_{d-1} ) \cdot S^i_{\ell}( X_i ) = c_i\cdot ( (1−X_i) + X_i\cdot \beta_i ) \cdot \sum_{\ell = 0}^{2^{d-i-1}-1} \beta_{i+1}^{\ell_{i+1}} @@ -211,7 +211,7 @@ template class SumcheckProver { setup_zk_sumcheck_data(zk_sumcheck_data); }; - bb::PowPolynomial pow_univariate(gate_challenges, multivariate_d); + bb::GateSeparatorPolynomial gate_separators(gate_challenges, multivariate_d); std::vector multivariate_challenge; multivariate_challenge.reserve(multivariate_d); @@ -220,7 +220,7 @@ template class SumcheckProver { // #partially_evaluated_polynomials, which has \f$ n/2 \f$ rows and \f$ N \f$ columns. When the Flavor has ZK, // compute_univariate also takes into account the zk_sumcheck_data. auto round_univariate = round.compute_univariate( - round_idx, full_polynomials, relation_parameters, pow_univariate, alpha, zk_sumcheck_data); + round_idx, full_polynomials, relation_parameters, gate_separators, alpha, zk_sumcheck_data); { ZoneScopedN("rest of sumcheck round 1"); @@ -234,7 +234,7 @@ template class SumcheckProver { if constexpr (Flavor::HasZK) { update_zk_sumcheck_data(zk_sumcheck_data, round_challenge, round_idx); }; - pow_univariate.partially_evaluate(round_challenge); + gate_separators.partially_evaluate(round_challenge); round.round_size = round.round_size >> 1; // TODO(#224)(Cody): Maybe partially_evaluate should do this and // release memory? // All but final round // We operate on partially_evaluated_polynomials in place. @@ -245,7 +245,7 @@ template class SumcheckProver { round_univariate = round.compute_univariate(round_idx, partially_evaluated_polynomials, relation_parameters, - pow_univariate, + gate_separators, alpha, zk_sumcheck_data); // Place evaluations of Sumcheck Round Univariate in the transcript @@ -259,7 +259,7 @@ template class SumcheckProver { update_zk_sumcheck_data(zk_sumcheck_data, round_challenge, round_idx); }; - pow_univariate.partially_evaluate(round_challenge); + gate_separators.partially_evaluate(round_challenge); round.round_size = round.round_size >> 1; } // Check that the challenges \f$ u_0,\ldots, u_{d-1} \f$ do not satisfy the equation \f$ u_0(1-u_0) + \ldots + @@ -720,7 +720,7 @@ template class SumcheckVerifier { { bool verified(true); - bb::PowPolynomial pow_univariate(gate_challenges); + bb::GateSeparatorPolynomial gate_separators(gate_challenges); // All but final round. // target_total_sum is initialized to zero then mutated in place. @@ -762,7 +762,7 @@ template class SumcheckVerifier { multivariate_challenge.emplace_back(round_challenge); round.compute_next_target_sum(round_univariate, round_challenge, dummy_round); - pow_univariate.partially_evaluate(round_challenge, dummy_round); + gate_separators.partially_evaluate(round_challenge, dummy_round); } else { if (round_idx < multivariate_d) { @@ -770,7 +770,7 @@ template class SumcheckVerifier { verified = verified && checked; multivariate_challenge.emplace_back(round_challenge); round.compute_next_target_sum(round_univariate, round_challenge); - pow_univariate.partially_evaluate(round_challenge); + gate_separators.partially_evaluate(round_challenge); } else { multivariate_challenge.emplace_back(round_challenge); } @@ -797,7 +797,7 @@ template class SumcheckVerifier { // Evaluate the Honk relation at the point (u_0, ..., u_{d-1}) using claimed evaluations of prover polynomials. // In ZK Flavors, the evaluation is corrected by full_libra_purported_value FF full_honk_purported_value = round.compute_full_honk_relation_purported_value( - purported_evaluations, relation_parameters, pow_univariate, alpha, full_libra_purported_value); + purported_evaluations, relation_parameters, gate_separators, alpha, full_libra_purported_value); bool final_check(false); //! [Final Verification Step] if constexpr (IsRecursiveFlavor) { diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 2a0fad04e6b..95a3e756d43 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -157,7 +157,7 @@ template class SumcheckProverRound { const size_t round_idx, ProverPolynomialsOrPartiallyEvaluatedMultivariates& polynomials, const bb::RelationParameters& relation_parameters, - const bb::PowPolynomial& pow_polynomial, + const bb::GateSeparatorPolynomial& gate_sparators, const RelationSeparator alpha, std::optional> zk_sumcheck_data = std::nullopt) // only submitted when Flavor HasZK { @@ -201,7 +201,7 @@ template class SumcheckProverRound { accumulate_relation_univariates(thread_univariate_accumulators[thread_idx], extended_edges[thread_idx], relation_parameters, - pow_polynomial[(edge_idx >> 1) * pow_polynomial.periodicity]); + gate_sparators[(edge_idx >> 1) * gate_sparators.periodicity]); } }); @@ -214,13 +214,13 @@ template class SumcheckProverRound { auto libra_round_univariate = compute_libra_round_univariate(zk_sumcheck_data.value(), round_idx); // Batch the univariate contributions from each sub-relation to obtain the round univariate auto round_univariate = - batch_over_relations(univariate_accumulators, alpha, pow_polynomial); + batch_over_relations(univariate_accumulators, alpha, gate_sparators); // Mask the round univariate return round_univariate + libra_round_univariate; } // Batch the univariate contributions from each sub-relation to obtain the round univariate else { - return batch_over_relations(univariate_accumulators, alpha, pow_polynomial); + return batch_over_relations(univariate_accumulators, alpha, gate_sparators); } } @@ -238,18 +238,18 @@ template class SumcheckProverRound { * \tilde{S}^i(D))\f$. * * @param challenge Challenge \f$\alpha\f$. - * @param pow_polynomial Round \f$pow_{\beta}\f$-factor given by \f$ ( (1−u_i) + u_i\cdot \beta_i )\f$. + * @param gate_sparators Round \f$pow_{\beta}\f$-factor given by \f$ ( (1−u_i) + u_i\cdot \beta_i )\f$. */ template static ExtendedUnivariate batch_over_relations(ContainerOverSubrelations& univariate_accumulators, const RelationSeparator& challenge, - const bb::PowPolynomial& pow_polynomial) + const bb::GateSeparatorPolynomial& gate_sparators) { auto running_challenge = FF(1); Utils::scale_univariates(univariate_accumulators, challenge, running_challenge); auto result = ExtendedUnivariate(0); - extend_and_batch_univariates(univariate_accumulators, result, pow_polynomial); + extend_and_batch_univariates(univariate_accumulators, result, gate_sparators); // Reset all univariate accumulators to 0 before beginning accumulation in the next round Utils::zero_univariates(univariate_accumulators); @@ -267,16 +267,16 @@ template class SumcheckProverRound { * @tparam extended_size Size after extension * @param tuple A tuple of tuples of Univariates * @param result Round univariate \f$ \tilde{S}^i\f$ represented by its evaluations over \f$ \{0,\ldots, D\} \f$. - * @param pow_polynomial Round \f$pow_{\beta}\f$-factor \f$ ( (1−X_i) + X_i\cdot \beta_i )\f$. + * @param gate_sparators Round \f$pow_{\beta}\f$-factor \f$ ( (1−X_i) + X_i\cdot \beta_i )\f$. */ template static void extend_and_batch_univariates(const TupleOfTuplesOfUnivariates& tuple, ExtendedUnivariate& result, - const bb::PowPolynomial& pow_polynomial) + const bb::GateSeparatorPolynomial& gate_sparators) { ExtendedUnivariate extended_random_polynomial; // Pow-Factor \f$ (1-X) + X\beta_i \f$ - auto random_polynomial = bb::Univariate({ 1, pow_polynomial.current_element() }); + auto random_polynomial = bb::Univariate({ 1, gate_sparators.current_element() }); extended_random_polynomial = random_polynomial.template extend_to(); auto extend_and_sum = [&](Element& element) { @@ -295,7 +295,7 @@ template class SumcheckProverRound { // Multiply by the pow polynomial univariate contribution and the partial // evaluation result c_i (i.e. \f$ pow(u_0,...,u_{l-1})) \f$ where \f$(u_0,...,u_{i-1})\f$ are the // verifier challenges from previous rounds. - result += extended * extended_random_polynomial * pow_polynomial.partial_evaluation_result; + result += extended * extended_random_polynomial * gate_sparators.partial_evaluation_result; } }; Utils::apply_to_tuple_of_tuples(tuple, extend_and_sum); @@ -347,7 +347,8 @@ template class SumcheckProverRound { * @param extended_edges Contains tuples of evaluations of \f$ P_j\left(u_0,\ldots, u_{i-1}, k, \vec \ell \right) *\f$, for \f$ j=1,\ldots, N \f$, \f$ k \in \{0,\ldots, D\} \f$ and fixed \f$\vec \ell \in \{0,1\}^{d-1 - i} \f$. * @param scaling_factor In Round \f$ i \f$, for \f$ (\ell_{i+1}, \ldots, \ell_{d-1}) \in \{0,1\}^{d-1-i}\f$ takes - *an element of \ref bb::PowPolynomial< FF >::pow_betas "vector of powers of challenges" at index \f$ 2^{i+1} + *an element of \ref bb::GateSeparatorPolynomial< FF >::beta_products "vector of powers of challenges" at index \f$ + *2^{i+1} *(\ell_{i+1} 2^{i+1} +\ldots + \ell_{d-1} 2^{d-1})\f$. * @result #univariate_accumulators are updated with the contribution from the current group of edges. For each * relation, a univariate of some degree is computed by accumulating the contributions of each group of edges. @@ -520,13 +521,13 @@ template class SumcheckVerifierRound { // kill the pow_univariate FF compute_full_honk_relation_purported_value(ClaimedEvaluations purported_evaluations, const bb::RelationParameters& relation_parameters, - const bb::PowPolynomial& pow_polynomial, + const bb::GateSeparatorPolynomial& gate_sparators, const RelationSeparator alpha, std::optional full_libra_purported_value = std::nullopt) { // The verifier should never skip computation of contributions from any relation Utils::template accumulate_relation_evaluations_without_skipping<>( - purported_evaluations, relation_evaluations, relation_parameters, pow_polynomial.partial_evaluation_result); + purported_evaluations, relation_evaluations, relation_parameters, gate_sparators.partial_evaluation_result); FF running_challenge{ 1 }; FF output{ 0 }; diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp index 932ab785acf..236757ac1b8 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.test.cpp @@ -33,9 +33,9 @@ TEST(SumcheckRound, SumcheckTupleOfTuplesOfUnivariates) RelationUtils::scale_univariates(tuple_of_tuples, challenge, running_challenge); // Use extend_and_batch_univariates to extend to MAX_LENGTH then accumulate - PowPolynomial pow_polynomial({ 1 }); + GateSeparatorPolynomial gate_separators({ 1 }); auto result = Univariate(); - SumcheckProverRound::extend_and_batch_univariates(tuple_of_tuples, result, pow_polynomial); + SumcheckProverRound::extend_and_batch_univariates(tuple_of_tuples, result, gate_separators); // Repeat the batching process manually auto result_expected = univariate_1.template extend_to() * 1 + From 2f0cb59403dbb0eece846bbafea91f98df68dbed Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 16:34:02 +0000 Subject: [PATCH 26/36] Rename pow files --- ...pow.bench.cpp => gate_separator.bench.hpp} | 2 +- .../polynomials/gate_separator.hpp | 248 ++++++++++++++++++ .../{pow.test.cpp => gate_separator.test.cpp} | 2 +- .../cpp/src/barretenberg/polynomials/pow.hpp | 2 +- .../protogalaxy/protogalaxy.test.cpp | 2 +- .../cpp/src/barretenberg/relations/utils.hpp | 2 +- .../barretenberg/sumcheck/sumcheck_round.hpp | 2 +- 7 files changed, 254 insertions(+), 6 deletions(-) rename barretenberg/cpp/src/barretenberg/polynomials/{pow.bench.cpp => gate_separator.bench.hpp} (93%) create mode 100644 barretenberg/cpp/src/barretenberg/polynomials/gate_separator.hpp rename barretenberg/cpp/src/barretenberg/polynomials/{pow.test.cpp => gate_separator.test.cpp} (97%) diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.bench.cpp b/barretenberg/cpp/src/barretenberg/polynomials/gate_separator.bench.hpp similarity index 93% rename from barretenberg/cpp/src/barretenberg/polynomials/pow.bench.cpp rename to barretenberg/cpp/src/barretenberg/polynomials/gate_separator.bench.hpp index 5a092bbcadc..ae5bde5c3ea 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/gate_separator.bench.hpp @@ -1,5 +1,5 @@ -#include "barretenberg/polynomials/pow.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" +#include "barretenberg/polynomials/gate_separator.hpp" #include using namespace benchmark; diff --git a/barretenberg/cpp/src/barretenberg/polynomials/gate_separator.hpp b/barretenberg/cpp/src/barretenberg/polynomials/gate_separator.hpp new file mode 100644 index 00000000000..5ef5580fcbc --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/polynomials/gate_separator.hpp @@ -0,0 +1,248 @@ +#pragma once +#include "barretenberg/common/compiler_hints.hpp" +#include "barretenberg/common/op_count.hpp" +#include "barretenberg/common/thread.hpp" +#include "barretenberg/stdlib/primitives/bool/bool.hpp" + +#include +#include +namespace bb { + +template struct GateSeparatorPolynomial { + /** + * @brief The challenges \f$(\beta_0,\ldots, \beta_{d-1}) \f$ + * + */ + std::vector betas; + + /** + * @brief The consecutive evaluations \f$ pow_{\ell}(\beta) = pow_{\beta}(\vec \ell) \f$ for \f$\vec \ell\f$ + * identified with the integers \f$\ell = 0,\ldots, 2^d-1\f$ + * + */ + std::vector beta_products; + /** + * @brief In Round \f$ i\f$ of Sumcheck, it points to the \f$ i \f$-th element in \f$ \vec \beta \f$ + * + */ + size_t current_element_idx = 0; + /** + * @brief In Round \f$ i\f$ of Sumcheck, the periodicity equals to \f$ 2^{i+1}\f$ and represents the fixed interval + * at which elements not containing either of \f$ (\beta_0,\ldots ,β_i)\f$ appear in #beta_products. + * + */ + size_t periodicity = 2; + /** + * @brief The value \f$c_i\f$ obtained by partially evaluating one variable in the power polynomial at each round. + * At the end of Round \f$ i \f$ in the sumcheck protocol, variable \f$X_i\f$ is replaced by the challenge \f$u_i + * \f$. The partial evaluation result is updated to represent \f$ pow_{\beta}(u_0,.., u_{i}) = \prod_{k=0}^{i} ( + * (1-u_k) + u_k\cdot \beta_k) \f$. + * + */ + FF partial_evaluation_result = FF(1); + + /** + * @brief Construct a new GateSeparatorPolynomial + * + * @param betas + * @param log_num_monomials + */ + GateSeparatorPolynomial(const std::vector& betas, const size_t log_num_monomials) + : betas(betas) + , beta_products(compute_beta_products(betas, log_num_monomials)) + {} + + /** + * @brief Construct a new GateSeparatorPolynomial object without expanding to a vector of monomials + * @details The sumcheck verifier does not use beta_products + * + * @param betas + */ + GateSeparatorPolynomial(const std::vector& betas) + : betas(betas) + {} + + /** + * @brief Retruns the element in #beta_products at place #idx. + * + * @param idx + * @return FF const& + */ + FF const& operator[](size_t idx) const { return beta_products[idx]; } + /** + * @brief Computes the component at index #current_element_idx in #betas. + * + * @return FF + */ + FF current_element() const { return betas[current_element_idx]; } + + /** + * @brief Evaluate \f$ ((1−X_{i}) + X_{i}\cdot \beta_{i})\f$ at the challenge point \f$ X_{i}=u_{i} \f$. + */ + FF univariate_eval(FF challenge) const { return (FF(1) + (challenge * (betas[current_element_idx] - FF(1)))); }; + + /** + * @brief Evaluate \f$ ((1−X_{i}) + X_{i}\cdot \beta_{i})\f$ at the challenge point \f$ X_{i}=u_{i} \f$. + */ + template FF univariate_eval(const FF& challenge, const Bool& dummy_round) const + { + FF beta_or_dummy; + // For the Ultra Recursive flavor to ensure constant size proofs, we perform constant amount of hashing + // producing 28 gate betas and we need to use the betas in the dummy rounds to ensure the permutation related + // selectors stay the same regardless of real circuit size. The other recursive verifiers aren't constant for + // the dummy sumcheck rounds we just use 1 as we only generated real log_n betas + if (current_element_idx < betas.size()) { + beta_or_dummy = betas[current_element_idx]; + } else { + beta_or_dummy = FF::from_witness(challenge.get_context(), 1); + } + FF beta_val = FF::conditional_assign(dummy_round, FF::from_witness(challenge.get_context(), 1), beta_or_dummy); + return (FF(1) + (challenge * (beta_val - FF(1)))); + } + + /** + * @brief Partially evaluate the \f$pow_{\beta} \f$-polynomial at the new challenge and update \f$ c_i \f$ + * @details Update the constant \f$c_{i} \to c_{i+1} \f$ multiplying it by \f$pow_{\beta}\f$'s factor \f$\left( + * (1-X_i) + X_i\cdot \beta_i\right)\vert_{X_i = u_i}\f$ computed by \ref univariate_eval. + * @param challenge \f$ i \f$-th verifier challenge \f$ u_{i}\f$ + */ + void partially_evaluate(FF challenge) + { + FF current_univariate_eval = univariate_eval(challenge); + partial_evaluation_result *= current_univariate_eval; + current_element_idx++; + periodicity *= 2; + } + + /** + * @brief Partially evaluate the \f$pow_{\beta} \f$-polynomial at the new challenge and update \f$ c_i \f$ + * @details Update the constant \f$c_{i} \to c_{i+1} \f$ multiplying it by \f$pow_{\beta}\f$'s factor \f$\left( + * (1-X_i) + X_i\cdot \beta_i\right)\vert_{X_i = u_i}\f$ computed by \ref univariate_eval. + * @param challenge \f$ i \f$-th verifier challenge \f$ u_{i}\f$ + */ + template void partially_evaluate(const FF& challenge, const stdlib::bool_t& dummy) + { + FF current_univariate_eval = univariate_eval(challenge, dummy); + // If dummy round, make no update to the partial_evaluation_result + partial_evaluation_result = FF::conditional_assign( + dummy, partial_evaluation_result, partial_evaluation_result * current_univariate_eval); + current_element_idx++; + periodicity *= 2; + } + + /** + * @brief Given \f$ \vec\beta = (\beta_0,...,\beta_{d-1})\f$ compute \f$ pow_{\ell}(\vec \beta) = pow_{\beta}(\vec + * \ell)\f$ for \f$ \ell =0,\ldots,2^{d}-1\f$. + * + * @param log_num_monomials Determines the number of beta challenges used to compute beta_products (required because + * when we generate CONST_SIZE_PROOF_LOG_N, currently 28, challenges but the real circuit size is less than 1 << + * CONST_SIZE_PROOF_LOG_N, we should compute unnecessarily a vector of beta_products of length 1 << 28 ) + */ + BB_PROFILE static std::vector compute_beta_products(const std::vector& betas, + const size_t log_num_monomials) + { + + size_t pow_size = 1 << log_num_monomials; + std::vector beta_products(pow_size); + + // Determine number of threads for multithreading. + // Note: Multithreading is "on" for every round but we reduce the number of threads from the max available based + // on a specified minimum number of iterations per thread. This eventually leads to the use of a single thread. + // For now we use a power of 2 number of threads simply to ensure the round size is evenly divided. + size_t max_num_threads = get_num_cpus_pow2(); // number of available threads (power of 2) + size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread + size_t desired_num_threads = pow_size / min_iterations_per_thread; + size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified + num_threads = num_threads > 0 ? num_threads : 1; // ensure num threads is >= 1 + size_t iterations_per_thread = pow_size / num_threads; // actual iterations per thread + + // TODO(https://github.com/AztecProtocol/barretenberg/issues/864): This computation is asymtotically slow as it + // does pow_size * log(pow_size) work. However, in practice, its super efficient because its trivially + // parallelizable and only takes 45ms for the whole 6 iter IVC benchmark. Its also very readable, so we're + // leaving it unoptimized for now. + parallel_for(num_threads, [&](size_t thread_idx) { + size_t start = thread_idx * iterations_per_thread; + size_t end = (thread_idx + 1) * iterations_per_thread; + for (size_t i = start; i < end; i++) { + auto res = FF(1); + for (size_t j = i, beta_idx = 0; j > 0; j >>= 1, beta_idx++) { + if ((j & 1) == 1) { + res *= betas[beta_idx]; + } + } + beta_products[i] = res; + } + }); + + return beta_products; + } +}; +/**< + * @struct GateSeparatorPolynomial + * @brief Implementation of the methods for the \f$pow_{\ell}\f$-polynomials used in Protogalaxy and +\f$pow_{\beta}\f$-polynomials used in Sumcheck. + * + * @details + * ## GateSeparatorPolynomial in Protogalaxy + * + * \todo Expand this while completing PG docs. + * + * For \f$0\leq \ell \leq 2^d-1 \f$, the \f$pow_{\ell} \f$-polynomials used in Protogalaxy is a multilinear polynomial +defined by the formula + * \f{align} pow_{\ell}(X_0,\ldots, X_{d-1}) + = \prod_{k=0}^{d-1} ( ( 1-\ell_k ) + \ell_k \cdot X_k ) + = \prod_{k=0}^{d-1} X_{k}^{ \ell_k } + \f} + *where \f$(\ell_0,\ldots, \ell_{d-1})\f$ is the binary representation of \f$\ell \f$. + * + * + ## Pow-contributions to Round Univariates in Sumcheck {#PowContributions} + * For a fixed \f$ \vec \beta \in \mathbb{F}^d\f$, the map \f$ \ell \mapsto pow_{\ell} (\vec \beta)\f$ defines a + polynomial \f{align}{ pow_{\beta} (X_0,\ldots, X_{d-1}) = \prod_{k=0}^{d-1} (1- X_k + X_k \cdot \beta_k) + \f} +such that \f$ pow_{\beta} (\vec \ell) = pow_{\ell} (\vec \beta) \f$ for any \f$0\leq \ell \leq 2^d-1 \f$ and any vector +\f$(\beta_0,\ldots, \beta_{d-1}) \in \mathbb{F} ^d\f$. + + * Let \f$ i \f$ be the current Sumcheck round, \f$ i \in \{0, …, d-1\}\f$ and \f$ u_{0}, ..., u_{i-1} \f$ be the +challenges generated in Rounds \f$ 0 \f$ to \f$ i-1\f$. + * + * In Round \f$ i \f$, we iterate over the points \f$ (\ell_{i+1}, \ldots, \ell_{d-1}) \in +\{0,1\}^{d-1-i}\f$. +Define a univariate polynomial \f$pow_{\beta}^i(X_i, \vec \ell) \f$ as follows + * \f{align}{ pow_{\beta}^i(X_i, \vec \ell) = pow_{\beta} ( u_{0}, ..., u_{i-1}, X_i, \ell_{i+1}, \ldots, +\ell_{d-1}) = c_i \cdot ( (1−X_i) + X_i \cdot \beta_i ) \cdot \beta_{i+1}^{\ell_{i+1}}\cdot \cdots \cdot +\beta_{d-1}^{\ell_{d-1}}, \f} where \f$ c_i = \prod_{k=0}^{i-1} (1- u_k + u_k \cdot \beta_k) \f$. It will be used below +to simplify the computation of Sumcheck round univariates. + + ### Computing Sumcheck Round Univariates + * We identify \f$ \vec \ell = (\ell_{i+1}, \ldots, \ell_{d-1}) \in \{0,1\}^{d-1 - i}\f$ with the binary representation +of the integer \f$ \ell \in \{0,\ldots, 2^{d-1-i}-1 \}\f$. + * + * Set + \f{align}{S^i_{\ell}( X_i ) = F( u_{0}, ..., u_{i-1}, X_{i}, \vec \ell ), \f} + * i.e. \f$ S^{i}_{\ell}( X_i ) \f$ is the univariate of the full relation \f$ F \f$ defined by its partial evaluation +at \f$(u_0,\ldots,u_{i-1}, \ell_{i+1},\ldots, \ell_{d-1}) \f$ + * which is an alpha-linear-combination of the subrelations evaluated at this point. + * + * In Round \f$i\f$, the prover + * \ref bb::SumcheckProverRound< Flavor >::compute_univariate "computes the univariate polynomial" for the relation +defined by \f$ \tilde{F} (X_0,\ldots, X_{d-1}) = pow_{\beta}(X_0,\ldots, X_{d-1}) \cdot F\f$, namely + * \f{align}{ + \tilde{S}^{i}(X_i) = \sum_{ \ell = 0} ^{2^{d-i-1}-1} pow^i_\beta ( X_i, \ell_{i+1}, \ldots, \ell_{d-1} ) +S^i_{\ell}( X_i ) + * = c_i \cdot ( (1−X_i) + X_i\cdot \beta_i ) \cdot \sum_{ \ell = 0} ^{2^{d-i-1}-1} \beta_{i+1}^{\ell_{i+1}} +\cdot \ldots \cdot \beta_{d-1}^{\ell_{d-1}} \cdot S^i_{\ell}( X_i ) \f} + * + * Define + \f{align} T^{i}( X_i ) = \sum_{\ell = 0}^{2^{d-i-1}-1} \beta_{i+1}^{\ell_{i+1}} \cdot \ldots \cdot +\beta_{d-1}^{\ell_{d-1}} \cdot S^{i}_{\ell}( X_i ) \f} then \f$ \deg_{X_i} (T^i) \leq \deg_{X_i} S^i \f$. + ### Features of GateSeparatorPolynomial used by Sumcheck Prover + - The factor \f$ c_i \f$ is the #partial_evaluation_result, it is updated by \ref partially_evaluate. + - The challenges \f$(\beta_0,\ldots, \beta_{d-1}) \f$ are recorded in #betas. + - The consecutive evaluations \f$ pow_{\ell}(\vec \beta) = pow_{\beta}(\vec \ell) \f$ for \f$\vec \ell\f$ identified +with the integers \f$\ell = 0,\ldots, 2^d-1\f$ represented in binary are pre-computed by \ref compute_values and stored +in #beta_products. + * + */ + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp b/barretenberg/cpp/src/barretenberg/polynomials/gate_separator.test.cpp similarity index 97% rename from barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp rename to barretenberg/cpp/src/barretenberg/polynomials/gate_separator.test.cpp index 6bcaa734f3f..59d49091a7b 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.test.cpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/gate_separator.test.cpp @@ -1,4 +1,4 @@ -#include "pow.hpp" +#include "gate_separator.hpp" #include "barretenberg/ecc/curves/bn254/fr.hpp" #include diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp index 5ef5580fcbc..29f93d62185 100644 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp +++ b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp @@ -15,7 +15,7 @@ template struct GateSeparatorPolynomial { */ std::vector betas; - /** + /**j * @brief The consecutive evaluations \f$ pow_{\ell}(\beta) = pow_{\beta}(\vec \ell) \f$ for \f$\vec \ell\f$ * identified with the integers \f$\ell = 0,\ldots, 2^d-1\f$ * diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index 674ed5bbb24..c79afa7cb43 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -1,5 +1,5 @@ #include "barretenberg/goblin/mock_circuits.hpp" -#include "barretenberg/polynomials/pow.hpp" +#include "barretenberg/polynomials/gate_separator.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover_internal.hpp" #include "barretenberg/protogalaxy/protogalaxy_verifier.hpp" diff --git a/barretenberg/cpp/src/barretenberg/relations/utils.hpp b/barretenberg/cpp/src/barretenberg/relations/utils.hpp index 681363124ad..49fedad8c38 100644 --- a/barretenberg/cpp/src/barretenberg/relations/utils.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/utils.hpp @@ -1,6 +1,6 @@ #pragma once #include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/polynomials/pow.hpp" +#include "barretenberg/polynomials/gate_separator.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 95a3e756d43..d20721152e8 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -1,7 +1,7 @@ #pragma once #include "barretenberg/common/thread.hpp" #include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/polynomials/pow.hpp" +#include "barretenberg/polynomials/gate_separator.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/relations/relation_types.hpp" #include "barretenberg/relations/utils.hpp" From 4b1c76612544617bddb3841af7df24222efb4785 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 16:37:34 +0000 Subject: [PATCH 27/36] Revert changes to changelog --- CHANGELOG.md | 2 +- barretenberg/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ead5f24ecb..04695b78f76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3957,7 +3957,7 @@ * **docs:** Docs deeper dive into unconstrained functions ([#4233](https://github.com/AztecProtocol/aztec-packages/issues/4233)) ([6af548e](https://github.com/AztecProtocol/aztec-packages/commit/6af548e369d5d20bcbd08d346f5c6f89b7363f39)) * Emit single functions from class registerer ([#4429](https://github.com/AztecProtocol/aztec-packages/issues/4429)) ([19e03ad](https://github.com/AztecProtocol/aztec-packages/commit/19e03adc71ab7561d33dc9d75b9bdb7c19883fc9)), closes [#4427](https://github.com/AztecProtocol/aztec-packages/issues/4427) * Extend Historical Access APIs [#4179](https://github.com/AztecProtocol/aztec-packages/issues/4179) ([#4375](https://github.com/AztecProtocol/aztec-packages/issues/4375)) ([c918d8d](https://github.com/AztecProtocol/aztec-packages/commit/c918d8d1a6ba306afd2feab97ddb8527b76d1a82)) -* Folding `GoblinUltra` instances in Protogalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) +* Folding `GoblinUltra` instances in ProtoGalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) * Hashing output of `serialize()` in noir + more tests ([#4365](https://github.com/AztecProtocol/aztec-packages/issues/4365)) ([5a71bb9](https://github.com/AztecProtocol/aztec-packages/commit/5a71bb95a57bf22189e2611035e5f1faae92426b)) * Implementation for bigint opcodes ([#4288](https://github.com/AztecProtocol/aztec-packages/issues/4288)) ([b61dace](https://github.com/AztecProtocol/aztec-packages/commit/b61dacee47f57a8fce6657f28b64e7a3128d0dba)) * Improve ivc bench ([#4242](https://github.com/AztecProtocol/aztec-packages/issues/4242)) ([9d28354](https://github.com/AztecProtocol/aztec-packages/commit/9d28354ecefc9f7db71c7d2f40da7eae30e133c5)) diff --git a/barretenberg/CHANGELOG.md b/barretenberg/CHANGELOG.md index 0100a467b37..fd3bb3bba9e 100644 --- a/barretenberg/CHANGELOG.md +++ b/barretenberg/CHANGELOG.md @@ -1248,7 +1248,7 @@ - **avm:** Add command to call avm proving in bb binary ([#4369](https://github.com/AztecProtocol/aztec-packages/issues/4369)) ([4f6d607](https://github.com/AztecProtocol/aztec-packages/commit/4f6d607d7dce36819d84ba6ce69bbd57e0ad79a0)), closes [#4039](https://github.com/AztecProtocol/aztec-packages/issues/4039) - **avm:** Back in avm context with macro - refactor context ([#4438](https://github.com/AztecProtocol/aztec-packages/issues/4438)) ([ccf9b17](https://github.com/AztecProtocol/aztec-packages/commit/ccf9b17495ec46df6494fa93e1c848c87a05d071)) - **bb:** Wasmtime and remote benchmarking ([#4204](https://github.com/AztecProtocol/aztec-packages/issues/4204)) ([fd27808](https://github.com/AztecProtocol/aztec-packages/commit/fd27808721b1f32b4828db5465b502cca2f1ce6c)) -- Folding `Mega` instances in Protogalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) +- Folding `Mega` instances in ProtoGalaxy ([#4340](https://github.com/AztecProtocol/aztec-packages/issues/4340)) ([8569e7c](https://github.com/AztecProtocol/aztec-packages/commit/8569e7c091c3db424a3f1c70b0749489d8574ad2)) - Implementation for bigint opcodes ([#4288](https://github.com/AztecProtocol/aztec-packages/issues/4288)) ([b61dace](https://github.com/AztecProtocol/aztec-packages/commit/b61dacee47f57a8fce6657f28b64e7a3128d0dba)) - Improve ivc bench ([#4242](https://github.com/AztecProtocol/aztec-packages/issues/4242)) ([9d28354](https://github.com/AztecProtocol/aztec-packages/commit/9d28354ecefc9f7db71c7d2f40da7eae30e133c5)) - Memory only brillig ([#4215](https://github.com/AztecProtocol/aztec-packages/issues/4215)) ([018177b](https://github.com/AztecProtocol/aztec-packages/commit/018177bc757cce3258c153a56f1f7a871fec681c)) From 9136c7f47b91f3dac3e0592911adc0d8a55548f0 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 16:40:19 +0000 Subject: [PATCH 28/36] Rename compute_full_honk_evaluations to be more agnostic --- .../src/barretenberg/protogalaxy/protogalaxy.test.cpp | 6 +++--- .../protogalaxy/protogalaxy_prover_internal.hpp | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp index c79afa7cb43..910903abf24 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy.test.cpp @@ -95,7 +95,7 @@ template class ProtogalaxyTests : public testing::Test { static void check_accumulator_target_sum_manual(std::shared_ptr& accumulator, bool expected_result) { auto instance_size = accumulator->proving_key.circuit_size; - auto expected_honk_evals = Fun::compute_full_honk_evaluations( + auto expected_honk_evals = Fun::compute_row_evaluations( accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); // Construct pow(\vec{betas*}) as in the paper GateSeparatorPolynomial expected_gate_separators(accumulator->gate_challenges, @@ -148,7 +148,7 @@ template class ProtogalaxyTests : public testing::Test { for (auto& alpha : instance->alphas) { alpha = FF::random_element(); } - auto full_honk_evals = Fun::compute_full_honk_evaluations( + auto full_honk_evals = Fun::compute_row_evaluations( instance->proving_key.polynomials, instance->alphas, instance->relation_parameters); // Evaluations should be 0 for valid circuit @@ -197,7 +197,7 @@ template class ProtogalaxyTests : public testing::Test { alpha = FF::random_element(); } - auto full_honk_evals = Fun::compute_full_honk_evaluations(full_polynomials, alphas, relation_parameters); + auto full_honk_evals = Fun::compute_row_evaluations(full_polynomials, alphas, relation_parameters); std::vector betas(log_instance_size); for (size_t idx = 0; idx < log_instance_size; idx++) { betas[idx] = FF::random_element(); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 8a72b3125e8..2ab91be5803 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -67,12 +67,12 @@ template class ProtogalaxyProverInternal { * sum f_0(ω) + α_j*g(ω) where f_0 represents the full honk evaluation at row 0, g(ω) is the linearly dependent * subrelation and α_j is its corresponding batching challenge. */ - static std::vector compute_full_honk_evaluations(const ProverPolynomials& instance_polynomials, - const RelationSeparator& alpha, - const RelationParameters& relation_parameters) + static std::vector compute_row_evaluations(const ProverPolynomials& instance_polynomials, + const RelationSeparator& alpha, + const RelationParameters& relation_parameters) { - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::compute_full_honk_evaluations"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::compute_row_evaluations"); auto instance_size = instance_polynomials.get_polynomial_size(); std::vector full_honk_evaluations(instance_size); const std::vector linearly_dependent_contribution_accumulators = parallel_for_heuristic( @@ -170,7 +170,7 @@ template class ProtogalaxyProverInternal { const std::vector& deltas) { BB_OP_COUNT_TIME(); - auto full_honk_evaluations = compute_full_honk_evaluations( + auto full_honk_evaluations = compute_row_evaluations( accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); const auto betas = accumulator->gate_challenges; ASSERT(betas.size() == deltas.size()); From ca6174976445a19bf6dd0313baaac2bbe4ddc248 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 16:45:27 +0000 Subject: [PATCH 29/36] Let's also make this more agnostic --- barretenberg/cpp/docs/src/sumcheck-outline.md | 46 +++++++++---------- .../src/barretenberg/sumcheck/sumcheck.hpp | 4 +- .../barretenberg/sumcheck/sumcheck_round.hpp | 12 ++--- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/barretenberg/cpp/docs/src/sumcheck-outline.md b/barretenberg/cpp/docs/src/sumcheck-outline.md index c141e96446e..85081c4482a 100644 --- a/barretenberg/cpp/docs/src/sumcheck-outline.md +++ b/barretenberg/cpp/docs/src/sumcheck-outline.md @@ -142,7 +142,7 @@ and computed \f$\sigma_d = \tilde{S}^{d-1}(u_{d-1})\f$. ### Final Verification Step {#NonZKSumcheckVerification} - Extract claimed evaluations of prover polynomials \f$P_1,\ldots, P_N\f$ at the challenge point \f$ - (u_0,\ldots,u_{d-1}) \f$ from the transcript and \ref bb::SumcheckVerifierRound< Flavor >::compute_full_honk_relation_purported_value "compute evaluation:" + (u_0,\ldots,u_{d-1}) \f$ from the transcript and \ref bb::SumcheckVerifierRound< Flavor >::compute_full_relation_purported_value "compute evaluation:" \f{align}{\tilde{F}\left( P_1(u_0,\ldots, u_{d-1}), \ldots, P_N(u_0,\ldots, u_{d-1}) \right)\f} - Compare \f$ \sigma_d \f$ against the evaluation of \f$ \tilde{F} \f$ at \f$P_1(u_0,\ldots, u_{d-1}), \ldots, @@ -171,11 +171,11 @@ To prevent the witness information leakage through the Round Univariates determi \f{align}{ G \gets \sum_{i=0}^{d-1} g_{i}(X_i), \f} -where \f$ d \f$ is the number of Sumcheck rounds, and the Libra univariates are given by the formula +where \f$ d \f$ is the number of Sumcheck rounds, and the Libra univariates are given by the formula \f{align}{ g_{i} = \sum_{j=0}^{\tilde{D}} g_{i,j} \cdot L_{j,\{0,\ldots, \tilde{D}\}}(X_i) \quad \text{for } (g_{i,j}) \gets_{\$} \mathbb{F}^{d\cdot (\tilde{D}+1)} \f} -and \f$L_{j, \{0,\ldots, \tilde{D}\}}\f$ is the \f$j\f$th univariate Lagrange polynomial for the domain \f$\{0,\ldots, \tilde{D}\}\f$. Recall that \f$\deg_{X_i} \left(L_{j, \{0,\ldots, \tilde{D}\}} (X_i)\right) = \tilde{D}\f$. +and \f$L_{j, \{0,\ldots, \tilde{D}\}}\f$ is the \f$j\f$th univariate Lagrange polynomial for the domain \f$\{0,\ldots, \tilde{D}\}\f$. Recall that \f$\deg_{X_i} \left(L_{j, \{0,\ldots, \tilde{D}\}} (X_i)\right) = \tilde{D}\f$. Set \f{align}{ @@ -197,7 +197,7 @@ Observe that \f$ G \f$ has several important properties The first two properties imply that the evaluations of Sumcheck Round Univariates for \f$G\f$ are independent and uniformly distributed. We call them Libra Round Univarites. -Consider Round Univariates for \f$ \tilde{F} + \texttt{libra_challenge}\cdot G\f$ which are the sums of the Sumcheck Round Univariates for \f$ \tilde{F} \f$ and Libra Round Univarites multiplied by the challenge. +Consider Round Univariates for \f$ \tilde{F} + \texttt{libra_challenge}\cdot G\f$ which are the sums of the Sumcheck Round Univariates for \f$ \tilde{F} \f$ and Libra Round Univarites multiplied by the challenge. The fact that the degrees of Libra Round Univariates are big enough (i.e. \f$ \tilde{D}\geq D \f$) and that their evaluations are random imply that the evaluations \f$ \tilde{S}^i(0),\ldots,\tilde{S}^i(\tilde D)\f$ defined in [Compute Round Univariates](#ComputeRoundUnivariates) are now masked by the evaluations of Libra Round Univariates. These evaluations are described explicitly [below](#LibraRoundUnivariates). ### Example {#LibraPolynomialExample} @@ -221,7 +221,7 @@ Since \f$G\f$ is a polynomial of a very special form, the computation of \f$\tex \f} since the evaluations of \f$ g_i \f$ at \f$\vec \ell \in \{0,1\}^{d}\f$ depend only on \f$ \ell_i \f$, and therefore, there are \f$2^{d-1}\f$ summands \f$ g_i(0) \f$ corresponding to the points \f$\vec \ell\f$ with \f$\ell_i=0\f$ and \f$2^{d-1}\f$ summands \f$ g_i(1) \f$ corresponding to \f$\vec \ell\f$ with \f$\ell_i=1\f$. -The prover computes +The prover computes \f{align}{ \texttt{libra_total_sum} \gets 2^{d-1} \sum_{i = 0}^{d-1} \left( g_i(0) + g_i(1) \right). \f} @@ -232,8 +232,8 @@ As in [Sumcheck Book-keeping](#BookKeepingTable), we use a table of evaluations Namely, before entering the first round, the prover updates the vector of Libra univariates in place \f{align}{ \texttt{libra_univariates}_{j}(k) \gets \texttt{libra_challenge} \cdot 2^{d-1} \cdot g_{j}(k) \text{ for } j= i,\ldots, d-1, \text{ and } k=0,\ldots, \tilde{D} -\f} -and computes the term +\f} +and computes the term \f{align}{ \texttt{libra_running_sum} \gets 2^{-1} \left( \texttt{libra_challenge} \cdot \texttt{libra_total_sum} - \left(\texttt{libra_univariates}_{0}(0) + \texttt{libra_univariates}_{0}(1)\right) \right). \f} @@ -255,12 +255,12 @@ By design of the method \ref bb::SumcheckProver< Flavor >::setup_zk_sumcheck_dat \f} for \f$k=0,\ldots, \tilde{D}\f$. It is done by the method \ref bb::SumcheckProverRound< Flavor >::compute_libra_round_univariate "compute_libra_round_univariate" called inside \ref bb::SumcheckProverRound< Flavor >::compute_univariate "Sumcheck Round Univariate computation", which also takes care of adding \f$\texttt{libra_round_univariate}\f$ to the \f$\texttt{round_unviariate}\f$. -When the prover receives the challenge \f$u_0\f$, it \ref bb::SumcheckProver< Flavor >::update_libra_data "updates Libra data": +When the prover receives the challenge \f$u_0\f$, it \ref bb::SumcheckProver< Flavor >::update_libra_data "updates Libra data": - updates the table of Libra univariates by multiplying every term by \f$1/2\f$. -- computes the value \f$2^{d-2} \cdot \texttt{libra_challenge} \cdot g_0(u_0)\f$ applying \ref bb::Univariate::evaluate "evaluate" method to the first univariate in the table \f$\texttt{libra_univariates}\f$ +- computes the value \f$2^{d-2} \cdot \texttt{libra_challenge} \cdot g_0(u_0)\f$ applying \ref bb::Univariate::evaluate "evaluate" method to the first univariate in the table \f$\texttt{libra_univariates}\f$ - places the value \f$ g_0(u_0)\f$ to the vector \f$ \texttt{libra_evaluations}\f$ -- updates the running sum +- updates the running sum \f{align}{ \texttt{libra_running_sum} \gets 2^{d-2} \cdot \texttt{libra_challenge} \cdot g_0(u_0) + 2^{-1} \cdot \left( \texttt{libra_running_sum} - (\texttt{libra_univariates}_{1}(0) + \texttt{libra_univariates}_{1}(1)) \right) \f} @@ -270,7 +270,7 @@ In Round \f$ i \f$, the prover computes \f$ i \f$-th Libra round univariate \f{align}{ \texttt{libra_univariate}_i(X_i) = \texttt{libra_challenge} \cdot \sum_{\vec \ell \in \{0,1\}^{d-1 - i}} G(u_0,\ldots, u_{i-1}, X_{i}, \vec \ell) = \texttt{libra_challenge} \cdot 2^{d-1 - i} \left( \sum_{j = 0}^{i-1} g_j(u_{j}) + g_{i}(X_i) + \sum_{j=i+1}^{d-1} \left(g_{j,0} + g_{j,1}\right) \right) -\f} +\f} By design of the method \ref bb::SumcheckProver< Flavor >::update_zk_sumcheck_data "update_zk_sumcheck_data", the latter could be expressed as follows \f{align}{ @@ -284,13 +284,13 @@ for \f$k=0,\ldots, \tilde{D}\f$. This computation is done by the method \ref bb: When the prover receives new challenge \f$u_i\f$, it \ref bb::SumcheckProver< Flavor >::update_libra_data "updates Libra data". If \f$ i < d-1\f$, the prover - updates the table of Libra univariates by multiplying every term by \f$1/2\f$. -- computes the value \f$2^{d-i - 2} \cdot \texttt{libra_challenge} \cdot g_0(u_0)\f$ applying \ref bb::Univariate::evaluate "evaluate" method to the first univariate in the table \f$\texttt{libra_univariates}\f$ +- computes the value \f$2^{d-i - 2} \cdot \texttt{libra_challenge} \cdot g_0(u_0)\f$ applying \ref bb::Univariate::evaluate "evaluate" method to the first univariate in the table \f$\texttt{libra_univariates}\f$ - places the value \f$ g_0(u_0)\f$ to the vector \f$ \texttt{libra_evaluations}\f$ -- updates the running sum +- updates the running sum \f{align}{ \texttt{libra_running_sum} \gets 2^{d-i-2} \cdot \texttt{libra_challenge} \cdot g_0(u_0) + 2^{-1} \cdot \left( \texttt{libra_running_sum} - (\texttt{libra_univariates}_{i+1}(0) + \texttt{libra_univariates}_{i+1}(1)) \right) \f} -If \f$ i = d-1\f$, the prover +If \f$ i = d-1\f$, the prover - computes the value \f$ g_{d-1}(u_{d-1})\f$ applying \ref bb::Univariate::evaluate "evaluate" method to the last univariate in the table \f$\texttt{libra_univariates}\f$ and dividing the result by \f$ \texttt{libra_challenge} \f$. - updates the table of Libra univariates by multiplying every term by \f$\texttt{libra_challenge}^{-1}\f$. @@ -385,13 +385,13 @@ Note that \f$ \tilde{D} \f$ sets up the corresponding parameter of [Lib The random scalars \f$ \rho_1,\ldots, \rho_{N_w}\f$ are created by the method \ref bb::SumcheckProver< Flavor >::setup_zk_sumcheck_data "setup_zk_sumcheck_data" and are stored as \f$ \texttt{eval_masking_scalars} \f$. ### Book-keeping {#BookKeepingMaskingWitnesses} -To faciliate the computation of Sumcheck Round Univariates, the prover \ref bb::SumcheckProver< Flavor >::create_evaluation_masking_table "creates the vector" of univariates +To faciliate the computation of Sumcheck Round Univariates, the prover \ref bb::SumcheckProver< Flavor >::create_evaluation_masking_table "creates the vector" of univariates \f{align}{ \texttt{masking_terms_evaluations}_j(k)\gets \texttt{eval_masking_scalars}_j \cdot (1-k) k \f} of the same size as the ExtendedEdges created by the ZK Flavor running Sumcheck. -When the prover receives the challenge \f$ u_i \f$, this vector is \ref bb::SumcheckProver< Flavor >::update_masking_terms_evaluations "updated" as follows +When the prover receives the challenge \f$ u_i \f$, this vector is \ref bb::SumcheckProver< Flavor >::update_masking_terms_evaluations "updated" as follows \f{align}{ \texttt{masking_terms_evaluations}_j(k) \gets \texttt{eval_masking_scalars}_j \cdot u_i \cdot (1-u_i) @@ -408,9 +408,9 @@ which reduces to computing at most \f$ (D+ D_w + 1) \times N \times 2^{d-1 - i}\ &\ P_j(u_0,\ldots, u_{i-1}, k, \vec \ell) + \rho_j \cdot \sum_{k=0}^{i-1} u_k(1-u_k) + \rho_j\cdot (1-k) k \quad \text{ for } j=1,\ldots, N_w\\ &\ P_j(u_0,\ldots, u_{i-1}, k, \vec \ell) \quad \text { for } j= N_w+1,\ldots, N \f} -By design, we have -\f{align}{ - \texttt{masking_terms_evaluations}_j(k) = \rho_j \cdot \sum_{k=0}^{i-1} u_k(1-u_k) + \rho_j\cdot (1-k) k. +By design, we have +\f{align}{ + \texttt{masking_terms_evaluations}_j(k) = \rho_j \cdot \sum_{k=0}^{i-1} u_k(1-u_k) + \rho_j\cdot (1-k) k. \f} Then the method \ref bb::SumcheckProverRound< Flavor >::extend_zk_edges "extend_zk_edges" gets the \f$j\f$-th edge corresponding to the witness polynomial and corrects it with the univariate \f$ \texttt{masking_terms_evaluations}_j\f$. The non-witness polynomials are treated as in \ref bb::SumcheckProverRound< Flavor >::extend_edges "extend_edges" used in non-ZK Flavors. @@ -460,10 +460,10 @@ The total costs of ZK Sumcheck are obtained from [Libra Costs](#LibraCosts) and Group Operations

\f$+ d\f$ MSMs of size \f$(D+D_w)\f$ = [Libra Commitments](#LibraCommitments)

\f$+ \left(2 \cdot (D+D_w) D+1\right)\f$ group ops = shplonk

-

\f$+ N_w\f$ MSMs of size \f$2^d\f$ (same group element multiplied by \f$\rho_1,\ldots,\rho_{N_w}\f$)

+

\f$+ N_w\f$ MSMs of size \f$2^d\f$ (same group element multiplied by \f$\rho_1,\ldots,\rho_{N_w}\f$)

\f$ + (d + 3) \f$ group ops

-

\f$ + N_w\f$ MSMs of size \f$2\f$

+

\f$ + N_w\f$ MSMs of size \f$2\f$

@@ -478,7 +478,7 @@ The total costs of ZK Sumcheck are obtained from [Libra Costs](#LibraCosts) and Communication -

\f$+ (d+ 2)\f$ group elements for Libra; \f$+N_w\f$ group elements for witness masking

+

\f$+ (d+ 2)\f$ group elements for Libra; \f$+N_w\f$ group elements for witness masking

\f$+ D_w \cdot d \f$ field elements

@@ -486,7 +486,7 @@ The total costs of ZK Sumcheck are obtained from [Libra Costs](#LibraCosts) and ## Theoretic Field Operations vs. Implementation The table above sets a reasonable upper bound on the amount of prover's field operations. -However, in the implementation, the relation \f$ F \f$ is computed as a vector of its subrelations, which allows us to decrease the costs of computing the round univariates. Namely, for a given subrelation \f$ F_j \f$, its maximum partial degree \f$D_j\f$ and its witness degree \f$D_{w,j} \f$ are generally less than \f$ D\f$ and \f$ D_w \f$, respectively. +However, in the implementation, the relation \f$ F \f$ is computed as a vector of its subrelations, which allows us to decrease the costs of computing the round univariates. Namely, for a given subrelation \f$ F_j \f$, its maximum partial degree \f$D_j\f$ and its witness degree \f$D_{w,j} \f$ are generally less than \f$ D\f$ and \f$ D_w \f$, respectively. Therefore, we compute \f$ F_j \f$'s contribution to Sumcheck Round Univariates by evaluating the univariate polynomial \f{align}{ \sum_{\vec \ell\in \{0,1\}^{d-1-i}} pow_{\beta}(u_0,\ldots, u_{i-1}, X_i, \vec \ell) \cdot F_j(u_0,\ldots, u_{i-1}, X_i,\vec \ell) diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp index 47eea0c0da9..e635cd05d10 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck.hpp @@ -653,7 +653,7 @@ polynomials that are sent in clear. * ### Final Verification Step * - Extract \ref ClaimedEvaluations of prover polynomials \f$P_1,\ldots, P_N\f$ at the challenge point \f$ (u_0,\ldots,u_{d-1}) \f$ from the transcript and \ref bb::SumcheckVerifierRound< Flavor - >::compute_full_honk_relation_purported_value "compute evaluation:" + >::compute_full_relation_purported_value "compute evaluation:" \f{align}{\tilde{F}\left( P_1(u_0,\ldots, u_{d-1}), \ldots, P_N(u_0,\ldots, u_{d-1}) \right)\f} and store it at \f$ \texttt{full_honk_relation_purported_value} \f$. * - Compare \f$ \sigma_d \f$ against the evaluation of \f$ \tilde{F} \f$ at \f$P_1(u_0,\ldots, u_{d-1}), \ldots, @@ -796,7 +796,7 @@ template class SumcheckVerifier { } // Evaluate the Honk relation at the point (u_0, ..., u_{d-1}) using claimed evaluations of prover polynomials. // In ZK Flavors, the evaluation is corrected by full_libra_purported_value - FF full_honk_purported_value = round.compute_full_honk_relation_purported_value( + FF full_honk_purported_value = round.compute_full_relation_purported_value( purported_evaluations, relation_parameters, gate_separators, alpha, full_libra_purported_value); bool final_check(false); //! [Final Verification Step] diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index d20721152e8..11428131c78 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -392,7 +392,7 @@ template class SumcheckProverRound { * * The last step of the verifification requires to compute the value \f$ pow(u_0,\ldots, u_{d-1}) \cdot F \left(P_1(u_0,\ldots, u_{d-1}), \ldots, P_N(u_0,\ldots, u_{d-1}) \right) \f$ implemented as - * - \ref compute_full_honk_relation_purported_value method needed at the last verification step. + * - \ref compute_full_relation_purported_value method needed at the last verification step. */ template class SumcheckVerifierRound { using Utils = bb::RelationUtils; @@ -519,11 +519,11 @@ template class SumcheckVerifierRound { // also copy paste in PG // so instead of having claimed evaluations of each relation in part you have the actual evaluations // kill the pow_univariate - FF compute_full_honk_relation_purported_value(ClaimedEvaluations purported_evaluations, - const bb::RelationParameters& relation_parameters, - const bb::GateSeparatorPolynomial& gate_sparators, - const RelationSeparator alpha, - std::optional full_libra_purported_value = std::nullopt) + FF compute_full_relation_purported_value(ClaimedEvaluations purported_evaluations, + const bb::RelationParameters& relation_parameters, + const bb::GateSeparatorPolynomial& gate_sparators, + const RelationSeparator alpha, + std::optional full_libra_purported_value = std::nullopt) { // The verifier should never skip computation of contributions from any relation Utils::template accumulate_relation_evaluations_without_skipping<>( From 89b39f345096ea11c9536ddb5176aff2372cf775 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 17:05:02 +0000 Subject: [PATCH 30/36] Remove stray pow.hpp --- .../cpp/src/barretenberg/polynomials/pow.hpp | 248 ------------------ 1 file changed, 248 deletions(-) delete mode 100644 barretenberg/cpp/src/barretenberg/polynomials/pow.hpp diff --git a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp b/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp deleted file mode 100644 index 29f93d62185..00000000000 --- a/barretenberg/cpp/src/barretenberg/polynomials/pow.hpp +++ /dev/null @@ -1,248 +0,0 @@ -#pragma once -#include "barretenberg/common/compiler_hints.hpp" -#include "barretenberg/common/op_count.hpp" -#include "barretenberg/common/thread.hpp" -#include "barretenberg/stdlib/primitives/bool/bool.hpp" - -#include -#include -namespace bb { - -template struct GateSeparatorPolynomial { - /** - * @brief The challenges \f$(\beta_0,\ldots, \beta_{d-1}) \f$ - * - */ - std::vector betas; - - /**j - * @brief The consecutive evaluations \f$ pow_{\ell}(\beta) = pow_{\beta}(\vec \ell) \f$ for \f$\vec \ell\f$ - * identified with the integers \f$\ell = 0,\ldots, 2^d-1\f$ - * - */ - std::vector beta_products; - /** - * @brief In Round \f$ i\f$ of Sumcheck, it points to the \f$ i \f$-th element in \f$ \vec \beta \f$ - * - */ - size_t current_element_idx = 0; - /** - * @brief In Round \f$ i\f$ of Sumcheck, the periodicity equals to \f$ 2^{i+1}\f$ and represents the fixed interval - * at which elements not containing either of \f$ (\beta_0,\ldots ,β_i)\f$ appear in #beta_products. - * - */ - size_t periodicity = 2; - /** - * @brief The value \f$c_i\f$ obtained by partially evaluating one variable in the power polynomial at each round. - * At the end of Round \f$ i \f$ in the sumcheck protocol, variable \f$X_i\f$ is replaced by the challenge \f$u_i - * \f$. The partial evaluation result is updated to represent \f$ pow_{\beta}(u_0,.., u_{i}) = \prod_{k=0}^{i} ( - * (1-u_k) + u_k\cdot \beta_k) \f$. - * - */ - FF partial_evaluation_result = FF(1); - - /** - * @brief Construct a new GateSeparatorPolynomial - * - * @param betas - * @param log_num_monomials - */ - GateSeparatorPolynomial(const std::vector& betas, const size_t log_num_monomials) - : betas(betas) - , beta_products(compute_beta_products(betas, log_num_monomials)) - {} - - /** - * @brief Construct a new GateSeparatorPolynomial object without expanding to a vector of monomials - * @details The sumcheck verifier does not use beta_products - * - * @param betas - */ - GateSeparatorPolynomial(const std::vector& betas) - : betas(betas) - {} - - /** - * @brief Retruns the element in #beta_products at place #idx. - * - * @param idx - * @return FF const& - */ - FF const& operator[](size_t idx) const { return beta_products[idx]; } - /** - * @brief Computes the component at index #current_element_idx in #betas. - * - * @return FF - */ - FF current_element() const { return betas[current_element_idx]; } - - /** - * @brief Evaluate \f$ ((1−X_{i}) + X_{i}\cdot \beta_{i})\f$ at the challenge point \f$ X_{i}=u_{i} \f$. - */ - FF univariate_eval(FF challenge) const { return (FF(1) + (challenge * (betas[current_element_idx] - FF(1)))); }; - - /** - * @brief Evaluate \f$ ((1−X_{i}) + X_{i}\cdot \beta_{i})\f$ at the challenge point \f$ X_{i}=u_{i} \f$. - */ - template FF univariate_eval(const FF& challenge, const Bool& dummy_round) const - { - FF beta_or_dummy; - // For the Ultra Recursive flavor to ensure constant size proofs, we perform constant amount of hashing - // producing 28 gate betas and we need to use the betas in the dummy rounds to ensure the permutation related - // selectors stay the same regardless of real circuit size. The other recursive verifiers aren't constant for - // the dummy sumcheck rounds we just use 1 as we only generated real log_n betas - if (current_element_idx < betas.size()) { - beta_or_dummy = betas[current_element_idx]; - } else { - beta_or_dummy = FF::from_witness(challenge.get_context(), 1); - } - FF beta_val = FF::conditional_assign(dummy_round, FF::from_witness(challenge.get_context(), 1), beta_or_dummy); - return (FF(1) + (challenge * (beta_val - FF(1)))); - } - - /** - * @brief Partially evaluate the \f$pow_{\beta} \f$-polynomial at the new challenge and update \f$ c_i \f$ - * @details Update the constant \f$c_{i} \to c_{i+1} \f$ multiplying it by \f$pow_{\beta}\f$'s factor \f$\left( - * (1-X_i) + X_i\cdot \beta_i\right)\vert_{X_i = u_i}\f$ computed by \ref univariate_eval. - * @param challenge \f$ i \f$-th verifier challenge \f$ u_{i}\f$ - */ - void partially_evaluate(FF challenge) - { - FF current_univariate_eval = univariate_eval(challenge); - partial_evaluation_result *= current_univariate_eval; - current_element_idx++; - periodicity *= 2; - } - - /** - * @brief Partially evaluate the \f$pow_{\beta} \f$-polynomial at the new challenge and update \f$ c_i \f$ - * @details Update the constant \f$c_{i} \to c_{i+1} \f$ multiplying it by \f$pow_{\beta}\f$'s factor \f$\left( - * (1-X_i) + X_i\cdot \beta_i\right)\vert_{X_i = u_i}\f$ computed by \ref univariate_eval. - * @param challenge \f$ i \f$-th verifier challenge \f$ u_{i}\f$ - */ - template void partially_evaluate(const FF& challenge, const stdlib::bool_t& dummy) - { - FF current_univariate_eval = univariate_eval(challenge, dummy); - // If dummy round, make no update to the partial_evaluation_result - partial_evaluation_result = FF::conditional_assign( - dummy, partial_evaluation_result, partial_evaluation_result * current_univariate_eval); - current_element_idx++; - periodicity *= 2; - } - - /** - * @brief Given \f$ \vec\beta = (\beta_0,...,\beta_{d-1})\f$ compute \f$ pow_{\ell}(\vec \beta) = pow_{\beta}(\vec - * \ell)\f$ for \f$ \ell =0,\ldots,2^{d}-1\f$. - * - * @param log_num_monomials Determines the number of beta challenges used to compute beta_products (required because - * when we generate CONST_SIZE_PROOF_LOG_N, currently 28, challenges but the real circuit size is less than 1 << - * CONST_SIZE_PROOF_LOG_N, we should compute unnecessarily a vector of beta_products of length 1 << 28 ) - */ - BB_PROFILE static std::vector compute_beta_products(const std::vector& betas, - const size_t log_num_monomials) - { - - size_t pow_size = 1 << log_num_monomials; - std::vector beta_products(pow_size); - - // Determine number of threads for multithreading. - // Note: Multithreading is "on" for every round but we reduce the number of threads from the max available based - // on a specified minimum number of iterations per thread. This eventually leads to the use of a single thread. - // For now we use a power of 2 number of threads simply to ensure the round size is evenly divided. - size_t max_num_threads = get_num_cpus_pow2(); // number of available threads (power of 2) - size_t min_iterations_per_thread = 1 << 6; // min number of iterations for which we'll spin up a unique thread - size_t desired_num_threads = pow_size / min_iterations_per_thread; - size_t num_threads = std::min(desired_num_threads, max_num_threads); // fewer than max if justified - num_threads = num_threads > 0 ? num_threads : 1; // ensure num threads is >= 1 - size_t iterations_per_thread = pow_size / num_threads; // actual iterations per thread - - // TODO(https://github.com/AztecProtocol/barretenberg/issues/864): This computation is asymtotically slow as it - // does pow_size * log(pow_size) work. However, in practice, its super efficient because its trivially - // parallelizable and only takes 45ms for the whole 6 iter IVC benchmark. Its also very readable, so we're - // leaving it unoptimized for now. - parallel_for(num_threads, [&](size_t thread_idx) { - size_t start = thread_idx * iterations_per_thread; - size_t end = (thread_idx + 1) * iterations_per_thread; - for (size_t i = start; i < end; i++) { - auto res = FF(1); - for (size_t j = i, beta_idx = 0; j > 0; j >>= 1, beta_idx++) { - if ((j & 1) == 1) { - res *= betas[beta_idx]; - } - } - beta_products[i] = res; - } - }); - - return beta_products; - } -}; -/**< - * @struct GateSeparatorPolynomial - * @brief Implementation of the methods for the \f$pow_{\ell}\f$-polynomials used in Protogalaxy and -\f$pow_{\beta}\f$-polynomials used in Sumcheck. - * - * @details - * ## GateSeparatorPolynomial in Protogalaxy - * - * \todo Expand this while completing PG docs. - * - * For \f$0\leq \ell \leq 2^d-1 \f$, the \f$pow_{\ell} \f$-polynomials used in Protogalaxy is a multilinear polynomial -defined by the formula - * \f{align} pow_{\ell}(X_0,\ldots, X_{d-1}) - = \prod_{k=0}^{d-1} ( ( 1-\ell_k ) + \ell_k \cdot X_k ) - = \prod_{k=0}^{d-1} X_{k}^{ \ell_k } - \f} - *where \f$(\ell_0,\ldots, \ell_{d-1})\f$ is the binary representation of \f$\ell \f$. - * - * - ## Pow-contributions to Round Univariates in Sumcheck {#PowContributions} - * For a fixed \f$ \vec \beta \in \mathbb{F}^d\f$, the map \f$ \ell \mapsto pow_{\ell} (\vec \beta)\f$ defines a - polynomial \f{align}{ pow_{\beta} (X_0,\ldots, X_{d-1}) = \prod_{k=0}^{d-1} (1- X_k + X_k \cdot \beta_k) - \f} -such that \f$ pow_{\beta} (\vec \ell) = pow_{\ell} (\vec \beta) \f$ for any \f$0\leq \ell \leq 2^d-1 \f$ and any vector -\f$(\beta_0,\ldots, \beta_{d-1}) \in \mathbb{F} ^d\f$. - - * Let \f$ i \f$ be the current Sumcheck round, \f$ i \in \{0, …, d-1\}\f$ and \f$ u_{0}, ..., u_{i-1} \f$ be the -challenges generated in Rounds \f$ 0 \f$ to \f$ i-1\f$. - * - * In Round \f$ i \f$, we iterate over the points \f$ (\ell_{i+1}, \ldots, \ell_{d-1}) \in -\{0,1\}^{d-1-i}\f$. -Define a univariate polynomial \f$pow_{\beta}^i(X_i, \vec \ell) \f$ as follows - * \f{align}{ pow_{\beta}^i(X_i, \vec \ell) = pow_{\beta} ( u_{0}, ..., u_{i-1}, X_i, \ell_{i+1}, \ldots, -\ell_{d-1}) = c_i \cdot ( (1−X_i) + X_i \cdot \beta_i ) \cdot \beta_{i+1}^{\ell_{i+1}}\cdot \cdots \cdot -\beta_{d-1}^{\ell_{d-1}}, \f} where \f$ c_i = \prod_{k=0}^{i-1} (1- u_k + u_k \cdot \beta_k) \f$. It will be used below -to simplify the computation of Sumcheck round univariates. - - ### Computing Sumcheck Round Univariates - * We identify \f$ \vec \ell = (\ell_{i+1}, \ldots, \ell_{d-1}) \in \{0,1\}^{d-1 - i}\f$ with the binary representation -of the integer \f$ \ell \in \{0,\ldots, 2^{d-1-i}-1 \}\f$. - * - * Set - \f{align}{S^i_{\ell}( X_i ) = F( u_{0}, ..., u_{i-1}, X_{i}, \vec \ell ), \f} - * i.e. \f$ S^{i}_{\ell}( X_i ) \f$ is the univariate of the full relation \f$ F \f$ defined by its partial evaluation -at \f$(u_0,\ldots,u_{i-1}, \ell_{i+1},\ldots, \ell_{d-1}) \f$ - * which is an alpha-linear-combination of the subrelations evaluated at this point. - * - * In Round \f$i\f$, the prover - * \ref bb::SumcheckProverRound< Flavor >::compute_univariate "computes the univariate polynomial" for the relation -defined by \f$ \tilde{F} (X_0,\ldots, X_{d-1}) = pow_{\beta}(X_0,\ldots, X_{d-1}) \cdot F\f$, namely - * \f{align}{ - \tilde{S}^{i}(X_i) = \sum_{ \ell = 0} ^{2^{d-i-1}-1} pow^i_\beta ( X_i, \ell_{i+1}, \ldots, \ell_{d-1} ) -S^i_{\ell}( X_i ) - * = c_i \cdot ( (1−X_i) + X_i\cdot \beta_i ) \cdot \sum_{ \ell = 0} ^{2^{d-i-1}-1} \beta_{i+1}^{\ell_{i+1}} -\cdot \ldots \cdot \beta_{d-1}^{\ell_{d-1}} \cdot S^i_{\ell}( X_i ) \f} - * - * Define - \f{align} T^{i}( X_i ) = \sum_{\ell = 0}^{2^{d-i-1}-1} \beta_{i+1}^{\ell_{i+1}} \cdot \ldots \cdot -\beta_{d-1}^{\ell_{d-1}} \cdot S^{i}_{\ell}( X_i ) \f} then \f$ \deg_{X_i} (T^i) \leq \deg_{X_i} S^i \f$. - ### Features of GateSeparatorPolynomial used by Sumcheck Prover - - The factor \f$ c_i \f$ is the #partial_evaluation_result, it is updated by \ref partially_evaluate. - - The challenges \f$(\beta_0,\ldots, \beta_{d-1}) \f$ are recorded in #betas. - - The consecutive evaluations \f$ pow_{\ell}(\vec \beta) = pow_{\beta}(\vec \ell) \f$ for \f$\vec \ell\f$ identified -with the integers \f$\ell = 0,\ldots, 2^d-1\f$ represented in binary are pre-computed by \ref compute_values and stored -in #beta_products. - * - */ - -} // namespace bb \ No newline at end of file From 5a088892f3b621892b1b921143e453b00da7b615 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 19:08:11 +0000 Subject: [PATCH 31/36] Rename finalize_and_send more literally --- .../protogalaxy/protogalaxy_prover.hpp | 2 +- .../protogalaxy/protogalaxy_prover_impl.hpp | 318 +++++++++--------- 2 files changed, 161 insertions(+), 159 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 4c7b36903a0..f848ad70104 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -54,7 +54,7 @@ template class ProtogalaxyProver_ { * @param domain_separator separates the same type of data coming from difference instances by instance * index */ - void finalise_and_send_instance(std::shared_ptr, const std::string& domain_separator); + void run_oink_prover_on_instance(std::shared_ptr, const std::string& domain_separator); /** * @brief Execute the folding prover. diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 5da1b977212..bd371338b08 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -1,4 +1,4 @@ -#pragma once +z #pragma once #include "barretenberg/common/op_count.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover_internal.hpp" #include "barretenberg/protogalaxy/prover_verifier_shared.hpp" @@ -6,189 +6,191 @@ #include "barretenberg/ultra_honk/oink_prover.hpp" #include "protogalaxy_prover.hpp" -namespace bb { -template -void ProtogalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, - const std::string& domain_separator) + namespace bb { - ZoneScopedN("ProtogalaxyProver::finalise_and_send_instance"); - OinkProver oink_prover(instance, transcript, domain_separator + '_'); - - oink_prover.prove(); -} - -/** - * @brief Given the challenge \gamma, compute Z(\gamma) and {L_0(\gamma),L_1(\gamma)} - * TODO(https://github.com/AztecProtocol/barretenberg/issues/764): Generalize the vanishing polynomial formula - * and the computation of Lagrange basis for k instances - */ -template -FoldingResult ProtogalaxyProver_::update_target_sum_and_fold( - const ProverInstances& instances, - const CombinerQuotient& combiner_quotient, - const UnivariateRelationSeparator& alphas, - const UnivariateRelationParameters& univariate_relation_parameters, - const FF& perturbator_evaluation) -{ - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::update_target_sum_and_fold"); - using Fun = ProtogalaxyProverInternal; - - const FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); - - FoldingResult result{ .accumulator = instances[0], .proof = std::move(transcript->proof_data) }; + template + void ProtogalaxyProver_::run_oink_prover_on_instance(std::shared_ptr instance, + const std::string& domain_separator) + { + ZoneScopedN("ProtogalaxyProver::run_oink_prover_on_instance"); + OinkProver oink_prover(instance, transcript, domain_separator + '_'); + oink_prover.prove(); + } - // TODO(https://github.com/AztecProtocol/barretenberg/issues/881): bad pattern - result.accumulator->is_accumulator = true; + /** + * @brief Given the challenge \gamma, compute Z(\gamma) and {L_0(\gamma),L_1(\gamma)} + * TODO(https://github.com/AztecProtocol/barretenberg/issues/764): Generalize the vanishing polynomial formula + * and the computation of Lagrange basis for k instances + */ + template + FoldingResult ProtogalaxyProver_::update_target_sum_and_fold( + const ProverInstances& instances, + const CombinerQuotient& combiner_quotient, + const UnivariateRelationSeparator& alphas, + const UnivariateRelationParameters& univariate_relation_parameters, + const FF& perturbator_evaluation) + { + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::update_target_sum_and_fold"); + using Fun = ProtogalaxyProverInternal; + + const FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); + + FoldingResult result{ .accumulator = instances[0], .proof = std::move(transcript->proof_data) }; + + // TODO(https://github.com/AztecProtocol/barretenberg/issues/881): bad pattern + result.accumulator->is_accumulator = true; + + // Compute the next target sum + auto [vanishing_polynomial_at_challenge, lagranges] = + Fun::compute_vanishing_polynomial_and_lagranges(combiner_challenge); + result.accumulator->target_sum = + perturbator_evaluation * lagranges[0] + + vanishing_polynomial_at_challenge * combiner_quotient.evaluate(combiner_challenge); + + // Fold the proving key polynomials + for (auto& poly : result.accumulator->proving_key.polynomials.get_unshifted()) { + poly *= lagranges[0]; + } + for (size_t inst_idx = 1; inst_idx < ProverInstances::NUM; inst_idx++) { + for (auto [acc_poly, inst_poly] : zip_view(result.accumulator->proving_key.polynomials.get_unshifted(), + instances[inst_idx]->proving_key.polynomials.get_unshifted())) { + acc_poly.add_scaled(inst_poly, lagranges[inst_idx]); + } + } - // Compute the next target sum - auto [vanishing_polynomial_at_challenge, lagranges] = - Fun::compute_vanishing_polynomial_and_lagranges(combiner_challenge); - result.accumulator->target_sum = perturbator_evaluation * lagranges[0] + - vanishing_polynomial_at_challenge * combiner_quotient.evaluate(combiner_challenge); + // Evaluate the combined batching α_i univariate at challenge to obtain next α_i and send it to the + // verifier, where i ∈ {0,...,NUM_SUBRELATIONS - 1} + for (auto [folded_alpha, inst_alpha] : zip_view(result.accumulator->alphas, alphas)) { + folded_alpha = inst_alpha.evaluate(combiner_challenge); + } - // Fold the proving key polynomials - for (auto& poly : result.accumulator->proving_key.polynomials.get_unshifted()) { - poly *= lagranges[0]; - } - for (size_t inst_idx = 1; inst_idx < ProverInstances::NUM; inst_idx++) { - for (auto [acc_poly, inst_poly] : zip_view(result.accumulator->proving_key.polynomials.get_unshifted(), - instances[inst_idx]->proving_key.polynomials.get_unshifted())) { - acc_poly.add_scaled(inst_poly, lagranges[inst_idx]); + // Evaluate each relation parameter univariate at challenge to obtain the folded relation parameters. + for (auto [univariate, value] : zip_view(univariate_relation_parameters.get_to_fold(), + result.accumulator->relation_parameters.get_to_fold())) { + value = univariate.evaluate(combiner_challenge); } - } - // Evaluate the combined batching α_i univariate at challenge to obtain next α_i and send it to the - // verifier, where i ∈ {0,...,NUM_SUBRELATIONS - 1} - for (auto [folded_alpha, inst_alpha] : zip_view(result.accumulator->alphas, alphas)) { - folded_alpha = inst_alpha.evaluate(combiner_challenge); + return result; } - // Evaluate each relation parameter univariate at challenge to obtain the folded relation parameters. - for (auto [univariate, value] : zip_view(univariate_relation_parameters.get_to_fold(), - result.accumulator->relation_parameters.get_to_fold())) { - value = univariate.evaluate(combiner_challenge); - } + template void ProtogalaxyProver_::run_oink_prover_on_each_instance() + { + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::run_oink_prover_on_each_instance"); + auto idx = 0; + auto& instance = instances[0]; + auto domain_separator = std::to_string(idx); - return result; -} + if (!instance->is_accumulator) { + run_oink_prover_on_instance(instance, domain_separator); + instance->target_sum = 0; + instance->gate_challenges = std::vector(instance->proving_key.log_circuit_size, 0); + } -template void ProtogalaxyProver_::run_oink_prover_on_each_instance() -{ - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::run_oink_prover_on_each_instance"); - auto idx = 0; - auto& instance = instances[0]; - auto domain_separator = std::to_string(idx); - - if (!instance->is_accumulator) { - finalise_and_send_instance(instance, domain_separator); - instance->target_sum = 0; - instance->gate_challenges = std::vector(instance->proving_key.log_circuit_size, 0); - } + idx++; - idx++; + for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) { + auto instance = *it; + auto domain_separator = std::to_string(idx); + run_oink_prover_on_instance(instance, domain_separator); + } - for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) { - auto instance = *it; - auto domain_separator = std::to_string(idx); - finalise_and_send_instance(instance, domain_separator); - } + state.accumulator = instances[0]; + }; + + template + std::tuple, + LegacyPolynomial> + ProtogalaxyProver_::perturbator_round( + const std::shared_ptr& accumulator) + { + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::perturbator_round"); + + using Fun = ProtogalaxyProverInternal; + + const FF delta = transcript->template get_challenge("delta"); + const std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); + // An honest prover with valid initial instances computes that the perturbator is 0 in the first round + const LegacyPolynomial perturbator = + accumulator->is_accumulator ? Fun::compute_perturbator(accumulator, deltas) + : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); + // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of + // the accumulator which the folding verifier has from the previous iteration. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is + // different + if (accumulator->is_accumulator) { + for (size_t idx = 1; idx <= accumulator->proving_key.log_circuit_size; idx++) { + transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); + } + } - state.accumulator = instances[0]; -}; + return std::make_tuple(deltas, perturbator); + }; -template -std::tuple, LegacyPolynomial> -ProtogalaxyProver_::perturbator_round( - const std::shared_ptr& accumulator) -{ - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::perturbator_round"); - - using Fun = ProtogalaxyProverInternal; - - const FF delta = transcript->template get_challenge("delta"); - const std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); - // An honest prover with valid initial instances computes that the perturbator is 0 in the first round - const LegacyPolynomial perturbator = accumulator->is_accumulator - ? Fun::compute_perturbator(accumulator, deltas) - : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); - // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of - // the accumulator which the folding verifier has from the previous iteration. - // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is different - if (accumulator->is_accumulator) { - for (size_t idx = 1; idx <= accumulator->proving_key.log_circuit_size; idx++) { - transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); - } - } + template + std::tuple, + typename ProtogalaxyProver_::UnivariateRelationSeparator, + typename ProtogalaxyProver_::UnivariateRelationParameters, + typename ProverInstances::Flavor::FF, + typename ProtogalaxyProver_::CombinerQuotient> + ProtogalaxyProver_::combiner_quotient_round( + const std::vector& gate_challenges, const std::vector& deltas, const ProverInstances& instances) + { + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::combiner_quotient_round"); - return std::make_tuple(deltas, perturbator); -}; - -template -std::tuple, - typename ProtogalaxyProver_::UnivariateRelationSeparator, - typename ProtogalaxyProver_::UnivariateRelationParameters, - typename ProverInstances::Flavor::FF, - typename ProtogalaxyProver_::CombinerQuotient> -ProtogalaxyProver_::combiner_quotient_round(const std::vector& gate_challenges, - const std::vector& deltas, - const ProverInstances& instances) -{ - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::combiner_quotient_round"); + using Fun = ProtogalaxyProverInternal; - using Fun = ProtogalaxyProverInternal; + const FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); - const FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); + const std::vector updated_gate_challenges = + update_gate_challenges(perturbator_challenge, gate_challenges, deltas); + const UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); + const GateSeparatorPolynomial gate_separators{ updated_gate_challenges, + instances[0]->proving_key.log_circuit_size }; + const UnivariateRelationParameters relation_parameters = + Fun::template compute_extended_relation_parameters(instances); - const std::vector updated_gate_challenges = - update_gate_challenges(perturbator_challenge, gate_challenges, deltas); - const UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); - const GateSeparatorPolynomial gate_separators{ updated_gate_challenges, - instances[0]->proving_key.log_circuit_size }; - const UnivariateRelationParameters relation_parameters = - Fun::template compute_extended_relation_parameters(instances); + TupleOfTuplesOfUnivariates accumulators; + auto combiner = Fun::compute_combiner(instances, gate_separators, relation_parameters, alphas, accumulators); - TupleOfTuplesOfUnivariates accumulators; - auto combiner = Fun::compute_combiner(instances, gate_separators, relation_parameters, alphas, accumulators); + const FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); + const CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); - const FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); - const CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); + for (size_t idx = ProverInstances::NUM; idx < ProverInstances::BATCHED_EXTENDED_LENGTH; idx++) { + transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), combiner_quotient.value_at(idx)); + } - for (size_t idx = ProverInstances::NUM; idx < ProverInstances::BATCHED_EXTENDED_LENGTH; idx++) { - transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), combiner_quotient.value_at(idx)); + return std::make_tuple( + updated_gate_challenges, alphas, relation_parameters, perturbator_evaluation, combiner_quotient); } - return std::make_tuple( - updated_gate_challenges, alphas, relation_parameters, perturbator_evaluation, combiner_quotient); -} - -template -FoldingResult ProtogalaxyProver_::prove() -{ - ZoneScopedN("ProtogalaxyProver::prove"); - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove"); - // Ensure instances are all of the same size - for (size_t idx = 0; idx < ProverInstances::NUM - 1; ++idx) { - if (instances[idx]->proving_key.circuit_size != instances[idx + 1]->proving_key.circuit_size) { - info("ProtogalaxyProver: circuit size mismatch!"); - info("Instance ", idx, " size = ", instances[idx]->proving_key.circuit_size); - info("Instance ", idx + 1, " size = ", instances[idx + 1]->proving_key.circuit_size); - ASSERT(false); + template + FoldingResult ProtogalaxyProver_::prove() + { + ZoneScopedN("ProtogalaxyProver::prove"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove"); + // Ensure instances are all of the same size + for (size_t idx = 0; idx < ProverInstances::NUM - 1; ++idx) { + if (instances[idx]->proving_key.circuit_size != instances[idx + 1]->proving_key.circuit_size) { + info("ProtogalaxyProver: circuit size mismatch!"); + info("Instance ", idx, " size = ", instances[idx]->proving_key.circuit_size); + info("Instance ", idx + 1, " size = ", instances[idx + 1]->proving_key.circuit_size); + ASSERT(false); + } } - } - run_oink_prover_on_each_instance(); + run_oink_prover_on_each_instance(); - std::tie(state.deltas, state.perturbator) = perturbator_round(state.accumulator); + std::tie(state.deltas, state.perturbator) = perturbator_round(state.accumulator); - std::tie(state.accumulator->gate_challenges, - state.alphas, - state.relation_parameters, - state.perturbator_evaluation, - state.combiner_quotient) = - combiner_quotient_round(state.accumulator->gate_challenges, state.deltas, instances); + std::tie(state.accumulator->gate_challenges, + state.alphas, + state.relation_parameters, + state.perturbator_evaluation, + state.combiner_quotient) = + combiner_quotient_round(state.accumulator->gate_challenges, state.deltas, instances); - const FoldingResult result = update_target_sum_and_fold( - instances, state.combiner_quotient, state.alphas, state.relation_parameters, state.perturbator_evaluation); + const FoldingResult result = update_target_sum_and_fold( + instances, state.combiner_quotient, state.alphas, state.relation_parameters, state.perturbator_evaluation); - return result; -} + return result; + } } // namespace bb \ No newline at end of file From 01e4e8104d326cd87cd6372755ed1a9ce5318eb5 Mon Sep 17 00:00:00 2001 From: codygunton Date: Thu, 29 Aug 2024 19:17:37 +0000 Subject: [PATCH 32/36] Rearrange so header and impl match order --- .../protogalaxy/protogalaxy_prover.hpp | 26 +- .../protogalaxy/protogalaxy_prover_impl.hpp | 316 +++++++++--------- 2 files changed, 170 insertions(+), 172 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index f848ad70104..b1363ecd4f7 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -46,6 +46,10 @@ template class ProtogalaxyProver_ { // TODO(https://github.com/AztecProtocol/barretenberg/issues/878) , commitment_key(instances[1]->proving_key.commitment_key){}; + // Returns the accumulator, which is the first element in ProverInstances. The accumulator is assumed to have the + // FoldingParameters set and be the result of a previous round of folding. + std::shared_ptr get_accumulator() { return instances[0]; } + /** * @brief For each instance produced by a circuit, prior to folding, we need to complete the computation of its * prover polynomials, commit to witnesses and generate the relation parameters as well as send the public data ϕ of @@ -56,19 +60,6 @@ template class ProtogalaxyProver_ { */ void run_oink_prover_on_instance(std::shared_ptr, const std::string& domain_separator); - /** - * @brief Execute the folding prover. - * - * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/753): fold goblin polynomials - * @return FoldingResult is a pair consisting of an accumulator and a folding proof, which is a proof that the - * accumulator was computed correctly. - */ - BB_PROFILE FoldingResult prove(); - - // Returns the accumulator, which is the first element in ProverInstances. The accumulator is assumed to have the - // FoldingParameters set and be the result of a previous round of folding. - std::shared_ptr get_accumulator() { return instances[0]; } - /** * @brief Create inputs to folding protocol (an Oink interaction). * @details Finalise the prover instances that will be folded: complete computation of all the witness polynomials @@ -106,5 +97,14 @@ template class ProtogalaxyProver_ { const UnivariateRelationSeparator& alphas, const UnivariateRelationParameters& univariate_relation_parameters, const FF& perturbator_evaluation); + + /** + * @brief Execute the folding prover. + * + * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/753): fold goblin polynomials + * @return FoldingResult is a pair consisting of an accumulator and a folding proof, which is a proof that the + * accumulator was computed correctly. + */ + BB_PROFILE FoldingResult prove(); }; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index bd371338b08..126fda16a4d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -1,4 +1,4 @@ -z #pragma once +#pragma once #include "barretenberg/common/op_count.hpp" #include "barretenberg/protogalaxy/protogalaxy_prover_internal.hpp" #include "barretenberg/protogalaxy/prover_verifier_shared.hpp" @@ -6,191 +6,189 @@ z #pragma once #include "barretenberg/ultra_honk/oink_prover.hpp" #include "protogalaxy_prover.hpp" - namespace bb +namespace bb { +template +void ProtogalaxyProver_::run_oink_prover_on_instance(std::shared_ptr instance, + const std::string& domain_separator) { - template - void ProtogalaxyProver_::run_oink_prover_on_instance(std::shared_ptr instance, - const std::string& domain_separator) - { - ZoneScopedN("ProtogalaxyProver::run_oink_prover_on_instance"); - OinkProver oink_prover(instance, transcript, domain_separator + '_'); - oink_prover.prove(); + ZoneScopedN("ProtogalaxyProver::run_oink_prover_on_instance"); + OinkProver oink_prover(instance, transcript, domain_separator + '_'); + oink_prover.prove(); +} + +template void ProtogalaxyProver_::run_oink_prover_on_each_instance() +{ + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::run_oink_prover_on_each_instance"); + auto idx = 0; + auto& instance = instances[0]; + auto domain_separator = std::to_string(idx); + + if (!instance->is_accumulator) { + run_oink_prover_on_instance(instance, domain_separator); + instance->target_sum = 0; + instance->gate_challenges = std::vector(instance->proving_key.log_circuit_size, 0); } - /** - * @brief Given the challenge \gamma, compute Z(\gamma) and {L_0(\gamma),L_1(\gamma)} - * TODO(https://github.com/AztecProtocol/barretenberg/issues/764): Generalize the vanishing polynomial formula - * and the computation of Lagrange basis for k instances - */ - template - FoldingResult ProtogalaxyProver_::update_target_sum_and_fold( - const ProverInstances& instances, - const CombinerQuotient& combiner_quotient, - const UnivariateRelationSeparator& alphas, - const UnivariateRelationParameters& univariate_relation_parameters, - const FF& perturbator_evaluation) - { - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::update_target_sum_and_fold"); - using Fun = ProtogalaxyProverInternal; - - const FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); - - FoldingResult result{ .accumulator = instances[0], .proof = std::move(transcript->proof_data) }; - - // TODO(https://github.com/AztecProtocol/barretenberg/issues/881): bad pattern - result.accumulator->is_accumulator = true; - - // Compute the next target sum - auto [vanishing_polynomial_at_challenge, lagranges] = - Fun::compute_vanishing_polynomial_and_lagranges(combiner_challenge); - result.accumulator->target_sum = - perturbator_evaluation * lagranges[0] + - vanishing_polynomial_at_challenge * combiner_quotient.evaluate(combiner_challenge); - - // Fold the proving key polynomials - for (auto& poly : result.accumulator->proving_key.polynomials.get_unshifted()) { - poly *= lagranges[0]; - } - for (size_t inst_idx = 1; inst_idx < ProverInstances::NUM; inst_idx++) { - for (auto [acc_poly, inst_poly] : zip_view(result.accumulator->proving_key.polynomials.get_unshifted(), - instances[inst_idx]->proving_key.polynomials.get_unshifted())) { - acc_poly.add_scaled(inst_poly, lagranges[inst_idx]); - } - } + idx++; - // Evaluate the combined batching α_i univariate at challenge to obtain next α_i and send it to the - // verifier, where i ∈ {0,...,NUM_SUBRELATIONS - 1} - for (auto [folded_alpha, inst_alpha] : zip_view(result.accumulator->alphas, alphas)) { - folded_alpha = inst_alpha.evaluate(combiner_challenge); - } + for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) { + auto instance = *it; + auto domain_separator = std::to_string(idx); + run_oink_prover_on_instance(instance, domain_separator); + } - // Evaluate each relation parameter univariate at challenge to obtain the folded relation parameters. - for (auto [univariate, value] : zip_view(univariate_relation_parameters.get_to_fold(), - result.accumulator->relation_parameters.get_to_fold())) { - value = univariate.evaluate(combiner_challenge); - } + state.accumulator = instances[0]; +}; - return result; +template +std::tuple, LegacyPolynomial> +ProtogalaxyProver_::perturbator_round( + const std::shared_ptr& accumulator) +{ + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::perturbator_round"); + + using Fun = ProtogalaxyProverInternal; + + const FF delta = transcript->template get_challenge("delta"); + const std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); + // An honest prover with valid initial instances computes that the perturbator is 0 in the first round + const LegacyPolynomial perturbator = accumulator->is_accumulator + ? Fun::compute_perturbator(accumulator, deltas) + : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); + // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of + // the accumulator which the folding verifier has from the previous iteration. + // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is + // different + if (accumulator->is_accumulator) { + for (size_t idx = 1; idx <= accumulator->proving_key.log_circuit_size; idx++) { + transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); + } } - template void ProtogalaxyProver_::run_oink_prover_on_each_instance() - { - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::run_oink_prover_on_each_instance"); - auto idx = 0; - auto& instance = instances[0]; - auto domain_separator = std::to_string(idx); + return std::make_tuple(deltas, perturbator); +}; + +template +std::tuple, + typename ProtogalaxyProver_::UnivariateRelationSeparator, + typename ProtogalaxyProver_::UnivariateRelationParameters, + typename ProverInstances::Flavor::FF, + typename ProtogalaxyProver_::CombinerQuotient> +ProtogalaxyProver_::combiner_quotient_round(const std::vector& gate_challenges, + const std::vector& deltas, + const ProverInstances& instances) +{ + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::combiner_quotient_round"); - if (!instance->is_accumulator) { - run_oink_prover_on_instance(instance, domain_separator); - instance->target_sum = 0; - instance->gate_challenges = std::vector(instance->proving_key.log_circuit_size, 0); - } + using Fun = ProtogalaxyProverInternal; - idx++; + const FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); - for (auto it = instances.begin() + 1; it != instances.end(); it++, idx++) { - auto instance = *it; - auto domain_separator = std::to_string(idx); - run_oink_prover_on_instance(instance, domain_separator); - } + const std::vector updated_gate_challenges = + update_gate_challenges(perturbator_challenge, gate_challenges, deltas); + const UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); + const GateSeparatorPolynomial gate_separators{ updated_gate_challenges, + instances[0]->proving_key.log_circuit_size }; + const UnivariateRelationParameters relation_parameters = + Fun::template compute_extended_relation_parameters(instances); - state.accumulator = instances[0]; - }; - - template - std::tuple, - LegacyPolynomial> - ProtogalaxyProver_::perturbator_round( - const std::shared_ptr& accumulator) - { - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::perturbator_round"); - - using Fun = ProtogalaxyProverInternal; - - const FF delta = transcript->template get_challenge("delta"); - const std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); - // An honest prover with valid initial instances computes that the perturbator is 0 in the first round - const LegacyPolynomial perturbator = - accumulator->is_accumulator ? Fun::compute_perturbator(accumulator, deltas) - : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); - // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of - // the accumulator which the folding verifier has from the previous iteration. - // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is - // different - if (accumulator->is_accumulator) { - for (size_t idx = 1; idx <= accumulator->proving_key.log_circuit_size; idx++) { - transcript->send_to_verifier("perturbator_" + std::to_string(idx), perturbator[idx]); - } - } + TupleOfTuplesOfUnivariates accumulators; + auto combiner = Fun::compute_combiner(instances, gate_separators, relation_parameters, alphas, accumulators); - return std::make_tuple(deltas, perturbator); - }; + const FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); + const CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); - template - std::tuple, - typename ProtogalaxyProver_::UnivariateRelationSeparator, - typename ProtogalaxyProver_::UnivariateRelationParameters, - typename ProverInstances::Flavor::FF, - typename ProtogalaxyProver_::CombinerQuotient> - ProtogalaxyProver_::combiner_quotient_round( - const std::vector& gate_challenges, const std::vector& deltas, const ProverInstances& instances) - { - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::combiner_quotient_round"); + for (size_t idx = ProverInstances::NUM; idx < ProverInstances::BATCHED_EXTENDED_LENGTH; idx++) { + transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), combiner_quotient.value_at(idx)); + } - using Fun = ProtogalaxyProverInternal; + return std::make_tuple( + updated_gate_challenges, alphas, relation_parameters, perturbator_evaluation, combiner_quotient); +} + +/** + * @brief Given the challenge \gamma, compute Z(\gamma) and {L_0(\gamma),L_1(\gamma)} + * TODO(https://github.com/AztecProtocol/barretenberg/issues/764): Generalize the vanishing polynomial formula + * and the computation of Lagrange basis for k instances + */ +template +FoldingResult ProtogalaxyProver_::update_target_sum_and_fold( + const ProverInstances& instances, + const CombinerQuotient& combiner_quotient, + const UnivariateRelationSeparator& alphas, + const UnivariateRelationParameters& univariate_relation_parameters, + const FF& perturbator_evaluation) +{ + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver_::update_target_sum_and_fold"); + using Fun = ProtogalaxyProverInternal; - const FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); + const FF combiner_challenge = transcript->template get_challenge("combiner_quotient_challenge"); - const std::vector updated_gate_challenges = - update_gate_challenges(perturbator_challenge, gate_challenges, deltas); - const UnivariateRelationSeparator alphas = Fun::compute_and_extend_alphas(instances); - const GateSeparatorPolynomial gate_separators{ updated_gate_challenges, - instances[0]->proving_key.log_circuit_size }; - const UnivariateRelationParameters relation_parameters = - Fun::template compute_extended_relation_parameters(instances); + FoldingResult result{ .accumulator = instances[0], .proof = std::move(transcript->proof_data) }; - TupleOfTuplesOfUnivariates accumulators; - auto combiner = Fun::compute_combiner(instances, gate_separators, relation_parameters, alphas, accumulators); + // TODO(https://github.com/AztecProtocol/barretenberg/issues/881): bad pattern + result.accumulator->is_accumulator = true; - const FF perturbator_evaluation = state.perturbator.evaluate(perturbator_challenge); - const CombinerQuotient combiner_quotient = Fun::compute_combiner_quotient(perturbator_evaluation, combiner); + // Compute the next target sum + auto [vanishing_polynomial_at_challenge, lagranges] = + Fun::compute_vanishing_polynomial_and_lagranges(combiner_challenge); + result.accumulator->target_sum = perturbator_evaluation * lagranges[0] + + vanishing_polynomial_at_challenge * combiner_quotient.evaluate(combiner_challenge); - for (size_t idx = ProverInstances::NUM; idx < ProverInstances::BATCHED_EXTENDED_LENGTH; idx++) { - transcript->send_to_verifier("combiner_quotient_" + std::to_string(idx), combiner_quotient.value_at(idx)); + // Fold the proving key polynomials + for (auto& poly : result.accumulator->proving_key.polynomials.get_unshifted()) { + poly *= lagranges[0]; + } + for (size_t inst_idx = 1; inst_idx < ProverInstances::NUM; inst_idx++) { + for (auto [acc_poly, inst_poly] : zip_view(result.accumulator->proving_key.polynomials.get_unshifted(), + instances[inst_idx]->proving_key.polynomials.get_unshifted())) { + acc_poly.add_scaled(inst_poly, lagranges[inst_idx]); } + } - return std::make_tuple( - updated_gate_challenges, alphas, relation_parameters, perturbator_evaluation, combiner_quotient); + // Evaluate the combined batching α_i univariate at challenge to obtain next α_i and send it to the + // verifier, where i ∈ {0,...,NUM_SUBRELATIONS - 1} + for (auto [folded_alpha, inst_alpha] : zip_view(result.accumulator->alphas, alphas)) { + folded_alpha = inst_alpha.evaluate(combiner_challenge); } - template - FoldingResult ProtogalaxyProver_::prove() - { - ZoneScopedN("ProtogalaxyProver::prove"); - BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove"); - // Ensure instances are all of the same size - for (size_t idx = 0; idx < ProverInstances::NUM - 1; ++idx) { - if (instances[idx]->proving_key.circuit_size != instances[idx + 1]->proving_key.circuit_size) { - info("ProtogalaxyProver: circuit size mismatch!"); - info("Instance ", idx, " size = ", instances[idx]->proving_key.circuit_size); - info("Instance ", idx + 1, " size = ", instances[idx + 1]->proving_key.circuit_size); - ASSERT(false); - } + // Evaluate each relation parameter univariate at challenge to obtain the folded relation parameters. + for (auto [univariate, value] : zip_view(univariate_relation_parameters.get_to_fold(), + result.accumulator->relation_parameters.get_to_fold())) { + value = univariate.evaluate(combiner_challenge); + } + + return result; +} + +template +FoldingResult ProtogalaxyProver_::prove() +{ + ZoneScopedN("ProtogalaxyProver::prove"); + BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::prove"); + // Ensure instances are all of the same size + for (size_t idx = 0; idx < ProverInstances::NUM - 1; ++idx) { + if (instances[idx]->proving_key.circuit_size != instances[idx + 1]->proving_key.circuit_size) { + info("ProtogalaxyProver: circuit size mismatch!"); + info("Instance ", idx, " size = ", instances[idx]->proving_key.circuit_size); + info("Instance ", idx + 1, " size = ", instances[idx + 1]->proving_key.circuit_size); + ASSERT(false); } - run_oink_prover_on_each_instance(); + } + run_oink_prover_on_each_instance(); - std::tie(state.deltas, state.perturbator) = perturbator_round(state.accumulator); + std::tie(state.deltas, state.perturbator) = perturbator_round(state.accumulator); - std::tie(state.accumulator->gate_challenges, - state.alphas, - state.relation_parameters, - state.perturbator_evaluation, - state.combiner_quotient) = - combiner_quotient_round(state.accumulator->gate_challenges, state.deltas, instances); + std::tie(state.accumulator->gate_challenges, + state.alphas, + state.relation_parameters, + state.perturbator_evaluation, + state.combiner_quotient) = + combiner_quotient_round(state.accumulator->gate_challenges, state.deltas, instances); - const FoldingResult result = update_target_sum_and_fold( - instances, state.combiner_quotient, state.alphas, state.relation_parameters, state.perturbator_evaluation); + const FoldingResult result = update_target_sum_and_fold( + instances, state.combiner_quotient, state.alphas, state.relation_parameters, state.perturbator_evaluation); - return result; - } + return result; +} } // namespace bb \ No newline at end of file From c0a0c268d6bdcc99552278e6095440e1e909454d Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Aug 2024 18:44:02 +0000 Subject: [PATCH 33/36] Add comment --- .../cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp | 6 ++++-- .../barretenberg/protogalaxy/protogalaxy_prover_impl.hpp | 5 ----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 54b6722f466..6069413e9e4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -99,8 +99,10 @@ template class ProtoGalaxyProver_ { /** * @brief Steps 12 - 13 of the paper plus the prover folding work. - * @details Compute the next prover accumulator (ω* in the paper), encapsulated in a ProverInstance with folding - * parameters set. + * @details Compute \f$ e^* \f$ plus, then update the prover accumulator by taking a Lagrange-linear combination of + * the current accumulator and the instances to be folded. In our mental model, we are doing a scalar multipliation + * of matrices whose columns are polynomials, as well as taking similar linear combinations of the relation + * parameters. */ FoldingResult update_target_sum_and_fold(const ProverInstances_& instances, const CombinerQuotient& combiner_quotient, diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 1986ff73dce..7b6dbddcf1d 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -17,11 +17,6 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared oink_prover.prove(); } -/** - * @brief Given the challenge \gamma, compute Z(\gamma) and {L_0(\gamma),L_1(\gamma)} - * TODO(https://github.com/AztecProtocol/barretenberg/issues/764): Generalize the vanishing polynomial formula - * and the computation of Lagrange basis for k instances - */ template FoldingResult ProtoGalaxyProver_::update_target_sum_and_fold( const ProverInstances& instances, From b1fc7cdd6024d1d541d59ca17bda7e0e516c808c Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Aug 2024 18:59:24 +0000 Subject: [PATCH 34/36] Don't use LegacyPolynomial --- .../src/barretenberg/protogalaxy/protogalaxy_prover.hpp | 7 +++---- .../barretenberg/protogalaxy/protogalaxy_prover_impl.hpp | 8 ++++---- .../protogalaxy/protogalaxy_prover_internal.hpp | 6 +++--- .../src/barretenberg/protogalaxy/protogalaxy_verifier.cpp | 2 +- .../protogalaxy_recursive_verifier.test.cpp | 2 +- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index 6069413e9e4..8ba4f990c13 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -21,7 +21,7 @@ template class ProtoGalaxyProver_ { struct State { std::shared_ptr accumulator; - LegacyPolynomial perturbator; + Polynomial perturbator; std::vector deltas; CombinerQuotient combiner_quotient; FF perturbator_evaluation; @@ -81,10 +81,9 @@ template class ProtoGalaxyProver_ { * @details Compute perturbator (F polynomial in paper). Send all but the constant coefficient to verifier. * * @param accumulator - * @return std::tuple, LegacyPolynomial> deltas, perturbator + * @return std::tuple, Polynomial> deltas, perturbator */ - std::tuple, LegacyPolynomial> perturbator_round( - const std::shared_ptr& accumulator); + std::tuple, Polynomial> perturbator_round(const std::shared_ptr& accumulator); /** * @brief Steps 6 - 11 of the paper. diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 7b6dbddcf1d..7ba4ceb8410 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -92,7 +92,7 @@ template void ProtoGalaxyProver_::run_o }; template -std::tuple, LegacyPolynomial> +std::tuple, Polynomial> ProtoGalaxyProver_::perturbator_round( const std::shared_ptr& accumulator) { @@ -103,9 +103,9 @@ ProtoGalaxyProver_::perturbator_round( const FF delta = transcript->template get_challenge("delta"); const std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); // An honest prover with valid initial instances computes that the perturbator is 0 in the first round - const LegacyPolynomial perturbator = accumulator->is_accumulator - ? Fun::compute_perturbator(accumulator, deltas) - : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); + const Polynomial perturbator = accumulator->is_accumulator + ? Fun::compute_perturbator(accumulator, deltas) + : Polynomial(accumulator->proving_key.log_circuit_size + 1); // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of // the accumulator which the folding verifier has from the previous iteration. // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is different diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 133c194eb86..a6ceea085e4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -165,15 +165,15 @@ template class ProtogalaxyProverInternal { * * */ - static LegacyPolynomial compute_perturbator(const std::shared_ptr& accumulator, - const std::vector& deltas) + static Polynomial compute_perturbator(const std::shared_ptr& accumulator, + const std::vector& deltas) { BB_OP_COUNT_TIME(); auto full_honk_evaluations = compute_full_honk_evaluations( accumulator->proving_key.polynomials, accumulator->alphas, accumulator->relation_parameters); const auto betas = accumulator->gate_challenges; ASSERT(betas.size() == deltas.size()); - return LegacyPolynomial(construct_perturbator_coefficients(betas, deltas, full_honk_evaluations)); + return Polynomial(construct_perturbator_coefficients(betas, deltas, full_honk_evaluations)); } /** diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index c61576cdfc0..4896413da80 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -54,7 +54,7 @@ std::shared_ptr ProtoGalaxyVerifier_target_sum; - auto perturbator = LegacyPolynomial(perturbator_coeffs); + Polynomial perturbator(perturbator_coeffs); FF perturbator_challenge = transcript->template get_challenge("perturbator_challenge"); auto perturbator_at_challenge = perturbator.evaluate(perturbator_challenge); diff --git a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp index f64f0580f40..3486b600f35 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/protogalaxy_verifier/protogalaxy_recursive_verifier.test.cpp @@ -161,7 +161,7 @@ template class ProtoGalaxyRecursiveTests : public tes coeffs.emplace_back(el); coeffs_ct.emplace_back(fr_ct(&builder, el)); } - LegacyPolynomial poly(coeffs); + Polynomial poly(coeffs); fr point = fr::random_element(); fr_ct point_ct(fr_ct(&builder, point)); auto res1 = poly.evaluate(point); From a73b55b28cce7ba2da506e16b1c0857b05ec1764 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Aug 2024 19:35:43 +0000 Subject: [PATCH 35/36] Respond to review --- .../src/barretenberg/protogalaxy/protogalaxy_prover.hpp | 1 - .../protogalaxy/protogalaxy_prover_internal.hpp | 8 ++++---- .../cpp/src/barretenberg/sumcheck/sumcheck_round.hpp | 3 --- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp index a62fa474e51..0f9b09079ff 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.hpp @@ -102,7 +102,6 @@ template class ProtogalaxyProver_ { /** * @brief Execute the folding prover. * - * @todo TODO(https://github.com/AztecProtocol/barretenberg/issues/753): fold goblin polynomials * @return FoldingResult is a pair consisting of an accumulator and a folding proof, which is a proof that the * accumulator was computed correctly. */ diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp index 007513f330d..8767b4e076b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_internal.hpp @@ -56,10 +56,10 @@ template class ProtogalaxyProverInternal { static constexpr size_t NUM_SUBRELATIONS = ProverInstances::NUM_SUBRELATIONS; /** - * @brief Compute the values of the full Honk relation at each row in the execution trace, representing f_i(ω) in - * the Protogalaxy paper, given the evaluations of all the prover polynomials and \vec{α} (the batching challenges - * that help establishing each subrelation is independently valid in Honk - from the Plonk paper, DO NOT confuse - * with α in Protogalaxy). + * @brief Compute the values of the aggregated relation evaluations at each row in the execution trace, representing + * f_i(ω) in the Protogalaxy paper, given the evaluations of all the prover polynomials and \vec{α} (the batching + * challenges that help establishing each subrelation is independently valid in Honk - from the Plonk paper, DO NOT + * confuse with α in Protogalaxy). * * @details When folding Mega instances, one of the relations is linearly dependent. We define such relations * as acting on the entire execution trace and hence requiring to be accumulated separately as we iterate over each diff --git a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp index 11428131c78..4e9d11108af 100644 --- a/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp +++ b/barretenberg/cpp/src/barretenberg/sumcheck/sumcheck_round.hpp @@ -516,9 +516,6 @@ template class SumcheckVerifierRound { * method computes the evaluation of \f$ \tilde{F} \f$ taking these values as arguments. * */ - // also copy paste in PG - // so instead of having claimed evaluations of each relation in part you have the actual evaluations - // kill the pow_univariate FF compute_full_relation_purported_value(ClaimedEvaluations purported_evaluations, const bb::RelationParameters& relation_parameters, const bb::GateSeparatorPolynomial& gate_sparators, From 882b4c410998a34f6c8230d28e0400cb63511b97 Mon Sep 17 00:00:00 2001 From: codygunton Date: Fri, 30 Aug 2024 20:04:40 +0000 Subject: [PATCH 36/36] Fix broken merge --- .../barretenberg/protogalaxy/protogalaxy_prover_impl.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp index 126fda16a4d..9f9d7b59a8e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover_impl.hpp @@ -41,7 +41,7 @@ template void ProtogalaxyProver_::run_o }; template -std::tuple, LegacyPolynomial> +std::tuple, Polynomial> ProtogalaxyProver_::perturbator_round( const std::shared_ptr& accumulator) { @@ -52,9 +52,9 @@ ProtogalaxyProver_::perturbator_round( const FF delta = transcript->template get_challenge("delta"); const std::vector deltas = compute_round_challenge_pows(accumulator->proving_key.log_circuit_size, delta); // An honest prover with valid initial instances computes that the perturbator is 0 in the first round - const LegacyPolynomial perturbator = accumulator->is_accumulator - ? Fun::compute_perturbator(accumulator, deltas) - : LegacyPolynomial(accumulator->proving_key.log_circuit_size + 1); + const Polynomial perturbator = accumulator->is_accumulator + ? Fun::compute_perturbator(accumulator, deltas) + : Polynomial(accumulator->proving_key.log_circuit_size + 1); // Prover doesn't send the constant coefficient of F because this is supposed to be equal to the target sum of // the accumulator which the folding verifier has from the previous iteration. // TODO(https://github.com/AztecProtocol/barretenberg/issues/1087): Verifier circuit for first IVC step is