From f4bd85efc286825b6d39b140630ded408e7b1eda Mon Sep 17 00:00:00 2001 From: ledwards2225 <98505400+ledwards2225@users.noreply.github.com> Date: Mon, 14 Aug 2023 09:32:46 -0700 Subject: [PATCH] chore: Remove Params concept (#1541) The `Params` concept, originally introduced by Adrian, was outdated and largely superseded by the `Flavor` concept. It previously specified the Curve, various Curve subtypes, and defined CommitmentKey and VerificationKey for different PCS suites. The information contained in Params was redundant and confusing and led to issues in my work on the recursive verifier. This work: - Defines CommitmentKey and VerificationKey in unique files as single classes templated by Curve with appropriate specializations - Removes the concept of `Params` altogether (along with the poorly named `commitment_key.hpp`). Things previously templated by Params are now templated by Curve. (The new `commitment_key.hpp` now just contains.. the `CommitmentKey`) - Specifies the Curve, CommitmentKey, and PCSVerificationKey directly in the Flavor classes # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [ ] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [ ] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist). --- .../honk/composer/standard_composer.cpp | 3 +- .../honk/composer/standard_composer.hpp | 7 +- .../honk/composer/ultra_composer.cpp | 2 +- .../honk/composer/ultra_composer.hpp | 9 +- .../barretenberg/honk/flavor/goblin_ultra.hpp | 8 +- .../src/barretenberg/honk/flavor/standard.hpp | 8 +- .../honk/flavor/standard_grumpkin.hpp | 9 +- .../src/barretenberg/honk/flavor/ultra.hpp | 8 +- .../honk/flavor/ultra_grumpkin.hpp | 8 +- .../cpp/src/barretenberg/honk/pcs/claim.hpp | 48 +--- .../barretenberg/honk/pcs/commitment_key.hpp | 251 +++--------------- .../honk/pcs/commitment_key.test.hpp | 84 +++--- .../barretenberg/honk/pcs/gemini/gemini.cpp | 54 ++-- .../barretenberg/honk/pcs/gemini/gemini.hpp | 36 ++- .../honk/pcs/gemini/gemini.test.cpp | 28 +- .../cpp/src/barretenberg/honk/pcs/ipa/ipa.hpp | 18 +- .../barretenberg/honk/pcs/ipa/ipa.test.cpp | 33 +-- .../cpp/src/barretenberg/honk/pcs/kzg/kzg.hpp | 19 +- .../barretenberg/honk/pcs/kzg/kzg.test.cpp | 19 +- .../barretenberg/honk/pcs/shplonk/shplonk.hpp | 41 +-- .../honk/pcs/shplonk/shplonk.test.cpp | 6 +- .../honk/pcs/verification_key.hpp | 101 +++++++ .../cpp/src/barretenberg/honk/pcs/wrapper.hpp | 1 - .../honk/proof_system/composer_lib.hpp | 2 +- .../barretenberg/honk/proof_system/prover.cpp | 2 +- .../barretenberg/honk/proof_system/prover.hpp | 18 +- .../honk/proof_system/ultra_prover.cpp | 3 +- .../honk/proof_system/ultra_prover.hpp | 18 +- .../honk/proof_system/ultra_verifier.cpp | 6 +- .../honk/proof_system/ultra_verifier.hpp | 4 +- .../honk/proof_system/verifier.cpp | 6 +- .../honk/proof_system/verifier.hpp | 4 +- .../honk/proof_system/work_queue.hpp | 13 +- .../plonk/composer/composer_lib.cpp | 6 +- .../plonk/composer/standard_composer.cpp | 1 - .../plonk/composer/standard_composer.hpp | 1 - .../proof_system/flavor/flavor.hpp | 2 + 37 files changed, 377 insertions(+), 510 deletions(-) create mode 100644 circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/verification_key.hpp diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.cpp index 72cbcc0f7e2..571ac034634 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.cpp @@ -1,5 +1,4 @@ #include "standard_composer.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" @@ -105,7 +104,7 @@ StandardVerifier_ StandardComposer_::create_verifier(const Circu StandardVerifier_ output_state(verification_key); auto pcs_verification_key = - std::make_unique(verification_key->circuit_size, crs_factory_); + std::make_unique(verification_key->circuit_size, crs_factory_); output_state.pcs_verification_key = std::move(pcs_verification_key); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp index 8bf37eae502..9d94311686b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/standard_composer.hpp @@ -14,11 +14,10 @@ namespace proof_system::honk { template class StandardComposer_ { public: - using PCSParams = typename Flavor::PCSParams; using CircuitBuilder = typename Flavor::CircuitBuilder; using ProvingKey = typename Flavor::ProvingKey; using VerificationKey = typename Flavor::VerificationKey; - using PCSCommitmentKey = typename PCSParams::CommitmentKey; + using CommitmentKey = typename Flavor::CommitmentKey; static constexpr std::string_view NAME_STRING = "StandardHonk"; static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; @@ -29,7 +28,7 @@ template class StandardComposer_ { std::shared_ptr> crs_factory_; // The commitment key is passed to the prover but also used herein to compute the verfication key commitments - std::shared_ptr commitment_key; + std::shared_ptr commitment_key; size_t total_num_gates; // total num gates prior to computing dyadic size size_t dyadic_circuit_size; // final dyadic circuit size @@ -76,7 +75,7 @@ template class StandardComposer_ { void compute_commitment_key(size_t circuit_size) { - commitment_key = std::make_shared(circuit_size, crs_factory_); + commitment_key = std::make_shared(circuit_size, crs_factory_); }; }; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.cpp index 2fb01186140..6d088299f4b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.cpp @@ -213,7 +213,7 @@ UltraVerifier_ UltraComposer_::create_verifier(const CircuitBuil UltraVerifier_ output_state(verification_key); - auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); + auto pcs_verification_key = std::make_unique(verification_key->circuit_size, crs_factory_); output_state.pcs_verification_key = std::move(pcs_verification_key); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.hpp index dd1c9542828..ec9c39b9149 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/composer/ultra_composer.hpp @@ -17,10 +17,9 @@ template class UltraComposer_ { using CircuitBuilder = typename Flavor::CircuitBuilder; using ProvingKey = typename Flavor::ProvingKey; using VerificationKey = typename Flavor::VerificationKey; - using PCSParams = typename Flavor::PCSParams; using PCS = typename Flavor::PCS; - using PCSCommitmentKey = typename PCSParams::CommitmentKey; - using PCSVerificationKey = typename PCSParams::VerificationKey; + using CommitmentKey = typename Flavor::CommitmentKey; + using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; // offset due to placing zero wires at the start of execution trace static constexpr size_t num_zero_rows = Flavor::has_zero_row ? 1 : 0; @@ -34,7 +33,7 @@ template class UltraComposer_ { std::shared_ptr> crs_factory_; // The commitment key is passed to the prover but also used herein to compute the verfication key commitments - std::shared_ptr commitment_key; + std::shared_ptr commitment_key; std::vector recursive_proof_public_input_indices; bool contains_recursive_proof = false; @@ -79,7 +78,7 @@ template class UltraComposer_ { void compute_commitment_key(size_t circuit_size) { - commitment_key = std::make_shared(circuit_size, crs_factory_); + commitment_key = std::make_shared(circuit_size, crs_factory_); }; }; extern template class UltraComposer_; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp index 8036f054158..2b56c16e6cc 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/goblin_ultra.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" #include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" @@ -29,15 +28,16 @@ namespace proof_system::honk::flavor { class GoblinUltra { public: using CircuitBuilder = UltraCircuitBuilder; - using PCSParams = pcs::kzg::Params; - using PCS = pcs::kzg::KZG; - using Curve = PCSParams::Curve; + using Curve = curve::BN254; + using PCS = pcs::kzg::KZG; using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using CommitmentHandle = Curve::AffineElement; using FF = Curve::ScalarField; using Polynomial = barretenberg::Polynomial; using PolynomialHandle = std::span; + using CommitmentKey = pcs::CommitmentKey; + using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp index d7e5411603f..91324a69ea1 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" #include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" @@ -32,15 +31,16 @@ namespace proof_system::honk::flavor { class Standard { public: using CircuitBuilder = StandardCircuitBuilder; - using PCSParams = pcs::kzg::Params; - using PCS = pcs::kzg::KZG; - using Curve = PCSParams::Curve; + using Curve = curve::BN254; + using PCS = pcs::kzg::KZG; using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using CommitmentHandle = Curve::AffineElement; using FF = Curve::ScalarField; using Polynomial = barretenberg::Polynomial; using PolynomialHandle = std::span; + using CommitmentKey = pcs::CommitmentKey; + using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp index 400e49bb55c..90adf4d5387 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/standard_grumpkin.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/pcs/ipa/ipa.hpp" #include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" @@ -24,15 +23,17 @@ class StandardGrumpkin { // purposes. This will be changed to Grumpkin once generating Honk proofs over Grumpkin has been enabled. public: using CircuitBuilder = StandardGrumpkinCircuitBuilder; - using PCSParams = pcs::ipa::Params; - using PCS = pcs::ipa::IPA; - using Curve = PCSParams::Curve; + using Curve = curve::Grumpkin; + using PCS = pcs::ipa::IPA; using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using CommitmentHandle = Curve::AffineElement; using FF = Curve::ScalarField; using Polynomial = barretenberg::Polynomial; using PolynomialHandle = std::span; + using CommitmentKey = pcs::CommitmentKey; + using VerifierCommitmentKey = pcs::VerifierCommitmentKey; + static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often // need containers of this size to hold related data, so we choose a name more agnostic than `NUM_POLYNOMIALS` diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp index a87550f8146..d5c348f2df6 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" #include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" @@ -28,15 +27,16 @@ namespace proof_system::honk::flavor { class Ultra { public: using CircuitBuilder = UltraCircuitBuilder; - using PCSParams = pcs::kzg::Params; - using PCS = pcs::kzg::KZG; - using Curve = PCSParams::Curve; + using Curve = curve::BN254; + using PCS = pcs::kzg::KZG; using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using CommitmentHandle = Curve::AffineElement; using FF = Curve::ScalarField; using Polynomial = barretenberg::Polynomial; using PolynomialHandle = std::span; + using CommitmentKey = pcs::CommitmentKey; + using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp index c949a4cb343..173ee9de622 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/flavor/ultra_grumpkin.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/pcs/ipa/ipa.hpp" #include "barretenberg/honk/pcs/kzg/kzg.hpp" #include "barretenberg/honk/sumcheck/polynomials/barycentric_data.hpp" @@ -30,15 +29,16 @@ class UltraGrumpkin { // purposes. This can be changed to Grumpkin and IPA once UltraCircuitBuilder also works on Grumpkin. public: using CircuitBuilder = UltraCircuitBuilder; - using PCSParams = pcs::kzg::Params; - using PCS = pcs::kzg::KZG; - using Curve = PCSParams::Curve; + using Curve = curve::BN254; + using PCS = pcs::kzg::KZG; using GroupElement = Curve::Element; using Commitment = Curve::AffineElement; using CommitmentHandle = Curve::AffineElement; using FF = Curve::ScalarField; using Polynomial = barretenberg::Polynomial; using PolynomialHandle = std::span; + using CommitmentKey = pcs::CommitmentKey; + using VerifierCommitmentKey = pcs::VerifierCommitmentKey; static constexpr size_t NUM_WIRES = CircuitBuilder::NUM_WIRES; // The number of multivariate polynomials on which a sumcheck prover sumcheck operates (including shifts). We often diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/claim.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/claim.hpp index a07a0706561..35a52e4970b 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/claim.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/claim.hpp @@ -1,6 +1,7 @@ #pragma once #include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/honk/pcs/commitment_key.hpp" namespace proof_system::honk::pcs { /** @@ -8,8 +9,8 @@ namespace proof_system::honk::pcs { * * @tparam Params for the given commitment scheme */ -template class OpeningPair { - using Fr = typename Params::Fr; +template class OpeningPair { + using Fr = typename Curve::ScalarField; public: Fr challenge; // r @@ -25,14 +26,14 @@ template class OpeningPair { * * @tparam Params for the given commitment scheme */ -template class OpeningClaim { - using CK = typename Params::CommitmentKey; - using Commitment = typename Params::Commitment; - using Fr = typename Params::Fr; +template class OpeningClaim { + using CK = CommitmentKey; + using Commitment = typename Curve::AffineElement; + using Fr = typename Curve::ScalarField; public: // (challenge r, evaluation v = p(r)) - OpeningPair opening_pair; + OpeningPair opening_pair; // commitment to univariate polynomial p(X) Commitment commitment; @@ -57,37 +58,4 @@ template class OpeningClaim { bool operator==(const OpeningClaim& other) const = default; }; - -/** - * @brief stores a claim of the form (C, v) for u=(u₀,…,uₘ₋₁) - * where C is a univariate commitment to a polynomial - * - * f(X) = a₀ + a₁⋅X + … + aₙ₋₁⋅Xⁿ⁻¹ - * - * and v is a multi-linear evaluation of f(X₀,…,Xₘ₋₁) - * which has the same coefficients as f. - * v = ∑ᵢ aᵢ⋅Lᵢ(u) - * - * If the evaluations is shift, we assume that a₀ = 0 and - * take g(X) = f↺(X), so that - * g(X) = a₁ + … + aₙ₋₁⋅Xⁿ⁻² = f(X)/X - * The evaluation will be - * v↺ = a₁⋅L₀(u) + … + aₙ₋₁⋅Lₙ₋₂(u) - * The commitment C is [f]. - * - * @tparam CommitmentKey - */ -template class MLEOpeningClaim { - using Commitment = typename Params::Commitment; - using Fr = typename Params::Fr; - - public: - // commitment to a univariate polynomial - // whose coefficients are the multi-linear evaluations - // of C = [f] - Commitment commitment; - // v = f(u) = ∑ᵢ aᵢ⋅Lᵢ(u) - // v↺ = g(u) = a₁⋅L₀(u) + … + aₙ₋₁⋅Lₙ₋₂(u) - Fr evaluation; -}; } // namespace proof_system::honk::pcs diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.hpp index 02046f1c98d..2e9c65864a0 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.hpp @@ -23,239 +23,56 @@ namespace proof_system::honk::pcs { -namespace kzg { +/** + * @brief CommitmentKey object over a pairing group 𝔾₁. + * + * @details Commitments are computed as C = [p(x)] = ∑ᵢ aᵢ⋅Gᵢ where Gᵢ is the i-th element of the SRS. For BN254, + * the SRS is given as a list of 𝔾₁ points { [xʲ]₁ }ⱼ where 'x' is unknown. For Grumpkin, they are random points. The + * SRS stored in the commitment key is after applying the pippenger_point_table thus being double the size of what is + * loaded from path. + */ +template class CommitmentKey { -struct Params { - using Curve = curve::BN254; using Fr = typename Curve::ScalarField; using Commitment = typename Curve::AffineElement; - using GroupElement = typename Curve::Element; - using Polynomial = barretenberg::Polynomial; + public: + CommitmentKey() = delete; - class CommitmentKey; - class VerificationKey; /** - * @brief CommitmentKey object over a pairing group 𝔾₁, using a structured reference string (SRS). - * The SRS is given as a list of 𝔾₁ points { [xʲ]₁ }ⱼ where 'x' is unknown. The SRS stored in the commitment key is - * after applying the pippenger_point_table thus being double the size of what is loaded from path. + * @brief Construct a new Kate Commitment Key object from existing SRS * + * @param n + * @param path * */ - class CommitmentKey { - - public: - CommitmentKey() = delete; - - /** - * @brief Construct a new Kate Commitment Key object from existing SRS - * - * @param n - * @param path - * - */ - CommitmentKey(const size_t num_points, - std::shared_ptr> crs_factory) - : pippenger_runtime_state(num_points) - , srs(crs_factory->get_prover_crs(num_points)) - {} - - // Note: This constructor is used only by Plonk; For Honk the CommitmentKey is solely responsible for extracting - // the srs. - CommitmentKey(const size_t num_points, - std::shared_ptr> prover_crs) - : pippenger_runtime_state(num_points) - , srs(prover_crs) - {} - - /** - * @brief Uses the ProverSRS to create a commitment to p(X) - * - * @param polynomial a univariate polynomial p(X) = ∑ᵢ aᵢ⋅Xⁱ () - * @return Commitment computed as C = [p(x)] = ∑ᵢ aᵢ⋅[xⁱ]₁ where x is the secret trapdoor - */ - Commitment commit(std::span polynomial) - { - const size_t degree = polynomial.size(); - ASSERT(degree <= srs->get_monomial_size()); - return barretenberg::scalar_multiplication::pippenger_unsafe( - const_cast(polynomial.data()), srs->get_monomial_points(), degree, pippenger_runtime_state); - }; - - barretenberg::scalar_multiplication::pippenger_runtime_state pippenger_runtime_state; - std::shared_ptr> srs; - }; - - class VerificationKey { - - public: - VerificationKey() = delete; - - /** - * @brief Construct a new Kate Verification Key object from existing SRS - * - * @param num_points - * @paramsrs verifier G2 point - */ - VerificationKey([[maybe_unused]] size_t num_points, - std::shared_ptr> crs_factory) - : srs(crs_factory->get_verifier_crs()) - {} - - /** - * @brief verifies a pairing equation over 2 points using the verifier SRS - * - * @param p0 = P₀ - * @param p1 = P₁ - * @return e(P₀,[1]₁)e(P₁,[x]₂) ≡ [1]ₜ - */ - bool pairing_check(const GroupElement& p0, const GroupElement& p1) - { - Commitment pairing_points[2]{ p0, p1 }; - // The final pairing check of step 12. - Curve::TargetField result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( - pairing_points, srs->get_precomputed_g2_lines(), 2); - - return (result == Curve::TargetField::one()); - } - - std::shared_ptr> srs; - }; -}; - -} // namespace kzg - -namespace fake { - -// Define a common trapdoor for both keys -namespace { -template constexpr typename G::Fr trapdoor(5); -} - -template struct Params { - using Fr = typename G::Fr; - using Commitment = typename G::affine_element; - using GroupElement = typename G::element; - - using Polynomial = barretenberg::Polynomial; + CommitmentKey(const size_t num_points, std::shared_ptr> crs_factory) + : pippenger_runtime_state(num_points) + , srs(crs_factory->get_prover_crs(num_points)) + {} - template class CommitmentKey; - template class VerificationKey; + // Note: This constructor is used only by Plonk; For Honk the srs is extracted by the CommitmentKey + CommitmentKey(const size_t num_points, std::shared_ptr> prover_crs) + : pippenger_runtime_state(num_points) + , srs(prover_crs) + {} /** - * @brief Simulates a KZG CommitmentKey, but where we know the secret trapdoor - * which allows us to commit to polynomials using a single group multiplication. + * @brief Uses the ProverSRS to create a commitment to p(X) * - * @tparam G the commitment group + * @param polynomial a univariate polynomial p(X) = ∑ᵢ aᵢ⋅Xⁱ + * @return Commitment computed as C = [p(x)] = ∑ᵢ aᵢ⋅Gᵢ */ - template class CommitmentKey { - - public: - /** - * @brief efficiently create a KZG commitment to p(X) using the trapdoor 'secret' - * Uses only 1 group scalar multiplication, and 1 polynomial evaluation - * - * - * @param polynomial a univariate polynomial p(X) - * @return Commitment computed as C = p(secret)•[1]_1 . - */ - Commitment commit(std::span polynomial) - { - const Fr eval_secret = barretenberg::polynomial_arithmetic::evaluate(polynomial, trapdoor); - return Commitment::one() * eval_secret; - }; - }; - - template class VerificationKey { - - public: - /** - * @brief verifies a pairing equation over 2 points using the trapdoor - * - * @param p0 = P₀ - * @param p1 = P₁ - * @return P₀ - x⋅P₁ ≡ [1] - */ - bool pairing_check(const Commitment& p0, const Commitment& p1) - { - Commitment result = p0 + p1 * trapdoor; - return result.is_point_at_infinity(); - } - }; -}; -} // namespace fake - -namespace ipa { - -struct Params { - using Curve = curve::Grumpkin; - using Fr = typename Curve::ScalarField; - using Commitment = typename Curve::AffineElement; - using GroupElement = typename Curve::Element; - - using Polynomial = barretenberg::Polynomial; - - class CommitmentKey; - class VerificationKey; - - class CommitmentKey { - - public: - CommitmentKey() = delete; - - /** - * @brief Construct a new IPA Commitment Key object from existing SRS.. - * - * @param num_points - * @param path - * - */ - CommitmentKey(const size_t num_points, - std::shared_ptr> crs_factory) - : pippenger_runtime_state(num_points) - , srs(crs_factory->get_prover_crs(num_points)) - {} - - /** - * @brief Uses the ProverSRS to create an unblinded commitment to p(X) - * - * @param polynomial a univariate polynomial p(X) = ∑ᵢ aᵢ⋅Xⁱ () - * @return Commitment computed as C = [p(x)] = ∑ᵢ aᵢ⋅Gᵢ where Gᵢ is the i-th element of the SRS - */ - Commitment commit(std::span polynomial) - { - const size_t degree = polynomial.size(); - ASSERT(degree <= srs->get_monomial_size()); - return barretenberg::scalar_multiplication::pippenger_unsafe( - const_cast(polynomial.data()), srs->get_monomial_points(), degree, pippenger_runtime_state); - }; - - barretenberg::scalar_multiplication::pippenger_runtime_state pippenger_runtime_state; - std::shared_ptr> srs; + Commitment commit(std::span polynomial) + { + const size_t degree = polynomial.size(); + ASSERT(degree <= srs->get_monomial_size()); + return barretenberg::scalar_multiplication::pippenger_unsafe( + const_cast(polynomial.data()), srs->get_monomial_points(), degree, pippenger_runtime_state); }; - class VerificationKey { - public: - VerificationKey() = delete; - - /** - * @brief Construct a new IPA Verification Key object from existing SRS - * - * - * @param num_points specifies the length of the SRS - * @param path is the location to the SRS file - */ - VerificationKey(size_t num_points, std::shared_ptr> crs_factory) - : pippenger_runtime_state(num_points) - , srs(crs_factory->get_verifier_crs(num_points)) - - {} - - barretenberg::scalar_multiplication::pippenger_runtime_state pippenger_runtime_state; - std::shared_ptr> srs; - }; + barretenberg::scalar_multiplication::pippenger_runtime_state pippenger_runtime_state; + std::shared_ptr> srs; }; -} // namespace ipa - } // namespace proof_system::honk::pcs diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.test.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.test.hpp index 4f27faff9d6..4e86c350df9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.test.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/commitment_key.test.hpp @@ -9,32 +9,33 @@ #include #include "barretenberg/ecc/curves/bn254/g1.hpp" +#include "barretenberg/honk/pcs/commitment_key.hpp" +#include "barretenberg/honk/pcs/verification_key.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/srs/factories/file_crs_factory.hpp" #include "../../transcript/transcript_wrappers.hpp" #include "claim.hpp" -#include "commitment_key.hpp" namespace proof_system::honk::pcs { template inline std::shared_ptr CreateCommitmentKey(); -template <> inline std::shared_ptr CreateCommitmentKey() +template <> inline std::shared_ptr> CreateCommitmentKey>() { constexpr size_t n = 4096; - std::shared_ptr> crs_factory( - new barretenberg::srs::factories::FileCrsFactory("../srs_db/ignition", 4096)); - return std::make_shared(n, crs_factory); + std::shared_ptr> crs_factory( + new barretenberg::srs::factories::FileCrsFactory("../srs_db/ignition", 4096)); + return std::make_shared>(n, crs_factory); } // For IPA -template <> inline std::shared_ptr CreateCommitmentKey() +template <> inline std::shared_ptr> CreateCommitmentKey>() { constexpr size_t n = 4096; - std::shared_ptr> crs_factory( - new barretenberg::srs::factories::FileCrsFactory("../srs_db/grumpkin", 4096)); - return std::make_shared(n, crs_factory); + std::shared_ptr> crs_factory( + new barretenberg::srs::factories::FileCrsFactory("../srs_db/grumpkin", 4096)); + return std::make_shared>(n, crs_factory); } template inline std::shared_ptr CreateCommitmentKey() @@ -43,35 +44,36 @@ template inline std::shared_ptr CreateCommitmentKey() return std::make_shared(); } -template inline std::shared_ptr CreateVerificationKey(); +template inline std::shared_ptr CreateVerifierCommitmentKey(); -template <> inline std::shared_ptr CreateVerificationKey() +template <> inline std::shared_ptr> CreateVerifierCommitmentKey>() { constexpr size_t n = 4096; - std::shared_ptr> crs_factory( - new barretenberg::srs::factories::FileCrsFactory("../srs_db/ignition", 4096)); - return std::make_shared(n, crs_factory); + std::shared_ptr> crs_factory( + new barretenberg::srs::factories::FileCrsFactory("../srs_db/ignition", 4096)); + return std::make_shared>(n, crs_factory); } // For IPA -template <> inline std::shared_ptr CreateVerificationKey() +template <> +inline std::shared_ptr> CreateVerifierCommitmentKey>() { constexpr size_t n = 4096; - std::shared_ptr> crs_factory( - new barretenberg::srs::factories::FileCrsFactory("../srs_db/grumpkin", 4096)); - return std::make_shared(n, crs_factory); + std::shared_ptr> crs_factory( + new barretenberg::srs::factories::FileCrsFactory("../srs_db/grumpkin", 4096)); + return std::make_shared>(n, crs_factory); } -template inline std::shared_ptr CreateVerificationKey() +template inline std::shared_ptr CreateVerifierCommitmentKey() // requires std::default_initializable { return std::make_shared(); } -template class CommitmentTest : public ::testing::Test { - using CK = typename Params::CommitmentKey; - using VK = typename Params::VerificationKey; +template class CommitmentTest : public ::testing::Test { + using CK = CommitmentKey; + using VK = VerifierCommitmentKey; - using Fr = typename Params::Fr; - using Commitment = typename Params::Commitment; - using Polynomial = typename Params::Polynomial; + using Fr = typename Curve::ScalarField; + using Commitment = typename Curve::AffineElement; + using Polynomial = barretenberg::Polynomial; public: CommitmentTest() @@ -94,19 +96,19 @@ template class CommitmentTest : public ::testing::Test { Fr random_element() { return Fr::random_element(engine); } - OpeningPair random_eval(const Polynomial& polynomial) + OpeningPair random_eval(const Polynomial& polynomial) { Fr x{ random_element() }; Fr y{ polynomial.evaluate(x) }; return { x, y }; } - std::pair, Polynomial> random_claim(const size_t n) + std::pair, Polynomial> random_claim(const size_t n) { auto polynomial = random_polynomial(n); auto opening_pair = random_eval(polynomial); auto commitment = commit(polynomial); - auto opening_claim = OpeningClaim{ opening_pair, commitment }; + auto opening_claim = OpeningClaim{ opening_pair, commitment }; return { opening_claim, polynomial }; }; @@ -119,7 +121,7 @@ template class CommitmentTest : public ::testing::Test { return u; } - void verify_opening_claim(const OpeningClaim& claim, const Polynomial& witness) + void verify_opening_claim(const OpeningClaim& claim, const Polynomial& witness) { auto& commitment = claim.commitment; auto& [x, y] = claim.opening_pair; @@ -130,7 +132,7 @@ template class CommitmentTest : public ::testing::Test { EXPECT_EQ(commitment, commitment_expected) << "OpeningClaim: commitment mismatch"; } - void verify_opening_pair(const OpeningPair& opening_pair, const Polynomial& witness) + void verify_opening_pair(const OpeningPair& opening_pair, const Polynomial& witness) { auto& [x, y] = opening_pair; Fr y_expected = witness.evaluate(x); @@ -144,7 +146,7 @@ template class CommitmentTest : public ::testing::Test { * - each 'queries' is a subset of 'all_queries' and 'all_queries' is the union of all 'queries' * - each 'commitment' of each 'SubClaim' appears only once. */ - void verify_batch_opening_claim(std::span> multi_claims, + void verify_batch_opening_claim(std::span> multi_claims, std::span witnesses) { const size_t num_claims = multi_claims.size(); @@ -159,7 +161,7 @@ template class CommitmentTest : public ::testing::Test { * @brief Ensures that a set of opening pairs is correct by checking that evaluations are * correct by recomputing them from each witness polynomial. */ - void verify_batch_opening_pair(std::span> opening_pairs, + void verify_batch_opening_pair(std::span> opening_pairs, std::span witnesses) { const size_t num_pairs = opening_pairs.size(); @@ -182,7 +184,7 @@ template class CommitmentTest : public ::testing::Test { commitment_key = CreateCommitmentKey(); } if (verification_key == nullptr) { - verification_key = CreateVerificationKey(); + verification_key = CreateVerifierCommitmentKey(); } } @@ -191,17 +193,17 @@ template class CommitmentTest : public ::testing::Test { // Can be omitted if not needed. static void TearDownTestSuite() {} - static typename std::shared_ptr commitment_key; - static typename std::shared_ptr verification_key; + static typename std::shared_ptr commitment_key; + static typename std::shared_ptr verification_key; }; -template -typename std::shared_ptr CommitmentTest::commitment_key = nullptr; -template -typename std::shared_ptr CommitmentTest::verification_key = nullptr; +template +typename std::shared_ptr> CommitmentTest::commitment_key = nullptr; +template +typename std::shared_ptr> CommitmentTest::verification_key = nullptr; -using CommitmentSchemeParams = ::testing::Types; -using IpaCommitmentSchemeParams = ::testing::Types; +using CommitmentSchemeParams = ::testing::Types; +using IpaCommitmentSchemeParams = ::testing::Types; // IMPROVEMENT: reinstate typed-tests for multiple field types, i.e.: // using CommitmentSchemeParams = // ::testing::Types, fake::Params, kzg::Params>; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.cpp index 57f5d48d2bf..fe2b0dbde86 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.cpp @@ -52,14 +52,10 @@ namespace proof_system::honk::pcs::gemini { * @param batched_to_be_shifted G(X) = ∑ⱼ ρᵏ⁺ʲ gⱼ(X) * @return std::vector */ -template -std::vector> GeminiProver_::compute_fold_polynomials( +template +std::vector> GeminiProver_::compute_fold_polynomials( std::span mle_opening_point, Polynomial&& batched_unshifted, Polynomial&& batched_to_be_shifted) { - - using Fr = typename Params::Fr; - using Polynomial = barretenberg::Polynomial; - const size_t num_variables = mle_opening_point.size(); // m const size_t num_threads = get_num_cpus_pow2(); @@ -144,15 +140,11 @@ std::vector> GeminiProver * and G(X) = ∑ⱼ ρᵏ⁺ʲ gⱼ(X), and the next d-1 elements are Fold_i, i = 1, ..., d-1. * @param r_challenge univariate opening challenge */ -template -ProverOutput GeminiProver_::compute_fold_polynomial_evaluations(std::span mle_opening_point, +template +ProverOutput GeminiProver_::compute_fold_polynomial_evaluations(std::span mle_opening_point, std::vector&& fold_polynomials, const Fr& r_challenge) { - - using Fr = typename Params::Fr; - using Polynomial = barretenberg::Polynomial; - const size_t num_variables = mle_opening_point.size(); // m Polynomial& batched_F = fold_polynomials[0]; // F(X) = ∑ⱼ ρʲ fⱼ(X) @@ -179,16 +171,16 @@ ProverOutput GeminiProver_::compute_fold_polynomial_evaluations( // A₀₋(X) = F(X) - G(X)/r, s.t. A₀₋(-r) = A₀(-r) A_0_neg -= tmp; - std::vector> fold_poly_opening_pairs; + std::vector> fold_poly_opening_pairs; fold_poly_opening_pairs.reserve(num_variables + 1); // Compute first opening pair {r, A₀(r)} - fold_poly_opening_pairs.emplace_back(OpeningPair{ r_challenge, fold_polynomials[0].evaluate(r_challenge) }); + fold_poly_opening_pairs.emplace_back(OpeningPair{ r_challenge, fold_polynomials[0].evaluate(r_challenge) }); // Compute the remaining m opening pairs {−r^{2ˡ}, Aₗ(−r^{2ˡ})}, l = 0, ..., m-1. for (size_t l = 0; l < num_variables; ++l) { fold_poly_opening_pairs.emplace_back( - OpeningPair{ -r_squares[l], fold_polynomials[l + 1].evaluate(-r_squares[l]) }); + OpeningPair{ -r_squares[l], fold_polynomials[l + 1].evaluate(-r_squares[l]) }); } return { fold_poly_opening_pairs, std::move(fold_polynomials) }; @@ -207,16 +199,13 @@ ProverOutput GeminiProver_::compute_fold_polynomial_evaluations( * (Cⱼ, Aⱼ(-r^{2ʲ}), -r^{2}), j = [1, ..., m-1] */ -template -std::vector> GeminiVerifier_::reduce_verification(std::span mle_opening_point, /* u */ +template +std::vector> GeminiVerifier_::reduce_verification(std::span mle_opening_point, /* u */ const Fr batched_evaluation, /* all */ GroupElement& batched_f, /* unshifted */ GroupElement& batched_g, /* to-be-shifted */ VerifierTranscript& transcript) { - - using Fr = typename Params::Fr; - using Commitment = typename Params::Commitment; const size_t num_variables = mle_opening_point.size(); // Get polynomials Fold_i, i = 1,...,m-1 from transcript @@ -246,17 +235,17 @@ std::vector> GeminiVerifier_::reduce_verification(s // C₀_r_pos = ∑ⱼ ρʲ⋅[fⱼ] - r⁻¹⋅∑ⱼ ρᵏ⁺ʲ [gⱼ] auto [c0_r_pos, c0_r_neg] = compute_simulated_commitments(batched_f, batched_g, r); - std::vector> fold_polynomial_opening_claims; + std::vector> fold_polynomial_opening_claims; fold_polynomial_opening_claims.reserve(num_variables + 1); // ( [A₀₊], r, A₀(r) ) - fold_polynomial_opening_claims.emplace_back(OpeningClaim{ { r, a_0_pos }, c0_r_pos }); + fold_polynomial_opening_claims.emplace_back(OpeningClaim{ { r, a_0_pos }, c0_r_pos }); // ( [A₀₋], -r, A₀(-r) ) - fold_polynomial_opening_claims.emplace_back(OpeningClaim{ { -r, evaluations[0] }, c0_r_neg }); + fold_polynomial_opening_claims.emplace_back(OpeningClaim{ { -r, evaluations[0] }, c0_r_neg }); for (size_t l = 0; l < num_variables - 1; ++l) { // ([A₀₋], −r^{2ˡ}, Aₗ(−r^{2ˡ}) ) fold_polynomial_opening_claims.emplace_back( - OpeningClaim{ { -r_squares[l + 1], evaluations[l + 1] }, commitments[l] }); + OpeningClaim{ { -r_squares[l + 1], evaluations[l + 1] }, commitments[l] }); } return fold_polynomial_opening_claims; @@ -271,13 +260,12 @@ std::vector> GeminiVerifier_::reduce_verification(s * @param fold_polynomial_evals series of Aᵢ₋₁(−r^{2ⁱ⁻¹}) * @return evaluation A₀(r) */ -template -typename Params::Fr GeminiVerifier_::compute_eval_pos(const Fr batched_mle_eval, +template +typename Curve::ScalarField GeminiVerifier_::compute_eval_pos(const Fr batched_mle_eval, std::span mle_vars, std::span r_squares, std::span fold_polynomial_evals) { - using Fr = typename Params::Fr; const size_t num_variables = mle_vars.size(); const auto& evals = fold_polynomial_evals; @@ -309,8 +297,8 @@ typename Params::Fr GeminiVerifier_::compute_eval_pos(const Fr batched_m * @param r evaluation point at which we have partially evaluated A₀ at r and -r. * @return std::pair c0_r_pos, c0_r_neg */ -template -std::pair GeminiVerifier_::compute_simulated_commitments( +template +std::pair GeminiVerifier_::compute_simulated_commitments( GroupElement& batched_f, GroupElement& batched_g, Fr r) { // C₀ᵣ₊ = [F] + r⁻¹⋅[G] @@ -326,8 +314,8 @@ std::pair GeminiVe return { C0_r_pos, C0_r_neg }; }; -template class GeminiProver_; -template class GeminiProver_; -template class GeminiVerifier_; -template class GeminiVerifier_; +template class GeminiProver_; +template class GeminiProver_; +template class GeminiVerifier_; +template class GeminiVerifier_; }; // namespace proof_system::honk::pcs::gemini diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.hpp index 340e8027a12..27ab3969762 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.hpp @@ -1,7 +1,6 @@ #pragma once #include "../claim.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/polynomial.hpp" @@ -56,11 +55,11 @@ namespace proof_system::honk::pcs::gemini { * ... * Aₘ₋₁(X) = (1-uₘ₋₂)⋅even(Aₘ₋₂)(X) + uₘ₋₂⋅odd(Aₘ₋₂)(X) * ] - * @tparam Params CommitmentScheme parameters + * @tparam Curve CommitmentScheme parameters */ -template struct ProverOutput { - std::vector> opening_pairs; - std::vector> witnesses; +template struct ProverOutput { + std::vector> opening_pairs; + std::vector> witnesses; }; /** @@ -84,10 +83,9 @@ template inline std::vector powers_of_rho(const Fr rho, const siz /** * @brief Compute squares of folding challenge r * - * @tparam Params * @param r * @param num_squares The number of foldings - * @return std::vector + * @return std::vector */ template inline std::vector squares_of_r(const Fr r, const size_t num_squares) { @@ -99,8 +97,8 @@ template inline std::vector squares_of_r(const Fr r, const size_t return squares; }; -template class GeminiProver_ { - using Fr = typename Params::Fr; +template class GeminiProver_ { + using Fr = typename Curve::ScalarField; using Polynomial = barretenberg::Polynomial; public: @@ -108,18 +106,18 @@ template class GeminiProver_ { Polynomial&& batched_unshifted, Polynomial&& batched_to_be_shifted); - static ProverOutput compute_fold_polynomial_evaluations(std::span mle_opening_point, + static ProverOutput compute_fold_polynomial_evaluations(std::span mle_opening_point, std::vector&& fold_polynomials, const Fr& r_challenge); }; // namespace proof_system::honk::pcs::gemini -template class GeminiVerifier_ { - using Fr = typename Params::Fr; - using GroupElement = typename Params::GroupElement; - using Commitment = typename Params::Commitment; +template class GeminiVerifier_ { + using Fr = typename Curve::ScalarField; + using GroupElement = typename Curve::Element; + using Commitment = typename Curve::AffineElement; public: - static std::vector> reduce_verification(std::span mle_opening_point, /* u */ + static std::vector> reduce_verification(std::span mle_opening_point, /* u */ const Fr batched_evaluation, /* all */ GroupElement& batched_f, /* unshifted */ GroupElement& batched_g, /* to-be-shifted */ @@ -136,9 +134,9 @@ template class GeminiVerifier_ { Fr r); }; // namespace proof_system::honk::pcs::gemini -extern template class GeminiProver_; -extern template class GeminiProver_; -extern template class GeminiVerifier_; -extern template class GeminiVerifier_; +extern template class GeminiProver_; +extern template class GeminiProver_; +extern template class GeminiVerifier_; +extern template class GeminiVerifier_; } // namespace proof_system::honk::pcs::gemini diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.test.cpp index 98bb3f83a4d..b0e647a4802 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/gemini/gemini.test.cpp @@ -9,11 +9,11 @@ namespace proof_system::honk::pcs::gemini { -template class GeminiTest : public CommitmentTest { - using GeminiProver = GeminiProver_; - using GeminiVerifier = GeminiVerifier_; - using Fr = typename Params::Fr; - using GroupElement = typename Params::GroupElement; +template class GeminiTest : public CommitmentTest { + using GeminiProver = GeminiProver_; + using GeminiVerifier = GeminiVerifier_; + using Fr = typename Curve::ScalarField; + using GroupElement = typename Curve::Element; using Polynomial = typename barretenberg::Polynomial; public: @@ -101,13 +101,13 @@ template class GeminiTest : public CommitmentTest { } }; -using ParamsTypes = ::testing::Types; +using ParamsTypes = ::testing::Types; TYPED_TEST_SUITE(GeminiTest, ParamsTypes); TYPED_TEST(GeminiTest, Single) { - using Fr = typename TypeParam::Fr; - using GroupElement = typename TypeParam::GroupElement; + using Fr = typename TypeParam::ScalarField; + using GroupElement = typename TypeParam::Element; const size_t n = 16; const size_t log_n = 4; @@ -135,8 +135,8 @@ TYPED_TEST(GeminiTest, Single) TYPED_TEST(GeminiTest, SingleShift) { - using Fr = typename TypeParam::Fr; - using GroupElement = typename TypeParam::GroupElement; + using Fr = typename TypeParam::ScalarField; + using GroupElement = typename TypeParam::Element; const size_t n = 16; const size_t log_n = 4; @@ -168,8 +168,8 @@ TYPED_TEST(GeminiTest, SingleShift) TYPED_TEST(GeminiTest, Double) { - using Fr = typename TypeParam::Fr; - using GroupElement = typename TypeParam::GroupElement; + using Fr = typename TypeParam::ScalarField; + using GroupElement = typename TypeParam::Element; const size_t n = 16; const size_t log_n = 4; @@ -203,8 +203,8 @@ TYPED_TEST(GeminiTest, Double) TYPED_TEST(GeminiTest, DoubleWithShift) { - using Fr = typename TypeParam::Fr; - using GroupElement = typename TypeParam::GroupElement; + using Fr = typename TypeParam::ScalarField; + using GroupElement = typename TypeParam::Element; const size_t n = 16; const size_t log_n = 4; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.hpp index 4bc02e0f4a2..453d013c062 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.hpp @@ -2,7 +2,6 @@ #include "barretenberg/common/assert.hpp" #include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" #include "barretenberg/honk/pcs/claim.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include #include @@ -15,13 +14,12 @@ * */ namespace proof_system::honk::pcs::ipa { -template class IPA { - using Curve = typename Params::Curve; - using Fr = typename Params::Fr; - using GroupElement = typename Params::GroupElement; - using Commitment = typename Params::Commitment; - using CK = typename Params::CommitmentKey; - using VK = typename Params::VerificationKey; +template class IPA { + using Fr = typename Curve::ScalarField; + using GroupElement = typename Curve::Element; + using Commitment = typename Curve::AffineElement; + using CK = CommitmentKey; + using VK = VerifierCommitmentKey; using Polynomial = barretenberg::Polynomial; public: @@ -34,7 +32,7 @@ template class IPA { * @param transcript Prover transcript */ static void compute_opening_proof(std::shared_ptr ck, - const OpeningPair& opening_pair, + const OpeningPair& opening_pair, const Polynomial& polynomial, ProverTranscript& transcript) { @@ -136,7 +134,7 @@ template class IPA { * @return true/false depending on if the proof verifies */ static bool verify(std::shared_ptr vk, - const OpeningClaim& opening_claim, + const OpeningClaim& opening_claim, VerifierTranscript& transcript) { auto poly_degree = static_cast(transcript.template receive_from_prover("IPA:poly_degree")); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.test.cpp index 5088347d801..3e8959084c4 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/ipa/ipa.test.cpp @@ -3,21 +3,22 @@ #include "barretenberg/common/mem.hpp" #include "barretenberg/ecc/curves/bn254/fq12.hpp" #include "barretenberg/ecc/curves/types.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/pcs/commitment_key.test.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/polynomials/polynomial_arithmetic.hpp" #include "ipa.hpp" #include using namespace barretenberg; -namespace proof_system::honk::pcs::ipa { +namespace proof_system::honk::pcs::ipa::test { -class IPATest : public CommitmentTest { +using Curve = curve::Grumpkin; + +class IPATest : public CommitmentTest { public: - using Fr = typename Params::Fr; - using GroupElement = typename Params::GroupElement; - using CK = typename Params::CommitmentKey; - using VK = typename Params::VerificationKey; + using Fr = typename Curve::ScalarField; + using GroupElement = typename Curve::Element; + using CK = CommitmentKey; + using VK = VerifierCommitmentKey; using Polynomial = barretenberg::Polynomial; }; @@ -59,14 +60,14 @@ TEST_F(IPATest, Commit) TEST_F(IPATest, Open) { - using IPA = IPA; + using IPA = IPA; // generate a random polynomial, degree needs to be a power of two size_t n = 128; auto poly = this->random_polynomial(n); auto [x, eval] = this->random_eval(poly); auto commitment = this->commit(poly); - const OpeningPair opening_pair = { x, eval }; - const OpeningClaim opening_claim{ opening_pair, commitment }; + const OpeningPair opening_pair = { x, eval }; + const OpeningClaim opening_claim{ opening_pair, commitment }; // initialize empty prover transcript ProverTranscript prover_transcript; @@ -83,11 +84,11 @@ TEST_F(IPATest, Open) TEST_F(IPATest, GeminiShplonkIPAWithShift) { - using IPA = IPA; - using ShplonkProver = shplonk::ShplonkProver_; - using ShplonkVerifier = shplonk::ShplonkVerifier_; - using GeminiProver = gemini::GeminiProver_; - using GeminiVerifier = gemini::GeminiVerifier_; + using IPA = IPA; + using ShplonkProver = shplonk::ShplonkProver_; + using ShplonkVerifier = shplonk::ShplonkVerifier_; + using GeminiProver = gemini::GeminiProver_; + using GeminiVerifier = gemini::GeminiVerifier_; const size_t n = 8; const size_t log_n = 3; @@ -173,4 +174,4 @@ TEST_F(IPATest, GeminiShplonkIPAWithShift) EXPECT_EQ(verified, true); } -} // namespace proof_system::honk::pcs::ipa +} // namespace proof_system::honk::pcs::ipa::test diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.hpp index f85ddd85d99..dea5508c352 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.hpp @@ -1,21 +1,22 @@ #pragma once #include "../claim.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/transcript/transcript.hpp" #include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/honk/pcs/commitment_key.hpp" +#include "barretenberg/honk/pcs/verification_key.hpp" #include #include namespace proof_system::honk::pcs::kzg { -template class KZG { - using CK = typename Params::CommitmentKey; - using VK = typename Params::VerificationKey; - using Fr = typename Params::Fr; - using Commitment = typename Params::Commitment; - using GroupElement = typename Params::GroupElement; +template class KZG { + using CK = CommitmentKey; + using VK = VerifierCommitmentKey; + using Fr = typename Curve::ScalarField; + using Commitment = typename Curve::AffineElement; + using GroupElement = typename Curve::Element; using Polynomial = barretenberg::Polynomial; /** @@ -28,7 +29,7 @@ template class KZG { */ public: static void compute_opening_proof(std::shared_ptr ck, - const OpeningPair& opening_pair, + const OpeningPair& opening_pair, const Polynomial& polynomial, ProverTranscript& prover_trancript) { @@ -54,7 +55,7 @@ template class KZG { * - P₁ = [Q(x)]₁ */ static bool verify(std::shared_ptr vk, - const OpeningClaim& claim, + const OpeningClaim& claim, VerifierTranscript& verifier_transcript) { auto quotient_commitment = verifier_transcript.template receive_from_prover("KZG:W"); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.test.cpp index b752bb0aae7..1e7f5753659 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/kzg/kzg.test.cpp @@ -5,7 +5,6 @@ #include "../commitment_key.test.hpp" #include "barretenberg/honk/pcs/claim.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" @@ -15,11 +14,11 @@ namespace proof_system::honk::pcs::kzg { -template class KZGTest : public CommitmentTest { +template class KZGTest : public CommitmentTest { public: - using Fr = typename Params::Fr; - using Commitment = typename Params::Commitment; - using GroupElement = typename Params::GroupElement; + using Fr = typename Curve::ScalarField; + using Commitment = typename Curve::AffineElement; + using GroupElement = typename Curve::Element; using Polynomial = barretenberg::Polynomial; }; @@ -30,7 +29,7 @@ TYPED_TEST(KZGTest, single) const size_t n = 16; using KZG = KZG; - using Fr = typename TypeParam::Fr; + using Fr = typename TypeParam::ScalarField; auto witness = this->random_polynomial(n); barretenberg::g1::element commitment = this->commit(witness); @@ -60,11 +59,11 @@ TYPED_TEST(KZGTest, GeminiShplonkKzgWithShift) { using ShplonkProver = shplonk::ShplonkProver_; using ShplonkVerifier = shplonk::ShplonkVerifier_; - using GeminiProver = gemini::GeminiProver_; - using GeminiVerifier = gemini::GeminiVerifier_; + using GeminiProver = gemini::GeminiProver_; + using GeminiVerifier = gemini::GeminiVerifier_; using KZG = KZG; - using Fr = typename TypeParam::Fr; - using GroupElement = typename TypeParam::GroupElement; + using Fr = typename TypeParam::ScalarField; + using GroupElement = typename TypeParam::Element; using Polynomial = typename barretenberg::Polynomial; const size_t n = 16; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.hpp index ca1afcf6a38..12bcc5ad1df 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.hpp @@ -1,7 +1,8 @@ #pragma once #include "barretenberg/honk/pcs/claim.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/transcript/transcript.hpp" +#include "barretenberg/honk/pcs/commitment_key.hpp" +#include "barretenberg/honk/pcs/verification_key.hpp" /** * @brief Reduces multiple claims about commitments, each opened at a single point @@ -22,28 +23,28 @@ namespace proof_system::honk::pcs::shplonk { /** * @brief Polynomial G(X) = Q(X) - ∑ₖ ẑₖ(r)⋅( Bₖ(X) − Tₖ(z) ), where Q(X) = ∑ₖ ( Bₖ(X) − Tₖ(X) ) / zₖ(X) * - * @tparam Params CommitmentScheme parameters + * @tparam Curve EC parameters */ -template using OutputWitness = barretenberg::Polynomial; +template using OutputWitness = barretenberg::Polynomial; /** * @brief Prover output (claim=([G], r, 0), witness = G(X), proof = [Q]) * that can be passed on to a univariate opening protocol. * - * @tparam Params CommitmentScheme parameters + * @tparam Curve EC parameters */ -template struct ProverOutput { - OpeningPair opening_pair; // single opening pair (challenge, evaluation) - OutputWitness witness; // single polynomial G(X) +template struct ProverOutput { + OpeningPair opening_pair; // single opening pair (challenge, evaluation) + OutputWitness witness; // single polynomial G(X) }; /** * @brief Shplonk Prover * - * @tparam Params for the given commitment scheme + * @tparam Curve EC parameters */ -template class ShplonkProver_ { - using Fr = typename Params::Fr; +template class ShplonkProver_ { + using Fr = typename Curve::ScalarField; using Polynomial = barretenberg::Polynomial; public: @@ -55,7 +56,7 @@ template class ShplonkProver_ { * @param nu * @return Polynomial Q(X) */ - static Polynomial compute_batched_quotient(std::span> opening_pairs, + static Polynomial compute_batched_quotient(std::span> opening_pairs, std::span witness_polynomials, const Fr& nu) { @@ -96,8 +97,8 @@ template class ShplonkProver_ { * @param z_challenge * @return Output{OpeningPair, Polynomial} */ - static ProverOutput compute_partially_evaluated_batched_quotient( - std::span> opening_pairs, + static ProverOutput compute_partially_evaluated_batched_quotient( + std::span> opening_pairs, std::span witness_polynomials, Polynomial&& batched_quotient_Q, const Fr& nu_challenge, @@ -144,11 +145,11 @@ template class ShplonkProver_ { * @brief Shplonk Verifier * */ -template class ShplonkVerifier_ { - using Fr = typename Params::Fr; - using GroupElement = typename Params::GroupElement; - using Commitment = typename Params::Commitment; - using VK = typename Params::VerificationKey; +template class ShplonkVerifier_ { + using Fr = typename Curve::ScalarField; + using GroupElement = typename Curve::Element; + using Commitment = typename Curve::AffineElement; + using VK = VerifierCommitmentKey; public: /** @@ -160,8 +161,8 @@ template class ShplonkVerifier_ { * @param transcript * @return OpeningClaim */ - static OpeningClaim reduce_verification(std::shared_ptr vk, - std::span> claims, + static OpeningClaim reduce_verification(std::shared_ptr vk, + std::span> claims, VerifierTranscript& transcript) { const size_t num_claims = claims.size(); diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.test.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.test.cpp index f04d121b1af..b3307b2c240 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.test.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/shplonk/shplonk.test.cpp @@ -13,15 +13,15 @@ namespace proof_system::honk::pcs::shplonk { template class ShplonkTest : public CommitmentTest {}; -using ParamsTypes = ::testing::Types; -TYPED_TEST_SUITE(ShplonkTest, ParamsTypes); +using CurveTypes = ::testing::Types; +TYPED_TEST_SUITE(ShplonkTest, CurveTypes); // Test of Shplonk prover/verifier for two polynomials of different size, each opened at a single (different) point TYPED_TEST(ShplonkTest, ShplonkSimple) { using ShplonkProver = ShplonkProver_; using ShplonkVerifier = ShplonkVerifier_; - using Fr = typename TypeParam::Fr; + using Fr = typename TypeParam::ScalarField; using Polynomial = typename barretenberg::Polynomial; using OpeningPair = OpeningPair; using OpeningClaim = OpeningClaim; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/verification_key.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/verification_key.hpp new file mode 100644 index 00000000000..510799f41ec --- /dev/null +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/verification_key.hpp @@ -0,0 +1,101 @@ +#pragma once + +/** + * @brief Provides interfaces for different PCS 'VerificationKey' classes. + * + */ + +#include "barretenberg/ecc/curves/bn254/bn254.hpp" +#include "barretenberg/ecc/curves/bn254/pairing.hpp" +#include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" +#include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" +#include "barretenberg/honk/pcs/commitment_key.hpp" +#include "barretenberg/numeric/bitop/pow.hpp" +#include "barretenberg/polynomials/polynomial.hpp" +#include "barretenberg/polynomials/polynomial_arithmetic.hpp" +#include "barretenberg/srs/factories/crs_factory.hpp" +#include "barretenberg/srs/factories/file_crs_factory.hpp" + +#include +#include +#include + +namespace proof_system::honk::pcs { + +template class VerifierCommitmentKey; + +/** + * @brief Specialization for bn254 + * + * @tparam curve::BN254 + */ +template <> class VerifierCommitmentKey { + using Curve = curve::BN254; + using GroupElement = typename Curve::Element; + using Commitment = typename Curve::AffineElement; + + public: + VerifierCommitmentKey() = delete; + + /** + * @brief Construct a new Kate Verification Key object from existing SRS + * + * @param num_points + * @param srs verifier G2 point + */ + VerifierCommitmentKey([[maybe_unused]] size_t num_points, + std::shared_ptr> crs_factory) + : srs(crs_factory->get_verifier_crs()) + {} + + /** + * @brief verifies a pairing equation over 2 points using the verifier SRS + * + * @param p0 = P₀ + * @param p1 = P₁ + * @return e(P₀,[1]₁)e(P₁,[x]₂) ≡ [1]ₜ + */ + bool pairing_check(const GroupElement& p0, const GroupElement& p1) + { + Commitment pairing_points[2]{ p0, p1 }; + // The final pairing check of step 12. + Curve::TargetField result = barretenberg::pairing::reduced_ate_pairing_batch_precomputed( + pairing_points, srs->get_precomputed_g2_lines(), 2); + + return (result == Curve::TargetField::one()); + } + + std::shared_ptr> srs; +}; + +/** + * @brief Specialization for Grumpkin + * + * @tparam curve::Grumpkin + */ +template <> class VerifierCommitmentKey { + using Curve = curve::Grumpkin; + using GroupElement = typename Curve::Element; + using Commitment = typename Curve::AffineElement; + + public: + VerifierCommitmentKey() = delete; + + /** + * @brief Construct a new IPA Verification Key object from existing SRS + * + * + * @param num_points specifies the length of the SRS + * @param path is the location to the SRS file + */ + VerifierCommitmentKey(size_t num_points, std::shared_ptr> crs_factory) + : pippenger_runtime_state(num_points) + , srs(crs_factory->get_verifier_crs(num_points)) + + {} + + barretenberg::scalar_multiplication::pippenger_runtime_state pippenger_runtime_state; + std::shared_ptr> srs; +}; + +} // namespace proof_system::honk::pcs diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/wrapper.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/wrapper.hpp index 037c8ac2198..395f185d4f5 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/wrapper.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/pcs/wrapper.hpp @@ -1,7 +1,6 @@ #pragma once #include "barretenberg/ecc/curves/bn254/g1.hpp" -#include "commitment_key.hpp" #include "gemini/gemini.hpp" namespace proof_system::honk { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp index dca4f485139..557570d90d9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/composer_lib.hpp @@ -24,7 +24,7 @@ std::shared_ptr compute_verification_key_commo auto verification_key = std::make_shared( proving_key->circuit_size, proving_key->num_public_inputs, vrs); - auto commitment_key = typename Flavor::PCSParams::CommitmentKey(proving_key->circuit_size, proving_key->crs); + auto commitment_key = typename Flavor::CommitmentKey(proving_key->circuit_size, proving_key->crs); size_t poly_idx = 0; // TODO(#391) zip for (auto& polynomial : proving_key) { diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp index 72bbb4db476..a4a6b38e1de 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.cpp @@ -17,7 +17,7 @@ namespace proof_system::honk { * */ template StandardProver_::StandardProver_(const std::shared_ptr input_key, - const std::shared_ptr commitment_key) + const std::shared_ptr commitment_key) : key(input_key) , queue(commitment_key, transcript) , pcs_commitment_key(commitment_key) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp index dfd5afe2ab0..ac97786e4ff 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/prover.hpp @@ -21,12 +21,12 @@ template class StandardProver_ { using Polynomial = typename Flavor::Polynomial; using ProverPolynomials = typename Flavor::ProverPolynomials; using CommitmentLabels = typename Flavor::CommitmentLabels; - using PCSParams = typename Flavor::PCSParams; - using PCSCommitmentKey = typename Flavor::PCSParams::CommitmentKey; + using CommitmentKey = typename Flavor::CommitmentKey; using PCS = typename Flavor::PCS; + using Curve = typename Flavor::Curve; public: - explicit StandardProver_(std::shared_ptr input_key, std::shared_ptr commitment_key); + explicit StandardProver_(std::shared_ptr input_key, std::shared_ptr commitment_key); void execute_preamble_round(); void execute_wire_commitments_round(); @@ -68,15 +68,15 @@ template class StandardProver_ { Polynomial quotient_W; - work_queue queue; + work_queue queue; sumcheck::SumcheckOutput sumcheck_output; - pcs::gemini::ProverOutput gemini_output; - pcs::shplonk::ProverOutput shplonk_output; - std::shared_ptr pcs_commitment_key; + pcs::gemini::ProverOutput gemini_output; + pcs::shplonk::ProverOutput shplonk_output; + std::shared_ptr pcs_commitment_key; - using Gemini = pcs::gemini::GeminiProver_; - using Shplonk = pcs::shplonk::ShplonkProver_; + using Gemini = pcs::gemini::GeminiProver_; + using Shplonk = pcs::shplonk::ShplonkProver_; private: plonk::proof proof; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp index 807062806d6..b2f673b7cab 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.cpp @@ -2,7 +2,6 @@ #include "barretenberg/ecc/curves/bn254/fr.hpp" #include "barretenberg/ecc/curves/bn254/g1.hpp" #include "barretenberg/honk/pcs/claim.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/honk/proof_system/grand_product_library.hpp" #include "barretenberg/honk/proof_system/prover_library.hpp" #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" // will go away @@ -33,7 +32,7 @@ namespace proof_system::honk { * */ template UltraProver_::UltraProver_(std::shared_ptr input_key, - std::shared_ptr commitment_key) + std::shared_ptr commitment_key) : key(input_key) , queue(commitment_key, transcript) , pcs_commitment_key(commitment_key) diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp index 9d8c2209a26..4c711743921 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_prover.hpp @@ -17,16 +17,16 @@ namespace proof_system::honk { template class UltraProver_ { using FF = typename Flavor::FF; - using PCSParams = typename Flavor::PCSParams; using PCS = typename Flavor::PCS; - using PCSCommitmentKey = typename Flavor::PCSParams::CommitmentKey; + using CommitmentKey = typename Flavor::CommitmentKey; using ProvingKey = typename Flavor::ProvingKey; using Polynomial = typename Flavor::Polynomial; using ProverPolynomials = typename Flavor::ProverPolynomials; using CommitmentLabels = typename Flavor::CommitmentLabels; + using Curve = typename Flavor::Curve; public: - explicit UltraProver_(std::shared_ptr input_key, std::shared_ptr commitment_key); + explicit UltraProver_(std::shared_ptr input_key, std::shared_ptr commitment_key); void execute_preamble_round(); void execute_wire_commitments_round(); @@ -64,15 +64,15 @@ template class UltraProver_ { Polynomial quotient_W; - work_queue queue; + work_queue queue; sumcheck::SumcheckOutput sumcheck_output; - pcs::gemini::ProverOutput gemini_output; - pcs::shplonk::ProverOutput shplonk_output; - std::shared_ptr pcs_commitment_key; + pcs::gemini::ProverOutput gemini_output; + pcs::shplonk::ProverOutput shplonk_output; + std::shared_ptr pcs_commitment_key; - using Gemini = pcs::gemini::GeminiProver_; - using Shplonk = pcs::shplonk::ShplonkProver_; + using Gemini = pcs::gemini::GeminiProver_; + using Shplonk = pcs::shplonk::ShplonkProver_; private: plonk::proof proof; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp index 385b8a52ee4..ab6a6219df2 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.cpp @@ -37,10 +37,10 @@ template bool UltraVerifier_::verify_proof(const plonk using FF = typename Flavor::FF; using GroupElement = typename Flavor::GroupElement; using Commitment = typename Flavor::Commitment; - using PCSParams = typename Flavor::PCSParams; using PCS = typename Flavor::PCS; - using Gemini = pcs::gemini::GeminiVerifier_; - using Shplonk = pcs::shplonk::ShplonkVerifier_; + using Curve = typename Flavor::Curve; + using Gemini = pcs::gemini::GeminiVerifier_; + using Shplonk = pcs::shplonk::ShplonkVerifier_; using VerifierCommitments = typename Flavor::VerifierCommitments; using CommitmentLabels = typename Flavor::CommitmentLabels; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp index 9800497ba29..0f290f943ab 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/ultra_verifier.hpp @@ -10,7 +10,7 @@ template class UltraVerifier_ { using FF = typename Flavor::FF; using Commitment = typename Flavor::Commitment; using VerificationKey = typename Flavor::VerificationKey; - using PCSVerificationKey = typename Flavor::PCSParams::VerificationKey; + using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; public: explicit UltraVerifier_(std::shared_ptr verifier_key = nullptr); @@ -24,7 +24,7 @@ template class UltraVerifier_ { std::shared_ptr key; std::map commitments; std::map pcs_fr_elements; - std::shared_ptr pcs_verification_key; + std::shared_ptr pcs_verification_key; VerifierTranscript transcript; }; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp index 5772accd5c8..6631eb30dde 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.cpp @@ -58,9 +58,9 @@ template bool StandardVerifier_::verify_proof(const pl using FF = typename Flavor::FF; using GroupElement = typename Flavor::GroupElement; using Commitment = typename Flavor::Commitment; - using PCSParams = typename Flavor::PCSParams; - using Gemini = pcs::gemini::GeminiVerifier_; - using Shplonk = pcs::shplonk::ShplonkVerifier_; + using Curve = typename Flavor::Curve; + using Gemini = pcs::gemini::GeminiVerifier_; + using Shplonk = pcs::shplonk::ShplonkVerifier_; using PCS = typename Flavor::PCS; using VerifierCommitments = typename Flavor::VerifierCommitments; using CommitmentLabels = typename Flavor::CommitmentLabels; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp index 94bf19ed038..cf6120346ec 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/verifier.hpp @@ -9,7 +9,7 @@ template class StandardVerifier_ { using FF = typename Flavor::FF; using Commitment = typename Flavor::Commitment; using VerificationKey = typename Flavor::VerificationKey; - using PCSVerificationKey = typename Flavor::PCSParams::VerificationKey; + using VerifierCommitmentKey = typename Flavor::VerifierCommitmentKey; public: StandardVerifier_(std::shared_ptr verifier_key = nullptr); @@ -23,7 +23,7 @@ template class StandardVerifier_ { std::shared_ptr key; std::map commitments; std::map pcs_fr_elements; - std::shared_ptr pcs_verification_key; + std::shared_ptr pcs_verification_key; VerifierTranscript transcript; }; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/work_queue.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/work_queue.hpp index 8caecc341a2..bd052e5eccf 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/work_queue.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/honk/proof_system/work_queue.hpp @@ -10,14 +10,11 @@ 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 }; -// TODO(luke): This Params template parameter is the same type expected by e.g. components of the PCS. Eventually it -// should be replaced by some sort of Flavor concept that contains info about the Field etc. This should be resolved -// at the same time as the similar patterns in Gemini etc. -template class work_queue { - - using CommitmentKey = typename Params::CommitmentKey; - using FF = typename Params::Fr; - using Commitment = typename Params::Commitment; +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; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.cpp index caeb3dcd796..f0a84c077e3 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/composer_lib.cpp @@ -3,8 +3,8 @@ * @brief Contains some functions that are shared between the various Plonk composers. */ #include "composer_lib.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/srs/factories/crs_factory.hpp" +#include "barretenberg/honk/pcs/commitment_key.hpp" namespace proof_system::plonk { @@ -50,8 +50,8 @@ std::shared_ptr compute_verification_key_common( auto circuit_verification_key = std::make_shared( proving_key->circuit_size, proving_key->num_public_inputs, vrs, proving_key->circuit_type); // TODO(kesha): Dirty hack for now. Need to actually make commitment-agnositc - auto commitment_key = - proof_system::honk::pcs::kzg::Params::CommitmentKey(proving_key->circuit_size, proving_key->reference_string); + using KZGCommitmentKey = honk::pcs::CommitmentKey; + auto commitment_key = KZGCommitmentKey(proving_key->circuit_size, proving_key->reference_string); for (size_t i = 0; i < proving_key->polynomial_manifest.size(); ++i) { const auto& poly_info = proving_key->polynomial_manifest[i]; diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp index 66a3f6790aa..cc0c73577cf 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.cpp @@ -1,5 +1,4 @@ #include "standard_composer.hpp" -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/numeric/bitop/get_msb.hpp" #include "barretenberg/plonk/composer/composer_lib.hpp" #include "barretenberg/plonk/proof_system/commitment_scheme/kate_commitment_scheme.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.hpp index b954a49d67d..3ae5a1fbccb 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/plonk/composer/standard_composer.hpp @@ -1,6 +1,5 @@ #pragma once -#include "barretenberg/honk/pcs/commitment_key.hpp" #include "barretenberg/plonk/composer/composer_lib.hpp" #include "barretenberg/plonk/flavor/flavor.hpp" #include "barretenberg/plonk/proof_system/prover/prover.hpp" diff --git a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp index 99bbe7938c6..e7bc88628e9 100644 --- a/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp +++ b/circuits/cpp/barretenberg/cpp/src/barretenberg/proof_system/flavor/flavor.hpp @@ -68,6 +68,8 @@ #include "barretenberg/honk/sumcheck/polynomials/univariate.hpp" #include "barretenberg/polynomials/evaluation_domain.hpp" #include "barretenberg/proof_system/types/circuit_type.hpp" +#include "barretenberg/honk/pcs/commitment_key.hpp" +#include "barretenberg/honk/pcs/verification_key.hpp" #include #include #include