Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove Params concept #1541

Merged
merged 7 commits into from
Aug 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some cleanup and comments
  • Loading branch information
ledwards2225 committed Aug 12, 2023
commit aa180a4867ec80b2faba8bd1241813da588aaa0b
Original file line number Diff line number Diff line change
@@ -23,51 +23,45 @@

namespace proof_system::honk::pcs {

// using Curve = curve::BN254;

/**
* @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.
*
*
*/
template <class Curve>
class CommitmentKey {
* @brief CommitmentKey object over a pairing group 𝔾₁, using a structured reference string (SRS).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only applicable for KZG, for IPA the srs is random points in G_1

* 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.
*
*/
template <class Curve> class CommitmentKey {

using Fr = typename Curve::ScalarField;
using Commitment = typename Curve::AffineElement;

public:
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<barretenberg::srs::factories::CrsFactory<Curve>> crs_factory)
* @brief Construct a new Kate Commitment Key object from existing SRS
*
* @param n
* @param path
*
*/
CommitmentKey(const size_t num_points, std::shared_ptr<barretenberg::srs::factories::CrsFactory<Curve>> 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<barretenberg::srs::factories::ProverCrs<Curve>> prover_crs)
CommitmentKey(const size_t num_points, std::shared_ptr<barretenberg::srs::factories::ProverCrs<Curve>> 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
*/
* @brief Uses the ProverSRS to create a commitment to p(X)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, there are comments about the SRS for IPA in the ipa namespace of the previous version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected. thanks

*
* @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<const Fr> polynomial)
{
const size_t degree = polynomial.size();
Original file line number Diff line number Diff line change
@@ -9,38 +9,33 @@
#include <string_view>

#include "barretenberg/ecc/curves/bn254/g1.hpp"
#include "barretenberg/polynomials/polynomial.hpp"
#include "barretenberg/srs/factories/file_crs_factory.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"

namespace proof_system::honk::pcs {

using KZGCommitmentKey = CommitmentKey<curve::BN254>;
using IPACommitmentKey = CommitmentKey<curve::Grumpkin>;
using KZGVerificationKey = VerificationKey<curve::BN254>;
using IPAVerificationKey = VerificationKey<curve::Grumpkin>;

template <class CK> inline std::shared_ptr<CK> CreateCommitmentKey();

template <> inline std::shared_ptr<KZGCommitmentKey> CreateCommitmentKey<KZGCommitmentKey>()
template <> inline std::shared_ptr<CommitmentKey<curve::BN254>> CreateCommitmentKey<CommitmentKey<curve::BN254>>()
{
constexpr size_t n = 4096;
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> crs_factory(
new barretenberg::srs::factories::FileCrsFactory<curve::BN254>("../srs_db/ignition", 4096));
return std::make_shared<KZGCommitmentKey>(n, crs_factory);
return std::make_shared<CommitmentKey<curve::BN254>>(n, crs_factory);
}
// For IPA
template <> inline std::shared_ptr<IPACommitmentKey> CreateCommitmentKey<IPACommitmentKey>()
template <> inline std::shared_ptr<CommitmentKey<curve::Grumpkin>> CreateCommitmentKey<CommitmentKey<curve::Grumpkin>>()
{
constexpr size_t n = 4096;
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::Grumpkin>> crs_factory(
new barretenberg::srs::factories::FileCrsFactory<curve::Grumpkin>("../srs_db/grumpkin", 4096));
return std::make_shared<IPACommitmentKey>(n, crs_factory);
return std::make_shared<CommitmentKey<curve::Grumpkin>>(n, crs_factory);
}

template <typename CK> inline std::shared_ptr<CK> CreateCommitmentKey()
@@ -51,20 +46,21 @@ template <typename CK> inline std::shared_ptr<CK> CreateCommitmentKey()

template <class VK> inline std::shared_ptr<VK> CreateVerificationKey();

template <> inline std::shared_ptr<KZGVerificationKey> CreateVerificationKey<KZGVerificationKey>()
template <> inline std::shared_ptr<VerificationKey<curve::BN254>> CreateVerificationKey<VerificationKey<curve::BN254>>()
{
constexpr size_t n = 4096;
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::BN254>> crs_factory(
new barretenberg::srs::factories::FileCrsFactory<curve::BN254>("../srs_db/ignition", 4096));
return std::make_shared<KZGVerificationKey>(n, crs_factory);
return std::make_shared<VerificationKey<curve::BN254>>(n, crs_factory);
}
// For IPA
template <> inline std::shared_ptr<IPAVerificationKey> CreateVerificationKey<IPAVerificationKey>()
template <>
inline std::shared_ptr<VerificationKey<curve::Grumpkin>> CreateVerificationKey<VerificationKey<curve::Grumpkin>>()
{
constexpr size_t n = 4096;
std::shared_ptr<barretenberg::srs::factories::CrsFactory<curve::Grumpkin>> crs_factory(
new barretenberg::srs::factories::FileCrsFactory<curve::Grumpkin>("../srs_db/grumpkin", 4096));
return std::make_shared<IPAVerificationKey>(n, crs_factory);
return std::make_shared<VerificationKey<curve::Grumpkin>>(n, crs_factory);
}
template <typename VK> inline std::shared_ptr<VK> CreateVerificationKey()
// requires std::default_initializable<VK>
Original file line number Diff line number Diff line change
@@ -9,14 +9,16 @@
#include "ipa.hpp"
#include <gtest/gtest.h>
using namespace barretenberg;
namespace proof_system::honk::pcs::ipa {
namespace proof_system::honk::pcs::ipa::test {

class IPATest : public CommitmentTest<curve::Grumpkin> {
using Curve = curve::Grumpkin;

class IPATest : public CommitmentTest<Curve> {
public:
using Fr = typename curve::Grumpkin::ScalarField;
using GroupElement = typename curve::Grumpkin::Element;
using CK = CommitmentKey<curve::Grumpkin>;
using VK = VerificationKey<curve::Grumpkin>;
using Fr = typename Curve::ScalarField;
using GroupElement = typename Curve::Element;
using CK = CommitmentKey<Curve>;
using VK = VerificationKey<Curve>;
using Polynomial = barretenberg::Polynomial<Fr>;
};

@@ -58,14 +60,14 @@ TEST_F(IPATest, Commit)

TEST_F(IPATest, Open)
{
using IPA = IPA<curve::Grumpkin>;
using IPA = IPA<Curve>;
// 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<curve::Grumpkin> opening_pair = { x, eval };
const OpeningClaim<curve::Grumpkin> opening_claim{ opening_pair, commitment };
const OpeningPair<Curve> opening_pair = { x, eval };
const OpeningClaim<Curve> opening_claim{ opening_pair, commitment };

// initialize empty prover transcript
ProverTranscript<Fr> prover_transcript;
@@ -82,11 +84,11 @@ TEST_F(IPATest, Open)

TEST_F(IPATest, GeminiShplonkIPAWithShift)
{
using IPA = IPA<curve::Grumpkin>;
using ShplonkProver = shplonk::ShplonkProver_<curve::Grumpkin>;
using ShplonkVerifier = shplonk::ShplonkVerifier_<curve::Grumpkin>;
using GeminiProver = gemini::GeminiProver_<curve::Grumpkin>;
using GeminiVerifier = gemini::GeminiVerifier_<curve::Grumpkin>;
using IPA = IPA<Curve>;
using ShplonkProver = shplonk::ShplonkProver_<Curve>;
using ShplonkVerifier = shplonk::ShplonkVerifier_<Curve>;
using GeminiProver = gemini::GeminiProver_<Curve>;
using GeminiVerifier = gemini::GeminiVerifier_<Curve>;

const size_t n = 8;
const size_t log_n = 3;
@@ -172,4 +174,4 @@ TEST_F(IPATest, GeminiShplonkIPAWithShift)

EXPECT_EQ(verified, true);
}
} // namespace proof_system::honk::pcs::ipa
} // namespace proof_system::honk::pcs::ipa::test
Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@ 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 Curve CommitmentScheme parameters
* @tparam Curve EC parameters
*/
template <typename Curve> using OutputWitness = barretenberg::Polynomial<typename Curve::ScalarField>;

/**
* @brief Prover output (claim=([G], r, 0), witness = G(X), proof = [Q])
* that can be passed on to a univariate opening protocol.
*
* @tparam Curve CommitmentScheme parameters
* @tparam Curve EC parameters
*/
template <typename Curve> struct ProverOutput {
OpeningPair<Curve> opening_pair; // single opening pair (challenge, evaluation)
@@ -41,7 +41,7 @@ template <typename Curve> struct ProverOutput {
/**
* @brief Shplonk Prover
*
* @tparam Curve for the given commitment scheme
* @tparam Curve EC parameters
*/
template <typename Curve> class ShplonkProver_ {
using Fr = typename Curve::ScalarField;
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@
namespace proof_system::honk::pcs::shplonk {
template <class Params> class ShplonkTest : public CommitmentTest<Params> {};

using ParamsTypes = ::testing::Types<curve::BN254, curve::Grumpkin>;
TYPED_TEST_SUITE(ShplonkTest, ParamsTypes);
using CurveTypes = ::testing::Types<curve::BN254, curve::Grumpkin>;
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)
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#pragma once

/**
* @brief Provides interfaces for different 'CommitmentKey' classes.
* @brief Provides interfaces for different PCS 'VerificationKey' classes.
*
* TODO(#218)(Mara): This class should handle any modification to the SRS (e.g compute pippenger point table) to
* simplify the codebase.
*/

#include "barretenberg/ecc/curves/bn254/bn254.hpp"
@@ -26,6 +24,11 @@ namespace proof_system::honk::pcs {

template <class Curve> class VerificationKey;

/**
* @brief Specialization for bn254
*
* @tparam curve::BN254
*/
template <> class VerificationKey<curve::BN254> {
using Curve = curve::BN254;
using GroupElement = typename Curve::Element;
@@ -38,7 +41,7 @@ template <> class VerificationKey<curve::BN254> {
* @brief Construct a new Kate Verification Key object from existing SRS
*
* @param num_points
* @paramsrs verifier G2 point
* @param srs verifier G2 point
*/
VerificationKey([[maybe_unused]] size_t num_points,
std::shared_ptr<barretenberg::srs::factories::CrsFactory<Curve>> crs_factory)
@@ -65,6 +68,11 @@ template <> class VerificationKey<curve::BN254> {
std::shared_ptr<barretenberg::srs::factories::VerifierCrs<Curve>> srs;
};

/**
* @brief Specialization for Grumpkin
*
* @tparam curve::Grumpkin
*/
template <> class VerificationKey<curve::Grumpkin> {
using Curve = curve::Grumpkin;
using GroupElement = typename Curve::Element;