From 57ac1abc265928c58e1624a82b89c1bf490d724d Mon Sep 17 00:00:00 2001 From: mmagician Date: Thu, 28 Sep 2023 15:14:56 +0200 Subject: [PATCH 1/7] temp: remove default impl of open/check combinations from marlin_pc --- src/marlin/marlin_pc/mod.rs | 58 ++----------------------------------- 1 file changed, 2 insertions(+), 56 deletions(-) diff --git a/src/marlin/marlin_pc/mod.rs b/src/marlin/marlin_pc/mod.rs index a14228fa..de2182c7 100644 --- a/src/marlin/marlin_pc/mod.rs +++ b/src/marlin/marlin_pc/mod.rs @@ -1,7 +1,7 @@ use crate::{kzg10, marlin::Marlin, PCCommitterKey, CHALLENGE_SIZE}; use crate::{BTreeMap, BTreeSet, ToString, Vec}; -use crate::{BatchLCProof, Error, Evaluations, QuerySet}; -use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; +use crate::{Error, Evaluations, QuerySet}; +use crate::{LabeledCommitment, LabeledPolynomial}; use crate::{PCRandomness, PCUniversalParams, PolynomialCommitment}; use ark_ec::pairing::Pairing; use ark_ec::AffineRepr; @@ -403,60 +403,6 @@ where Ok(result) } - fn open_combinations<'a>( - ck: &Self::CommitterKey, - lc_s: impl IntoIterator>, - polynomials: impl IntoIterator>, - commitments: impl IntoIterator>, - query_set: &QuerySet, - opening_challenges: &mut ChallengeGenerator, - rands: impl IntoIterator, - rng: Option<&mut dyn RngCore>, - ) -> Result, Self::Error> - where - P: 'a, - Self::Randomness: 'a, - Self::Commitment: 'a, - { - Marlin::::open_combinations( - ck, - lc_s, - polynomials, - commitments, - query_set, - opening_challenges, - rands, - rng, - ) - } - - /// Checks that `values` are the true evaluations at `query_set` of the polynomials - /// committed in `labeled_commitments`. - fn check_combinations<'a, R: RngCore>( - vk: &Self::VerifierKey, - lc_s: impl IntoIterator>, - commitments: impl IntoIterator>, - query_set: &QuerySet, - evaluations: &Evaluations, - proof: &BatchLCProof, - opening_challenges: &mut ChallengeGenerator, - rng: &mut R, - ) -> Result - where - Self::Commitment: 'a, - { - Marlin::::check_combinations( - vk, - lc_s, - commitments, - query_set, - evaluations, - proof, - opening_challenges, - rng, - ) - } - /// On input a list of labeled polynomials and a query set, `open` outputs a proof of evaluation /// of the polynomials at the points in the query set. fn batch_open<'a>( From dcffaecc6b621174db3048811183b3960bd12f0d Mon Sep 17 00:00:00 2001 From: mmagician Date: Thu, 28 Sep 2023 16:32:43 +0200 Subject: [PATCH 2/7] fix check_combinations fix combinations remove prints remove old comments --- src/lib.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 772f7f3d..a07895b2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -354,16 +354,21 @@ pub trait PolynomialCommitment, S: Cryptographic Self::Commitment: 'a, { let BatchLCProof { proof, evals } = proof; - let lc_s = BTreeMap::from_iter(linear_combinations.into_iter().map(|lc| (lc.label(), lc))); let poly_query_set = lc_query_set_to_poly_query_set(lc_s.values().copied(), eqn_query_set); + let sorted_by_poly_and_query_label: BTreeSet<_> = poly_query_set + .iter() + .map(|(poly_label, v)| ((poly_label.clone(), v.1.clone()), v.0.clone())) + .collect(); + let poly_evals = Evaluations::from_iter( - poly_query_set + sorted_by_poly_and_query_label .iter() - .map(|(_, point)| point) - .cloned() - .zip(evals.clone().unwrap()), + .zip(evals.clone().unwrap()) + .map(|(((poly_label, point), _query_label), eval)| { + ((poly_label.clone(), point.clone()), eval) + }), ); for &(ref lc_label, (_, ref point)) in eqn_query_set { @@ -381,7 +386,9 @@ pub trait PolynomialCommitment, S: Cryptographic LCTerm::One => F::one(), LCTerm::PolyLabel(l) => *poly_evals .get(&(l.clone().into(), point.clone())) - .ok_or(Error::MissingEvaluation { label: l.clone() })?, + .ok_or(Error::MissingEvaluation { + label: format!("{}-{:?}", l.clone(), point.clone()), + })?, }; actual_rhs += &(*coeff * eval); From a209c8c3e2c00f8a11a3be032b2884d3e7611733 Mon Sep 17 00:00:00 2001 From: mmagician Date: Thu, 28 Sep 2023 15:14:56 +0200 Subject: [PATCH 3/7] Revert "temp: remove default impl of open/check combinations from marlin_pc" This reverts commit 25d4c8c3114731c9a6e28eab4a85761db6ce4f2d. --- src/marlin/marlin_pc/mod.rs | 58 +++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/src/marlin/marlin_pc/mod.rs b/src/marlin/marlin_pc/mod.rs index de2182c7..a14228fa 100644 --- a/src/marlin/marlin_pc/mod.rs +++ b/src/marlin/marlin_pc/mod.rs @@ -1,7 +1,7 @@ use crate::{kzg10, marlin::Marlin, PCCommitterKey, CHALLENGE_SIZE}; use crate::{BTreeMap, BTreeSet, ToString, Vec}; -use crate::{Error, Evaluations, QuerySet}; -use crate::{LabeledCommitment, LabeledPolynomial}; +use crate::{BatchLCProof, Error, Evaluations, QuerySet}; +use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCRandomness, PCUniversalParams, PolynomialCommitment}; use ark_ec::pairing::Pairing; use ark_ec::AffineRepr; @@ -403,6 +403,60 @@ where Ok(result) } + fn open_combinations<'a>( + ck: &Self::CommitterKey, + lc_s: impl IntoIterator>, + polynomials: impl IntoIterator>, + commitments: impl IntoIterator>, + query_set: &QuerySet, + opening_challenges: &mut ChallengeGenerator, + rands: impl IntoIterator, + rng: Option<&mut dyn RngCore>, + ) -> Result, Self::Error> + where + P: 'a, + Self::Randomness: 'a, + Self::Commitment: 'a, + { + Marlin::::open_combinations( + ck, + lc_s, + polynomials, + commitments, + query_set, + opening_challenges, + rands, + rng, + ) + } + + /// Checks that `values` are the true evaluations at `query_set` of the polynomials + /// committed in `labeled_commitments`. + fn check_combinations<'a, R: RngCore>( + vk: &Self::VerifierKey, + lc_s: impl IntoIterator>, + commitments: impl IntoIterator>, + query_set: &QuerySet, + evaluations: &Evaluations, + proof: &BatchLCProof, + opening_challenges: &mut ChallengeGenerator, + rng: &mut R, + ) -> Result + where + Self::Commitment: 'a, + { + Marlin::::check_combinations( + vk, + lc_s, + commitments, + query_set, + evaluations, + proof, + opening_challenges, + rng, + ) + } + /// On input a list of labeled polynomials and a query set, `open` outputs a proof of evaluation /// of the polynomials at the points in the query set. fn batch_open<'a>( From 8c82864bf48f22977d0dcf656af580a30c652d8a Mon Sep 17 00:00:00 2001 From: mmagician Date: Thu, 28 Sep 2023 15:55:26 +0200 Subject: [PATCH 4/7] remove deprecated deny --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index a07895b2..cb29ab0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ #![cfg_attr(not(feature = "std"), no_std)] //! A crate for polynomial commitment schemes. #![deny(unused_import_braces, unused_qualifications, trivial_casts)] -#![deny(trivial_numeric_casts, private_in_public, variant_size_differences)] +#![deny(trivial_numeric_casts, variant_size_differences)] #![deny(stable_features, unreachable_pub, non_shorthand_field_patterns)] #![deny(unused_attributes, unused_mut)] #![deny(missing_docs)] From afd07092de785855ddce9165986b4c67047ea9e9 Mon Sep 17 00:00:00 2001 From: mmagician Date: Fri, 29 Sep 2023 10:24:13 +0200 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Pratyush Mishra --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cb29ab0b..5d2911d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -358,8 +358,9 @@ pub trait PolynomialCommitment, S: Cryptographic let poly_query_set = lc_query_set_to_poly_query_set(lc_s.values().copied(), eqn_query_set); let sorted_by_poly_and_query_label: BTreeSet<_> = poly_query_set - .iter() - .map(|(poly_label, v)| ((poly_label.clone(), v.1.clone()), v.0.clone())) + .clone() + .into_iter() + .map(|(poly_label, v)| ((poly_label.clone(), v.1), v.0)) .collect(); let poly_evals = Evaluations::from_iter( @@ -367,7 +368,7 @@ pub trait PolynomialCommitment, S: Cryptographic .iter() .zip(evals.clone().unwrap()) .map(|(((poly_label, point), _query_label), eval)| { - ((poly_label.clone(), point.clone()), eval) + ((poly_label, point), eval) }), ); From fe78ab818e6e7855f7c79e61af4c2683cd42fe75 Mon Sep 17 00:00:00 2001 From: mmagician Date: Fri, 29 Sep 2023 10:25:57 +0200 Subject: [PATCH 6/7] apply suggestions from code review iter -> into_iter --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 5d2911d1..e788dfc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -365,7 +365,7 @@ pub trait PolynomialCommitment, S: Cryptographic let poly_evals = Evaluations::from_iter( sorted_by_poly_and_query_label - .iter() + .into_iter() .zip(evals.clone().unwrap()) .map(|(((poly_label, point), _query_label), eval)| { ((poly_label, point), eval) From bff82551235d07e8a160751a22a83611ea04d78f Mon Sep 17 00:00:00 2001 From: mmagician Date: Fri, 29 Sep 2023 10:27:43 +0200 Subject: [PATCH 7/7] format after fixes --- src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e788dfc3..08cf68eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -367,9 +367,7 @@ pub trait PolynomialCommitment, S: Cryptographic sorted_by_poly_and_query_label .into_iter() .zip(evals.clone().unwrap()) - .map(|(((poly_label, point), _query_label), eval)| { - ((poly_label, point), eval) - }), + .map(|(((poly_label, point), _query_label), eval)| ((poly_label, point), eval)), ); for &(ref lc_label, (_, ref point)) in eqn_query_set {