From 273c1f6db9ebaa8d3aacd51963d677eb0ec38448 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Fri, 16 Feb 2024 20:03:22 +0000 Subject: [PATCH 01/18] initial refactoring attempt --- .../protogalaxy/protogalaxy_prover.cpp | 94 +-------------- .../ultra_honk/shared_prover_setup.cpp | 110 ++++++++++++++++++ .../ultra_honk/shared_prover_setup.hpp | 14 +++ 3 files changed, 126 insertions(+), 92 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.cpp create mode 100644 barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.hpp diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index 372926ddafb..c0929c8189e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -1,102 +1,12 @@ #include "protogalaxy_prover.hpp" #include "barretenberg/flavor/flavor.hpp" +#include "barretenberg/ultra_honk/shared_prover_setup.hpp" namespace bb { template void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, const std::string& domain_separator) { - instance->initialize_prover_polynomials(); - - const auto instance_size = static_cast(instance->instance_size); - const auto num_public_inputs = static_cast(instance->public_inputs.size()); - transcript->send_to_verifier(domain_separator + "_instance_size", instance_size); - transcript->send_to_verifier(domain_separator + "_public_input_size", num_public_inputs); - - for (size_t i = 0; i < instance->public_inputs.size(); ++i) { - auto public_input_i = instance->public_inputs[i]; - transcript->send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i); - } - transcript->send_to_verifier(domain_separator + "_pub_inputs_offset", - static_cast(instance->pub_inputs_offset)); - - auto& witness_commitments = instance->witness_commitments; - - // Commit to the first three wire polynomials of the instance - // We only commit to the fourth wire polynomial after adding memory recordss - witness_commitments.w_l = commitment_key->commit(instance->proving_key->w_l); - witness_commitments.w_r = commitment_key->commit(instance->proving_key->w_r); - witness_commitments.w_o = commitment_key->commit(instance->proving_key->w_o); - - auto wire_comms = witness_commitments.get_wires(); - auto commitment_labels = instance->commitment_labels; - auto wire_labels = commitment_labels.get_wires(); - for (size_t idx = 0; idx < 3; ++idx) { - transcript->send_to_verifier(domain_separator + "_" + wire_labels[idx], wire_comms[idx]); - } - - if constexpr (IsGoblinFlavor) { - // Commit to Goblin ECC op wires - witness_commitments.ecc_op_wire_1 = commitment_key->commit(instance->proving_key->ecc_op_wire_1); - witness_commitments.ecc_op_wire_2 = commitment_key->commit(instance->proving_key->ecc_op_wire_2); - witness_commitments.ecc_op_wire_3 = commitment_key->commit(instance->proving_key->ecc_op_wire_3); - witness_commitments.ecc_op_wire_4 = commitment_key->commit(instance->proving_key->ecc_op_wire_4); - - auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); - auto labels = commitment_labels.get_ecc_op_wires(); - for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { - transcript->send_to_verifier(domain_separator + "_" + labels[idx], op_wire_comms[idx]); - } - // Commit to DataBus columns - witness_commitments.calldata = commitment_key->commit(instance->proving_key->calldata); - witness_commitments.calldata_read_counts = commitment_key->commit(instance->proving_key->calldata_read_counts); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata, - instance->witness_commitments.calldata); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata_read_counts, - instance->witness_commitments.calldata_read_counts); - } - - auto eta = transcript->template get_challenge(domain_separator + "_eta"); - instance->compute_sorted_accumulator_polynomials(eta); - - // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire - // polynomial - witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); - witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); - - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.sorted_accum, - witness_commitments.sorted_accum); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.w_4, witness_commitments.w_4); - - auto [beta, gamma] = - transcript->template get_challenges(domain_separator + "_beta", domain_separator + "_gamma"); - - if constexpr (IsGoblinFlavor) { - // Compute and commit to the logderivative inverse used in DataBus - instance->compute_logderivative_inverse(beta, gamma); - instance->witness_commitments.lookup_inverses = - commitment_key->commit(instance->prover_polynomials.lookup_inverses); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.lookup_inverses, - instance->witness_commitments.lookup_inverses); - } - - instance->compute_grand_product_polynomials(beta, gamma); - - witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); - witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); - - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.z_perm, - instance->witness_commitments.z_perm); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.z_lookup, - instance->witness_commitments.z_lookup); - for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) { - instance->alphas[idx] = - transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); - } - auto vk_view = instance->verification_key->get_all(); - auto labels = instance->commitment_labels.get_precomputed(); - for (size_t idx = 0; idx < labels.size(); idx++) { - transcript->send_to_verifier(domain_separator + "_" + labels[idx], vk_view[idx]); - } + prover_setup(instance, commitment_key, transcript, domain_separator); } template diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.cpp new file mode 100644 index 00000000000..fa2c616ee3f --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.cpp @@ -0,0 +1,110 @@ +#include "barretenberg/ultra_honk/shared_prover_setup.hpp" + +namespace bb { +template +void prover_setup(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator) +{ + using FF = typename Flavor::FF; + instance->initialize_prover_polynomials(); + + const auto instance_size = static_cast(instance->instance_size); + const auto num_public_inputs = static_cast(instance->public_inputs.size()); + transcript->send_to_verifier(domain_separator + "_instance_size", instance_size); + transcript->send_to_verifier(domain_separator + "_public_input_size", num_public_inputs); + + for (size_t i = 0; i < instance->public_inputs.size(); ++i) { + auto public_input_i = instance->public_inputs[i]; + transcript->send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i); + } + transcript->send_to_verifier(domain_separator + "_pub_inputs_offset", + static_cast(instance->pub_inputs_offset)); + + auto& witness_commitments = instance->witness_commitments; + + // Commit to the first three wire polynomials of the instance + // We only commit to the fourth wire polynomial after adding memory recordss + witness_commitments.w_l = commitment_key->commit(instance->proving_key->w_l); + witness_commitments.w_r = commitment_key->commit(instance->proving_key->w_r); + witness_commitments.w_o = commitment_key->commit(instance->proving_key->w_o); + + auto wire_comms = witness_commitments.get_wires(); + auto commitment_labels = instance->commitment_labels; + auto wire_labels = commitment_labels.get_wires(); + for (size_t idx = 0; idx < 3; ++idx) { + transcript->send_to_verifier(domain_separator + "_" + wire_labels[idx], wire_comms[idx]); + } + + if constexpr (IsGoblinFlavor) { + // Commit to Goblin ECC op wires + witness_commitments.ecc_op_wire_1 = commitment_key->commit(instance->proving_key->ecc_op_wire_1); + witness_commitments.ecc_op_wire_2 = commitment_key->commit(instance->proving_key->ecc_op_wire_2); + witness_commitments.ecc_op_wire_3 = commitment_key->commit(instance->proving_key->ecc_op_wire_3); + witness_commitments.ecc_op_wire_4 = commitment_key->commit(instance->proving_key->ecc_op_wire_4); + + auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); + auto labels = commitment_labels.get_ecc_op_wires(); + for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { + transcript->send_to_verifier(domain_separator + "_" + labels[idx], op_wire_comms[idx]); + } + // Commit to DataBus columns + witness_commitments.calldata = commitment_key->commit(instance->proving_key->calldata); + witness_commitments.calldata_read_counts = commitment_key->commit(instance->proving_key->calldata_read_counts); + transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata, + instance->witness_commitments.calldata); + transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata_read_counts, + instance->witness_commitments.calldata_read_counts); + } + + auto eta = transcript->template get_challenge(domain_separator + "_eta"); + instance->compute_sorted_accumulator_polynomials(eta); + + // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire + // polynomial + witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); + witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); + + transcript->send_to_verifier(domain_separator + "_" + commitment_labels.sorted_accum, + witness_commitments.sorted_accum); + transcript->send_to_verifier(domain_separator + "_" + commitment_labels.w_4, witness_commitments.w_4); + + auto [beta, gamma] = + transcript->template get_challenges(domain_separator + "_beta", domain_separator + "_gamma"); + + if constexpr (IsGoblinFlavor) { + // Compute and commit to the logderivative inverse used in DataBus + instance->compute_logderivative_inverse(beta, gamma); + instance->witness_commitments.lookup_inverses = + commitment_key->commit(instance->prover_polynomials.lookup_inverses); + transcript->send_to_verifier(domain_separator + "_" + commitment_labels.lookup_inverses, + instance->witness_commitments.lookup_inverses); + } + + instance->compute_grand_product_polynomials(beta, gamma); + + witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); + witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); + + transcript->send_to_verifier(domain_separator + "_" + commitment_labels.z_perm, + instance->witness_commitments.z_perm); + transcript->send_to_verifier(domain_separator + "_" + commitment_labels.z_lookup, + instance->witness_commitments.z_lookup); + for (size_t idx = 0; idx < Flavor::NUM_SUBRELATIONS - 1; idx++) { + instance->alphas[idx] = + transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); + } + auto vk_view = instance->verification_key->get_all(); + auto labels = instance->commitment_labels.get_precomputed(); + for (size_t idx = 0; idx < labels.size(); idx++) { + transcript->send_to_verifier(domain_separator + "_" + labels[idx], vk_view[idx]); + } +} + +// template void prover_setup(std::shared_ptr> instance, +// std::shared_ptr commitment_key, +// std::shared_ptr transcript, +// const std::string& domain_separator); + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.hpp new file mode 100644 index 00000000000..c6f5b64e0f0 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "barretenberg/flavor/goblin_ultra.hpp" +#include "barretenberg/flavor/ultra.hpp" +#include "barretenberg/sumcheck/instance/prover_instance.hpp" +#include "barretenberg/transcript/transcript.hpp" + +namespace bb { + +template +void prover_setup(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); +} \ No newline at end of file From c25d8574cd13faef66f19d8f239f834e7de8ad0c Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Fri, 16 Feb 2024 22:02:28 +0000 Subject: [PATCH 02/18] fixed build --- .../protogalaxy/protogalaxy_prover.cpp | 2 +- .../shared_prover_setup.cpp | 16 +++++++++++----- .../shared_prover_setup.hpp | 0 3 files changed, 12 insertions(+), 6 deletions(-) rename barretenberg/cpp/src/barretenberg/{ultra_honk => protogalaxy}/shared_prover_setup.cpp (88%) rename barretenberg/cpp/src/barretenberg/{ultra_honk => protogalaxy}/shared_prover_setup.hpp (100%) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index c0929c8189e..7cf11657474 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -1,6 +1,6 @@ #include "protogalaxy_prover.hpp" #include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/ultra_honk/shared_prover_setup.hpp" +#include "barretenberg/protogalaxy/shared_prover_setup.hpp" namespace bb { template void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp similarity index 88% rename from barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.cpp rename to barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp index fa2c616ee3f..a98f71da256 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/ultra_honk/shared_prover_setup.hpp" +#include "barretenberg/protogalaxy/shared_prover_setup.hpp" namespace bb { template @@ -102,9 +102,15 @@ void prover_setup(const std::shared_ptr>& instance, } } -// template void prover_setup(std::shared_ptr> instance, -// std::shared_ptr commitment_key, -// std::shared_ptr transcript, -// const std::string& domain_separator); +template void prover_setup(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void prover_setup( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/ultra_honk/shared_prover_setup.hpp rename to barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp From bb163efa34a8245a49c3270d5d25362ab5eeab8b Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 20 Feb 2024 15:42:18 +0000 Subject: [PATCH 03/18] using shared code in ultra prover --- .../protogalaxy/protogalaxy_prover.cpp | 12 +- .../protogalaxy/protogalaxy_verifier.cpp | 5 +- .../protogalaxy/shared_prover_setup.cpp | 46 ++-- .../protogalaxy_recursive_verifier.cpp | 9 +- .../verifier/ultra_recursive_verifier.cpp | 2 +- .../barretenberg/ultra_honk/ultra_prover.cpp | 260 +++++++++--------- .../barretenberg/ultra_honk/ultra_prover.hpp | 2 - .../ultra_honk/ultra_transcript.test.cpp | 2 +- .../ultra_honk/ultra_verifier.cpp | 2 +- 9 files changed, 169 insertions(+), 171 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index 7cf11657474..b5c2690d9d5 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -6,7 +6,17 @@ template void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, const std::string& domain_separator) { - prover_setup(instance, commitment_key, transcript, domain_separator); + instance->initialize_prover_polynomials(); + prover_setup(instance, commitment_key, transcript, domain_separator + '_'); + for (size_t idx = 0; idx < Flavor::NUM_SUBRELATIONS - 1; idx++) { + instance->alphas[idx] = + transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); + } + auto vk_view = instance->verification_key->get_all(); + auto labels = instance->commitment_labels.get_precomputed(); + for (size_t idx = 0; idx < labels.size(); idx++) { + transcript->send_to_verifier(domain_separator + "_" + labels[idx], vk_view[idx]); + } } template diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index 07b32554f34..dec8cea63d5 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -70,6 +70,8 @@ void ProtoGalaxyVerifier_::receive_and_finalise_instance(cons inst->log_instance_size = static_cast(numeric::get_msb(inst->instance_size)); inst->public_input_size = transcript->template receive_from_prover(domain_separator + "_public_input_size"); + inst->pub_inputs_offset = + transcript->template receive_from_prover(domain_separator + "_pub_inputs_offset"); for (size_t i = 0; i < inst->public_input_size; ++i) { auto public_input_i = @@ -77,9 +79,6 @@ void ProtoGalaxyVerifier_::receive_and_finalise_instance(cons inst->public_inputs.emplace_back(public_input_i); } - inst->pub_inputs_offset = - transcript->template receive_from_prover(domain_separator + "_pub_inputs_offset"); - // Get commitments to first three wire polynomials auto labels = inst->commitment_labels; auto& witness_commitments = inst->witness_commitments; diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp index a98f71da256..50037f9a166 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp @@ -8,19 +8,20 @@ void prover_setup(const std::shared_ptr>& instance, const std::string& domain_separator) { using FF = typename Flavor::FF; - instance->initialize_prover_polynomials(); const auto instance_size = static_cast(instance->instance_size); const auto num_public_inputs = static_cast(instance->public_inputs.size()); - transcript->send_to_verifier(domain_separator + "_instance_size", instance_size); - transcript->send_to_verifier(domain_separator + "_public_input_size", num_public_inputs); + transcript->send_to_verifier(domain_separator + "instance_size", instance_size); + transcript->send_to_verifier(domain_separator + "public_input_size", num_public_inputs); + transcript->send_to_verifier(domain_separator + "pub_inputs_offset", + static_cast(instance->pub_inputs_offset)); + + ASSERT(instance->proving_key->num_public_inputs == instance->public_inputs.size()); for (size_t i = 0; i < instance->public_inputs.size(); ++i) { auto public_input_i = instance->public_inputs[i]; - transcript->send_to_verifier(domain_separator + "_public_input_" + std::to_string(i), public_input_i); + transcript->send_to_verifier(domain_separator + "public_input_" + std::to_string(i), public_input_i); } - transcript->send_to_verifier(domain_separator + "_pub_inputs_offset", - static_cast(instance->pub_inputs_offset)); auto& witness_commitments = instance->witness_commitments; @@ -34,7 +35,7 @@ void prover_setup(const std::shared_ptr>& instance, auto commitment_labels = instance->commitment_labels; auto wire_labels = commitment_labels.get_wires(); for (size_t idx = 0; idx < 3; ++idx) { - transcript->send_to_verifier(domain_separator + "_" + wire_labels[idx], wire_comms[idx]); + transcript->send_to_verifier(domain_separator + wire_labels[idx], wire_comms[idx]); } if constexpr (IsGoblinFlavor) { @@ -47,18 +48,18 @@ void prover_setup(const std::shared_ptr>& instance, auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); auto labels = commitment_labels.get_ecc_op_wires(); for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { - transcript->send_to_verifier(domain_separator + "_" + labels[idx], op_wire_comms[idx]); + transcript->send_to_verifier(domain_separator + labels[idx], op_wire_comms[idx]); } // Commit to DataBus columns witness_commitments.calldata = commitment_key->commit(instance->proving_key->calldata); witness_commitments.calldata_read_counts = commitment_key->commit(instance->proving_key->calldata_read_counts); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata, + transcript->send_to_verifier(domain_separator + commitment_labels.calldata, instance->witness_commitments.calldata); transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata_read_counts, instance->witness_commitments.calldata_read_counts); } - auto eta = transcript->template get_challenge(domain_separator + "_eta"); + auto eta = transcript->template get_challenge(domain_separator + "eta"); instance->compute_sorted_accumulator_polynomials(eta); // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire @@ -66,19 +67,17 @@ void prover_setup(const std::shared_ptr>& instance, witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.sorted_accum, - witness_commitments.sorted_accum); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.w_4, witness_commitments.w_4); + transcript->send_to_verifier(domain_separator + commitment_labels.sorted_accum, witness_commitments.sorted_accum); + transcript->send_to_verifier(domain_separator + commitment_labels.w_4, witness_commitments.w_4); - auto [beta, gamma] = - transcript->template get_challenges(domain_separator + "_beta", domain_separator + "_gamma"); + auto [beta, gamma] = transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); if constexpr (IsGoblinFlavor) { // Compute and commit to the logderivative inverse used in DataBus instance->compute_logderivative_inverse(beta, gamma); instance->witness_commitments.lookup_inverses = commitment_key->commit(instance->prover_polynomials.lookup_inverses); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.lookup_inverses, + transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, instance->witness_commitments.lookup_inverses); } @@ -87,19 +86,8 @@ void prover_setup(const std::shared_ptr>& instance, witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.z_perm, - instance->witness_commitments.z_perm); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.z_lookup, - instance->witness_commitments.z_lookup); - for (size_t idx = 0; idx < Flavor::NUM_SUBRELATIONS - 1; idx++) { - instance->alphas[idx] = - transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); - } - auto vk_view = instance->verification_key->get_all(); - auto labels = instance->commitment_labels.get_precomputed(); - for (size_t idx = 0; idx < labels.size(); idx++) { - transcript->send_to_verifier(domain_separator + "_" + labels[idx], vk_view[idx]); - } + transcript->send_to_verifier(domain_separator + commitment_labels.z_perm, instance->witness_commitments.z_perm); + transcript->send_to_verifier(domain_separator + commitment_labels.z_lookup, instance->witness_commitments.z_lookup); } template void prover_setup(const std::shared_ptr>& instance, diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp index 047cfa4037e..3a246bddc52 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp @@ -75,6 +75,10 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst inst->instance_size = uint32_t(instance_size.get_value()); inst->log_instance_size = static_cast(numeric::get_msb(inst->instance_size)); inst->public_input_size = uint32_t(public_input_size.get_value()); + const auto pub_inputs_offset = + transcript->template receive_from_prover(domain_separator + "_pub_inputs_offset"); + + inst->pub_inputs_offset = uint32_t(pub_inputs_offset.get_value()); for (size_t i = 0; i < inst->public_input_size; ++i) { auto public_input_i = @@ -82,11 +86,6 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst inst->public_inputs.emplace_back(public_input_i); } - const auto pub_inputs_offset = - transcript->template receive_from_prover(domain_separator + "_pub_inputs_offset"); - - inst->pub_inputs_offset = uint32_t(pub_inputs_offset.get_value()); - // Get commitments to first three wire polynomials auto labels = inst->commitment_labels; auto& witness_commitments = inst->witness_commitments; diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp index 47d4be24aca..38e1a1dd782 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/ultra_recursive_verifier.cpp @@ -36,7 +36,7 @@ std::array UltraRecursiveVerifier_::ve VerifierCommitments commitments{ key }; CommitmentLabels commitment_labels; - const auto circuit_size = transcript->template receive_from_prover("circuit_size"); + const auto circuit_size = transcript->template receive_from_prover("instance_size"); const auto public_input_size = transcript->template receive_from_prover("public_input_size"); const auto pub_inputs_offset = transcript->template receive_from_prover("pub_inputs_offset"); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index e4630c377ea..ec3f693ff97 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -1,4 +1,5 @@ #include "ultra_prover.hpp" +#include "barretenberg/protogalaxy/shared_prover_setup.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" namespace bb { @@ -21,124 +22,125 @@ UltraProver_::UltraProver_(const std::shared_ptr& inst, instance->initialize_prover_polynomials(); } -/** - * @brief Add circuit size, public input size, and public inputs to transcript - * - */ -template void UltraProver_::execute_preamble_round() -{ - auto proving_key = instance->proving_key; - const auto circuit_size = static_cast(proving_key->circuit_size); - const auto num_public_inputs = static_cast(proving_key->num_public_inputs); - - transcript->send_to_verifier("circuit_size", circuit_size); - transcript->send_to_verifier("public_input_size", num_public_inputs); - transcript->send_to_verifier("pub_inputs_offset", static_cast(instance->pub_inputs_offset)); - - for (size_t i = 0; i < proving_key->num_public_inputs; ++i) { - auto public_input_i = instance->public_inputs[i]; - transcript->send_to_verifier("public_input_" + std::to_string(i), public_input_i); - } -} - -/** - * @brief Commit to the wire polynomials (part of the witness), with the exception of the fourth wire, which is - * only commited to after adding memory records. In the Goblin Flavor, we also commit to the ECC OP wires and the - * DataBus columns. - */ -template void UltraProver_::execute_wire_commitments_round() -{ - auto& witness_commitments = instance->witness_commitments; - auto& proving_key = instance->proving_key; - - // Commit to the first three wire polynomials - // We only commit to the fourth wire polynomial after adding memory recordss - witness_commitments.w_l = commitment_key->commit(proving_key->w_l); - witness_commitments.w_r = commitment_key->commit(proving_key->w_r); - witness_commitments.w_o = commitment_key->commit(proving_key->w_o); - - auto wire_comms = witness_commitments.get_wires(); - auto labels = commitment_labels.get_wires(); - for (size_t idx = 0; idx < 3; ++idx) { - transcript->send_to_verifier(labels[idx], wire_comms[idx]); - } - - if constexpr (IsGoblinFlavor) { - // Commit to Goblin ECC op wires - witness_commitments.ecc_op_wire_1 = commitment_key->commit(proving_key->ecc_op_wire_1); - witness_commitments.ecc_op_wire_2 = commitment_key->commit(proving_key->ecc_op_wire_2); - witness_commitments.ecc_op_wire_3 = commitment_key->commit(proving_key->ecc_op_wire_3); - witness_commitments.ecc_op_wire_4 = commitment_key->commit(proving_key->ecc_op_wire_4); - - auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); - auto labels = commitment_labels.get_ecc_op_wires(); - for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { - transcript->send_to_verifier(labels[idx], op_wire_comms[idx]); - } - - // Commit to DataBus columns - witness_commitments.calldata = commitment_key->commit(proving_key->calldata); - witness_commitments.calldata_read_counts = commitment_key->commit(proving_key->calldata_read_counts); - transcript->send_to_verifier(commitment_labels.calldata, instance->witness_commitments.calldata); - transcript->send_to_verifier(commitment_labels.calldata_read_counts, - instance->witness_commitments.calldata_read_counts); - } -} - -/** - * @brief Compute sorted witness-table accumulator and commit to the resulting polynomials. - * - */ -template void UltraProver_::execute_sorted_list_accumulator_round() -{ - FF eta = transcript->template get_challenge("eta"); - - instance->compute_sorted_accumulator_polynomials(eta); - - auto& witness_commitments = instance->witness_commitments; - // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire - // polynomial - witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); - witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); - - transcript->send_to_verifier(commitment_labels.sorted_accum, instance->witness_commitments.sorted_accum); - transcript->send_to_verifier(commitment_labels.w_4, instance->witness_commitments.w_4); -} - -/** - * @brief Compute log derivative inverse polynomial and its commitment, if required - * - */ -template void UltraProver_::execute_log_derivative_inverse_round() -{ - // Compute and store challenges beta and gamma - auto [beta, gamma] = transcript->template get_challenges("beta", "gamma"); - relation_parameters.beta = beta; - relation_parameters.gamma = gamma; - - if constexpr (IsGoblinFlavor) { - instance->compute_logderivative_inverse(beta, gamma); - instance->witness_commitments.lookup_inverses = - commitment_key->commit(instance->prover_polynomials.lookup_inverses); - transcript->send_to_verifier(commitment_labels.lookup_inverses, instance->witness_commitments.lookup_inverses); - } -} - -/** - * @brief Compute permutation and lookup grand product polynomials and their commitments - * - */ -template void UltraProver_::execute_grand_product_computation_round() -{ - - instance->compute_grand_product_polynomials(relation_parameters.beta, relation_parameters.gamma); - - auto& witness_commitments = instance->witness_commitments; - witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); - witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); - transcript->send_to_verifier(commitment_labels.z_perm, instance->witness_commitments.z_perm); - transcript->send_to_verifier(commitment_labels.z_lookup, instance->witness_commitments.z_lookup); -} +// /** +// * @brief Add circuit size, public input size, and public inputs to transcript +// * +// */ +// template void UltraProver_::execute_preamble_round() +// { +// auto proving_key = instance->proving_key; +// const auto circuit_size = static_cast(proving_key->circuit_size); +// const auto num_public_inputs = static_cast(proving_key->num_public_inputs); + +// transcript->send_to_verifier("circuit_size", circuit_size); +// transcript->send_to_verifier("public_input_size", num_public_inputs); +// transcript->send_to_verifier("pub_inputs_offset", static_cast(instance->pub_inputs_offset)); + +// for (size_t i = 0; i < proving_key->num_public_inputs; ++i) { +// auto public_input_i = instance->public_inputs[i]; +// transcript->send_to_verifier("public_input_" + std::to_string(i), public_input_i); +// } +// } + +// /** +// * @brief Commit to the wire polynomials (part of the witness), with the exception of the fourth wire, which is +// * only commited to after adding memory records. In the Goblin Flavor, we also commit to the ECC OP wires and the +// * DataBus columns. +// */ +// template void UltraProver_::execute_wire_commitments_round() +// { +// auto& witness_commitments = instance->witness_commitments; +// auto& proving_key = instance->proving_key; + +// // Commit to the first three wire polynomials +// // We only commit to the fourth wire polynomial after adding memory recordss +// witness_commitments.w_l = commitment_key->commit(proving_key->w_l); +// witness_commitments.w_r = commitment_key->commit(proving_key->w_r); +// witness_commitments.w_o = commitment_key->commit(proving_key->w_o); + +// auto wire_comms = witness_commitments.get_wires(); +// auto labels = commitment_labels.get_wires(); +// for (size_t idx = 0; idx < 3; ++idx) { +// transcript->send_to_verifier(labels[idx], wire_comms[idx]); +// } + +// if constexpr (IsGoblinFlavor) { +// // Commit to Goblin ECC op wires +// witness_commitments.ecc_op_wire_1 = commitment_key->commit(proving_key->ecc_op_wire_1); +// witness_commitments.ecc_op_wire_2 = commitment_key->commit(proving_key->ecc_op_wire_2); +// witness_commitments.ecc_op_wire_3 = commitment_key->commit(proving_key->ecc_op_wire_3); +// witness_commitments.ecc_op_wire_4 = commitment_key->commit(proving_key->ecc_op_wire_4); + +// auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); +// auto labels = commitment_labels.get_ecc_op_wires(); +// for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { +// transcript->send_to_verifier(labels[idx], op_wire_comms[idx]); +// } + +// // Commit to DataBus columns +// witness_commitments.calldata = commitment_key->commit(proving_key->calldata); +// witness_commitments.calldata_read_counts = commitment_key->commit(proving_key->calldata_read_counts); +// transcript->send_to_verifier(commitment_labels.calldata, instance->witness_commitments.calldata); +// transcript->send_to_verifier(commitment_labels.calldata_read_counts, +// instance->witness_commitments.calldata_read_counts); +// } +// } + +// /** +// * @brief Compute sorted witness-table accumulator and commit to the resulting polynomials. +// * +// */ +// template void UltraProver_::execute_sorted_list_accumulator_round() +// { +// FF eta = transcript->template get_challenge("eta"); + +// instance->compute_sorted_accumulator_polynomials(eta); + +// auto& witness_commitments = instance->witness_commitments; +// // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire +// // polynomial +// witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); +// witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); + +// transcript->send_to_verifier(commitment_labels.sorted_accum, instance->witness_commitments.sorted_accum); +// transcript->send_to_verifier(commitment_labels.w_4, instance->witness_commitments.w_4); +// } + +// /** +// * @brief Compute log derivative inverse polynomial and its commitment, if required +// * +// */ +// template void UltraProver_::execute_log_derivative_inverse_round() +// { +// // Compute and store challenges beta and gamma +// auto [beta, gamma] = transcript->template get_challenges("beta", "gamma"); +// relation_parameters.beta = beta; +// relation_parameters.gamma = gamma; + +// if constexpr (IsGoblinFlavor) { +// instance->compute_logderivative_inverse(beta, gamma); +// instance->witness_commitments.lookup_inverses = +// commitment_key->commit(instance->prover_polynomials.lookup_inverses); +// transcript->send_to_verifier(commitment_labels.lookup_inverses, +// instance->witness_commitments.lookup_inverses); +// } +// } + +// /** +// * @brief Compute permutation and lookup grand product polynomials and their commitments +// * +// */ +// template void UltraProver_::execute_grand_product_computation_round() +// { + +// instance->compute_grand_product_polynomials(relation_parameters.beta, relation_parameters.gamma); + +// auto& witness_commitments = instance->witness_commitments; +// witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); +// witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); +// transcript->send_to_verifier(commitment_labels.z_perm, instance->witness_commitments.z_perm); +// transcript->send_to_verifier(commitment_labels.z_lookup, instance->witness_commitments.z_lookup); +// } /** * @brief Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated. @@ -186,20 +188,22 @@ template HonkProof& UltraProver_::export_proof() template HonkProof& UltraProver_::construct_proof() { - // Add circuit size public input size and public inputs to transcript-> - execute_preamble_round(); + // // Add circuit size public input size and public inputs to transcript-> + // execute_preamble_round(); + + // // Compute first three wire commitments + // execute_wire_commitments_round(); - // Compute first three wire commitments - execute_wire_commitments_round(); + // // Compute sorted list accumulator and commitment + // execute_sorted_list_accumulator_round(); - // Compute sorted list accumulator and commitment - execute_sorted_list_accumulator_round(); + // // Fiat-Shamir: beta & gamma + // execute_log_derivative_inverse_round(); - // Fiat-Shamir: beta & gamma - execute_log_derivative_inverse_round(); + // // Compute grand product(s) and commitments. + // execute_grand_product_computation_round(); - // Compute grand product(s) and commitments. - execute_grand_product_computation_round(); + prover_setup(instance, commitment_key, transcript, ""); // Fiat-Shamir: alpha // Run sumcheck subprotocol. diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index e212a38abfa..1fb53b6c149 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -44,8 +44,6 @@ template class UltraProver_ { bb::RelationParameters relation_parameters; - CommitmentLabels commitment_labels; - Polynomial quotient_W; SumcheckOutput sumcheck_output; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp index fd6ccf7c148..d30f1a299a3 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_transcript.test.cpp @@ -42,7 +42,7 @@ class UltraTranscriptTests : public ::testing::Test { size_t frs_per_uint32 = bb::field_conversion::calc_num_bn254_frs(); size_t round = 0; - manifest_expected.add_entry(round, "circuit_size", frs_per_uint32); + manifest_expected.add_entry(round, "instance_size", frs_per_uint32); manifest_expected.add_entry(round, "public_input_size", frs_per_uint32); manifest_expected.add_entry(round, "pub_inputs_offset", frs_per_uint32); manifest_expected.add_entry(round, "public_input_0", frs_per_Fr); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp index 084e711ee71..a2790255b6c 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_verifier.cpp @@ -59,7 +59,7 @@ template bool UltraVerifier_::verify_proof(const HonkP CommitmentLabels commitment_labels; // TODO(Adrian): Change the initialization of the transcript to take the VK hash? - const auto circuit_size = transcript->template receive_from_prover("circuit_size"); + const auto circuit_size = transcript->template receive_from_prover("instance_size"); const auto public_input_size = transcript->template receive_from_prover("public_input_size"); const auto pub_inputs_offset = transcript->template receive_from_prover("pub_inputs_offset"); From a90c5de9564e624271e62f20c58d0a1cd15a136f Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 20 Feb 2024 15:48:42 +0000 Subject: [PATCH 04/18] commenting out headers too --- .../cpp/src/barretenberg/ultra_honk/ultra_prover.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index 1fb53b6c149..d4656ffb7e8 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -27,11 +27,11 @@ template class UltraProver_ { const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); - BB_PROFILE void execute_preamble_round(); - BB_PROFILE void execute_wire_commitments_round(); - BB_PROFILE void execute_sorted_list_accumulator_round(); - BB_PROFILE void execute_log_derivative_inverse_round(); - BB_PROFILE void execute_grand_product_computation_round(); + // BB_PROFILE void execute_preamble_round(); + // BB_PROFILE void execute_wire_commitments_round(); + // BB_PROFILE void execute_sorted_list_accumulator_round(); + // BB_PROFILE void execute_log_derivative_inverse_round(); + // BB_PROFILE void execute_grand_product_computation_round(); BB_PROFILE void execute_relation_check_rounds(); BB_PROFILE void execute_zeromorph_rounds(); From a983664705a23604873bfb7bfcb89d6452b3bd2c Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 20 Feb 2024 15:58:25 +0000 Subject: [PATCH 05/18] getting build to work --- .../protogalaxy/shared_prover_setup.hpp | 2 +- .../barretenberg/ultra_honk/ultra_prover.cpp | 240 +++++++++--------- .../barretenberg/ultra_honk/ultra_prover.hpp | 10 +- 3 files changed, 126 insertions(+), 126 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp index c6f5b64e0f0..9cb3657b341 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp @@ -10,5 +10,5 @@ template void prover_setup(const std::shared_ptr>& instance, const std::shared_ptr& commitment_key, const std::shared_ptr& transcript, - const std::string& domain_separator); + const std::string& domain_separator = ""); } \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index ec3f693ff97..f0d6f740f43 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -22,125 +22,125 @@ UltraProver_::UltraProver_(const std::shared_ptr& inst, instance->initialize_prover_polynomials(); } -// /** -// * @brief Add circuit size, public input size, and public inputs to transcript -// * -// */ -// template void UltraProver_::execute_preamble_round() -// { -// auto proving_key = instance->proving_key; -// const auto circuit_size = static_cast(proving_key->circuit_size); -// const auto num_public_inputs = static_cast(proving_key->num_public_inputs); - -// transcript->send_to_verifier("circuit_size", circuit_size); -// transcript->send_to_verifier("public_input_size", num_public_inputs); -// transcript->send_to_verifier("pub_inputs_offset", static_cast(instance->pub_inputs_offset)); - -// for (size_t i = 0; i < proving_key->num_public_inputs; ++i) { -// auto public_input_i = instance->public_inputs[i]; -// transcript->send_to_verifier("public_input_" + std::to_string(i), public_input_i); -// } -// } - -// /** -// * @brief Commit to the wire polynomials (part of the witness), with the exception of the fourth wire, which is -// * only commited to after adding memory records. In the Goblin Flavor, we also commit to the ECC OP wires and the -// * DataBus columns. -// */ -// template void UltraProver_::execute_wire_commitments_round() -// { -// auto& witness_commitments = instance->witness_commitments; -// auto& proving_key = instance->proving_key; - -// // Commit to the first three wire polynomials -// // We only commit to the fourth wire polynomial after adding memory recordss -// witness_commitments.w_l = commitment_key->commit(proving_key->w_l); -// witness_commitments.w_r = commitment_key->commit(proving_key->w_r); -// witness_commitments.w_o = commitment_key->commit(proving_key->w_o); - -// auto wire_comms = witness_commitments.get_wires(); -// auto labels = commitment_labels.get_wires(); -// for (size_t idx = 0; idx < 3; ++idx) { -// transcript->send_to_verifier(labels[idx], wire_comms[idx]); -// } - -// if constexpr (IsGoblinFlavor) { -// // Commit to Goblin ECC op wires -// witness_commitments.ecc_op_wire_1 = commitment_key->commit(proving_key->ecc_op_wire_1); -// witness_commitments.ecc_op_wire_2 = commitment_key->commit(proving_key->ecc_op_wire_2); -// witness_commitments.ecc_op_wire_3 = commitment_key->commit(proving_key->ecc_op_wire_3); -// witness_commitments.ecc_op_wire_4 = commitment_key->commit(proving_key->ecc_op_wire_4); - -// auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); -// auto labels = commitment_labels.get_ecc_op_wires(); -// for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { -// transcript->send_to_verifier(labels[idx], op_wire_comms[idx]); -// } - -// // Commit to DataBus columns -// witness_commitments.calldata = commitment_key->commit(proving_key->calldata); -// witness_commitments.calldata_read_counts = commitment_key->commit(proving_key->calldata_read_counts); -// transcript->send_to_verifier(commitment_labels.calldata, instance->witness_commitments.calldata); -// transcript->send_to_verifier(commitment_labels.calldata_read_counts, -// instance->witness_commitments.calldata_read_counts); -// } -// } - -// /** -// * @brief Compute sorted witness-table accumulator and commit to the resulting polynomials. -// * -// */ -// template void UltraProver_::execute_sorted_list_accumulator_round() -// { -// FF eta = transcript->template get_challenge("eta"); - -// instance->compute_sorted_accumulator_polynomials(eta); - -// auto& witness_commitments = instance->witness_commitments; -// // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire -// // polynomial -// witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); -// witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); - -// transcript->send_to_verifier(commitment_labels.sorted_accum, instance->witness_commitments.sorted_accum); -// transcript->send_to_verifier(commitment_labels.w_4, instance->witness_commitments.w_4); -// } - -// /** -// * @brief Compute log derivative inverse polynomial and its commitment, if required -// * -// */ -// template void UltraProver_::execute_log_derivative_inverse_round() -// { -// // Compute and store challenges beta and gamma -// auto [beta, gamma] = transcript->template get_challenges("beta", "gamma"); -// relation_parameters.beta = beta; -// relation_parameters.gamma = gamma; - -// if constexpr (IsGoblinFlavor) { -// instance->compute_logderivative_inverse(beta, gamma); -// instance->witness_commitments.lookup_inverses = -// commitment_key->commit(instance->prover_polynomials.lookup_inverses); -// transcript->send_to_verifier(commitment_labels.lookup_inverses, -// instance->witness_commitments.lookup_inverses); -// } -// } - -// /** -// * @brief Compute permutation and lookup grand product polynomials and their commitments -// * -// */ -// template void UltraProver_::execute_grand_product_computation_round() -// { - -// instance->compute_grand_product_polynomials(relation_parameters.beta, relation_parameters.gamma); - -// auto& witness_commitments = instance->witness_commitments; -// witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); -// witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); -// transcript->send_to_verifier(commitment_labels.z_perm, instance->witness_commitments.z_perm); -// transcript->send_to_verifier(commitment_labels.z_lookup, instance->witness_commitments.z_lookup); -// } +/** + * @brief Add circuit size, public input size, and public inputs to transcript + * + */ +template void UltraProver_::execute_preamble_round() +{ + auto proving_key = instance->proving_key; + const auto circuit_size = static_cast(proving_key->circuit_size); + const auto num_public_inputs = static_cast(proving_key->num_public_inputs); + + transcript->send_to_verifier("instance_size", circuit_size); + transcript->send_to_verifier("public_input_size", num_public_inputs); + transcript->send_to_verifier("pub_inputs_offset", static_cast(instance->pub_inputs_offset)); + + for (size_t i = 0; i < proving_key->num_public_inputs; ++i) { + auto public_input_i = instance->public_inputs[i]; + transcript->send_to_verifier("public_input_" + std::to_string(i), public_input_i); + } +} + +/** + * @brief Commit to the wire polynomials (part of the witness), with the exception of the fourth wire, which is + * only commited to after adding memory records. In the Goblin Flavor, we also commit to the ECC OP wires and the + * DataBus columns. + */ +template void UltraProver_::execute_wire_commitments_round() +{ + auto& witness_commitments = instance->witness_commitments; + auto& proving_key = instance->proving_key; + + // Commit to the first three wire polynomials + // We only commit to the fourth wire polynomial after adding memory recordss + witness_commitments.w_l = commitment_key->commit(proving_key->w_l); + witness_commitments.w_r = commitment_key->commit(proving_key->w_r); + witness_commitments.w_o = commitment_key->commit(proving_key->w_o); + + auto wire_comms = witness_commitments.get_wires(); + auto labels = instance->commitment_labels.get_wires(); + for (size_t idx = 0; idx < 3; ++idx) { + transcript->send_to_verifier(labels[idx], wire_comms[idx]); + } + + if constexpr (IsGoblinFlavor) { + // Commit to Goblin ECC op wires + witness_commitments.ecc_op_wire_1 = commitment_key->commit(proving_key->ecc_op_wire_1); + witness_commitments.ecc_op_wire_2 = commitment_key->commit(proving_key->ecc_op_wire_2); + witness_commitments.ecc_op_wire_3 = commitment_key->commit(proving_key->ecc_op_wire_3); + witness_commitments.ecc_op_wire_4 = commitment_key->commit(proving_key->ecc_op_wire_4); + + auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); + auto labels = instance->commitment_labels.get_ecc_op_wires(); + for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { + transcript->send_to_verifier(labels[idx], op_wire_comms[idx]); + } + + // Commit to DataBus columns + witness_commitments.calldata = commitment_key->commit(proving_key->calldata); + witness_commitments.calldata_read_counts = commitment_key->commit(proving_key->calldata_read_counts); + transcript->send_to_verifier(instance->commitment_labels.calldata, instance->witness_commitments.calldata); + transcript->send_to_verifier(instance->commitment_labels.calldata_read_counts, + instance->witness_commitments.calldata_read_counts); + } +} + +/** + * @brief Compute sorted witness-table accumulator and commit to the resulting polynomials. + * + */ +template void UltraProver_::execute_sorted_list_accumulator_round() +{ + FF eta = transcript->template get_challenge("eta"); + + instance->compute_sorted_accumulator_polynomials(eta); + + auto& witness_commitments = instance->witness_commitments; + // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire + // polynomial + witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); + witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); + + transcript->send_to_verifier(instance->commitment_labels.sorted_accum, instance->witness_commitments.sorted_accum); + transcript->send_to_verifier(instance->commitment_labels.w_4, instance->witness_commitments.w_4); +} + +/** + * @brief Compute log derivative inverse polynomial and its commitment, if required + * + */ +template void UltraProver_::execute_log_derivative_inverse_round() +{ + // Compute and store challenges beta and gamma + auto [beta, gamma] = transcript->template get_challenges("beta", "gamma"); + relation_parameters.beta = beta; + relation_parameters.gamma = gamma; + + if constexpr (IsGoblinFlavor) { + instance->compute_logderivative_inverse(beta, gamma); + instance->witness_commitments.lookup_inverses = + commitment_key->commit(instance->prover_polynomials.lookup_inverses); + transcript->send_to_verifier(instance->commitment_labels.lookup_inverses, + instance->witness_commitments.lookup_inverses); + } +} + +/** + * @brief Compute permutation and lookup grand product polynomials and their commitments + * + */ +template void UltraProver_::execute_grand_product_computation_round() +{ + + instance->compute_grand_product_polynomials(relation_parameters.beta, relation_parameters.gamma); + + auto& witness_commitments = instance->witness_commitments; + witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); + witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); + transcript->send_to_verifier(instance->commitment_labels.z_perm, instance->witness_commitments.z_perm); + transcript->send_to_verifier(instance->commitment_labels.z_lookup, instance->witness_commitments.z_lookup); +} /** * @brief Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated. @@ -203,7 +203,7 @@ template HonkProof& UltraProver_::construct_proof // // Compute grand product(s) and commitments. // execute_grand_product_computation_round(); - prover_setup(instance, commitment_key, transcript, ""); + prover_setup(instance, commitment_key, transcript); // Fiat-Shamir: alpha // Run sumcheck subprotocol. diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index d4656ffb7e8..1fb53b6c149 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -27,11 +27,11 @@ template class UltraProver_ { const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); - // BB_PROFILE void execute_preamble_round(); - // BB_PROFILE void execute_wire_commitments_round(); - // BB_PROFILE void execute_sorted_list_accumulator_round(); - // BB_PROFILE void execute_log_derivative_inverse_round(); - // BB_PROFILE void execute_grand_product_computation_round(); + BB_PROFILE void execute_preamble_round(); + BB_PROFILE void execute_wire_commitments_round(); + BB_PROFILE void execute_sorted_list_accumulator_round(); + BB_PROFILE void execute_log_derivative_inverse_round(); + BB_PROFILE void execute_grand_product_computation_round(); BB_PROFILE void execute_relation_check_rounds(); BB_PROFILE void execute_zeromorph_rounds(); From ed8a2d13c1ddd0c56df7b53192b6a5fb6c0c6f17 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 20 Feb 2024 16:10:42 +0000 Subject: [PATCH 06/18] fix test --- .../cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp | 2 +- .../barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp index 50037f9a166..3dff02a9151 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp @@ -55,7 +55,7 @@ void prover_setup(const std::shared_ptr>& instance, witness_commitments.calldata_read_counts = commitment_key->commit(instance->proving_key->calldata_read_counts); transcript->send_to_verifier(domain_separator + commitment_labels.calldata, instance->witness_commitments.calldata); - transcript->send_to_verifier(domain_separator + "_" + commitment_labels.calldata_read_counts, + transcript->send_to_verifier(domain_separator + commitment_labels.calldata_read_counts, instance->witness_commitments.calldata_read_counts); } diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp index 5e97fd5bfaf..27ac53f3392 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/goblin_ultra_transcript.test.cpp @@ -42,7 +42,7 @@ class GoblinUltraTranscriptTests : public ::testing::Test { size_t frs_per_uint32 = bb::field_conversion::calc_num_bn254_frs(); size_t round = 0; - manifest_expected.add_entry(round, "circuit_size", frs_per_uint32); + manifest_expected.add_entry(round, "instance_size", frs_per_uint32); manifest_expected.add_entry(round, "public_input_size", frs_per_uint32); manifest_expected.add_entry(round, "pub_inputs_offset", frs_per_uint32); manifest_expected.add_entry(round, "public_input_0", frs_per_Fr); From 3b7f1e0315e91c0574251b3daae0e9899bb8a42d Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Wed, 21 Feb 2024 12:06:14 +0000 Subject: [PATCH 07/18] split into rounds, but should fail to link --- .../protogalaxy/protogalaxy_prover.cpp | 2 +- .../protogalaxy/shared_prover_setup.cpp | 78 ++++++++++--- .../protogalaxy/shared_prover_setup.hpp | 38 ++++++- .../barretenberg/ultra_honk/ultra_prover.cpp | 106 +++--------------- 4 files changed, 113 insertions(+), 111 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index b5c2690d9d5..1ffd7ec2981 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -7,7 +7,7 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared const std::string& domain_separator) { instance->initialize_prover_polynomials(); - prover_setup(instance, commitment_key, transcript, domain_separator + '_'); + prover_setup_(instance, commitment_key, transcript, domain_separator + '_'); for (size_t idx = 0; idx < Flavor::NUM_SUBRELATIONS - 1; idx++) { instance->alphas[idx] = transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp index 3dff02a9151..0e0dfcf77b0 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp @@ -1,14 +1,12 @@ #include "barretenberg/protogalaxy/shared_prover_setup.hpp" namespace bb { + template -void prover_setup(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator) +void execute_preamble_round_(const std::shared_ptr>& instance, + const std::shared_ptr& transcript, + const std::string& domain_separator) { - using FF = typename Flavor::FF; - const auto instance_size = static_cast(instance->instance_size); const auto num_public_inputs = static_cast(instance->public_inputs.size()); transcript->send_to_verifier(domain_separator + "instance_size", instance_size); @@ -22,7 +20,14 @@ void prover_setup(const std::shared_ptr>& instance, auto public_input_i = instance->public_inputs[i]; transcript->send_to_verifier(domain_separator + "public_input_" + std::to_string(i), public_input_i); } +} +template +void execute_wire_commitments_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator) +{ auto& witness_commitments = instance->witness_commitments; // Commit to the first three wire polynomials of the instance @@ -58,8 +63,18 @@ void prover_setup(const std::shared_ptr>& instance, transcript->send_to_verifier(domain_separator + commitment_labels.calldata_read_counts, instance->witness_commitments.calldata_read_counts); } +} - auto eta = transcript->template get_challenge(domain_separator + "eta"); +template +void execute_sorted_list_accumulator_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator) +{ + auto& witness_commitments = instance->witness_commitments; + const auto& commitment_labels = instance->commitment_labels; + + auto eta = transcript->template get_challenge(domain_separator + "eta"); instance->compute_sorted_accumulator_polynomials(eta); // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire @@ -69,9 +84,20 @@ void prover_setup(const std::shared_ptr>& instance, transcript->send_to_verifier(domain_separator + commitment_labels.sorted_accum, witness_commitments.sorted_accum); transcript->send_to_verifier(domain_separator + commitment_labels.w_4, witness_commitments.w_4); +} - auto [beta, gamma] = transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); +template +void execute_log_derivative_inverse_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator) +{ + const auto& commitment_labels = instance->commitment_labels; + auto [beta, gamma] = + transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); + instance->relation_parameters.beta = beta; + instance->relation_parameters.gamma = gamma; if constexpr (IsGoblinFlavor) { // Compute and commit to the logderivative inverse used in DataBus instance->compute_logderivative_inverse(beta, gamma); @@ -80,8 +106,19 @@ void prover_setup(const std::shared_ptr>& instance, transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, instance->witness_commitments.lookup_inverses); } +} - instance->compute_grand_product_polynomials(beta, gamma); +template +void execute_grand_product_computation_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator) +{ + auto& witness_commitments = instance->witness_commitments; + const auto& commitment_labels = instance->commitment_labels; + + instance->compute_grand_product_polynomials(instance->relation_parameters.beta, + instance->relation_parameters.gamma); witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); @@ -90,12 +127,25 @@ void prover_setup(const std::shared_ptr>& instance, transcript->send_to_verifier(domain_separator + commitment_labels.z_lookup, instance->witness_commitments.z_lookup); } -template void prover_setup(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); +template +void prover_setup_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator) +{ + execute_preamble_round_(instance, transcript, domain_separator); + execute_wire_commitments_round_(instance, commitment_key, transcript, domain_separator); + execute_sorted_list_accumulator_round_(instance, commitment_key, transcript, domain_separator); + execute_log_derivative_inverse_round_(instance, commitment_key, transcript, domain_separator); + execute_grand_product_computation_round_(instance, commitment_key, transcript, domain_separator); +} + +template void prover_setup_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); -template void prover_setup( +template void prover_setup_( const std::shared_ptr>& instance, const std::shared_ptr& commitment_key, const std::shared_ptr& transcript, diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp index 9cb3657b341..8fc037a3a5e 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp @@ -7,8 +7,36 @@ namespace bb { template -void prover_setup(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator = ""); -} \ No newline at end of file +void execute_preamble_round_(const std::shared_ptr>& instance, + const std::shared_ptr& transcript, + const std::string& domain_separator = ""); + +template +void execute_wire_commitments_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator = ""); + +template +void execute_sorted_list_accumulator_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator = ""); + +template +void execute_log_derivative_inverse_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator = ""); + +template +void execute_grand_product_computation_round_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator = ""); +template +void prover_setup_(const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator = ""); +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index f0d6f740f43..61775d1e465 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -28,18 +28,7 @@ UltraProver_::UltraProver_(const std::shared_ptr& inst, */ template void UltraProver_::execute_preamble_round() { - auto proving_key = instance->proving_key; - const auto circuit_size = static_cast(proving_key->circuit_size); - const auto num_public_inputs = static_cast(proving_key->num_public_inputs); - - transcript->send_to_verifier("instance_size", circuit_size); - transcript->send_to_verifier("public_input_size", num_public_inputs); - transcript->send_to_verifier("pub_inputs_offset", static_cast(instance->pub_inputs_offset)); - - for (size_t i = 0; i < proving_key->num_public_inputs; ++i) { - auto public_input_i = instance->public_inputs[i]; - transcript->send_to_verifier("public_input_" + std::to_string(i), public_input_i); - } + execute_preamble_round_(instance, transcript); } /** @@ -49,41 +38,7 @@ template void UltraProver_::execute_preamble_roun */ template void UltraProver_::execute_wire_commitments_round() { - auto& witness_commitments = instance->witness_commitments; - auto& proving_key = instance->proving_key; - - // Commit to the first three wire polynomials - // We only commit to the fourth wire polynomial after adding memory recordss - witness_commitments.w_l = commitment_key->commit(proving_key->w_l); - witness_commitments.w_r = commitment_key->commit(proving_key->w_r); - witness_commitments.w_o = commitment_key->commit(proving_key->w_o); - - auto wire_comms = witness_commitments.get_wires(); - auto labels = instance->commitment_labels.get_wires(); - for (size_t idx = 0; idx < 3; ++idx) { - transcript->send_to_verifier(labels[idx], wire_comms[idx]); - } - - if constexpr (IsGoblinFlavor) { - // Commit to Goblin ECC op wires - witness_commitments.ecc_op_wire_1 = commitment_key->commit(proving_key->ecc_op_wire_1); - witness_commitments.ecc_op_wire_2 = commitment_key->commit(proving_key->ecc_op_wire_2); - witness_commitments.ecc_op_wire_3 = commitment_key->commit(proving_key->ecc_op_wire_3); - witness_commitments.ecc_op_wire_4 = commitment_key->commit(proving_key->ecc_op_wire_4); - - auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); - auto labels = instance->commitment_labels.get_ecc_op_wires(); - for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { - transcript->send_to_verifier(labels[idx], op_wire_comms[idx]); - } - - // Commit to DataBus columns - witness_commitments.calldata = commitment_key->commit(proving_key->calldata); - witness_commitments.calldata_read_counts = commitment_key->commit(proving_key->calldata_read_counts); - transcript->send_to_verifier(instance->commitment_labels.calldata, instance->witness_commitments.calldata); - transcript->send_to_verifier(instance->commitment_labels.calldata_read_counts, - instance->witness_commitments.calldata_read_counts); - } + execute_wire_commitments_round_(instance, commitment_key, transcript); } /** @@ -92,18 +47,7 @@ template void UltraProver_::execute_wire_commitme */ template void UltraProver_::execute_sorted_list_accumulator_round() { - FF eta = transcript->template get_challenge("eta"); - - instance->compute_sorted_accumulator_polynomials(eta); - - auto& witness_commitments = instance->witness_commitments; - // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire - // polynomial - witness_commitments.sorted_accum = commitment_key->commit(instance->prover_polynomials.sorted_accum); - witness_commitments.w_4 = commitment_key->commit(instance->prover_polynomials.w_4); - - transcript->send_to_verifier(instance->commitment_labels.sorted_accum, instance->witness_commitments.sorted_accum); - transcript->send_to_verifier(instance->commitment_labels.w_4, instance->witness_commitments.w_4); + execute_sorted_list_accumulator_round_(instance, commitment_key, transcript); } /** @@ -112,18 +56,7 @@ template void UltraProver_::execute_sorted_list_a */ template void UltraProver_::execute_log_derivative_inverse_round() { - // Compute and store challenges beta and gamma - auto [beta, gamma] = transcript->template get_challenges("beta", "gamma"); - relation_parameters.beta = beta; - relation_parameters.gamma = gamma; - - if constexpr (IsGoblinFlavor) { - instance->compute_logderivative_inverse(beta, gamma); - instance->witness_commitments.lookup_inverses = - commitment_key->commit(instance->prover_polynomials.lookup_inverses); - transcript->send_to_verifier(instance->commitment_labels.lookup_inverses, - instance->witness_commitments.lookup_inverses); - } + execute_log_derivative_inverse_round_(instance, commitment_key, transcript); } /** @@ -132,14 +65,7 @@ template void UltraProver_::execute_log_derivativ */ template void UltraProver_::execute_grand_product_computation_round() { - - instance->compute_grand_product_polynomials(relation_parameters.beta, relation_parameters.gamma); - - auto& witness_commitments = instance->witness_commitments; - witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); - witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); - transcript->send_to_verifier(instance->commitment_labels.z_perm, instance->witness_commitments.z_perm); - transcript->send_to_verifier(instance->commitment_labels.z_lookup, instance->witness_commitments.z_lookup); + execute_grand_product_computation_round_(instance, commitment_key, transcript); } /** @@ -188,22 +114,20 @@ template HonkProof& UltraProver_::export_proof() template HonkProof& UltraProver_::construct_proof() { - // // Add circuit size public input size and public inputs to transcript-> - // execute_preamble_round(); - - // // Compute first three wire commitments - // execute_wire_commitments_round(); + // Add circuit size public input size and public inputs to transcript-> + execute_preamble_round(); - // // Compute sorted list accumulator and commitment - // execute_sorted_list_accumulator_round(); + // Compute first three wire commitments + execute_wire_commitments_round(); - // // Fiat-Shamir: beta & gamma - // execute_log_derivative_inverse_round(); + // Compute sorted list accumulator and commitment + execute_sorted_list_accumulator_round(); - // // Compute grand product(s) and commitments. - // execute_grand_product_computation_round(); + // Fiat-Shamir: beta & gamma + execute_log_derivative_inverse_round(); - prover_setup(instance, commitment_key, transcript); + // Compute grand product(s) and commitments. + execute_grand_product_computation_round(); // Fiat-Shamir: alpha // Run sumcheck subprotocol. From fa8f3c46b1e71c943fbb0f0ca91cee481e5feb82 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Wed, 21 Feb 2024 12:13:53 +0000 Subject: [PATCH 08/18] link works --- .../protogalaxy/shared_prover_setup.cpp | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp index 0e0dfcf77b0..7dd29961011 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp @@ -140,6 +140,63 @@ void prover_setup_(const std::shared_ptr>& instance, execute_grand_product_computation_round_(instance, commitment_key, transcript, domain_separator); } +template void execute_preamble_round_(const std::shared_ptr>& instance, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_preamble_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_wire_commitments_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_wire_commitments_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_sorted_list_accumulator_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_sorted_list_accumulator_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_log_derivative_inverse_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_log_derivative_inverse_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_grand_product_computation_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + +template void execute_grand_product_computation_round_( + const std::shared_ptr>& instance, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + const std::string& domain_separator); + template void prover_setup_(const std::shared_ptr>& instance, const std::shared_ptr& commitment_key, const std::shared_ptr& transcript, From 2c14dbc2686333c311bbac8600ef54f3840ee1ee Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 26 Feb 2024 23:04:17 +0000 Subject: [PATCH 09/18] making presumcheck prover class --- .../ultra_bench/ultra_honk_rounds.bench.cpp | 11 +- .../ecc/curves/bn254/fr_straight.bench.cpp | 4 +- .../protogalaxy/protogalaxy_prover.cpp | 8 +- .../protogalaxy/shared_prover_setup.cpp | 132 ++++-------------- .../protogalaxy/shared_prover_setup.hpp | 56 ++++---- .../barretenberg/ultra_honk/ultra_prover.cpp | 62 +------- .../barretenberg/ultra_honk/ultra_prover.hpp | 3 + 7 files changed, 84 insertions(+), 192 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp index 619ba60a8c1..d30f57a8374 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp @@ -45,11 +45,12 @@ BB_PROFILE static void test_round_inner(State& state, GoblinUltraProver& prover, } }; - time_if_index(PREAMBLE, [&] { prover.execute_preamble_round(); }); - time_if_index(WIRE_COMMITMENTS, [&] { prover.execute_wire_commitments_round(); }); - time_if_index(SORTED_LIST_ACCUMULATOR, [&] { prover.execute_sorted_list_accumulator_round(); }); - time_if_index(LOG_DERIVATIVE_INVERSE, [&] { prover.execute_log_derivative_inverse_round(); }); - time_if_index(GRAND_PRODUCT_COMPUTATION, [&] { prover.execute_grand_product_computation_round(); }); + time_if_index(PREAMBLE, [&] { prover.pre_sumcheck_prover.execute_preamble_round(); }); + time_if_index(WIRE_COMMITMENTS, [&] { prover.pre_sumcheck_prover.execute_wire_commitments_round(); }); + time_if_index(SORTED_LIST_ACCUMULATOR, [&] { prover.pre_sumcheck_prover.execute_sorted_list_accumulator_round(); }); + time_if_index(LOG_DERIVATIVE_INVERSE, [&] { prover.pre_sumcheck_prover.execute_log_derivative_inverse_round(); }); + time_if_index(GRAND_PRODUCT_COMPUTATION, + [&] { prover.pre_sumcheck_prover.execute_grand_product_computation_round(); }); time_if_index(RELATION_CHECK, [&] { prover.execute_relation_check_rounds(); }); time_if_index(ZEROMORPH, [&] { prover.execute_zeromorph_rounds(); }); } diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp index 70cd9dce8fa..5f5b64705c7 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp @@ -206,6 +206,6 @@ void sqr(State& state) noexcept BENCHMARK(sqr); } // namespace +#endif // NOLINTNEXTLINE macro invocation triggers style guideline errors from googletest code -BENCHMARK_MAIN(); -#endif \ No newline at end of file +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index 1ffd7ec2981..15cec136acb 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -6,8 +6,12 @@ template void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, const std::string& domain_separator) { - instance->initialize_prover_polynomials(); - prover_setup_(instance, commitment_key, transcript, domain_separator + '_'); + PreSumcheckProver pre_sumcheck_prover(instance, commitment_key, transcript, domain_separator + '_'); + pre_sumcheck_prover.execute_preamble_round(); + pre_sumcheck_prover.execute_wire_commitments_round(); + pre_sumcheck_prover.execute_sorted_list_accumulator_round(); + pre_sumcheck_prover.execute_log_derivative_inverse_round(); + pre_sumcheck_prover.execute_grand_product_computation_round(); for (size_t idx = 0; idx < Flavor::NUM_SUBRELATIONS - 1; idx++) { instance->alphas[idx] = transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp index 7dd29961011..bec5f858bb1 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp @@ -2,10 +2,11 @@ namespace bb { -template -void execute_preamble_round_(const std::shared_ptr>& instance, - const std::shared_ptr& transcript, - const std::string& domain_separator) +/** + * @brief Add circuit size, public input size, and public inputs to transcript + * + */ +template void PreSumcheckProver::execute_preamble_round() { const auto instance_size = static_cast(instance->instance_size); const auto num_public_inputs = static_cast(instance->public_inputs.size()); @@ -22,11 +23,12 @@ void execute_preamble_round_(const std::shared_ptr>& ins } } -template -void execute_wire_commitments_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator) +/** + * @brief Commit to the wire polynomials (part of the witness), with the exception of the fourth wire, which is + * only commited to after adding memory records. In the Goblin Flavor, we also commit to the ECC OP wires and the + * DataBus columns. + */ +template void PreSumcheckProver::execute_wire_commitments_round() { auto& witness_commitments = instance->witness_commitments; @@ -65,11 +67,11 @@ void execute_wire_commitments_round_(const std::shared_ptr -void execute_sorted_list_accumulator_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator) +/** + * @brief Compute sorted witness-table accumulator and commit to the resulting polynomials. + * + */ +template void PreSumcheckProver::execute_sorted_list_accumulator_round() { auto& witness_commitments = instance->witness_commitments; const auto& commitment_labels = instance->commitment_labels; @@ -86,11 +88,11 @@ void execute_sorted_list_accumulator_round_(const std::shared_ptrsend_to_verifier(domain_separator + commitment_labels.w_4, witness_commitments.w_4); } -template -void execute_log_derivative_inverse_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator) +/** + * @brief Compute log derivative inverse polynomial and its commitment, if required + * + */ +template void PreSumcheckProver::execute_log_derivative_inverse_round() { const auto& commitment_labels = instance->commitment_labels; @@ -108,11 +110,11 @@ void execute_log_derivative_inverse_round_(const std::shared_ptr -void execute_grand_product_computation_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator) +/** + * @brief Compute permutation and lookup grand product polynomials and their commitments + * + */ +template void PreSumcheckProver::execute_grand_product_computation_round() { auto& witness_commitments = instance->witness_commitments; const auto& commitment_labels = instance->commitment_labels; @@ -127,85 +129,7 @@ void execute_grand_product_computation_round_(const std::shared_ptrsend_to_verifier(domain_separator + commitment_labels.z_lookup, instance->witness_commitments.z_lookup); } -template -void prover_setup_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator) -{ - execute_preamble_round_(instance, transcript, domain_separator); - execute_wire_commitments_round_(instance, commitment_key, transcript, domain_separator); - execute_sorted_list_accumulator_round_(instance, commitment_key, transcript, domain_separator); - execute_log_derivative_inverse_round_(instance, commitment_key, transcript, domain_separator); - execute_grand_product_computation_round_(instance, commitment_key, transcript, domain_separator); -} - -template void execute_preamble_round_(const std::shared_ptr>& instance, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_preamble_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_wire_commitments_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_wire_commitments_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_sorted_list_accumulator_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_sorted_list_accumulator_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_log_derivative_inverse_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_log_derivative_inverse_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_grand_product_computation_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void execute_grand_product_computation_round_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void prover_setup_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); - -template void prover_setup_( - const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator); +template class PreSumcheckProver; +template class PreSumcheckProver; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp index 8fc037a3a5e..b55445faaa4 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp @@ -1,4 +1,6 @@ #pragma once +#include + #include "barretenberg/flavor/goblin_ultra.hpp" #include "barretenberg/flavor/ultra.hpp" #include "barretenberg/sumcheck/instance/prover_instance.hpp" @@ -6,34 +8,40 @@ namespace bb { -template -void execute_preamble_round_(const std::shared_ptr>& instance, - const std::shared_ptr& transcript, - const std::string& domain_separator = ""); +template class PreSumcheckProver { + using CommitmentKey = typename Flavor::CommitmentKey; + using Instance = ProverInstance_; + using Transcript = typename Flavor::Transcript; -template -void execute_wire_commitments_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator = ""); + public: + PreSumcheckProver(const std::shared_ptr>& inst, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + std::string domain_separator = "") + : instance(inst) + , transcript(transcript) + , commitment_key(commitment_key) + , domain_separator(std::move(domain_separator)) + { + instance->initialize_prover_polynomials(); + } -template -void execute_sorted_list_accumulator_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator = ""); + void execute_preamble_round(); -template -void execute_log_derivative_inverse_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator = ""); + void execute_wire_commitments_round(); + + void execute_sorted_list_accumulator_round(); + + void execute_log_derivative_inverse_round(); + + void execute_grand_product_computation_round(); + + std::shared_ptr instance; + std::shared_ptr transcript; + std::shared_ptr commitment_key; + std::string domain_separator; +}; -template -void execute_grand_product_computation_round_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator = ""); template void prover_setup_(const std::shared_ptr>& instance, const std::shared_ptr& commitment_key, diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index 61775d1e465..44309563fd6 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -1,5 +1,4 @@ #include "ultra_prover.hpp" -#include "barretenberg/protogalaxy/shared_prover_setup.hpp" #include "barretenberg/sumcheck/sumcheck.hpp" namespace bb { @@ -17,56 +16,9 @@ UltraProver_::UltraProver_(const std::shared_ptr& inst, const std::shared_ptr& transcript) : instance(std::move(inst)) , transcript(transcript) + , pre_sumcheck_prover(inst, commitment_key, transcript, "") , commitment_key(commitment_key) -{ - instance->initialize_prover_polynomials(); -} - -/** - * @brief Add circuit size, public input size, and public inputs to transcript - * - */ -template void UltraProver_::execute_preamble_round() -{ - execute_preamble_round_(instance, transcript); -} - -/** - * @brief Commit to the wire polynomials (part of the witness), with the exception of the fourth wire, which is - * only commited to after adding memory records. In the Goblin Flavor, we also commit to the ECC OP wires and the - * DataBus columns. - */ -template void UltraProver_::execute_wire_commitments_round() -{ - execute_wire_commitments_round_(instance, commitment_key, transcript); -} - -/** - * @brief Compute sorted witness-table accumulator and commit to the resulting polynomials. - * - */ -template void UltraProver_::execute_sorted_list_accumulator_round() -{ - execute_sorted_list_accumulator_round_(instance, commitment_key, transcript); -} - -/** - * @brief Compute log derivative inverse polynomial and its commitment, if required - * - */ -template void UltraProver_::execute_log_derivative_inverse_round() -{ - execute_log_derivative_inverse_round_(instance, commitment_key, transcript); -} - -/** - * @brief Compute permutation and lookup grand product polynomials and their commitments - * - */ -template void UltraProver_::execute_grand_product_computation_round() -{ - execute_grand_product_computation_round_(instance, commitment_key, transcript); -} +{} /** * @brief Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated. @@ -115,19 +67,19 @@ template HonkProof& UltraProver_::export_proof() template HonkProof& UltraProver_::construct_proof() { // Add circuit size public input size and public inputs to transcript-> - execute_preamble_round(); + pre_sumcheck_prover.execute_preamble_round(); // Compute first three wire commitments - execute_wire_commitments_round(); + pre_sumcheck_prover.execute_wire_commitments_round(); // Compute sorted list accumulator and commitment - execute_sorted_list_accumulator_round(); + pre_sumcheck_prover.execute_sorted_list_accumulator_round(); // Fiat-Shamir: beta & gamma - execute_log_derivative_inverse_round(); + pre_sumcheck_prover.execute_log_derivative_inverse_round(); // Compute grand product(s) and commitments. - execute_grand_product_computation_round(); + pre_sumcheck_prover.execute_grand_product_computation_round(); // Fiat-Shamir: alpha // Run sumcheck subprotocol. diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index 1fb53b6c149..e8c95ed987f 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -3,6 +3,7 @@ #include "barretenberg/flavor/goblin_ultra.hpp" #include "barretenberg/flavor/ultra.hpp" #include "barretenberg/honk/proof_system/types/proof.hpp" +#include "barretenberg/protogalaxy/shared_prover_setup.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/instance/prover_instance.hpp" #include "barretenberg/sumcheck/sumcheck_output.hpp" @@ -46,6 +47,8 @@ template class UltraProver_ { Polynomial quotient_W; + PreSumcheckProver pre_sumcheck_prover; + SumcheckOutput sumcheck_output; std::shared_ptr commitment_key; From 35338f3ff79496f6a149b441d1b267f5255bb30a Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 26 Feb 2024 23:11:56 +0000 Subject: [PATCH 10/18] fix ultra honk rounds bench --- .../benchmark/ultra_bench/ultra_honk_rounds.bench.cpp | 3 +++ .../src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp index d30f57a8374..bc35ceda448 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp @@ -64,7 +64,10 @@ BB_PROFILE static void test_round(State& state, size_t index) noexcept GoblinUltraProver prover = bb::mock_proofs::get_prover( composer, &bb::mock_proofs::generate_basic_arithmetic_circuit, log2_num_gates); for (auto _ : state) { + state.PauseTiming(); test_round_inner(state, prover, index); + state.ResumeTiming(); + // NOTE: google bench is very finnicky, must end in ResumeTiming() for correctness } } #define ROUND_BENCHMARK(round) \ diff --git a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp index aca3795c351..a2e7f810a98 100644 --- a/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/ecc/curves/bn254/fr_straight.bench.cpp @@ -207,6 +207,5 @@ BENCHMARK(sqr); } // namespace #endif -#endif // NOLINTNEXTLINE macro invocation triggers style guideline errors from googletest code BENCHMARK_MAIN(); From 219d68fa6f165e434a94d7a099ba0638699aee92 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 27 Feb 2024 22:21:14 +0000 Subject: [PATCH 11/18] update to naming --- .../{shared_prover_setup.cpp => presumcheck_prover.cpp} | 2 +- .../{shared_prover_setup.hpp => presumcheck_prover.hpp} | 0 .../cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp | 2 +- barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename barretenberg/cpp/src/barretenberg/protogalaxy/{shared_prover_setup.cpp => presumcheck_prover.cpp} (99%) rename barretenberg/cpp/src/barretenberg/protogalaxy/{shared_prover_setup.hpp => presumcheck_prover.hpp} (100%) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.cpp similarity index 99% rename from barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp rename to barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.cpp index bec5f858bb1..446bdb0857b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/protogalaxy/shared_prover_setup.hpp" +#include "barretenberg/protogalaxy/presumcheck_prover.hpp" namespace bb { diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/protogalaxy/shared_prover_setup.hpp rename to barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index fd6d79e4cac..ef66a6774de 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -1,6 +1,6 @@ #include "protogalaxy_prover.hpp" #include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/protogalaxy/shared_prover_setup.hpp" +#include "barretenberg/protogalaxy/presumcheck_prover.hpp" namespace bb { template void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index e8c95ed987f..b291c44eab8 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -3,7 +3,7 @@ #include "barretenberg/flavor/goblin_ultra.hpp" #include "barretenberg/flavor/ultra.hpp" #include "barretenberg/honk/proof_system/types/proof.hpp" -#include "barretenberg/protogalaxy/shared_prover_setup.hpp" +#include "barretenberg/protogalaxy/presumcheck_prover.hpp" #include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/sumcheck/instance/prover_instance.hpp" #include "barretenberg/sumcheck/sumcheck_output.hpp" From f8d66fc3436efbdf5bff5e0f53b42e81d0bdcbc0 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Wed, 28 Feb 2024 15:43:05 +0000 Subject: [PATCH 12/18] added comments, removed unused function --- .../protogalaxy/presumcheck_prover.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp b/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp index b55445faaa4..3e506515409 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp @@ -8,6 +8,14 @@ namespace bb { +/** + * @brief Class for all the presumcheck rounds, which are shared between the folding prover and ultra prover. + * @details This class contains execute_preamble_round(), execute_wire_commitments_round(), + * execute_sorted_list_accumulator_round(), execute_log_derivative_inverse_round(), and + * execute_grand_product_computation_round(). + * + * @tparam Flavor + */ template class PreSumcheckProver { using CommitmentKey = typename Flavor::CommitmentKey; using Instance = ProverInstance_; @@ -41,10 +49,4 @@ template class PreSumcheckProver { std::shared_ptr commitment_key; std::string domain_separator; }; - -template -void prover_setup_(const std::shared_ptr>& instance, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - const std::string& domain_separator = ""); } // namespace bb \ No newline at end of file From c48aed1d7d6b7bd8246d038a8c7792607915944e Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 11 Mar 2024 17:38:56 +0000 Subject: [PATCH 13/18] moved presumcheck_prover --- .../presumcheck_prover.cpp | 16 ++++++++-------- .../presumcheck_prover.hpp | 0 2 files changed, 8 insertions(+), 8 deletions(-) rename barretenberg/cpp/src/barretenberg/{protogalaxy => ultra_honk}/presumcheck_prover.cpp (92%) rename barretenberg/cpp/src/barretenberg/{protogalaxy => ultra_honk}/presumcheck_prover.hpp (100%) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.cpp similarity index 92% rename from barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.cpp rename to barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.cpp index 446bdb0857b..c1429aa80fd 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/protogalaxy/presumcheck_prover.hpp" +#include "barretenberg/ultra_honk/presumcheck_prover.hpp" namespace bb { @@ -8,17 +8,17 @@ namespace bb { */ template void PreSumcheckProver::execute_preamble_round() { - const auto instance_size = static_cast(instance->instance_size); - const auto num_public_inputs = static_cast(instance->public_inputs.size()); - transcript->send_to_verifier(domain_separator + "instance_size", instance_size); + const auto circuit_size = static_cast(instance->proving_key->circuit_size); + const auto num_public_inputs = static_cast(instance->proving_key->public_inputs.size()); + transcript->send_to_verifier(domain_separator + "circuit_size", circuit_size); transcript->send_to_verifier(domain_separator + "public_input_size", num_public_inputs); transcript->send_to_verifier(domain_separator + "pub_inputs_offset", - static_cast(instance->pub_inputs_offset)); + static_cast(instance->proving_key->pub_inputs_offset)); - ASSERT(instance->proving_key->num_public_inputs == instance->public_inputs.size()); + ASSERT(instance->proving_key->num_public_inputs == instance->proving_key->public_inputs.size()); - for (size_t i = 0; i < instance->public_inputs.size(); ++i) { - auto public_input_i = instance->public_inputs[i]; + for (size_t i = 0; i < instance->proving_key->num_public_inputs; ++i) { + auto public_input_i = instance->proving_key->public_inputs[i]; transcript->send_to_verifier(domain_separator + "public_input_" + std::to_string(i), public_input_i); } } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.hpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/protogalaxy/presumcheck_prover.hpp rename to barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.hpp From fa2ebc918a9128eee53b7c1a6220bdc4c0c2c91f Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 11 Mar 2024 18:03:25 +0000 Subject: [PATCH 14/18] renaming presumcheck to oink, other small fixes --- .../ultra_bench/ultra_honk_rounds.bench.cpp | 11 +++--- .../protogalaxy/protogalaxy_prover.cpp | 25 +++++++++---- .../protogalaxy/protogalaxy_verifier.cpp | 1 - .../protogalaxy_recursive_verifier.cpp | 1 - ...presumcheck_prover.cpp => oink_prover.cpp} | 37 +++++++++---------- ...presumcheck_prover.hpp => oink_prover.hpp} | 16 +++----- .../barretenberg/ultra_honk/ultra_prover.cpp | 14 +++---- .../barretenberg/ultra_honk/ultra_prover.hpp | 4 +- circuits/cpp/build-bench/_deps/benchmark-src | 1 + circuits/cpp/build-bench/_deps/gtest-src | 1 + circuits/cpp/build-bench/_deps/leveldb-src | 1 + 11 files changed, 59 insertions(+), 53 deletions(-) rename barretenberg/cpp/src/barretenberg/ultra_honk/{presumcheck_prover.cpp => oink_prover.cpp} (80%) rename barretenberg/cpp/src/barretenberg/ultra_honk/{presumcheck_prover.hpp => oink_prover.hpp} (73%) create mode 160000 circuits/cpp/build-bench/_deps/benchmark-src create mode 160000 circuits/cpp/build-bench/_deps/gtest-src create mode 160000 circuits/cpp/build-bench/_deps/leveldb-src diff --git a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp index 3dc457e0237..aebc60b1912 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/ultra_bench/ultra_honk_rounds.bench.cpp @@ -45,12 +45,11 @@ BB_PROFILE static void test_round_inner(State& state, GoblinUltraProver& prover, } }; - time_if_index(PREAMBLE, [&] { prover.pre_sumcheck_prover.execute_preamble_round(); }); - time_if_index(WIRE_COMMITMENTS, [&] { prover.pre_sumcheck_prover.execute_wire_commitments_round(); }); - time_if_index(SORTED_LIST_ACCUMULATOR, [&] { prover.pre_sumcheck_prover.execute_sorted_list_accumulator_round(); }); - time_if_index(LOG_DERIVATIVE_INVERSE, [&] { prover.pre_sumcheck_prover.execute_log_derivative_inverse_round(); }); - time_if_index(GRAND_PRODUCT_COMPUTATION, - [&] { prover.pre_sumcheck_prover.execute_grand_product_computation_round(); }); + time_if_index(PREAMBLE, [&] { prover.oink_prover.execute_preamble_round(); }); + time_if_index(WIRE_COMMITMENTS, [&] { prover.oink_prover.execute_wire_commitments_round(); }); + time_if_index(SORTED_LIST_ACCUMULATOR, [&] { prover.oink_prover.execute_sorted_list_accumulator_round(); }); + time_if_index(LOG_DERIVATIVE_INVERSE, [&] { prover.oink_prover.execute_log_derivative_inverse_round(); }); + time_if_index(GRAND_PRODUCT_COMPUTATION, [&] { prover.oink_prover.execute_grand_product_computation_round(); }); time_if_index(RELATION_CHECK, [&] { prover.execute_relation_check_rounds(); }); time_if_index(ZEROMORPH, [&] { prover.execute_zeromorph_rounds(); }); } diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index 6cc6bf5eb2e..7b2de62f66b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -1,17 +1,28 @@ #include "protogalaxy_prover.hpp" #include "barretenberg/flavor/flavor.hpp" -#include "barretenberg/ultra_honk/presumcheck_prover.hpp" +#include "barretenberg/ultra_honk/oink_prover.hpp" namespace bb { template void ProtoGalaxyProver_::finalise_and_send_instance(std::shared_ptr instance, const std::string& domain_separator) { - PreSumcheckProver pre_sumcheck_prover(instance, commitment_key, transcript, domain_separator + '_'); - pre_sumcheck_prover.execute_preamble_round(); - pre_sumcheck_prover.execute_wire_commitments_round(); - pre_sumcheck_prover.execute_sorted_list_accumulator_round(); - pre_sumcheck_prover.execute_log_derivative_inverse_round(); - pre_sumcheck_prover.execute_grand_product_computation_round(); + OinkProver oink_prover(instance, commitment_key, transcript, domain_separator + '_'); + + // Add circuit size public input size and public inputs to transcript-> + oink_prover.execute_preamble_round(); + + // Compute first three wire commitments + oink_prover.execute_wire_commitments_round(); + + // Compute sorted list accumulator and commitment + oink_prover.execute_sorted_list_accumulator_round(); + + // Fiat-Shamir: beta & gamma + oink_prover.execute_log_derivative_inverse_round(); + + // Compute grand product(s) and commitments. + oink_prover.execute_grand_product_computation_round(); + for (size_t idx = 0; idx < Flavor::NUM_SUBRELATIONS - 1; idx++) { instance->alphas[idx] = transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp index e284967430f..cf08f67d30a 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_verifier.cpp @@ -15,7 +15,6 @@ void ProtoGalaxyVerifier_::receive_and_finalise_instance(cons transcript->template receive_from_prover(domain_separator + "_public_input_size"); inst->verification_key->pub_inputs_offset = transcript->template receive_from_prover(domain_separator + "_pub_inputs_offset"); - inst->verification_key->public_inputs.clear(); for (size_t i = 0; i < inst->verification_key->num_public_inputs; ++i) { auto public_input_i = diff --git a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp index eaeb5847362..2eb8fd4f209 100644 --- a/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/stdlib/recursion/honk/verifier/protogalaxy_recursive_verifier.cpp @@ -18,7 +18,6 @@ void ProtoGalaxyRecursiveVerifier_::receive_and_finalise_inst inst->verification_key->num_public_inputs = uint32_t(public_input_size.get_value()); const auto pub_inputs_offset = transcript->template receive_from_prover(domain_separator + "_pub_inputs_offset"); - inst->verification_key->pub_inputs_offset = uint32_t(pub_inputs_offset.get_value()); inst->verification_key->public_inputs.clear(); diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp similarity index 80% rename from barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.cpp rename to barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index c1429aa80fd..191f772c360 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -1,4 +1,4 @@ -#include "barretenberg/ultra_honk/presumcheck_prover.hpp" +#include "barretenberg/ultra_honk/oink_prover.hpp" namespace bb { @@ -6,10 +6,10 @@ namespace bb { * @brief Add circuit size, public input size, and public inputs to transcript * */ -template void PreSumcheckProver::execute_preamble_round() +template void OinkProver::execute_preamble_round() { const auto circuit_size = static_cast(instance->proving_key->circuit_size); - const auto num_public_inputs = static_cast(instance->proving_key->public_inputs.size()); + const auto num_public_inputs = static_cast(instance->proving_key->num_public_inputs); transcript->send_to_verifier(domain_separator + "circuit_size", circuit_size); transcript->send_to_verifier(domain_separator + "public_input_size", num_public_inputs); transcript->send_to_verifier(domain_separator + "pub_inputs_offset", @@ -28,7 +28,7 @@ template void PreSumcheckProver::execute_preamble * only commited to after adding memory records. In the Goblin Flavor, we also commit to the ECC OP wires and the * DataBus columns. */ -template void PreSumcheckProver::execute_wire_commitments_round() +template void OinkProver::execute_wire_commitments_round() { auto& witness_commitments = instance->witness_commitments; @@ -39,7 +39,7 @@ template void PreSumcheckProver::execute_wire_com witness_commitments.w_o = commitment_key->commit(instance->proving_key->w_o); auto wire_comms = witness_commitments.get_wires(); - auto commitment_labels = instance->commitment_labels; + auto& commitment_labels = instance->commitment_labels; auto wire_labels = commitment_labels.get_wires(); for (size_t idx = 0; idx < 3; ++idx) { transcript->send_to_verifier(domain_separator + wire_labels[idx], wire_comms[idx]); @@ -52,7 +52,7 @@ template void PreSumcheckProver::execute_wire_com witness_commitments.ecc_op_wire_3 = commitment_key->commit(instance->proving_key->ecc_op_wire_3); witness_commitments.ecc_op_wire_4 = commitment_key->commit(instance->proving_key->ecc_op_wire_4); - auto op_wire_comms = instance->witness_commitments.get_ecc_op_wires(); + auto op_wire_comms = witness_commitments.get_ecc_op_wires(); auto labels = commitment_labels.get_ecc_op_wires(); for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { transcript->send_to_verifier(domain_separator + labels[idx], op_wire_comms[idx]); @@ -60,10 +60,9 @@ template void PreSumcheckProver::execute_wire_com // Commit to DataBus columns witness_commitments.calldata = commitment_key->commit(instance->proving_key->calldata); witness_commitments.calldata_read_counts = commitment_key->commit(instance->proving_key->calldata_read_counts); - transcript->send_to_verifier(domain_separator + commitment_labels.calldata, - instance->witness_commitments.calldata); + transcript->send_to_verifier(domain_separator + commitment_labels.calldata, witness_commitments.calldata); transcript->send_to_verifier(domain_separator + commitment_labels.calldata_read_counts, - instance->witness_commitments.calldata_read_counts); + witness_commitments.calldata_read_counts); } } @@ -71,7 +70,7 @@ template void PreSumcheckProver::execute_wire_com * @brief Compute sorted witness-table accumulator and commit to the resulting polynomials. * */ -template void PreSumcheckProver::execute_sorted_list_accumulator_round() +template void OinkProver::execute_sorted_list_accumulator_round() { auto& witness_commitments = instance->witness_commitments; const auto& commitment_labels = instance->commitment_labels; @@ -92,8 +91,9 @@ template void PreSumcheckProver::execute_sorted_l * @brief Compute log derivative inverse polynomial and its commitment, if required * */ -template void PreSumcheckProver::execute_log_derivative_inverse_round() +template void OinkProver::execute_log_derivative_inverse_round() { + auto& witness_commitments = instance->witness_commitments; const auto& commitment_labels = instance->commitment_labels; auto [beta, gamma] = @@ -103,10 +103,9 @@ template void PreSumcheckProver::execute_log_deri if constexpr (IsGoblinFlavor) { // Compute and commit to the logderivative inverse used in DataBus instance->compute_logderivative_inverse(beta, gamma); - instance->witness_commitments.lookup_inverses = - commitment_key->commit(instance->prover_polynomials.lookup_inverses); + witness_commitments.lookup_inverses = commitment_key->commit(instance->prover_polynomials.lookup_inverses); transcript->send_to_verifier(domain_separator + commitment_labels.lookup_inverses, - instance->witness_commitments.lookup_inverses); + witness_commitments.lookup_inverses); } } @@ -114,7 +113,7 @@ template void PreSumcheckProver::execute_log_deri * @brief Compute permutation and lookup grand product polynomials and their commitments * */ -template void PreSumcheckProver::execute_grand_product_computation_round() +template void OinkProver::execute_grand_product_computation_round() { auto& witness_commitments = instance->witness_commitments; const auto& commitment_labels = instance->commitment_labels; @@ -125,11 +124,11 @@ template void PreSumcheckProver::execute_grand_pr witness_commitments.z_perm = commitment_key->commit(instance->prover_polynomials.z_perm); witness_commitments.z_lookup = commitment_key->commit(instance->prover_polynomials.z_lookup); - transcript->send_to_verifier(domain_separator + commitment_labels.z_perm, instance->witness_commitments.z_perm); - transcript->send_to_verifier(domain_separator + commitment_labels.z_lookup, instance->witness_commitments.z_lookup); + transcript->send_to_verifier(domain_separator + commitment_labels.z_perm, witness_commitments.z_perm); + transcript->send_to_verifier(domain_separator + commitment_labels.z_lookup, witness_commitments.z_lookup); } -template class PreSumcheckProver; -template class PreSumcheckProver; +template class OinkProver; +template class OinkProver; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp similarity index 73% rename from barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.hpp rename to barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp index 3e506515409..3410dd2028c 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/presumcheck_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp @@ -9,23 +9,23 @@ namespace bb { /** - * @brief Class for all the presumcheck rounds, which are shared between the folding prover and ultra prover. + * @brief Class for all the oink rounds, which are shared between the folding prover and ultra prover. * @details This class contains execute_preamble_round(), execute_wire_commitments_round(), * execute_sorted_list_accumulator_round(), execute_log_derivative_inverse_round(), and * execute_grand_product_computation_round(). * * @tparam Flavor */ -template class PreSumcheckProver { +template class OinkProver { using CommitmentKey = typename Flavor::CommitmentKey; using Instance = ProverInstance_; using Transcript = typename Flavor::Transcript; public: - PreSumcheckProver(const std::shared_ptr>& inst, - const std::shared_ptr& commitment_key, - const std::shared_ptr& transcript, - std::string domain_separator = "") + OinkProver(const std::shared_ptr>& inst, + const std::shared_ptr& commitment_key, + const std::shared_ptr& transcript, + std::string domain_separator = "") : instance(inst) , transcript(transcript) , commitment_key(commitment_key) @@ -35,13 +35,9 @@ template class PreSumcheckProver { } void execute_preamble_round(); - void execute_wire_commitments_round(); - void execute_sorted_list_accumulator_round(); - void execute_log_derivative_inverse_round(); - void execute_grand_product_computation_round(); std::shared_ptr instance; diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp index 2a985d3e8e6..fe78a0d7d88 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.cpp @@ -15,7 +15,7 @@ UltraProver_::UltraProver_(const std::shared_ptr& inst, const : instance(std::move(inst)) , transcript(transcript) , commitment_key(instance->proving_key->commitment_key) - , pre_sumcheck_prover(inst, commitment_key, transcript, "") + , oink_prover(inst, commitment_key, transcript, "") {} /** @@ -30,7 +30,7 @@ UltraProver_::UltraProver_(Builder& circuit) : instance(std::make_shared(circuit)) , transcript(std::make_shared()) , commitment_key(instance->proving_key->commitment_key) - , pre_sumcheck_prover(instance, commitment_key, transcript, "") + , oink_prover(instance, commitment_key, transcript, "") {} /** @@ -80,19 +80,19 @@ template HonkProof& UltraProver_::export_proof() template HonkProof& UltraProver_::construct_proof() { // Add circuit size public input size and public inputs to transcript-> - pre_sumcheck_prover.execute_preamble_round(); + oink_prover.execute_preamble_round(); // Compute first three wire commitments - pre_sumcheck_prover.execute_wire_commitments_round(); + oink_prover.execute_wire_commitments_round(); // Compute sorted list accumulator and commitment - pre_sumcheck_prover.execute_sorted_list_accumulator_round(); + oink_prover.execute_sorted_list_accumulator_round(); // Fiat-Shamir: beta & gamma - pre_sumcheck_prover.execute_log_derivative_inverse_round(); + oink_prover.execute_log_derivative_inverse_round(); // Compute grand product(s) and commitments. - pre_sumcheck_prover.execute_grand_product_computation_round(); + oink_prover.execute_grand_product_computation_round(); // Fiat-Shamir: alpha // Run sumcheck subprotocol. diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index 26e4e0eed4a..ee6afeeb106 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -7,7 +7,7 @@ #include "barretenberg/sumcheck/instance/prover_instance.hpp" #include "barretenberg/sumcheck/sumcheck_output.hpp" #include "barretenberg/transcript/transcript.hpp" -#include "barretenberg/ultra_honk/presumcheck_prover.hpp" +#include "barretenberg/ultra_honk/oink_prover.hpp" namespace bb { @@ -55,7 +55,7 @@ template class UltraProver_ { std::shared_ptr commitment_key; - PreSumcheckProver pre_sumcheck_prover; + OinkProver oink_prover; using ZeroMorph = ZeroMorphProver_; diff --git a/circuits/cpp/build-bench/_deps/benchmark-src b/circuits/cpp/build-bench/_deps/benchmark-src new file mode 160000 index 00000000000..d572f477734 --- /dev/null +++ b/circuits/cpp/build-bench/_deps/benchmark-src @@ -0,0 +1 @@ +Subproject commit d572f4777349d43653b21d6c2fc63020ab326db2 diff --git a/circuits/cpp/build-bench/_deps/gtest-src b/circuits/cpp/build-bench/_deps/gtest-src new file mode 160000 index 00000000000..703bd9caab5 --- /dev/null +++ b/circuits/cpp/build-bench/_deps/gtest-src @@ -0,0 +1 @@ +Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e diff --git a/circuits/cpp/build-bench/_deps/leveldb-src b/circuits/cpp/build-bench/_deps/leveldb-src new file mode 160000 index 00000000000..78b39d68c15 --- /dev/null +++ b/circuits/cpp/build-bench/_deps/leveldb-src @@ -0,0 +1 @@ +Subproject commit 78b39d68c15ba020c0d60a3906fb66dbf1697595 From c082b255bb3cb9bf74c592fa8120c715ac19fbb4 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 11 Mar 2024 19:39:37 +0000 Subject: [PATCH 15/18] small changes to prep review --- barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp | 5 ++--- barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp | 1 + circuits/cpp/build-bench/_deps/benchmark-src | 1 - circuits/cpp/build-bench/_deps/gtest-src | 1 - circuits/cpp/build-bench/_deps/leveldb-src | 1 - 5 files changed, 3 insertions(+), 6 deletions(-) delete mode 160000 circuits/cpp/build-bench/_deps/benchmark-src delete mode 160000 circuits/cpp/build-bench/_deps/gtest-src delete mode 160000 circuits/cpp/build-bench/_deps/leveldb-src diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp index 191f772c360..bfb1d0ad97f 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.cpp @@ -75,7 +75,7 @@ template void OinkProver::execute_sorted_list_acc auto& witness_commitments = instance->witness_commitments; const auto& commitment_labels = instance->commitment_labels; - auto eta = transcript->template get_challenge(domain_separator + "eta"); + auto eta = transcript->template get_challenge(domain_separator + "eta"); instance->compute_sorted_accumulator_polynomials(eta); // Commit to the sorted witness-table accumulator and the finalized (i.e. with memory records) fourth wire @@ -96,8 +96,7 @@ template void OinkProver::execute_log_derivative_ auto& witness_commitments = instance->witness_commitments; const auto& commitment_labels = instance->commitment_labels; - auto [beta, gamma] = - transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); + auto [beta, gamma] = transcript->template get_challenges(domain_separator + "beta", domain_separator + "gamma"); instance->relation_parameters.beta = beta; instance->relation_parameters.gamma = gamma; if constexpr (IsGoblinFlavor) { diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp index 3410dd2028c..95713daffd8 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp @@ -20,6 +20,7 @@ template class OinkProver { using CommitmentKey = typename Flavor::CommitmentKey; using Instance = ProverInstance_; using Transcript = typename Flavor::Transcript; + using FF = typename Flavor::FF; public: OinkProver(const std::shared_ptr>& inst, diff --git a/circuits/cpp/build-bench/_deps/benchmark-src b/circuits/cpp/build-bench/_deps/benchmark-src deleted file mode 160000 index d572f477734..00000000000 --- a/circuits/cpp/build-bench/_deps/benchmark-src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d572f4777349d43653b21d6c2fc63020ab326db2 diff --git a/circuits/cpp/build-bench/_deps/gtest-src b/circuits/cpp/build-bench/_deps/gtest-src deleted file mode 160000 index 703bd9caab5..00000000000 --- a/circuits/cpp/build-bench/_deps/gtest-src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e diff --git a/circuits/cpp/build-bench/_deps/leveldb-src b/circuits/cpp/build-bench/_deps/leveldb-src deleted file mode 160000 index 78b39d68c15..00000000000 --- a/circuits/cpp/build-bench/_deps/leveldb-src +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 78b39d68c15ba020c0d60a3906fb66dbf1697595 From 9e042d33d766981f56ee12bbb039453e8b2616d6 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 11 Mar 2024 19:56:44 +0000 Subject: [PATCH 16/18] moving member vars to top of class --- .../barretenberg/ultra_honk/oink_prover.hpp | 10 +++--- .../barretenberg/ultra_honk/ultra_prover.hpp | 31 +++++++++---------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp index 95713daffd8..470794d8237 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/oink_prover.hpp @@ -23,6 +23,11 @@ template class OinkProver { using FF = typename Flavor::FF; public: + std::shared_ptr instance; + std::shared_ptr transcript; + std::shared_ptr commitment_key; + std::string domain_separator; + OinkProver(const std::shared_ptr>& inst, const std::shared_ptr& commitment_key, const std::shared_ptr& transcript, @@ -40,10 +45,5 @@ template class OinkProver { void execute_sorted_list_accumulator_round(); void execute_log_derivative_inverse_round(); void execute_grand_product_computation_round(); - - std::shared_ptr instance; - std::shared_ptr transcript; - std::shared_ptr commitment_key; - std::string domain_separator; }; } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp index ee6afeeb106..46aa631f6cb 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/ultra_prover.hpp @@ -26,6 +26,21 @@ template class UltraProver_ { using Instance = ProverInstance; using Transcript = typename Flavor::Transcript; using RelationSeparator = typename Flavor::RelationSeparator; + using ZeroMorph = ZeroMorphProver_; + + std::shared_ptr instance; + + std::shared_ptr transcript; + + bb::RelationParameters relation_parameters; + + Polynomial quotient_W; + + SumcheckOutput sumcheck_output; + + std::shared_ptr commitment_key; + + OinkProver oink_prover; explicit UltraProver_(const std::shared_ptr&, const std::shared_ptr& transcript = std::make_shared()); @@ -43,22 +58,6 @@ template class UltraProver_ { HonkProof& export_proof(); HonkProof& construct_proof(); - std::shared_ptr instance; - - std::shared_ptr transcript; - - bb::RelationParameters relation_parameters; - - Polynomial quotient_W; - - SumcheckOutput sumcheck_output; - - std::shared_ptr commitment_key; - - OinkProver oink_prover; - - using ZeroMorph = ZeroMorphProver_; - private: HonkProof proof; }; From 48e8b5a7d07d0aaf0bab6beb5cd93592ec60abf1 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 11 Mar 2024 19:58:40 +0000 Subject: [PATCH 17/18] tiny update --- .../cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index 7b2de62f66b..d6b6f4e68e2 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -23,7 +23,7 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared // Compute grand product(s) and commitments. oink_prover.execute_grand_product_computation_round(); - for (size_t idx = 0; idx < Flavor::NUM_SUBRELATIONS - 1; idx++) { + for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) { instance->alphas[idx] = transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx)); } From 8cc1e6b1778a98e6c5ccc17d8419235478c63513 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 12 Mar 2024 15:51:12 +0000 Subject: [PATCH 18/18] address mara comments --- .../cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp index d6b6f4e68e2..131f52d4c8b 100644 --- a/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/protogalaxy/protogalaxy_prover.cpp @@ -8,7 +8,7 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared { OinkProver oink_prover(instance, commitment_key, transcript, domain_separator + '_'); - // Add circuit size public input size and public inputs to transcript-> + // Add circuit size public input size and public inputs to transcript oink_prover.execute_preamble_round(); // Compute first three wire commitments @@ -23,6 +23,7 @@ void ProtoGalaxyProver_::finalise_and_send_instance(std::shared // Compute grand product(s) and commitments. oink_prover.execute_grand_product_computation_round(); + // Generate relation separators alphas for sumcheck for (size_t idx = 0; idx < NUM_SUBRELATIONS - 1; idx++) { instance->alphas[idx] = transcript->template get_challenge(domain_separator + "_alpha_" + std::to_string(idx));