-
Notifications
You must be signed in to change notification settings - Fork 324
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
feat: eccvm sumcheck with commitments to round univariates #11206
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9a71a91
eccvm sumcheck butchered
iakovenkos 1b18f05
wip wip
iakovenkos e00dd04
eccvm verifies
iakovenkos 682c075
build fixed recursion failing
iakovenkos af6d6e6
debugging rec verifier
iakovenkos 9323abe
recursion fix
iakovenkos 230ce10
sumcheck output unified
iakovenkos f1eb3c5
remove self reduce
iakovenkos 8cb98b0
trying to constify eccvm recursive
iakovenkos 806ef49
Merge branch 'master' into si/fixing-eccvm-zk-sumcheck
iakovenkos 41654f3
Merge branch 'master' into si/fixing-eccvm-zk-sumcheck
iakovenkos c91f533
build fix
iakovenkos e1d1d11
Merge branch 'si/fixing-eccvm-zk-sumcheck' of github.com:AztecProtoco…
iakovenkos 7c73666
tests fixed
iakovenkos f525ef2
Merge branch 'master' into si/fixing-eccvm-zk-sumcheck
iakovenkos 6aec0f7
commited sumcheck test added
iakovenkos 74cd1a8
test cleaned up
iakovenkos f53a308
creating test for pcs
iakovenkos 2f1f99d
Merge branch 'si/fixing-eccvm-zk-sumcheck' of github.com:AztecProtoco…
iakovenkos 35df724
Merge branch 'master' into si/fixing-eccvm-zk-sumcheck
iakovenkos f4c3dc8
shplemini test + clean-up + figuring out constness
iakovenkos 1587941
const proof size + clean up + docs
iakovenkos e94c031
eccvm bench correction
iakovenkos 9e5e4e7
build fix
iakovenkos 51b3766
Merge branch 'master' into si/fixing-eccvm-zk-sumcheck
iakovenkos 6731c5d
more clean-up
iakovenkos fc108a3
Merge branch 'si/fixing-eccvm-zk-sumcheck' of github.com:AztecProtoco…
iakovenkos 80b6bf0
Merge branch 'master' into si/fixing-eccvm-zk-sumcheck
iakovenkos 48a1a18
eccvm recursive failure tests fixed
iakovenkos fdb62f1
bug fix
iakovenkos 4a3f07b
resolving comments
iakovenkos 98d304f
killed optional bool in sumcheck output + resolving comments
iakovenkos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
257 changes: 231 additions & 26 deletions
257
barretenberg/cpp/src/barretenberg/commitment_schemes/shplonk/shplemini.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
#include "barretenberg/commitment_schemes/utils/instance_witness_generator.hpp" | ||
#include "barretenberg/commitment_schemes/utils/test_settings.hpp" | ||
#include "barretenberg/ecc/curves/bn254/g1.hpp" | ||
#include "barretenberg/sumcheck/sumcheck.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
#include <vector> | ||
|
@@ -18,10 +19,53 @@ namespace bb { | |
|
||
template <class Flavor> class ShpleminiTest : public CommitmentTest<typename Flavor::Curve> { | ||
public: | ||
// Size of the test polynomials | ||
static constexpr size_t n = 32; | ||
static constexpr size_t log_n = 5; | ||
// Total number of random polynomials in each test | ||
static constexpr size_t num_polynomials = 5; | ||
// Number of shiftable polynomials | ||
static constexpr size_t num_shiftable = 2; | ||
|
||
// The length of the mock sumcheck univariates. | ||
static constexpr size_t sumcheck_univariate_length = 24; | ||
|
||
using Fr = typename Flavor::Curve::ScalarField; | ||
using GroupElement = typename Flavor::Curve::Element; | ||
using Commitment = typename Flavor::Curve::AffineElement; | ||
using CK = typename Flavor::CommitmentKey; | ||
|
||
void compute_sumcheck_opening_data(std::vector<bb::Polynomial<Fr>>& round_univariates, | ||
std::vector<Commitment>& sumcheck_commitments, | ||
std::vector<std::array<Fr, 3>>& sumcheck_evaluations, | ||
std::vector<Fr>& challenge, | ||
std::shared_ptr<CK>& ck) | ||
{ | ||
// Generate valid sumcheck polynomials of given length | ||
auto mock_sumcheck_polynomials = ZKSumcheckData<Flavor>(log_n, sumcheck_univariate_length); | ||
for (size_t idx = 0; idx < log_n; idx++) { | ||
bb::Polynomial<Fr> round_univariate = mock_sumcheck_polynomials.libra_univariates[idx]; | ||
|
||
round_univariate.at(0) += mock_sumcheck_polynomials.libra_running_sum; | ||
|
||
sumcheck_commitments.push_back(ck->commit(round_univariate)); | ||
|
||
sumcheck_evaluations.push_back({ round_univariate.at(0), | ||
round_univariate.evaluate(Fr(1)), | ||
round_univariate.evaluate(challenge[idx]) }); | ||
|
||
mock_sumcheck_polynomials.update_zk_sumcheck_data(challenge[idx], idx); | ||
round_univariates.push_back(round_univariate); | ||
} | ||
|
||
// Simulate the `const proof size` logic | ||
auto round_univariate = bb::Polynomial<Fr>(this->n); | ||
for (size_t idx = this->log_n; idx < CONST_PROOF_SIZE_LOG_N; idx++) { | ||
round_univariates.push_back(round_univariate); | ||
sumcheck_commitments.push_back(ck->commit(round_univariate)); | ||
sumcheck_evaluations.push_back({ Fr(0), Fr(0), Fr(0) }); | ||
} | ||
} | ||
}; | ||
|
||
using TestSettings = ::testing::Types<BN254Settings, GrumpkinSettings>; | ||
|
@@ -229,10 +273,10 @@ TYPED_TEST(ShpleminiTest, CorrectnessOfGeminiClaimBatching) | |
|
||
/** | ||
* @brief Test Shplemini with ZK data consisting of a hiding polynomial generated by GeminiProver and Libra polynomials | ||
* used to mask Sumcheck Round Univariates. | ||
* used to mask Sumcheck Round Univariates. This abstracts the PCS step in each ZK Flavor running over BN254. | ||
* | ||
*/ | ||
TYPED_TEST(ShpleminiTest, ShpleminiWithZK) | ||
TYPED_TEST(ShpleminiTest, ShpleminiZKNoSumcheckOpenings) | ||
{ | ||
using ZKData = ZKSumcheckData<TypeParam>; | ||
using Curve = TypeParam::Curve; | ||
|
@@ -259,8 +303,8 @@ TYPED_TEST(ShpleminiTest, ShpleminiWithZK) | |
const_size_mle_opening_point.begin() + this->log_n); | ||
|
||
// Generate random prover polynomials, compute their evaluations and commitments | ||
auto pcs_instance_witness = | ||
InstanceWitnessGenerator<Curve>(this->n, this->num_polynomials, this->num_shiftable, mle_opening_point, ck); | ||
InstanceWitnessGenerator<Curve> pcs_instance_witness( | ||
this->n, this->num_polynomials, this->num_shiftable, mle_opening_point, ck); | ||
|
||
// Compute the sum of the Libra constant term and Libra univariates evaluated at Sumcheck challenges | ||
const Fr claimed_inner_product = SmallSubgroupIPAProver<TypeParam>::compute_claimed_inner_product( | ||
|
@@ -269,7 +313,7 @@ TYPED_TEST(ShpleminiTest, ShpleminiWithZK) | |
prover_transcript->template send_to_verifier("Libra:claimed_evaluation", claimed_inner_product); | ||
|
||
// Instantiate SmallSubgroupIPAProver, this prover sends commitments to Big Sum and Quotient polynomials | ||
auto small_subgroup_ipa_prover = SmallSubgroupIPAProver<TypeParam>( | ||
SmallSubgroupIPAProver<TypeParam> small_subgroup_ipa_prover( | ||
zk_sumcheck_data, const_size_mle_opening_point, claimed_inner_product, prover_transcript, ck); | ||
|
||
// Reduce to KZG or IPA based on the curve used in the test Flavor | ||
|
@@ -341,4 +385,116 @@ TYPED_TEST(ShpleminiTest, ShpleminiWithZK) | |
} | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably, we need more granular tests for all zk methods in Shplemini, but this one covers the situation we currently have in ECCVM |
||
* @brief Test Shplemini with ZK data consisting of a hiding polynomial generated by GeminiProver, Libra polynomials | ||
* used to mask Sumcheck Round Univariates and prove/verify the claimed evaluations of committed sumcheck round | ||
* univariates. This test abstracts the PCS step in each ZK Flavor running over Grumpkin. | ||
* | ||
*/ | ||
TYPED_TEST(ShpleminiTest, ShpleminiZKWithSumcheckOpenings) | ||
{ | ||
using Curve = TypeParam::Curve; | ||
using Fr = typename Curve::ScalarField; | ||
using Commitment = typename Curve::AffineElement; | ||
using CK = typename TypeParam::CommitmentKey; | ||
|
||
using ShpleminiProver = ShpleminiProver_<Curve>; | ||
using ShpleminiVerifier = ShpleminiVerifier_<Curve>; | ||
|
||
std::shared_ptr<CK> ck = create_commitment_key<CK>(4096); | ||
|
||
// Generate Sumcheck challenge, current implementation of Sumcheck Round Univariates batching in Shplemini assumes | ||
// that the challenge is of CONST_PROOF_SIZE_LOG_N | ||
std::vector<Fr> challenge = this->random_evaluation_point(CONST_PROOF_SIZE_LOG_N); | ||
|
||
auto prover_transcript = TypeParam::Transcript::prover_init_empty(); | ||
|
||
// Generate masking polynomials for Sumcheck Round Univariates | ||
ZKSumcheckData<TypeParam> zk_sumcheck_data(this->log_n, prover_transcript, ck); | ||
// Generate mock witness | ||
InstanceWitnessGenerator<Curve> pcs_instance_witness(this->n, 1); | ||
|
||
// Generate valid sumcheck polynomials of given length | ||
pcs_instance_witness.template compute_sumcheck_opening_data<TypeParam>( | ||
this->n, this->log_n, this->sumcheck_univariate_length, challenge, ck); | ||
|
||
// Compute the sum of the Libra constant term and Libra univariates evaluated at Sumcheck challenges | ||
const Fr claimed_inner_product = | ||
SmallSubgroupIPAProver<TypeParam>::compute_claimed_inner_product(zk_sumcheck_data, challenge, this->log_n); | ||
|
||
prover_transcript->template send_to_verifier("Libra:claimed_evaluation", claimed_inner_product); | ||
|
||
// Instantiate SmallSubgroupIPAProver, this prover sends commitments to Big Sum and Quotient polynomials | ||
SmallSubgroupIPAProver<TypeParam> small_subgroup_ipa_prover( | ||
zk_sumcheck_data, challenge, claimed_inner_product, prover_transcript, ck); | ||
|
||
// Reduce proving to a single claimed fed to KZG or IPA | ||
const auto opening_claim = ShpleminiProver::prove(this->n, | ||
RefVector(pcs_instance_witness.unshifted_polynomials), | ||
RefVector(pcs_instance_witness.to_be_shifted_polynomials), | ||
challenge, | ||
ck, | ||
prover_transcript, | ||
small_subgroup_ipa_prover.get_witness_polynomials(), | ||
pcs_instance_witness.round_univariates, | ||
pcs_instance_witness.sumcheck_evaluations); | ||
|
||
if constexpr (std::is_same_v<TypeParam, GrumpkinSettings>) { | ||
IPA<Curve>::compute_opening_proof(this->ck(), opening_claim, prover_transcript); | ||
} else { | ||
KZG<Curve>::compute_opening_proof(this->ck(), opening_claim, prover_transcript); | ||
} | ||
|
||
// Initialize verifier's transcript | ||
auto verifier_transcript = NativeTranscript::verifier_init_empty(prover_transcript); | ||
|
||
std::array<Commitment, NUM_LIBRA_COMMITMENTS> libra_commitments = {}; | ||
libra_commitments[0] = | ||
verifier_transcript->template receive_from_prover<Commitment>("Libra:concatenation_commitment"); | ||
|
||
// Place Libra data to the transcript | ||
const Fr libra_total_sum = verifier_transcript->template receive_from_prover<Fr>("Libra:Sum"); | ||
const Fr libra_challenge = verifier_transcript->template get_challenge<Fr>("Libra:Challenge"); | ||
const Fr libra_evaluation = verifier_transcript->template receive_from_prover<Fr>("Libra:claimed_evaluation"); | ||
|
||
// Check that transcript is consistent | ||
EXPECT_EQ(libra_total_sum, zk_sumcheck_data.libra_total_sum); | ||
EXPECT_EQ(libra_challenge, zk_sumcheck_data.libra_challenge); | ||
EXPECT_EQ(libra_evaluation, claimed_inner_product); | ||
|
||
// Finalize the array of Libra/SmallSubgroupIpa commitments | ||
libra_commitments[1] = verifier_transcript->template receive_from_prover<Commitment>("Libra:big_sum_commitment"); | ||
libra_commitments[2] = verifier_transcript->template receive_from_prover<Commitment>("Libra:quotient_commitment"); | ||
|
||
bool consistency_checked = true; | ||
|
||
// Run Shplemini | ||
const auto batch_opening_claim = | ||
ShpleminiVerifier::compute_batch_opening_claim(this->n, | ||
RefVector(pcs_instance_witness.unshifted_commitments), | ||
{}, | ||
RefVector(pcs_instance_witness.unshifted_evals), | ||
{}, | ||
challenge, | ||
this->vk()->get_g1_identity(), | ||
verifier_transcript, | ||
{}, | ||
true, | ||
&consistency_checked, | ||
libra_commitments, | ||
libra_evaluation, | ||
pcs_instance_witness.sumcheck_commitments, | ||
pcs_instance_witness.sumcheck_evaluations); | ||
// Verify claim using KZG or IPA | ||
if constexpr (std::is_same_v<TypeParam, GrumpkinSettings>) { | ||
auto result = | ||
IPA<Curve>::reduce_verify_batch_opening_claim(batch_opening_claim, this->vk(), verifier_transcript); | ||
EXPECT_EQ(result, true); | ||
} else { | ||
const auto pairing_points = | ||
KZG<Curve>::reduce_verify_batch_opening_claim(batch_opening_claim, verifier_transcript); | ||
// Final pairing check: e([Q] - [Q_z] + z[W], [1]_2) = e([W], [x]_2) | ||
EXPECT_EQ(this->vk()->pairing_check(pairing_points[0], pairing_points[1]), true); | ||
} | ||
} | ||
} // namespace bb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was hitting an assert in ipa