From e97c95a1ec3b350876303fae0b9432d821457f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20G=C3=B3rny?= Date: Thu, 30 Jun 2022 12:14:44 +0200 Subject: [PATCH 1/9] Rename UVPolynomial to DenseUVPolynomial needed due to https://github.com/arkworks-rs/algebra/pull/412 --- src/ipa_pc/mod.rs | 10 +++---- src/kzg10/data_structures.rs | 14 ++++----- src/kzg10/mod.rs | 16 +++++----- src/lib.rs | 2 +- src/marlin/marlin_pc/data_structures.rs | 14 ++++----- src/marlin/marlin_pc/mod.rs | 10 +++---- src/marlin/marlin_pst13_pc/data_structures.rs | 30 +++++++++---------- src/marlin/marlin_pst13_pc/mod.rs | 10 +++---- src/sonic_pc/mod.rs | 10 +++---- src/streaming_kzg/mod.rs | 2 +- src/streaming_kzg/tests.rs | 8 ++--- src/streaming_kzg/time.rs | 2 +- 12 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index 4aed822e..ff76ef3a 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -1,5 +1,5 @@ use crate::{BTreeMap, BTreeSet, String, ToString, Vec, CHALLENGE_SIZE}; -use crate::{BatchLCProof, Error, Evaluations, QuerySet, UVPolynomial}; +use crate::{BatchLCProof, Error, Evaluations, QuerySet, DenseUVPolynomial}; use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, PolynomialCommitment}; @@ -34,7 +34,7 @@ use digest::Digest; pub struct InnerProductArgPC< G: AffineCurve, D: Digest, - P: UVPolynomial, + P: DenseUVPolynomial, S: CryptographicSponge, > { _projective: PhantomData, @@ -47,7 +47,7 @@ impl InnerProductArgPC where G: AffineCurve, D: Digest, - P: UVPolynomial, + P: DenseUVPolynomial, S: CryptographicSponge, { /// `PROTOCOL_NAME` is used as a seed for the setup function. @@ -316,7 +316,7 @@ impl PolynomialCommitment for InnerProductArgP where G: AffineCurve, D: Digest, - P: UVPolynomial, + P: DenseUVPolynomial, S: CryptographicSponge, { type UniversalParams = UniversalParams; @@ -1042,7 +1042,7 @@ mod tests { use ark_ec::AffineCurve; use ark_ed_on_bls12_381::{EdwardsAffine, Fr}; use ark_ff::PrimeField; - use ark_poly::{univariate::DensePolynomial as DensePoly, UVPolynomial}; + use ark_poly::{univariate::DensePolynomial as DensePoly, DenseUVPolynomial}; use ark_sponge::poseidon::PoseidonSponge; use blake2::Blake2s; use rand_chacha::ChaCha20Rng; diff --git a/src/kzg10/data_structures.rs b/src/kzg10/data_structures.rs index 640fccbe..778fbf7a 100644 --- a/src/kzg10/data_structures.rs +++ b/src/kzg10/data_structures.rs @@ -501,13 +501,13 @@ impl PreparedCommitment { PartialEq(bound = ""), Eq(bound = "") )] -pub struct Randomness> { +pub struct Randomness> { /// For KZG10, the commitment randomness is a random polynomial. pub blinding_polynomial: P, _field: PhantomData, } -impl> Randomness { +impl> Randomness { /// Does `self` provide any hiding properties to the corresponding commitment? /// `self.is_hiding() == true` only if the underlying polynomial is non-zero. #[inline] @@ -522,7 +522,7 @@ impl> Randomness { } } -impl> PCRandomness for Randomness { +impl> PCRandomness for Randomness { fn empty() -> Self { Self { blinding_polynomial: P::zero(), @@ -538,7 +538,7 @@ impl> PCRandomness for Randomness { } } -impl<'a, F: PrimeField, P: UVPolynomial> Add<&'a Randomness> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<&'a Randomness> for Randomness { type Output = Self; #[inline] @@ -548,7 +548,7 @@ impl<'a, F: PrimeField, P: UVPolynomial> Add<&'a Randomness> for Random } } -impl<'a, F: PrimeField, P: UVPolynomial> Add<(F, &'a Randomness)> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<(F, &'a Randomness)> for Randomness { type Output = Self; #[inline] @@ -558,14 +558,14 @@ impl<'a, F: PrimeField, P: UVPolynomial> Add<(F, &'a Randomness)> for R } } -impl<'a, F: PrimeField, P: UVPolynomial> AddAssign<&'a Randomness> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> AddAssign<&'a Randomness> for Randomness { #[inline] fn add_assign(&mut self, other: &'a Self) { self.blinding_polynomial += &other.blinding_polynomial; } } -impl<'a, F: PrimeField, P: UVPolynomial> AddAssign<(F, &'a Randomness)> +impl<'a, F: PrimeField, P: DenseUVPolynomial> AddAssign<(F, &'a Randomness)> for Randomness { #[inline] diff --git a/src/kzg10/mod.rs b/src/kzg10/mod.rs index fd1bcd71..0c418736 100644 --- a/src/kzg10/mod.rs +++ b/src/kzg10/mod.rs @@ -9,7 +9,7 @@ use crate::{BTreeMap, Error, LabeledPolynomial, PCRandomness, ToString, Vec}; use ark_ec::msm::{FixedBase, VariableBase}; use ark_ec::{group::Group, AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{One, PrimeField, UniformRand, Zero}; -use ark_poly::UVPolynomial; +use ark_poly::DenseUVPolynomial; use ark_std::{format, marker::PhantomData, ops::Div, vec}; use ark_std::rand::RngCore; @@ -23,7 +23,7 @@ pub use data_structures::*; /// [Kate, Zaverucha and Goldbgerg][kzg10] /// /// [kzg10]: http://cacr.uwaterloo.ca/techreports/2010/cacr2010-10.pdf -pub struct KZG10> { +pub struct KZG10> { _engine: PhantomData, _poly: PhantomData

