diff --git a/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.hpp b/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.hpp index 93b3b991461..7d8dd2c6ebb 100644 --- a/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/composer/eccvm_composer.hpp @@ -5,6 +5,7 @@ #include "barretenberg/proof_system/circuit_builder/eccvm/eccvm_circuit_builder.hpp" #include "barretenberg/proof_system/composer/composer_lib.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" +#include "barretenberg/srs/global_crs.hpp" namespace proof_system::honk { template class ECCVMComposer_ { diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp index dd4139cbbcf..9f5143ba028 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.cpp @@ -33,8 +33,7 @@ template ECCVMProver_::ECCVMProver_(std::shared_ptr input_key, std::shared_ptr commitment_key) : key(input_key) - , queue(commitment_key, transcript) - , pcs_commitment_key(commitment_key) + , commitment_key(commitment_key) { // TODO(@zac-williamson) Future work; is there a cleaner way of doing this? #2213 @@ -147,19 +146,6 @@ ECCVMProver_::ECCVMProver_(std::shared_ptr prover_polynomials.z_perm_shift = key->z_perm; // this will be initialized properly later } -/** - * @brief Commit to the first three wires only - * - */ -template void ECCVMProver_::compute_wire_commitments() -{ - auto wire_polys = key->get_wires(); - auto labels = commitment_labels.get_wires(); - for (size_t idx = 0; idx < wire_polys.size(); ++idx) { - queue.add_commitment(wire_polys[idx], labels[idx]); - } -} - /** * @brief Add circuit size, public input size, and public inputs to transcript * @@ -180,7 +166,7 @@ template void ECCVMProver_::execute_wire_commitment auto wire_polys = key->get_wires(); auto labels = commitment_labels.get_wires(); for (size_t idx = 0; idx < wire_polys.size(); ++idx) { - queue.add_commitment(wire_polys[idx], labels[idx]); + transcript.send_to_verifier(labels[idx], commitment_key->commit(wire_polys[idx])); } } @@ -204,7 +190,7 @@ template void ECCVMProver_::execute_log_derivative_ // Compute inverse polynomial for our logarithmic-derivative lookup method lookup_library::compute_logderivative_inverse( prover_polynomials, relation_parameters, key->circuit_size); - queue.add_commitment(key->lookup_inverses, commitment_labels.lookup_inverses); + transcript.send_to_verifier(commitment_labels.lookup_inverses, commitment_key->commit(key->lookup_inverses)); prover_polynomials.lookup_inverses = key->lookup_inverses; } @@ -217,7 +203,7 @@ template void ECCVMProver_::execute_grand_product_c // Compute permutation grand product and their commitments permutation_library::compute_permutation_grand_products(key, prover_polynomials, relation_parameters); - queue.add_commitment(key->z_perm, commitment_labels.z_perm); + transcript.send_to_verifier(commitment_labels.z_perm, commitment_key->commit(key->z_perm)); } /** @@ -266,7 +252,8 @@ template void ECCVMProver_::execute_univariatizatio // Compute and add to trasnscript the commitments [Fold^(i)], i = 1, ..., d-1 for (size_t l = 0; l < key->log_circuit_size - 1; ++l) { - queue.add_commitment(gemini_polynomials[l + 2], "Gemini:FOLD_" + std::to_string(l + 1)); + transcript.send_to_verifier("Gemini:FOLD_" + std::to_string(l + 1), + commitment_key->commit(gemini_polynomials[l + 2])); } } @@ -301,7 +288,7 @@ template void ECCVMProver_::execute_shplonk_batched Shplonk::compute_batched_quotient(gemini_output.opening_pairs, gemini_output.witnesses, nu_challenge); // commit to Q(X) and add [Q] to the transcript - queue.add_commitment(batched_quotient_Q, "Shplonk:Q"); + transcript.send_to_verifier("Shplonk:Q", commitment_key->commit(batched_quotient_Q)); } /** @@ -322,8 +309,7 @@ template void ECCVMProver_::execute_shplonk_partial * */ template void ECCVMProver_::execute_final_pcs_round() { - PCS::compute_opening_proof(pcs_commitment_key, shplonk_output.opening_pair, shplonk_output.witness, transcript); - // queue.add_commitment(quotient_W, "KZG:W"); + PCS::compute_opening_proof(commitment_key, shplonk_output.opening_pair, shplonk_output.witness, transcript); } template plonk::proof& ECCVMProver_::export_proof() @@ -339,16 +325,13 @@ template plonk::proof& ECCVMProver_::construct_proo // Compute first three wire commitments execute_wire_commitments_round(); - queue.process_queue(); // Compute sorted list accumulator and commitment execute_log_derivative_commitments_round(); - queue.process_queue(); // Fiat-Shamir: bbeta & gamma // Compute grand product(s) and commitments. execute_grand_product_computation_round(); - queue.process_queue(); // Fiat-Shamir: alpha // Run sumcheck subprotocol. @@ -357,7 +340,6 @@ template plonk::proof& ECCVMProver_::construct_proo // Fiat-Shamir: rho // Compute Fold polynomials and their commitments. execute_univariatization_round(); - queue.process_queue(); // Fiat-Shamir: r // Compute Fold evaluations @@ -366,7 +348,6 @@ template plonk::proof& ECCVMProver_::construct_proo // Fiat-Shamir: nu // Compute Shplonk batched quotient commitment Q execute_shplonk_batched_quotient_round(); - queue.process_queue(); // Fiat-Shamir: z // Compute partial evaluation Q_z diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.hpp index 0e5298b7f6a..d781fcb86c2 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/eccvm_prover.hpp @@ -2,7 +2,6 @@ #include "barretenberg/honk/flavor/ecc_vm.hpp" #include "barretenberg/honk/pcs/gemini/gemini.hpp" #include "barretenberg/honk/pcs/shplonk/shplonk.hpp" -#include "barretenberg/honk/proof_system/work_queue.hpp" #include "barretenberg/honk/sumcheck/sumcheck_output.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" @@ -37,8 +36,6 @@ template class ECCVMProver_ { void execute_shplonk_partial_evaluation_round(); void execute_final_pcs_round(); - void compute_wire_commitments(); - plonk::proof& export_proof(); plonk::proof& construct_proof(); @@ -63,12 +60,10 @@ template class ECCVMProver_ { Polynomial quotient_W; - work_queue queue; - sumcheck::SumcheckOutput sumcheck_output; pcs::gemini::ProverOutput gemini_output; pcs::shplonk::ProverOutput shplonk_output; - std::shared_ptr pcs_commitment_key; + std::shared_ptr commitment_key; using Gemini = pcs::gemini::GeminiProver_; using Shplonk = pcs::shplonk::ShplonkProver_; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp index e5cb11ee069..53d5d6f2e36 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp @@ -13,9 +13,8 @@ namespace proof_system::honk { * */ template UltraProver_::UltraProver_(std::shared_ptr inst) - : queue(inst->commitment_key, transcript) - , instance(std::move(inst)) - , pcs_commitment_key(instance->commitment_key) + : instance(std::move(inst)) + , commitment_key(instance->commitment_key) { instance->initialise_prover_polynomials(); } @@ -51,14 +50,14 @@ template void UltraProver_::execute_wire_commitment auto wire_polys = instance->proving_key->get_wires(); auto labels = commitment_labels.get_wires(); for (size_t idx = 0; idx < 3; ++idx) { - queue.add_commitment(wire_polys[idx], labels[idx]); + transcript.send_to_verifier(labels[idx], commitment_key->commit(wire_polys[idx])); } if constexpr (IsGoblinFlavor) { auto op_wire_polys = instance->proving_key->get_ecc_op_wires(); auto labels = commitment_labels.get_ecc_op_wires(); for (size_t idx = 0; idx < Flavor::NUM_WIRES; ++idx) { - queue.add_commitment(op_wire_polys[idx], labels[idx]); + transcript.send_to_verifier(labels[idx], commitment_key->commit(op_wire_polys[idx])); } } } @@ -75,8 +74,10 @@ template void UltraProver_::execute_sorted_list_acc // Commit to the sorted withness-table accumulator and the finalised (i.e. with memory records) fourth wire // polynomial - queue.add_commitment(instance->proving_key->sorted_accum, commitment_labels.sorted_accum); - queue.add_commitment(instance->proving_key->w_4, commitment_labels.w_4); + auto sorted_accum_commitment = commitment_key->commit(instance->proving_key->sorted_accum); + auto w_4_commitment = commitment_key->commit(instance->proving_key->w_4); + transcript.send_to_verifier(commitment_labels.sorted_accum, sorted_accum_commitment); + transcript.send_to_verifier(commitment_labels.w_4, w_4_commitment); } /** @@ -90,8 +91,10 @@ template void UltraProver_::execute_grand_product_c instance->compute_grand_product_polynomials(beta, gamma); - queue.add_commitment(instance->proving_key->z_perm, commitment_labels.z_perm); - queue.add_commitment(instance->proving_key->z_lookup, commitment_labels.z_lookup); + auto z_perm_commitment = commitment_key->commit(instance->proving_key->z_perm); + auto z_lookup_commitment = commitment_key->commit(instance->proving_key->z_lookup); + transcript.send_to_verifier(commitment_labels.z_perm, z_perm_commitment); + transcript.send_to_verifier(commitment_labels.z_lookup, z_lookup_commitment); } /** @@ -118,7 +121,7 @@ template void UltraProver_::execute_zeromorph_round instance->prover_polynomials.get_to_be_shifted(), sumcheck_output.claimed_evaluations, sumcheck_output.challenge, - pcs_commitment_key, + commitment_key, transcript); } @@ -135,16 +138,13 @@ template plonk::proof& UltraProver_::construct_proo // Compute first three wire commitments execute_wire_commitments_round(); - queue.process_queue(); // Compute sorted list accumulator and commitment execute_sorted_list_accumulator_round(); - queue.process_queue(); // Fiat-Shamir: beta & gamma // Compute grand product(s) and commitments. execute_grand_product_computation_round(); - queue.process_queue(); // Fiat-Shamir: alpha // Run sumcheck subprotocol. diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp index 19a70210890..8e339336d6d 100644 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp +++ b/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp @@ -4,7 +4,6 @@ #include "barretenberg/honk/flavor/ultra_grumpkin.hpp" #include "barretenberg/honk/instance/prover_instance.hpp" #include "barretenberg/honk/pcs/zeromorph/zeromorph.hpp" -#include "barretenberg/honk/proof_system/work_queue.hpp" #include "barretenberg/honk/sumcheck/sumcheck_output.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/plonk/proof_system/types/proof.hpp" @@ -44,12 +43,11 @@ template class UltraProver_ { Polynomial quotient_W; - work_queue queue; - std::shared_ptr instance; sumcheck::SumcheckOutput sumcheck_output; - std::shared_ptr pcs_commitment_key; + + std::shared_ptr commitment_key; using ZeroMorph = pcs::zeromorph::ZeroMorphProver_; diff --git a/barretenberg/cpp/src/barretenberg/honk/proof_system/work_queue.hpp b/barretenberg/cpp/src/barretenberg/honk/proof_system/work_queue.hpp deleted file mode 100644 index a95e40e45aa..00000000000 --- a/barretenberg/cpp/src/barretenberg/honk/proof_system/work_queue.hpp +++ /dev/null @@ -1,137 +0,0 @@ -#pragma once - -#include "barretenberg/honk/transcript/transcript.hpp" -#include "barretenberg/srs/global_crs.hpp" -#include -#include - -namespace proof_system::honk { - -// Currently only one type of work queue operation but there will likely be others related to Sumcheck -enum WorkType { SCALAR_MULTIPLICATION }; - -template class work_queue { - - using CommitmentKey = pcs::CommitmentKey; - using FF = typename Curve::ScalarField; - using Commitment = typename Curve::AffineElement; - - struct work_item_info { - uint32_t num_scalar_multiplications; - }; - - struct work_item { - WorkType work_type = SCALAR_MULTIPLICATION; - std::span mul_scalars; - std::string label; - }; - - private: - proof_system::honk::ProverTranscript& transcript; - std::shared_ptr commitment_key; - std::vector work_item_queue; - - public: - explicit work_queue(auto commitment_key, proof_system::honk::ProverTranscript& prover_transcript) - : transcript(prover_transcript) - , commitment_key(commitment_key){}; - - work_queue(const work_queue& other) = default; - work_queue(work_queue&& other) noexcept = default; - ~work_queue() = default; - - [[nodiscard]] work_item_info get_queued_work_item_info() const - { - uint32_t scalar_mul_count = 0; - for (const auto& item : work_item_queue) { - if (item.work_type == WorkType::SCALAR_MULTIPLICATION) { - ++scalar_mul_count; - } - } - return work_item_info{ scalar_mul_count }; - }; - - [[nodiscard]] FF* get_scalar_multiplication_data(size_t work_item_number) const - { - size_t count = 0; - for (const auto& item : work_item_queue) { - if (item.work_type == WorkType::SCALAR_MULTIPLICATION) { - if (count == work_item_number) { - return const_cast(item.mul_scalars.data()); - } - ++count; - } - } - return nullptr; - }; - - [[nodiscard]] size_t get_scalar_multiplication_size(size_t work_item_number) const - { - size_t count = 0; - for (const auto& item : work_item_queue) { - if (item.work_type == WorkType::SCALAR_MULTIPLICATION) { - if (count == work_item_number) { - return item.mul_scalars.size(); - } - ++count; - } - } - return 0; - }; - - void put_scalar_multiplication_data(const Commitment& result, size_t work_item_number) - { - size_t count = 0; - for (const auto& item : work_item_queue) { - if (item.work_type == WorkType::SCALAR_MULTIPLICATION) { - if (count == work_item_number) { - transcript.send_to_verifier(item.label, result); - return; - } - ++count; - } - } - }; - - void flush_queue() { work_item_queue = std::vector(); }; - - void add_commitment(std::span polynomial, std::string label) - { - add_to_queue({ SCALAR_MULTIPLICATION, polynomial, label }); - } - - void process_queue() - { - for (const auto& item : work_item_queue) { - switch (item.work_type) { - - case WorkType::SCALAR_MULTIPLICATION: { - - // Run pippenger multi-scalar multiplication. - auto commitment = commitment_key->commit(item.mul_scalars); - - transcript.send_to_verifier(item.label, commitment); - - break; - } - default: { - } - } - } - work_item_queue = std::vector(); - }; - - [[nodiscard]] std::vector get_queue() const { return work_item_queue; }; - - private: - void add_to_queue(const work_item& item) - { - // Note: currently no difference between wasm and native but may be in the future -#if defined(__wasm__) - work_item_queue.push_back(item); -#else - work_item_queue.push_back(item); -#endif - }; -}; -} // namespace proof_system::honk \ No newline at end of file