, } @@ -31,7 +31,7 @@ pub struct KZG10> { impl KZG10 where E: PairingEngine, - P: UVPolynomial, + P: DenseUVPolynomial, for<'a, 'b> &'a P: Div<&'b P, Output = P>, { /// Constructs public parameters when given as input the maximum degree `degree` @@ -416,7 +416,7 @@ where } } -fn skip_leading_zeros_and_convert_to_bigints>( +fn skip_leading_zeros_and_convert_to_bigints>( p: &P, ) -> (usize, Vec) { let mut num_leading_zeros = 0; @@ -453,7 +453,7 @@ mod tests { type UniPoly_377 = DensePoly<::Fr>; type KZG_Bls12_381 = KZG10; - impl> KZG10 { + impl> KZG10 { /// Specializes the public parameters for a given maximum degree `d` for polynomials /// `d` should be less that `pp.max_degree()`. pub(crate) fn trim( @@ -514,7 +514,7 @@ mod tests { fn end_to_end_test_template() -> Result<(), Error> where E: PairingEngine, - P: UVPolynomial, + P: DenseUVPolynomial, for<'a, 'b> &'a P: Div<&'b P, Output = P>, { let rng = &mut test_rng(); @@ -545,7 +545,7 @@ mod tests { fn linear_polynomial_test_template() -> Result<(), Error> where E: PairingEngine, - P: UVPolynomial, + P: DenseUVPolynomial, for<'a, 'b> &'a P: Div<&'b P, Output = P>, { let rng = &mut test_rng(); @@ -573,7 +573,7 @@ mod tests { fn batch_check_test_template() -> Result<(), Error> where E: PairingEngine, - P: UVPolynomial, + P: DenseUVPolynomial, for<'a, 'b> &'a P: Div<&'b P, Output = P>, { let rng = &mut test_rng(); diff --git a/src/lib.rs b/src/lib.rs index e8712db9..38f67468 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ extern crate derivative; extern crate ark_std; use ark_ff::{Field, PrimeField}; -pub use ark_poly::{Polynomial, UVPolynomial}; +pub use ark_poly::{Polynomial, DenseUVPolynomial}; use ark_std::rand::RngCore; use ark_std::{ diff --git a/src/marlin/marlin_pc/data_structures.rs b/src/marlin/marlin_pc/data_structures.rs index 71333585..9c4ca8da 100644 --- a/src/marlin/marlin_pc/data_structures.rs +++ b/src/marlin/marlin_pc/data_structures.rs @@ -1,6 +1,6 @@ use crate::{ PCCommitment, PCCommitterKey, PCPreparedCommitment, PCPreparedVerifierKey, PCRandomness, - PCVerifierKey, UVPolynomial, Vec, + PCVerifierKey, DenseUVPolynomial, Vec, }; use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ff::{Field, PrimeField, ToBytes, ToConstraintField}; @@ -329,7 +329,7 @@ impl PCPreparedCommitment> for PreparedCommitmen PartialEq(bound = ""), Eq(bound = "") )] -pub struct Randomness> { +pub struct Randomness> { /// Commitment randomness for a KZG10 commitment. pub rand: kzg10::Randomness, /// Commitment randomness for a KZG10 commitment to the shifted polynomial. @@ -338,7 +338,7 @@ pub struct Randomness> { pub shifted_rand: Option>, } -impl<'a, F: PrimeField, P: UVPolynomial> Add<&'a Self> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<&'a Self> for Randomness { type Output = Self; fn add(mut self, other: &'a Self) -> Self { @@ -347,7 +347,7 @@ impl<'a, F: PrimeField, P: UVPolynomial> Add<&'a Self> for Randomness { } } -impl<'a, F: PrimeField, P: UVPolynomial> AddAssign<&'a Self> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> AddAssign<&'a Self> for Randomness { #[inline] fn add_assign(&mut self, other: &'a Self) { self.rand += &other.rand; @@ -362,7 +362,7 @@ impl<'a, F: PrimeField, P: UVPolynomial> AddAssign<&'a Self> for Randomness> Add<(F, &'a Randomness)> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<(F, &'a Randomness)> for Randomness { type Output = Self; #[inline] @@ -372,7 +372,7 @@ impl<'a, F: PrimeField, P: UVPolynomial> Add<(F, &'a Randomness)> for R } } -impl<'a, F: PrimeField, P: UVPolynomial> AddAssign<(F, &'a Randomness)> +impl<'a, F: PrimeField, P: DenseUVPolynomial> AddAssign<(F, &'a Randomness)> for Randomness { #[inline] @@ -387,7 +387,7 @@ impl<'a, F: PrimeField, P: UVPolynomial> AddAssign<(F, &'a Randomness)> } } -impl> PCRandomness for Randomness { +impl> PCRandomness for Randomness { fn empty() -> Self { Self { rand: kzg10::Randomness::empty(), diff --git a/src/marlin/marlin_pc/mod.rs b/src/marlin/marlin_pc/mod.rs index 535fde40..c52f2790 100644 --- a/src/marlin/marlin_pc/mod.rs +++ b/src/marlin/marlin_pc/mod.rs @@ -5,7 +5,7 @@ use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCRandomness, PCUniversalParams, PolynomialCommitment}; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::Zero; -use ark_poly::UVPolynomial; +use ark_poly::DenseUVPolynomial; use ark_std::rand::RngCore; use ark_std::{marker::PhantomData, ops::Div, vec}; @@ -26,13 +26,13 @@ pub use data_structures::*; /// /// [kzg]: http://cacr.uwaterloo.ca/techreports/2010/cacr2010-10.pdf /// [marlin]: https://eprint.iacr.org/2019/104 -pub struct MarlinKZG10, S: CryptographicSponge> { +pub struct MarlinKZG10, S: CryptographicSponge> { _engine: PhantomData, _poly: PhantomData

, _sponge: PhantomData, } -pub(crate) fn shift_polynomial>( +pub(crate) fn shift_polynomial>( ck: &CommitterKey, p: &P, degree_bound: usize, @@ -56,7 +56,7 @@ pub(crate) fn shift_polynomial>( impl PolynomialCommitment for MarlinKZG10 where E: PairingEngine, - P: UVPolynomial, + P: DenseUVPolynomial, S: CryptographicSponge, for<'a, 'b> &'a P: Div<&'b P, Output = P>, { @@ -540,7 +540,7 @@ mod tests { use ark_bls12_381::Bls12_381; use ark_ec::PairingEngine; use ark_ff::UniformRand; - use ark_poly::{univariate::DensePolynomial as DensePoly, UVPolynomial}; + use ark_poly::{univariate::DensePolynomial as DensePoly, DenseUVPolynomial}; use ark_sponge::poseidon::PoseidonSponge; use rand_chacha::ChaCha20Rng; diff --git a/src/marlin/marlin_pst13_pc/data_structures.rs b/src/marlin/marlin_pst13_pc/data_structures.rs index ca8ddc61..ec23bd00 100644 --- a/src/marlin/marlin_pst13_pc/data_structures.rs +++ b/src/marlin/marlin_pst13_pc/data_structures.rs @@ -4,7 +4,7 @@ use crate::{ }; use ark_ec::PairingEngine; use ark_ff::{ToBytes, Zero}; -use ark_poly::MVPolynomial; +use ark_poly::DenseMVPolynomial; use ark_std::{ io::{Read, Write}, marker::PhantomData, @@ -20,7 +20,7 @@ use ark_std::rand::RngCore; pub struct UniversalParams where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { /// Contains group elements corresponding to all possible monomials with @@ -51,7 +51,7 @@ where impl CanonicalSerialize for UniversalParams where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { fn serialize(&self, mut writer: W) -> Result<(), SerializationError> { @@ -108,7 +108,7 @@ where impl CanonicalDeserialize for UniversalParams where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { fn deserialize(mut reader: R) -> Result { @@ -184,7 +184,7 @@ where impl PCUniversalParams for UniversalParams where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { fn max_degree(&self) -> usize { @@ -199,7 +199,7 @@ where pub struct CommitterKey where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { /// Contains group elements corresponding to all possible monomials with @@ -223,7 +223,7 @@ where impl PCCommitterKey for CommitterKey where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { fn max_degree(&self) -> usize { @@ -419,7 +419,7 @@ impl PCPreparedVerifierKey> for PreparedVerifie pub struct Randomness where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { /// A multivariate polynomial where each monomial is univariate with random coefficient @@ -430,7 +430,7 @@ where impl Randomness where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { /// Does `self` provide any hiding properties to the corresponding commitment? @@ -450,7 +450,7 @@ where impl PCRandomness for Randomness where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { fn empty() -> Self { @@ -474,10 +474,10 @@ where } } -impl<'a, E: PairingEngine, P: MVPolynomial> Add<&'a Randomness> for Randomness +impl<'a, E: PairingEngine, P: DenseMVPolynomial> Add<&'a Randomness> for Randomness where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { type Output = Self; @@ -492,7 +492,7 @@ where impl<'a, E, P> Add<(E::Fr, &'a Randomness)> for Randomness where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { type Output = Self; @@ -507,7 +507,7 @@ where impl<'a, E, P> AddAssign<&'a Randomness> for Randomness where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { #[inline] @@ -519,7 +519,7 @@ where impl<'a, E, P> AddAssign<(E::Fr, &'a Randomness)> for Randomness where E: PairingEngine, - P: MVPolynomial, + P: DenseMVPolynomial, P::Point: Index, { #[inline] diff --git a/src/marlin/marlin_pst13_pc/mod.rs b/src/marlin/marlin_pst13_pc/mod.rs index 45a78b5c..f9e1d220 100644 --- a/src/marlin/marlin_pst13_pc/mod.rs +++ b/src/marlin/marlin_pst13_pc/mod.rs @@ -12,7 +12,7 @@ use ark_ec::{ AffineCurve, PairingEngine, ProjectiveCurve, }; use ark_ff::{One, PrimeField, UniformRand, Zero}; -use ark_poly::{multivariate::Term, MVPolynomial}; +use ark_poly::{multivariate::Term, DenseMVPolynomial}; use ark_std::rand::RngCore; use ark_std::{marker::PhantomData, ops::Index, vec}; @@ -33,13 +33,13 @@ use rayon::prelude::*; /// /// [pst]: https://eprint.iacr.org/2011/587 /// [marlin]: https://eprint.iacr.org/2019/104 -pub struct MarlinPST13, S: CryptographicSponge> { +pub struct MarlinPST13, S: CryptographicSponge> { _engine: PhantomData, _poly: PhantomData

, _sponge: PhantomData, } -impl, S: CryptographicSponge> MarlinPST13 { +impl, S: CryptographicSponge> MarlinPST13 { /// Given some point `z`, compute the quotients `w_i(X)` s.t /// /// `p(X) - p(z) = (X_1-z_1)*w_1(X) + (X_2-z_2)*w_2(X) + ... + (X_l-z_l)*w_l(X)` @@ -143,7 +143,7 @@ impl, S: CryptographicSponge> MarlinPST impl PolynomialCommitment for MarlinPST13 where E: PairingEngine, - P: MVPolynomial + Sync, + P: DenseMVPolynomial + Sync, S: CryptographicSponge, P::Point: Index, { @@ -717,7 +717,7 @@ mod tests { use ark_ff::UniformRand; use ark_poly::{ multivariate::{SparsePolynomial as SparsePoly, SparseTerm}, - MVPolynomial, + DenseMVPolynomial, }; use ark_sponge::poseidon::PoseidonSponge; use rand_chacha::ChaCha20Rng; diff --git a/src/sonic_pc/mod.rs b/src/sonic_pc/mod.rs index c8b579b9..452a8f78 100644 --- a/src/sonic_pc/mod.rs +++ b/src/sonic_pc/mod.rs @@ -1,6 +1,6 @@ use crate::{kzg10, PCCommitterKey, CHALLENGE_SIZE}; use crate::{BTreeMap, BTreeSet, String, ToString, Vec}; -use crate::{BatchLCProof, Error, Evaluations, QuerySet, UVPolynomial}; +use crate::{BatchLCProof, Error, Evaluations, QuerySet, DenseUVPolynomial}; use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCRandomness, PCUniversalParams, PolynomialCommitment}; @@ -24,7 +24,7 @@ pub use data_structures::*; /// [sonic]: https://eprint.iacr.org/2019/099 /// [al]: https://eprint.iacr.org/2019/601 /// [marlin]: https://eprint.iacr.org/2019/1047 -pub struct SonicKZG10, S: CryptographicSponge> { +pub struct SonicKZG10, S: CryptographicSponge> { _engine: PhantomData, _poly: PhantomData

, _sponge: PhantomData, @@ -33,7 +33,7 @@ pub struct SonicKZG10, S: Cryptographic impl SonicKZG10 where E: PairingEngine, - P: UVPolynomial, + P: DenseUVPolynomial, S: CryptographicSponge, { fn accumulate_elems<'a>( @@ -137,7 +137,7 @@ where impl PolynomialCommitment for SonicKZG10 where E: PairingEngine, - P: UVPolynomial, + P: DenseUVPolynomial, S: CryptographicSponge, for<'a, 'b> &'a P: Div<&'b P, Output = P>, { @@ -683,7 +683,7 @@ mod tests { use ark_bls12_381::Bls12_381; use ark_ec::PairingEngine; use ark_ff::UniformRand; - use ark_poly::{univariate::DensePolynomial as DensePoly, UVPolynomial}; + use ark_poly::{univariate::DensePolynomial as DensePoly, DenseUVPolynomial}; use ark_sponge::poseidon::PoseidonSponge; use rand_chacha::ChaCha20Rng; diff --git a/src/streaming_kzg/mod.rs b/src/streaming_kzg/mod.rs index 06019cca..474bf5c7 100644 --- a/src/streaming_kzg/mod.rs +++ b/src/streaming_kzg/mod.rs @@ -96,7 +96,7 @@ pub use time::CommitterKey; pub mod tests; use ark_ff::{Field, One, PrimeField, Zero}; -use ark_poly::{univariate::DensePolynomial, UVPolynomial}; +use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial}; use ark_std::io::Write; use ark_std::ops::{Add, Mul}; diff --git a/src/streaming_kzg/tests.rs b/src/streaming_kzg/tests.rs index 2f84182c..14936573 100644 --- a/src/streaming_kzg/tests.rs +++ b/src/streaming_kzg/tests.rs @@ -1,6 +1,6 @@ use ark_bls12_381::{Bls12_381, Fr}; use ark_poly::univariate::DensePolynomial; -use ark_poly::UVPolynomial; +use ark_poly::DenseUVPolynomial; use ark_std::vec::Vec; use ark_std::{UniformRand, Zero}; @@ -153,7 +153,7 @@ fn test_trivial_commitment() { use ark_bls12_381::Bls12_381; use ark_bls12_381::Fr; use ark_poly::univariate::DensePolynomial; - use ark_poly::UVPolynomial; + use ark_poly::DenseUVPolynomial; use ark_std::One; let rng = &mut ark_std::test_rng(); @@ -174,7 +174,7 @@ fn test_commitment() { use ark_bls12_381::Fr; use ark_poly::univariate::DensePolynomial; use ark_poly::Polynomial; - use ark_poly::UVPolynomial; + use ark_poly::DenseUVPolynomial; let rng = &mut ark_std::test_rng(); let ck = CommitterKey::::new(100, 3, rng); @@ -195,7 +195,7 @@ fn test_open_multi_points() { use ark_bls12_381::{Bls12_381, Fr}; use ark_ff::Field; use ark_poly::univariate::DensePolynomial; - use ark_poly::UVPolynomial; + use ark_poly::DenseUVPolynomial; use ark_std::test_rng; let max_msm_buffer = 1 << 20; diff --git a/src/streaming_kzg/time.rs b/src/streaming_kzg/time.rs index d4a0d0f9..4255f074 100644 --- a/src/streaming_kzg/time.rs +++ b/src/streaming_kzg/time.rs @@ -4,7 +4,7 @@ use ark_ec::msm::FixedBase; use ark_ec::PairingEngine; use ark_ec::{AffineCurve, ProjectiveCurve}; use ark_ff::{PrimeField, Zero}; -use ark_poly::{univariate::DensePolynomial, UVPolynomial}; +use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial}; use ark_std::borrow::Borrow; use ark_std::ops::Div; use ark_std::rand::RngCore; From 7dc88c87769f5e062dbc94c35a0e2652fd46f02b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20G=C3=B3rny?= Date: Thu, 30 Jun 2022 12:19:03 +0200 Subject: [PATCH 2/9] Fix formatting --- src/ipa_pc/mod.rs | 2 +- src/kzg10/data_structures.rs | 8 ++++++-- src/lib.rs | 2 +- src/marlin/marlin_pc/data_structures.rs | 8 +++++--- src/marlin/marlin_pst13_pc/data_structures.rs | 3 ++- src/sonic_pc/mod.rs | 2 +- src/streaming_kzg/tests.rs | 2 +- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index ff76ef3a..2857c03d 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -1,5 +1,5 @@ use crate::{BTreeMap, BTreeSet, String, ToString, Vec, CHALLENGE_SIZE}; -use crate::{BatchLCProof, Error, Evaluations, QuerySet, DenseUVPolynomial}; +use crate::{BatchLCProof, DenseUVPolynomial, Error, Evaluations, QuerySet}; use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, PolynomialCommitment}; diff --git a/src/kzg10/data_structures.rs b/src/kzg10/data_structures.rs index 778fbf7a..0d568407 100644 --- a/src/kzg10/data_structures.rs +++ b/src/kzg10/data_structures.rs @@ -548,7 +548,9 @@ impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<&'a Randomness> for R } } -impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<(F, &'a Randomness)> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<(F, &'a Randomness)> + for Randomness +{ type Output = Self; #[inline] @@ -558,7 +560,9 @@ impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<(F, &'a Randomness)> } } -impl<'a, F: PrimeField, P: DenseUVPolynomial> AddAssign<&'a Randomness> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> AddAssign<&'a Randomness> + for Randomness +{ #[inline] fn add_assign(&mut self, other: &'a Self) { self.blinding_polynomial += &other.blinding_polynomial; diff --git a/src/lib.rs b/src/lib.rs index 38f67468..068906bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,7 @@ extern crate derivative; extern crate ark_std; use ark_ff::{Field, PrimeField}; -pub use ark_poly::{Polynomial, DenseUVPolynomial}; +pub use ark_poly::{DenseUVPolynomial, Polynomial}; use ark_std::rand::RngCore; use ark_std::{ diff --git a/src/marlin/marlin_pc/data_structures.rs b/src/marlin/marlin_pc/data_structures.rs index 9c4ca8da..f36fe742 100644 --- a/src/marlin/marlin_pc/data_structures.rs +++ b/src/marlin/marlin_pc/data_structures.rs @@ -1,6 +1,6 @@ use crate::{ - PCCommitment, PCCommitterKey, PCPreparedCommitment, PCPreparedVerifierKey, PCRandomness, - PCVerifierKey, DenseUVPolynomial, Vec, + DenseUVPolynomial, PCCommitment, PCCommitterKey, PCPreparedCommitment, PCPreparedVerifierKey, + PCRandomness, PCVerifierKey, Vec, }; use ark_ec::{PairingEngine, ProjectiveCurve}; use ark_ff::{Field, PrimeField, ToBytes, ToConstraintField}; @@ -362,7 +362,9 @@ impl<'a, F: PrimeField, P: DenseUVPolynomial> AddAssign<&'a Self> for Randomn } } -impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<(F, &'a Randomness)> for Randomness { +impl<'a, F: PrimeField, P: DenseUVPolynomial> Add<(F, &'a Randomness)> + for Randomness +{ type Output = Self; #[inline] diff --git a/src/marlin/marlin_pst13_pc/data_structures.rs b/src/marlin/marlin_pst13_pc/data_structures.rs index ec23bd00..7a1ff02c 100644 --- a/src/marlin/marlin_pst13_pc/data_structures.rs +++ b/src/marlin/marlin_pst13_pc/data_structures.rs @@ -474,7 +474,8 @@ where } } -impl<'a, E: PairingEngine, P: DenseMVPolynomial> Add<&'a Randomness> for Randomness +impl<'a, E: PairingEngine, P: DenseMVPolynomial> Add<&'a Randomness> + for Randomness where E: PairingEngine, P: DenseMVPolynomial, diff --git a/src/sonic_pc/mod.rs b/src/sonic_pc/mod.rs index 452a8f78..97ab3656 100644 --- a/src/sonic_pc/mod.rs +++ b/src/sonic_pc/mod.rs @@ -1,6 +1,6 @@ use crate::{kzg10, PCCommitterKey, CHALLENGE_SIZE}; use crate::{BTreeMap, BTreeSet, String, ToString, Vec}; -use crate::{BatchLCProof, Error, Evaluations, QuerySet, DenseUVPolynomial}; +use crate::{BatchLCProof, DenseUVPolynomial, Error, Evaluations, QuerySet}; use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCRandomness, PCUniversalParams, PolynomialCommitment}; diff --git a/src/streaming_kzg/tests.rs b/src/streaming_kzg/tests.rs index 14936573..bb2aa34e 100644 --- a/src/streaming_kzg/tests.rs +++ b/src/streaming_kzg/tests.rs @@ -173,8 +173,8 @@ fn test_commitment() { use ark_bls12_381::Bls12_381; use ark_bls12_381::Fr; use ark_poly::univariate::DensePolynomial; - use ark_poly::Polynomial; use ark_poly::DenseUVPolynomial; + use ark_poly::Polynomial; let rng = &mut ark_std::test_rng(); let ck = CommitterKey::::new(100, 3, rng); From 51181ca485393810eddbe152111b3a183a3dcd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20G=C3=B3rny?= Date: Tue, 5 Jul 2022 10:41:37 +0200 Subject: [PATCH 3/9] Fix `msm` usage after `ark-ec` breaking change Use `::msm_bigint` instead of `VariableBase::msm` --- src/ipa_pc/mod.rs | 6 ++++-- src/kzg10/mod.rs | 25 ++++++++++++++++++------- src/marlin/marlin_pst13_pc/mod.rs | 15 ++++++++++----- src/multilinear_pc/mod.rs | 12 +++++++++--- src/streaming_kzg/mod.rs | 11 ++++++----- src/streaming_kzg/space.rs | 7 +++++-- 6 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index 2857c03d..3b678bef 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -3,7 +3,7 @@ use crate::{BatchLCProof, DenseUVPolynomial, Error, Evaluations, QuerySet}; use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, PolynomialCommitment}; -use ark_ec::{msm::VariableBase, AffineCurve, ProjectiveCurve}; +use ark_ec::{msm::VariableBaseMSM, AffineCurve, ProjectiveCurve}; use ark_ff::{to_bytes, Field, One, PrimeField, UniformRand, Zero}; use ark_std::rand::RngCore; use ark_std::{convert::TryInto, format, marker::PhantomData, vec}; @@ -46,6 +46,7 @@ pub struct InnerProductArgPC< impl InnerProductArgPC where G: AffineCurve, + G::Projective: VariableBaseMSM, D: Digest, P: DenseUVPolynomial, S: CryptographicSponge, @@ -65,7 +66,7 @@ where .map(|s| s.into_bigint()) .collect::>(); - let mut comm = VariableBase::msm(comm_key, &scalars_bigint); + let mut comm = ::msm_bigint(comm_key, &scalars_bigint); if randomizer.is_some() { assert!(hiding_generator.is_some()); @@ -315,6 +316,7 @@ where impl PolynomialCommitment for InnerProductArgPC where G: AffineCurve, + G::Projective: VariableBaseMSM, D: Digest, P: DenseUVPolynomial, S: CryptographicSponge, diff --git a/src/kzg10/mod.rs b/src/kzg10/mod.rs index 0c418736..a268b162 100644 --- a/src/kzg10/mod.rs +++ b/src/kzg10/mod.rs @@ -6,7 +6,7 @@ //! This construction achieves extractability in the algebraic group model (AGM). use crate::{BTreeMap, Error, LabeledPolynomial, PCRandomness, ToString, Vec}; -use ark_ec::msm::{FixedBase, VariableBase}; +use ark_ec::msm::{FixedBase, VariableBaseMSM}; use ark_ec::{group::Group, AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{One, PrimeField, UniformRand, Zero}; use ark_poly::DenseUVPolynomial; @@ -152,8 +152,10 @@ where skip_leading_zeros_and_convert_to_bigints(polynomial); let msm_time = start_timer!(|| "MSM to compute commitment to plaintext poly"); - let mut commitment = - VariableBase::msm(&powers.powers_of_g[num_leading_zeros..], &plain_coeffs); + let mut commitment = ::msm_bigint( + &powers.powers_of_g[num_leading_zeros..], + &plain_coeffs, + ); end_timer!(msm_time); let mut randomness = Randomness::::empty(); @@ -174,8 +176,11 @@ where let random_ints = convert_to_bigints(&randomness.blinding_polynomial.coeffs()); let msm_time = start_timer!(|| "MSM to compute commitment to random poly"); - let random_commitment = - VariableBase::msm(&powers.powers_of_gamma_g, random_ints.as_slice()).into_affine(); + let random_commitment = ::msm_bigint( + &powers.powers_of_gamma_g, + random_ints.as_slice(), + ) + .into_affine(); end_timer!(msm_time); commitment.add_assign_mixed(&random_commitment); @@ -226,7 +231,10 @@ where skip_leading_zeros_and_convert_to_bigints(witness_polynomial); let witness_comm_time = start_timer!(|| "Computing commitment to witness polynomial"); - let mut w = VariableBase::msm(&powers.powers_of_g[num_leading_zeros..], &witness_coeffs); + let mut w = ::msm_bigint( + &powers.powers_of_g[num_leading_zeros..], + &witness_coeffs, + ); end_timer!(witness_comm_time); let random_v = if let Some(hiding_witness_polynomial) = hiding_witness_polynomial { @@ -238,7 +246,10 @@ where let random_witness_coeffs = convert_to_bigints(&hiding_witness_polynomial.coeffs()); let witness_comm_time = start_timer!(|| "Computing commitment to random witness polynomial"); - w += &VariableBase::msm(&powers.powers_of_gamma_g, &random_witness_coeffs); + w += &::msm_bigint( + &powers.powers_of_gamma_g, + &random_witness_coeffs, + ); end_timer!(witness_comm_time); Some(blinding_evaluation) } else { diff --git a/src/marlin/marlin_pst13_pc/mod.rs b/src/marlin/marlin_pst13_pc/mod.rs index f9e1d220..f4141d40 100644 --- a/src/marlin/marlin_pst13_pc/mod.rs +++ b/src/marlin/marlin_pst13_pc/mod.rs @@ -8,7 +8,7 @@ use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCRandomness, PCUniversalParams, PolynomialCommitment}; use crate::{ToString, Vec}; use ark_ec::{ - msm::{FixedBase, VariableBase}, + msm::{FixedBase, VariableBaseMSM}, AffineCurve, PairingEngine, ProjectiveCurve, }; use ark_ff::{One, PrimeField, UniformRand, Zero}; @@ -383,7 +383,8 @@ where end_timer!(to_bigint_time); let msm_time = start_timer!(|| "MSM to compute commitment to plaintext poly"); - let mut commitment = VariableBase::msm(&powers_of_g, &plain_ints); + let mut commitment = + ::msm_bigint(&powers_of_g, &plain_ints); end_timer!(msm_time); // Sample random polynomial @@ -419,7 +420,8 @@ where let msm_time = start_timer!(|| "MSM to compute commitment to random poly"); let random_commitment = - VariableBase::msm(&powers_of_gamma_g, &random_ints).into_affine(); + ::msm_bigint(&powers_of_gamma_g, &random_ints) + .into_affine(); end_timer!(msm_time); // Mask commitment with random poly @@ -487,7 +489,7 @@ where // Convert coefficients to BigInt let witness_ints = Self::convert_to_bigints(&w); // Compute MSM - VariableBase::msm(&powers_of_g, &witness_ints) + ::msm_bigint(&powers_of_g, &witness_ints) }) .collect::>(); end_timer!(witness_comm_time); @@ -517,7 +519,10 @@ where // Convert coefficients to BigInt let hiding_witness_ints = Self::convert_to_bigints(hiding_witness); // Compute MSM and add result to witness - *witness += &VariableBase::msm(&powers_of_gamma_g, &hiding_witness_ints); + *witness += &::msm_bigint( + &powers_of_gamma_g, + &hiding_witness_ints, + ); }); end_timer!(witness_comm_time); Some(r.blinding_polynomial.evaluate(point)) diff --git a/src/multilinear_pc/mod.rs b/src/multilinear_pc/mod.rs index 8473a7b9..d019c92f 100644 --- a/src/multilinear_pc/mod.rs +++ b/src/multilinear_pc/mod.rs @@ -1,7 +1,7 @@ use crate::multilinear_pc::data_structures::{ Commitment, CommitterKey, Proof, UniversalParams, VerifierKey, }; -use ark_ec::msm::{FixedBase, VariableBase}; +use ark_ec::msm::{FixedBase, VariableBaseMSM}; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{Field, PrimeField}; use ark_ff::{One, Zero}; @@ -146,7 +146,11 @@ impl MultilinearPC { .into_iter() .map(|x| x.into_bigint()) .collect(); - let g_product = VariableBase::msm(&ck.powers_of_g[0], scalars.as_slice()).into_affine(); + let g_product = ::msm_bigint( + &ck.powers_of_g[0], + scalars.as_slice(), + ) + .into_affine(); Commitment { nv, g_product } } @@ -178,7 +182,9 @@ impl MultilinearPC { .map(|x| q[k][x >> 1].into_bigint()) // fine .collect(); - let pi_h = VariableBase::msm(&ck.powers_of_h[i], &scalars).into_affine(); // no need to move outside and partition + let pi_h = + ::msm_bigint(&ck.powers_of_h[i], &scalars) + .into_affine(); // no need to move outside and partition proofs.push(pi_h); } diff --git a/src/streaming_kzg/mod.rs b/src/streaming_kzg/mod.rs index 474bf5c7..da67bb63 100644 --- a/src/streaming_kzg/mod.rs +++ b/src/streaming_kzg/mod.rs @@ -103,7 +103,7 @@ use ark_std::ops::{Add, Mul}; use ark_std::borrow::Borrow; use ark_std::fmt; -use ark_ec::{msm::VariableBase, AffineCurve, PairingEngine}; +use ark_ec::{msm::VariableBaseMSM, AffineCurve, PairingEngine}; /// A Kate polynomial commitment over a bilinear group, represented as a single \\(\GG_1\\) element. #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -119,7 +119,7 @@ impl Commitment { #[inline] fn msm(bases: &[E::G1Affine], scalars: &[E::Fr]) -> E::G1Affine { let scalars = scalars.iter().map(|x| x.into_bigint()).collect::>(); - let sp = VariableBase::msm(bases, &scalars); + let sp = ::msm_bigint(bases, &scalars); sp.into_affine() } @@ -184,7 +184,7 @@ impl VerifierKey { proof: &EvaluationProof, ) -> VerificationResult { let scalars = [(-alpha).into_bigint(), E::Fr::one().into_bigint()]; - let ep = VariableBase::msm(&self.powers_of_g2, &scalars); + let ep = ::msm_bigint(&self.powers_of_g2, &scalars); let lhs = commitment.0.into_projective() - self.powers_of_g[0].mul(evaluation.into_bigint()); let g2 = self.powers_of_g2[0]; @@ -213,7 +213,8 @@ impl VerifierKey { // Computing the vanishing polynomial over eval_points let zeros = vanishing_polynomial(eval_points); let zeros_repr = zeros.iter().map(|x| x.into_bigint()).collect::>(); - let zeros = VariableBase::msm(&self.powers_of_g2, &zeros_repr); + let zeros = + ::msm_bigint(&self.powers_of_g2, &zeros_repr); // Computing the inverse for the interpolation let mut sca_inverse = Vec::new(); @@ -256,7 +257,7 @@ impl VerifierKey { // Gathering commitments let comm_vec = commitments.iter().map(|x| x.0).collect::>(); let etas_repr = etas.iter().map(|e| e.into_bigint()).collect::>(); - let f_comm = VariableBase::msm(&comm_vec, &etas_repr); + let f_comm = ::msm_bigint(&comm_vec, &etas_repr); let g2 = self.powers_of_g2[0]; diff --git a/src/streaming_kzg/space.rs b/src/streaming_kzg/space.rs index f5c7365b..4fd4d13a 100644 --- a/src/streaming_kzg/space.rs +++ b/src/streaming_kzg/space.rs @@ -7,7 +7,7 @@ use ark_std::collections::VecDeque; use ark_std::vec::Vec; use crate::streaming_kzg::{ceil_div, vanishing_polynomial, FoldedPolynomialTree}; -use ark_ec::msm::{ChunkedPippenger, HashMapPippenger, VariableBase}; +use ark_ec::msm::{ChunkedPippenger, HashMapPippenger, VariableBaseMSM}; use ark_std::iterable::{Iterable, Reverse}; use super::{time::CommitterKey, VerifierKey}; @@ -135,7 +135,10 @@ where { assert!(self.powers_of_g.len() >= polynomial.len()); - Commitment(VariableBase::msm_chunks(&self.powers_of_g, polynomial).into_affine()) + Commitment( + ::msm_chunks(&self.powers_of_g, polynomial) + .into_affine(), + ) } /// The batch commitment procedures, that takes as input a committer key and the streaming coefficients of a list of polynomials, and produces the desired commitments. From f97a5dd0864484ab648d8b1055477b015a0c3f99 Mon Sep 17 00:00:00 2001 From: Yuwen Zhang Date: Sun, 31 Jul 2022 15:56:11 -0700 Subject: [PATCH 4/9] Removed ToBytes implementations and replaced uses of the tobytes! macro. --- Cargo.toml | 2 +- src/constraints.rs | 4 +- src/data_structures.rs | 13 +-- src/ipa_pc/data_structures.rs | 33 +------ src/ipa_pc/mod.rs | 97 ++++++++++++------- src/kzg10/data_structures.rs | 36 +------ src/kzg10/mod.rs | 8 +- src/marlin/marlin_pc/data_structures.rs | 31 +----- src/marlin/marlin_pst13_pc/data_structures.rs | 22 +---- src/marlin/marlin_pst13_pc/mod.rs | 10 +- src/marlin/mod.rs | 2 +- src/multilinear_pc/mod.rs | 1 + src/sonic_pc/mod.rs | 8 +- src/streaming_kzg/mod.rs | 14 +-- src/streaming_kzg/time.rs | 6 +- 15 files changed, 99 insertions(+), 188 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 98daed2a..2a40f8a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,7 +66,7 @@ ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves" } ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves" } ark-ed-on-bls12-381 = { git = "https://github.com/arkworks-rs/curves" } ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std" } -ark-sponge = { git = "https://github.com/arkworks-rs/sponge" } +ark-sponge = { git = "https://github.com/yuwen01/sponge" } [features] default = [ "std", "parallel" ] diff --git a/src/constraints.rs b/src/constraints.rs index a21fec2d..729b833c 100644 --- a/src/constraints.rs +++ b/src/constraints.rs @@ -100,13 +100,13 @@ pub trait PCCheckVar< >: Clone { /// An allocated version of `PC::VerifierKey`. - type VerifierKeyVar: AllocVar + Clone + ToBytesGadget; + type VerifierKeyVar: AllocVar + Clone; /// An allocated version of `PC::PreparedVerifierKey`. type PreparedVerifierKeyVar: AllocVar + Clone + PrepareGadget; /// An allocated version of `PC::Commitment`. - type CommitmentVar: AllocVar + Clone + ToBytesGadget; + type CommitmentVar: AllocVar + Clone; /// An allocated version of `PC::PreparedCommitment`. type PreparedCommitmentVar: AllocVar + PrepareGadget diff --git a/src/data_structures.rs b/src/data_structures.rs index 516a7094..2259451e 100644 --- a/src/data_structures.rs +++ b/src/data_structures.rs @@ -56,9 +56,7 @@ pub trait PCPreparedVerifierKey { /// Defines the minimal interface of commitments for any polynomial /// commitment scheme. -pub trait PCCommitment: - Clone + ark_ff::ToBytes + CanonicalSerialize + CanonicalDeserialize -{ +pub trait PCCommitment: Clone + CanonicalSerialize + CanonicalDeserialize { /// Outputs a non-hiding commitment to the zero polynomial. fn empty() -> Self; @@ -100,7 +98,7 @@ pub trait PCRandomness: Clone + CanonicalSerialize + CanonicalDeserialize { /// Defines the minimal interface of evaluation proofs for any polynomial /// commitment scheme. -pub trait PCProof: Clone + ark_ff::ToBytes + CanonicalSerialize + CanonicalDeserialize { +pub trait PCProof: Clone + CanonicalSerialize + CanonicalDeserialize { /// Size in bytes #[deprecated(since = "0.4.0", note = "Please use `.serialized_size()` instead.")] fn size_in_bytes(&self) -> usize { @@ -232,13 +230,6 @@ impl LabeledCommitment { } } -impl ark_ff::ToBytes for LabeledCommitment { - #[inline] - fn write(&self, writer: W) -> ark_std::io::Result<()> { - self.commitment.write(writer) - } -} - /// A term in a linear combination. #[derive(Hash, Ord, PartialOrd, Clone, Eq, PartialEq, Debug)] pub enum LCTerm { diff --git a/src/ipa_pc/data_structures.rs b/src/ipa_pc/data_structures.rs index dcaed801..8369becf 100644 --- a/src/ipa_pc/data_structures.rs +++ b/src/ipa_pc/data_structures.rs @@ -1,7 +1,7 @@ use crate::*; use crate::{PCCommitterKey, PCVerifierKey, Vec}; use ark_ec::AffineCurve; -use ark_ff::{Field, ToBytes, UniformRand, Zero}; +use ark_ff::{Field, UniformRand, Zero}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError}; use ark_std::rand::RngCore; use ark_std::{ @@ -121,19 +121,6 @@ impl PCCommitment for Commitment { } } -impl ToBytes for Commitment { - #[inline] - fn write(&self, mut writer: W) -> ark_std::io::Result<()> { - self.comm.write(&mut writer)?; - let shifted_exists = self.shifted_comm.is_some(); - shifted_exists.write(&mut writer)?; - self.shifted_comm - .as_ref() - .unwrap_or(&G::zero()) - .write(&mut writer) - } -} - /// Nothing to do to prepare this commitment (for now). pub type PreparedCommitment = Commitment; @@ -214,24 +201,6 @@ pub struct Proof { impl PCProof for Proof {} -impl ToBytes for Proof { - #[inline] - fn write(&self, mut writer: W) -> ark_std::io::Result<()> { - self.l_vec.write(&mut writer)?; - self.r_vec.write(&mut writer)?; - self.final_comm_key.write(&mut writer)?; - self.c.write(&mut writer)?; - self.hiding_comm - .as_ref() - .unwrap_or(&G::zero()) - .write(&mut writer)?; - self.rand - .as_ref() - .unwrap_or(&G::ScalarField::zero()) - .write(&mut writer) - } -} - /// `SuccinctCheckPolynomial` is a succinctly-representated polynomial /// generated from the `log_d` random oracle challenges generated in `open`. /// It has the special property that can be evaluated in `O(log_d)` time. diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index 3b678bef..a4b206f9 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -4,9 +4,10 @@ use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, PolynomialCommitment}; use ark_ec::{msm::VariableBaseMSM, AffineCurve, ProjectiveCurve}; -use ark_ff::{to_bytes, Field, One, PrimeField, UniformRand, Zero}; +use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; +use ark_serialize::CanonicalSerialize; use ark_std::rand::RngCore; -use ark_std::{convert::TryInto, format, marker::PhantomData, vec}; +use ark_std::{convert::TryInto, format, marker::PhantomData, vec, ops::Mul}; mod data_structures; pub use data_structures::*; @@ -80,8 +81,10 @@ where let mut i = 0u64; let mut challenge = None; while challenge.is_none() { - let hash_input = ark_ff::to_bytes![bytes, i].unwrap(); - let hash = D::digest(&hash_input); + // let hash_input = [bytes, &i.to_le_bytes()].concat().as_slice(); + let mut hash_input = bytes.to_vec(); + hash_input.extend(i.to_le_bytes()); + let hash = D::digest(&hash_input.as_slice()); challenge = ::from_random_bytes(&hash); i += 1; @@ -144,32 +147,44 @@ where if proof.hiding_comm.is_some() { let hiding_comm = proof.hiding_comm.unwrap(); let rand = proof.rand.unwrap(); - - let hiding_challenge = Self::compute_random_oracle_challenge( - &ark_ff::to_bytes![combined_commitment, point, combined_v, hiding_comm].unwrap(), - ); + let mut byte_vec = Vec::new(); + combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + // Self::print_byte_vec(&byte_vec); + point.serialize_uncompressed(&mut byte_vec).unwrap(); + // Self::print_byte_vec(&byte_vec); + combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); + hiding_comm.serialize_uncompressed(&mut byte_vec).unwrap(); + let bytes = byte_vec.as_slice(); + let hiding_challenge = Self::compute_random_oracle_challenge(bytes); combined_commitment_proj += &(hiding_comm.mul(hiding_challenge) - &vk.s.mul(rand)); combined_commitment = combined_commitment_proj.into_affine(); } // Challenge for each round let mut round_challenges = Vec::with_capacity(log_d); - let mut round_challenge = Self::compute_random_oracle_challenge( - &ark_ff::to_bytes![combined_commitment, point, combined_v].unwrap(), - ); + let mut byte_vec = Vec::new(); + combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + point.serialize_uncompressed(&mut byte_vec).unwrap(); + combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); + let bytes = byte_vec.as_slice(); + let mut round_challenge = Self::compute_random_oracle_challenge(bytes); let h_prime = vk.h.mul(round_challenge); let mut round_commitment_proj = - combined_commitment_proj + &h_prime.mul(&combined_v.into_bigint()); + combined_commitment_proj + &h_prime.mul(&combined_v); let l_iter = proof.l_vec.iter(); let r_iter = proof.r_vec.iter(); for (l, r) in l_iter.zip(r_iter) { - round_challenge = Self::compute_random_oracle_challenge( - &ark_ff::to_bytes![round_challenge, l, r].unwrap(), - ); + let mut byte_vec = Vec::new(); + round_challenge.serialize_uncompressed(&mut byte_vec).unwrap(); + l.serialize_uncompressed(&mut byte_vec).unwrap(); + r.serialize_uncompressed(&mut byte_vec).unwrap(); + let bytes = byte_vec.as_slice(); + + round_challenge = Self::compute_random_oracle_challenge(bytes); round_challenges.push(round_challenge); round_commitment_proj += &(l.mul(round_challenge.inverse().unwrap()) + &r.mul(round_challenge)); @@ -296,11 +311,20 @@ where let generators: Vec<_> = ark_std::cfg_into_iter!(0..num_generators) .map(|i| { let i = i as u64; - let mut hash = D::digest(&to_bytes![&Self::PROTOCOL_NAME, i].unwrap()); + let mut hash = D::digest( + [Self::PROTOCOL_NAME, &i.to_le_bytes()] + .concat() + .as_slice(), + ); let mut g = G::from_random_bytes(&hash); let mut j = 0u64; while g.is_none() { - hash = D::digest(&to_bytes![&Self::PROTOCOL_NAME, i, j].unwrap()); + // PROTOCOL NAME, i, j + let mut bytes = Self::PROTOCOL_NAME.to_vec(); + bytes.extend(i.to_le_bytes()); + bytes.extend(j.to_le_bytes()); + hash = D::digest(bytes.as_slice()); + // hash = D::digest(&to_bytes![&Self::PROTOCOL_NAME, i, j].unwrap()); g = G::from_random_bytes(&hash); j += 1; } @@ -563,10 +587,9 @@ where if has_hiding { let mut rng = rng.expect("hiding commitments require randomness"); let hiding_time = start_timer!(|| "Applying hiding."); - let mut hiding_polynomial = P::rand(d, &mut rng); + let mut hiding_polynomial = P::rand(0, &mut rng); hiding_polynomial -= &P::from_coefficients_slice(&[hiding_polynomial.evaluate(point)]); - - let hiding_rand = G::ScalarField::rand(rng); + let hiding_rand = G::ScalarField::rand(&mut rng); let hiding_commitment_proj = Self::cm_commit( ck.comm_key.as_slice(), hiding_polynomial.coeffs(), @@ -581,15 +604,13 @@ where hiding_commitment = Some(batch.pop().unwrap()); combined_commitment = batch.pop().unwrap(); - let hiding_challenge = Self::compute_random_oracle_challenge( - &ark_ff::to_bytes![ - combined_commitment, - point, - combined_v, - hiding_commitment.unwrap() - ] - .unwrap(), - ); + let mut byte_vec = Vec::new(); + combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + point.serialize_uncompressed(&mut byte_vec).unwrap(); + combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); + hiding_commitment.unwrap().serialize_uncompressed(&mut byte_vec).unwrap(); + let bytes = byte_vec.as_slice(); + let hiding_challenge = Self::compute_random_oracle_challenge(bytes); combined_polynomial += (hiding_challenge, &hiding_polynomial); combined_rand += &(hiding_challenge * &hiding_rand); combined_commitment_proj += @@ -610,9 +631,12 @@ where combined_commitment = combined_commitment_proj.into_affine(); // ith challenge - let mut round_challenge = Self::compute_random_oracle_challenge( - &ark_ff::to_bytes![combined_commitment, point, combined_v].unwrap(), - ); + let mut byte_vec = Vec::new(); + combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + point.serialize_uncompressed(&mut byte_vec).unwrap(); + combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); + let bytes = byte_vec.as_slice(); + let mut round_challenge = Self::compute_random_oracle_challenge(bytes); let h_prime = ck.h.mul(round_challenge).into_affine(); @@ -664,9 +688,12 @@ where l_vec.push(lr[0]); r_vec.push(lr[1]); - round_challenge = Self::compute_random_oracle_challenge( - &ark_ff::to_bytes![round_challenge, lr[0], lr[1]].unwrap(), - ); + let mut byte_vec = Vec::new(); + round_challenge.serialize_uncompressed(&mut byte_vec).unwrap(); + lr[0].serialize_uncompressed(&mut byte_vec).unwrap(); + lr[1].serialize_uncompressed(&mut byte_vec).unwrap(); + let bytes = byte_vec.as_slice(); + round_challenge = Self::compute_random_oracle_challenge(bytes); let round_challenge_inv = round_challenge.inverse().unwrap(); ark_std::cfg_iter_mut!(coeffs_l) diff --git a/src/kzg10/data_structures.rs b/src/kzg10/data_structures.rs index 0d568407..161e86f8 100644 --- a/src/kzg10/data_structures.rs +++ b/src/kzg10/data_structures.rs @@ -1,6 +1,6 @@ use crate::*; -use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; -use ark_ff::{PrimeField, ToBytes, ToConstraintField, Zero}; +use ark_ec::{PairingEngine, ProjectiveCurve}; +use ark_ff::{PrimeField, ToConstraintField, Zero}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError}; use ark_std::{ borrow::Cow, @@ -346,18 +346,6 @@ impl CanonicalDeserialize for VerifierKey { } } -impl ToBytes for VerifierKey { - #[inline] - fn write(&self, mut writer: W) -> ark_std::io::Result<()> { - self.g.write(&mut writer)?; - self.gamma_g.write(&mut writer)?; - self.h.write(&mut writer)?; - self.beta_h.write(&mut writer)?; - self.prepared_h.write(&mut writer)?; - self.prepared_beta_h.write(&mut writer) - } -} - impl ToConstraintField<::BasePrimeField> for VerifierKey where E::G1Affine: ToConstraintField<::BasePrimeField>, @@ -424,13 +412,6 @@ pub struct Commitment( pub E::G1Affine, ); -impl ToBytes for Commitment { - #[inline] - fn write(&self, writer: W) -> ark_std::io::Result<()> { - self.0.write(writer) - } -} - impl PCCommitment for Commitment { #[inline] fn empty() -> Self { @@ -454,7 +435,7 @@ where impl<'a, E: PairingEngine> AddAssign<(E::Fr, &'a Commitment)> for Commitment { #[inline] fn add_assign(&mut self, (f, other): (E::Fr, &'a Commitment)) { - let mut other = other.0.mul(f.into_bigint()); + let mut other = other.0 * f; other.add_assign_mixed(&self.0); self.0 = other.into(); } @@ -598,14 +579,3 @@ pub struct Proof { } impl PCProof for Proof {} - -impl ToBytes for Proof { - #[inline] - fn write(&self, mut writer: W) -> ark_std::io::Result<()> { - self.w.write(&mut writer)?; - self.random_v - .as_ref() - .unwrap_or(&E::Fr::zero()) - .write(&mut writer) - } -} diff --git a/src/kzg10/mod.rs b/src/kzg10/mod.rs index a268b162..33fcdb18 100644 --- a/src/kzg10/mod.rs +++ b/src/kzg10/mod.rs @@ -7,10 +7,10 @@ use crate::{BTreeMap, Error, LabeledPolynomial, PCRandomness, ToString, Vec}; use ark_ec::msm::{FixedBase, VariableBaseMSM}; -use ark_ec::{group::Group, AffineCurve, PairingEngine, ProjectiveCurve}; +use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{One, PrimeField, UniformRand, Zero}; use ark_poly::DenseUVPolynomial; -use ark_std::{format, marker::PhantomData, ops::Div, vec}; +use ark_std::{format, marker::PhantomData, ops::Div, ops::Mul, vec}; use ark_std::rand::RngCore; #[cfg(feature = "parallel")] @@ -342,8 +342,8 @@ where if let Some(random_v) = proof.random_v { gamma_g_multiplier += &(randomizer * &random_v); } - total_c += &c.mul(randomizer.into_bigint()); - total_w += &w.mul(randomizer.into_bigint()); + total_c += &c.mul(randomizer); + total_w += &w.mul(randomizer); // We don't need to sample randomizers from the full field, // only from 128-bit strings. randomizer = u128::rand(rng).into(); diff --git a/src/marlin/marlin_pc/data_structures.rs b/src/marlin/marlin_pc/data_structures.rs index f36fe742..955312d5 100644 --- a/src/marlin/marlin_pc/data_structures.rs +++ b/src/marlin/marlin_pc/data_structures.rs @@ -3,7 +3,7 @@ use crate::{ PCRandomness, PCVerifierKey, Vec, }; use ark_ec::{PairingEngine, ProjectiveCurve}; -use ark_ff::{Field, PrimeField, ToBytes, ToConstraintField}; +use ark_ff::{Field, PrimeField, ToConstraintField}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize, SerializationError}; use ark_std::io::{Read, Write}; use ark_std::ops::{Add, AddAssign}; @@ -132,22 +132,6 @@ impl PCVerifierKey for VerifierKey { } } -impl ToBytes for VerifierKey { - #[inline] - fn write(&self, mut writer: W) -> ark_std::io::Result<()> { - self.vk.write(&mut writer)?; - if let Some(degree_bounds_and_shift_powers) = &self.degree_bounds_and_shift_powers { - writer.write_all(°ree_bounds_and_shift_powers.len().to_le_bytes())?; - for (degree_bound, shift_power) in degree_bounds_and_shift_powers { - writer.write_all(°ree_bound.to_le_bytes())?; - shift_power.write(&mut writer)?; - } - } - writer.write_all(&self.supported_degree.to_le_bytes())?; - writer.write_all(&self.max_degree.to_le_bytes()) - } -} - impl ToConstraintField<::BasePrimeField> for VerifierKey where E::G1Affine: ToConstraintField<::BasePrimeField>, @@ -249,19 +233,6 @@ pub struct Commitment { pub shifted_comm: Option>, } -impl ToBytes for Commitment { - #[inline] - fn write(&self, mut writer: W) -> ark_std::io::Result<()> { - self.comm.write(&mut writer)?; - let shifted_exists = self.shifted_comm.is_some(); - shifted_exists.write(&mut writer)?; - self.shifted_comm - .as_ref() - .unwrap_or(&kzg10::Commitment::empty()) - .write(&mut writer) - } -} - impl ToConstraintField<::BasePrimeField> for Commitment where E::G1Affine: ToConstraintField<::BasePrimeField>, diff --git a/src/marlin/marlin_pst13_pc/data_structures.rs b/src/marlin/marlin_pst13_pc/data_structures.rs index 7a1ff02c..5fb60c18 100644 --- a/src/marlin/marlin_pst13_pc/data_structures.rs +++ b/src/marlin/marlin_pst13_pc/data_structures.rs @@ -3,7 +3,7 @@ use crate::{ PCCommitterKey, PCPreparedVerifierKey, PCProof, PCRandomness, PCUniversalParams, PCVerifierKey, }; use ark_ec::PairingEngine; -use ark_ff::{ToBytes, Zero}; +use ark_ff::Zero; use ark_poly::DenseMVPolynomial; use ark_std::{ io::{Read, Write}, @@ -550,24 +550,12 @@ pub struct Proof { impl PCProof for Proof { fn size_in_bytes(&self) -> usize { let hiding_size = if self.random_v.is_some() { - ark_ff::to_bytes![E::Fr::zero()].unwrap().len() + E::Fr::zero().serialized_size() + //ark_ff::to_bytes![E::Fr::zero()].unwrap().len() } else { 0 }; - (self.w.len() * ark_ff::to_bytes![E::G1Affine::zero()].unwrap().len()) / 2 + hiding_size - } -} - -impl ToBytes for Proof { - #[inline] - fn write(&self, mut writer: W) -> ark_std::io::Result<()> { - self.w - .iter() - .map(|e| e.write(&mut writer)) - .collect::>()?; - self.random_v - .as_ref() - .unwrap_or(&E::Fr::zero()) - .write(&mut writer) + (self.w.len() * E::G1Affine::zero().serialized_size()) / 2 + hiding_size + //(self.w.len() * ark_ff::to_bytes![E::G1Affine::zero()].unwrap().len()) / 2 + hiding_size } } diff --git a/src/marlin/marlin_pst13_pc/mod.rs b/src/marlin/marlin_pst13_pc/mod.rs index f4141d40..5e46500a 100644 --- a/src/marlin/marlin_pst13_pc/mod.rs +++ b/src/marlin/marlin_pst13_pc/mod.rs @@ -14,7 +14,7 @@ use ark_ec::{ use ark_ff::{One, PrimeField, UniformRand, Zero}; use ark_poly::{multivariate::Term, DenseMVPolynomial}; use ark_std::rand::RngCore; -use ark_std::{marker::PhantomData, ops::Index, vec}; +use ark_std::{marker::PhantomData, ops::Index, vec, ops::Mul}; mod data_structures; pub use data_structures::*; @@ -256,7 +256,7 @@ where .collect(); let beta_h: Vec<_> = betas .iter() - .map(|b| h.mul(&(*b).into_bigint()).into_affine()) + .map(|b| h.mul(b).into_affine()) .collect(); let h = h.into_affine(); let prepared_h = h.into(); @@ -630,7 +630,7 @@ where if let Some(random_v) = proof.random_v { gamma_g_multiplier += &(randomizer * &random_v); } - total_c += &c.mul(&randomizer.into_bigint()); + total_c += &c.mul(&randomizer); ark_std::cfg_iter_mut!(total_w) .enumerate() .for_each(|(i, w_i)| *w_i += &w[i].mul(randomizer)); @@ -638,8 +638,8 @@ where // only from 128-bit strings. randomizer = u128::rand(rng).into(); } - total_c -= &g.mul(&g_multiplier.into_bigint()); - total_c -= &gamma_g.mul(&gamma_g_multiplier.into_bigint()); + total_c -= &g.mul(&g_multiplier); + total_c -= &gamma_g.mul(&gamma_g_multiplier); end_timer!(combination_time); let to_affine_time = start_timer!(|| "Converting results to affine for pairing"); diff --git a/src/marlin/mod.rs b/src/marlin/mod.rs index 05ba0570..eff8c4ce 100644 --- a/src/marlin/mod.rs +++ b/src/marlin/mod.rs @@ -7,7 +7,7 @@ use crate::{PCRandomness, Polynomial, PolynomialCommitment}; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; use ark_ff::{One, Zero}; use ark_sponge::CryptographicSponge; -use ark_std::{convert::TryInto, hash::Hash, ops::AddAssign}; +use ark_std::{convert::TryInto, hash::Hash, ops::AddAssign, ops::Mul}; /// Polynomial commitment scheme from [[KZG10]][kzg] that enforces /// strict degree bounds and (optionally) enables hiding commitments by diff --git a/src/multilinear_pc/mod.rs b/src/multilinear_pc/mod.rs index d019c92f..f57b2033 100644 --- a/src/multilinear_pc/mod.rs +++ b/src/multilinear_pc/mod.rs @@ -11,6 +11,7 @@ use ark_std::iter::FromIterator; use ark_std::marker::PhantomData; use ark_std::rand::RngCore; use ark_std::vec::Vec; +use ark_std::ops::Mul; use ark_std::UniformRand; /// data structures used by multilinear extension commitment scheme diff --git a/src/sonic_pc/mod.rs b/src/sonic_pc/mod.rs index 97ab3656..7c48de7f 100644 --- a/src/sonic_pc/mod.rs +++ b/src/sonic_pc/mod.rs @@ -5,9 +5,9 @@ use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination}; use crate::{PCRandomness, PCUniversalParams, PolynomialCommitment}; use ark_ec::{AffineCurve, PairingEngine, ProjectiveCurve}; -use ark_ff::{One, PrimeField, UniformRand, Zero}; +use ark_ff::{One, UniformRand, Zero}; use ark_std::rand::RngCore; -use ark_std::{convert::TryInto, marker::PhantomData, ops::Div, vec}; +use ark_std::{convert::TryInto, marker::PhantomData, ops::Div, ops::Mul, vec}; mod data_structures; use crate::challenge::ChallengeGenerator; @@ -66,7 +66,7 @@ where let mut comm_with_challenge: E::G1Projective = comm.0.mul(curr_challenge); if let Some(randomizer) = randomizer { - comm_with_challenge = comm_with_challenge.mul(&randomizer.into_bigint()); + comm_with_challenge = comm_with_challenge.mul(&randomizer); } // Accumulate values in the BTreeMap @@ -85,7 +85,7 @@ where if let Some(randomizer) = randomizer { witness = proof.w.mul(randomizer); - adjusted_witness = adjusted_witness.mul(&randomizer.into_bigint()); + adjusted_witness = adjusted_witness.mul(&randomizer); } *combined_witness += &witness; diff --git a/src/streaming_kzg/mod.rs b/src/streaming_kzg/mod.rs index da67bb63..8feaaa27 100644 --- a/src/streaming_kzg/mod.rs +++ b/src/streaming_kzg/mod.rs @@ -87,6 +87,7 @@ mod space; mod time; use ark_ec::ProjectiveCurve; +use ark_serialize::CanonicalSerialize; use ark_std::vec::Vec; pub use data_structures::*; pub use space::CommitterKeyStream; @@ -97,7 +98,6 @@ pub mod tests; use ark_ff::{Field, One, PrimeField, Zero}; use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial}; -use ark_std::io::Write; use ark_std::ops::{Add, Mul}; use ark_std::borrow::Borrow; @@ -112,7 +112,8 @@ pub struct Commitment(pub(crate) E::G1Affine); impl Commitment { /// Return the size of Commitment in bytes. pub fn size_in_bytes(&self) -> usize { - ark_ff::to_bytes![E::G1Affine::zero()].unwrap().len() / 2 + // ark_ff::to_bytes![E::G1Affine::zero()].unwrap().len() / 2 + E::G1Affine::zero().serialized_size() / 2 } } @@ -123,13 +124,6 @@ fn msm(bases: &[E::G1Affine], scalars: &[E::Fr]) -> E::G1Affin sp.into_affine() } -impl ark_ff::ToBytes for Commitment { - #[inline] - fn write(&self, writer: W) -> ark_std::io::Result<()> { - self.0.write(writer) - } -} - /// Polynomial evaluation proof, represented as a single \\(\GG_1\\) element. #[derive(Clone, Debug, PartialEq, Eq)] pub struct EvaluationProof(pub E::G1Affine); @@ -186,7 +180,7 @@ impl VerifierKey { let scalars = [(-alpha).into_bigint(), E::Fr::one().into_bigint()]; let ep = ::msm_bigint(&self.powers_of_g2, &scalars); let lhs = - commitment.0.into_projective() - self.powers_of_g[0].mul(evaluation.into_bigint()); + commitment.0.into_projective() - self.powers_of_g[0].mul(evaluation); let g2 = self.powers_of_g2[0]; if E::pairing(lhs, g2) == E::pairing(proof.0, ep) { diff --git a/src/streaming_kzg/time.rs b/src/streaming_kzg/time.rs index 4255f074..c1dac1c4 100644 --- a/src/streaming_kzg/time.rs +++ b/src/streaming_kzg/time.rs @@ -2,11 +2,11 @@ //! with optimization from [\[BDFG20\]](https://eprint.iacr.org/2020/081.pdf). use ark_ec::msm::FixedBase; use ark_ec::PairingEngine; -use ark_ec::{AffineCurve, ProjectiveCurve}; +use ark_ec::ProjectiveCurve; use ark_ff::{PrimeField, Zero}; use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial}; use ark_std::borrow::Borrow; -use ark_std::ops::Div; +use ark_std::ops::{Mul, Div}; use ark_std::rand::RngCore; use ark_std::vec::Vec; use ark_std::UniformRand; @@ -64,7 +64,7 @@ impl CommitterKey { let powers_of_g2 = powers_of_tau .iter() .take(max_eval_points + 1) - .map(|t| g2.mul(t.into_bigint()).into_affine()) + .map(|t| g2.mul(t).into_affine()) .collect::>(); CommitterKey { From 93191b0a6e4a27063cb88bd07d808b02c16b9bef Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Thu, 25 Aug 2022 21:39:40 -0700 Subject: [PATCH 5/9] Update Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2a40f8a7..98daed2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,7 +66,7 @@ ark-bls12-381 = { git = "https://github.com/arkworks-rs/curves" } ark-bls12-377 = { git = "https://github.com/arkworks-rs/curves" } ark-ed-on-bls12-381 = { git = "https://github.com/arkworks-rs/curves" } ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std" } -ark-sponge = { git = "https://github.com/yuwen01/sponge" } +ark-sponge = { git = "https://github.com/arkworks-rs/sponge" } [features] default = [ "std", "parallel" ] From 9a6ae89e8580f4939c480e537c2eda71b8e6eb09 Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Thu, 25 Aug 2022 21:40:22 -0700 Subject: [PATCH 6/9] Update src/ipa_pc/mod.rs --- src/ipa_pc/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index a4b206f9..0a942e47 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -81,7 +81,6 @@ where let mut i = 0u64; let mut challenge = None; while challenge.is_none() { - // let hash_input = [bytes, &i.to_le_bytes()].concat().as_slice(); let mut hash_input = bytes.to_vec(); hash_input.extend(i.to_le_bytes()); let hash = D::digest(&hash_input.as_slice()); From 96b50785a336d4c672df7f44be6e53e9cdac519f Mon Sep 17 00:00:00 2001 From: Weikeng Chen Date: Thu, 25 Aug 2022 21:44:25 -0700 Subject: [PATCH 7/9] Apply suggestions from code review --- src/ipa_pc/mod.rs | 3 --- src/marlin/marlin_pst13_pc/data_structures.rs | 2 -- 2 files changed, 5 deletions(-) diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index 0a942e47..9cab63bd 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -148,9 +148,7 @@ where let rand = proof.rand.unwrap(); let mut byte_vec = Vec::new(); combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); - // Self::print_byte_vec(&byte_vec); point.serialize_uncompressed(&mut byte_vec).unwrap(); - // Self::print_byte_vec(&byte_vec); combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); hiding_comm.serialize_uncompressed(&mut byte_vec).unwrap(); let bytes = byte_vec.as_slice(); @@ -323,7 +321,6 @@ where bytes.extend(i.to_le_bytes()); bytes.extend(j.to_le_bytes()); hash = D::digest(bytes.as_slice()); - // hash = D::digest(&to_bytes![&Self::PROTOCOL_NAME, i, j].unwrap()); g = G::from_random_bytes(&hash); j += 1; } diff --git a/src/marlin/marlin_pst13_pc/data_structures.rs b/src/marlin/marlin_pst13_pc/data_structures.rs index 5fb60c18..62c9d31f 100644 --- a/src/marlin/marlin_pst13_pc/data_structures.rs +++ b/src/marlin/marlin_pst13_pc/data_structures.rs @@ -551,11 +551,9 @@ impl PCProof for Proof { fn size_in_bytes(&self) -> usize { let hiding_size = if self.random_v.is_some() { E::Fr::zero().serialized_size() - //ark_ff::to_bytes![E::Fr::zero()].unwrap().len() } else { 0 }; (self.w.len() * E::G1Affine::zero().serialized_size()) / 2 + hiding_size - //(self.w.len() * ark_ff::to_bytes![E::G1Affine::zero()].unwrap().len()) / 2 + hiding_size } } From 745124feebec2e10d8e5385dc55a459908e6d70a Mon Sep 17 00:00:00 2001 From: Yuwen Zhang Date: Thu, 25 Aug 2022 22:55:10 -0700 Subject: [PATCH 8/9] apply fmt --- src/ipa_pc/mod.rs | 41 ++++++++++++++++++++----------- src/marlin/marlin_pst13_pc/mod.rs | 7 ++---- src/multilinear_pc/mod.rs | 2 +- src/streaming_kzg/mod.rs | 3 +-- src/streaming_kzg/time.rs | 2 +- 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index 9cab63bd..c88520ef 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -7,7 +7,7 @@ use ark_ec::{msm::VariableBaseMSM, AffineCurve, ProjectiveCurve}; use ark_ff::{Field, One, PrimeField, UniformRand, Zero}; use ark_serialize::CanonicalSerialize; use ark_std::rand::RngCore; -use ark_std::{convert::TryInto, format, marker::PhantomData, vec, ops::Mul}; +use ark_std::{convert::TryInto, format, marker::PhantomData, ops::Mul, vec}; mod data_structures; pub use data_structures::*; @@ -147,7 +147,9 @@ where let hiding_comm = proof.hiding_comm.unwrap(); let rand = proof.rand.unwrap(); let mut byte_vec = Vec::new(); - combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + combined_commitment + .serialize_uncompressed(&mut byte_vec) + .unwrap(); point.serialize_uncompressed(&mut byte_vec).unwrap(); combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); hiding_comm.serialize_uncompressed(&mut byte_vec).unwrap(); @@ -160,7 +162,9 @@ where // Challenge for each round let mut round_challenges = Vec::with_capacity(log_d); let mut byte_vec = Vec::new(); - combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + combined_commitment + .serialize_uncompressed(&mut byte_vec) + .unwrap(); point.serialize_uncompressed(&mut byte_vec).unwrap(); combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); let bytes = byte_vec.as_slice(); @@ -168,15 +172,16 @@ where let h_prime = vk.h.mul(round_challenge); - let mut round_commitment_proj = - combined_commitment_proj + &h_prime.mul(&combined_v); + let mut round_commitment_proj = combined_commitment_proj + &h_prime.mul(&combined_v); let l_iter = proof.l_vec.iter(); let r_iter = proof.r_vec.iter(); for (l, r) in l_iter.zip(r_iter) { let mut byte_vec = Vec::new(); - round_challenge.serialize_uncompressed(&mut byte_vec).unwrap(); + round_challenge + .serialize_uncompressed(&mut byte_vec) + .unwrap(); l.serialize_uncompressed(&mut byte_vec).unwrap(); r.serialize_uncompressed(&mut byte_vec).unwrap(); let bytes = byte_vec.as_slice(); @@ -308,11 +313,8 @@ where let generators: Vec<_> = ark_std::cfg_into_iter!(0..num_generators) .map(|i| { let i = i as u64; - let mut hash = D::digest( - [Self::PROTOCOL_NAME, &i.to_le_bytes()] - .concat() - .as_slice(), - ); + let mut hash = + D::digest([Self::PROTOCOL_NAME, &i.to_le_bytes()].concat().as_slice()); let mut g = G::from_random_bytes(&hash); let mut j = 0u64; while g.is_none() { @@ -601,10 +603,15 @@ where combined_commitment = batch.pop().unwrap(); let mut byte_vec = Vec::new(); - combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + combined_commitment + .serialize_uncompressed(&mut byte_vec) + .unwrap(); point.serialize_uncompressed(&mut byte_vec).unwrap(); combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); - hiding_commitment.unwrap().serialize_uncompressed(&mut byte_vec).unwrap(); + hiding_commitment + .unwrap() + .serialize_uncompressed(&mut byte_vec) + .unwrap(); let bytes = byte_vec.as_slice(); let hiding_challenge = Self::compute_random_oracle_challenge(bytes); combined_polynomial += (hiding_challenge, &hiding_polynomial); @@ -628,7 +635,9 @@ where // ith challenge let mut byte_vec = Vec::new(); - combined_commitment.serialize_uncompressed(&mut byte_vec).unwrap(); + combined_commitment + .serialize_uncompressed(&mut byte_vec) + .unwrap(); point.serialize_uncompressed(&mut byte_vec).unwrap(); combined_v.serialize_uncompressed(&mut byte_vec).unwrap(); let bytes = byte_vec.as_slice(); @@ -685,7 +694,9 @@ where r_vec.push(lr[1]); let mut byte_vec = Vec::new(); - round_challenge.serialize_uncompressed(&mut byte_vec).unwrap(); + round_challenge + .serialize_uncompressed(&mut byte_vec) + .unwrap(); lr[0].serialize_uncompressed(&mut byte_vec).unwrap(); lr[1].serialize_uncompressed(&mut byte_vec).unwrap(); let bytes = byte_vec.as_slice(); diff --git a/src/marlin/marlin_pst13_pc/mod.rs b/src/marlin/marlin_pst13_pc/mod.rs index 5e46500a..20f7096b 100644 --- a/src/marlin/marlin_pst13_pc/mod.rs +++ b/src/marlin/marlin_pst13_pc/mod.rs @@ -14,7 +14,7 @@ use ark_ec::{ use ark_ff::{One, PrimeField, UniformRand, Zero}; use ark_poly::{multivariate::Term, DenseMVPolynomial}; use ark_std::rand::RngCore; -use ark_std::{marker::PhantomData, ops::Index, vec, ops::Mul}; +use ark_std::{marker::PhantomData, ops::Index, ops::Mul, vec}; mod data_structures; pub use data_structures::*; @@ -254,10 +254,7 @@ where .into_iter() .map(|v| E::G1Projective::batch_normalization_into_affine(&v)) .collect(); - let beta_h: Vec<_> = betas - .iter() - .map(|b| h.mul(b).into_affine()) - .collect(); + let beta_h: Vec<_> = betas.iter().map(|b| h.mul(b).into_affine()).collect(); let h = h.into_affine(); let prepared_h = h.into(); let prepared_beta_h = beta_h.iter().map(|bh| (*bh).into()).collect(); diff --git a/src/multilinear_pc/mod.rs b/src/multilinear_pc/mod.rs index f57b2033..6d001639 100644 --- a/src/multilinear_pc/mod.rs +++ b/src/multilinear_pc/mod.rs @@ -9,9 +9,9 @@ use ark_poly::{DenseMultilinearExtension, MultilinearExtension}; use ark_std::collections::LinkedList; use ark_std::iter::FromIterator; use ark_std::marker::PhantomData; +use ark_std::ops::Mul; use ark_std::rand::RngCore; use ark_std::vec::Vec; -use ark_std::ops::Mul; use ark_std::UniformRand; /// data structures used by multilinear extension commitment scheme diff --git a/src/streaming_kzg/mod.rs b/src/streaming_kzg/mod.rs index 8feaaa27..4c5e8385 100644 --- a/src/streaming_kzg/mod.rs +++ b/src/streaming_kzg/mod.rs @@ -179,8 +179,7 @@ impl VerifierKey { ) -> VerificationResult { let scalars = [(-alpha).into_bigint(), E::Fr::one().into_bigint()]; let ep = ::msm_bigint(&self.powers_of_g2, &scalars); - let lhs = - commitment.0.into_projective() - self.powers_of_g[0].mul(evaluation); + let lhs = commitment.0.into_projective() - self.powers_of_g[0].mul(evaluation); let g2 = self.powers_of_g2[0]; if E::pairing(lhs, g2) == E::pairing(proof.0, ep) { diff --git a/src/streaming_kzg/time.rs b/src/streaming_kzg/time.rs index c1dac1c4..251a0e9e 100644 --- a/src/streaming_kzg/time.rs +++ b/src/streaming_kzg/time.rs @@ -6,7 +6,7 @@ use ark_ec::ProjectiveCurve; use ark_ff::{PrimeField, Zero}; use ark_poly::{univariate::DensePolynomial, DenseUVPolynomial}; use ark_std::borrow::Borrow; -use ark_std::ops::{Mul, Div}; +use ark_std::ops::{Div, Mul}; use ark_std::rand::RngCore; use ark_std::vec::Vec; use ark_std::UniformRand; From 4eb59753227bf02f2af471d6dd2b55f151cebfed Mon Sep 17 00:00:00 2001 From: Yuwen Zhang Date: Thu, 25 Aug 2022 23:45:13 -0700 Subject: [PATCH 9/9] small change to ipa_pc open --- src/ipa_pc/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa_pc/mod.rs b/src/ipa_pc/mod.rs index c88520ef..4751f8c0 100644 --- a/src/ipa_pc/mod.rs +++ b/src/ipa_pc/mod.rs @@ -585,7 +585,7 @@ where if has_hiding { let mut rng = rng.expect("hiding commitments require randomness"); let hiding_time = start_timer!(|| "Applying hiding."); - let mut hiding_polynomial = P::rand(0, &mut rng); + let mut hiding_polynomial = P::rand(d, &mut rng); hiding_polynomial -= &P::from_coefficients_slice(&[hiding_polynomial.evaluate(point)]); let hiding_rand = G::ScalarField::rand(&mut rng); let hiding_commitment_proj = Self::cm_commit(