diff --git a/CHANGELOG.md b/CHANGELOG.md index 08d1b511e..389b9a703 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -160,6 +160,7 @@ - `MNT6Parameters` → `MNT6Config` - `GLVParameters` → `GLVConfig` - [\#557](https://github.com/arkworks-rs/algebra/pull/557) (`ark-ff`) Change `frobenius_map` to return the result, instead of mutating the input. Add `frobenius_map_in_place` for the old behavior. +- [\#537](https://github.com/arkworks-rs/algebra/pull/571) (`ark-ec`) Add `CanonicalSerialize` and `CanonicalDeserialize` traits to the arguments of `multi_miller_loop`. ### Features diff --git a/ec/src/models/bls12/mod.rs b/ec/src/models/bls12/mod.rs index ca8a66351..896aadbcc 100644 --- a/ec/src/models/bls12/mod.rs +++ b/ec/src/models/bls12/mod.rs @@ -12,6 +12,7 @@ use ark_ff::{ }, BitIteratorBE, CyclotomicMultSubgroup, Field, PrimeField, }; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::{marker::PhantomData, vec::Vec}; use num_traits::{One, Zero}; @@ -44,8 +45,12 @@ pub trait Bls12Config: 'static + Sized { >; fn multi_miller_loop( - a: impl IntoIterator>>, - b: impl IntoIterator>>, + a: impl IntoIterator< + Item = impl Into> + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into> + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput> { use itertools::Itertools; @@ -211,8 +216,12 @@ impl Pairing for Bls12

{ type TargetField = Fp12; fn multi_miller_loop( - a: impl IntoIterator>, - b: impl IntoIterator>, + a: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput { P::multi_miller_loop(a, b) } diff --git a/ec/src/models/bn/mod.rs b/ec/src/models/bn/mod.rs index 62f7d4c4c..a4fd99630 100644 --- a/ec/src/models/bn/mod.rs +++ b/ec/src/models/bn/mod.rs @@ -11,6 +11,7 @@ use ark_ff::{ }, CyclotomicMultSubgroup, }; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::{marker::PhantomData, vec::Vec}; use itertools::Itertools; use num_traits::One; @@ -102,8 +103,12 @@ impl Pairing for Bn

{ type TargetField = Fp12; fn multi_miller_loop( - a: impl IntoIterator>, - b: impl IntoIterator>, + a: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput { let mut pairs = a .into_iter() diff --git a/ec/src/models/bw6/mod.rs b/ec/src/models/bw6/mod.rs index 62c053fb8..7419e1ba6 100644 --- a/ec/src/models/bw6/mod.rs +++ b/ec/src/models/bw6/mod.rs @@ -10,6 +10,7 @@ use ark_ff::{ }, BitIteratorBE, CyclotomicMultSubgroup, }; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use itertools::Itertools; use num_traits::One; @@ -52,8 +53,12 @@ pub trait BW6Config: 'static + Eq + Sized { } fn multi_miller_loop( - a: impl IntoIterator>>, - b: impl IntoIterator>>, + a: impl IntoIterator< + Item = impl Into> + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into> + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput> { // Alg.5 in https://eprint.iacr.org/2020/351.pdf @@ -311,8 +316,12 @@ impl Pairing for BW6

{ } fn multi_miller_loop( - a: impl IntoIterator>, - b: impl IntoIterator>, + a: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput { P::multi_miller_loop(a, b) } diff --git a/ec/src/models/mnt4/mod.rs b/ec/src/models/mnt4/mod.rs index fc40d4cfc..5b49b892b 100644 --- a/ec/src/models/mnt4/mod.rs +++ b/ec/src/models/mnt4/mod.rs @@ -10,6 +10,7 @@ use ark_ff::{ use itertools::Itertools; use num_traits::{One, Zero}; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::{marker::PhantomData, vec::Vec}; #[cfg(feature = "parallel")] @@ -208,8 +209,12 @@ impl Pairing for MNT4

{ type TargetField = Fp4; fn multi_miller_loop( - a: impl IntoIterator>, - b: impl IntoIterator>, + a: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput { let pairs = a .into_iter() diff --git a/ec/src/models/mnt6/mod.rs b/ec/src/models/mnt6/mod.rs index 82e0b2ad9..42720720c 100644 --- a/ec/src/models/mnt6/mod.rs +++ b/ec/src/models/mnt6/mod.rs @@ -10,6 +10,7 @@ use ark_ff::{ use itertools::Itertools; use num_traits::{One, Zero}; +use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_std::{marker::PhantomData, vec::Vec}; #[cfg(feature = "parallel")] @@ -214,8 +215,12 @@ impl Pairing for MNT6

{ type TargetField = Fp6; fn multi_miller_loop( - a: impl IntoIterator>, - b: impl IntoIterator>, + a: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput { let pairs = a .into_iter() diff --git a/ec/src/pairing.rs b/ec/src/pairing.rs index 05071a593..90849a7a6 100644 --- a/ec/src/pairing.rs +++ b/ec/src/pairing.rs @@ -37,7 +37,9 @@ pub trait Pairing: Sized + 'static + Copy + Debug + Sync + Send + Eq { type G1Affine: AffineRepr + From + Into - + Into; + + Into + + CanonicalSerialize + + CanonicalDeserialize; /// A G1 element that has been preprocessed for use in a pairing. type G1Prepared: Default @@ -63,7 +65,9 @@ pub trait Pairing: Sized + 'static + Copy + Debug + Sync + Send + Eq { type G2Affine: AffineRepr + From + Into - + Into; + + Into + + CanonicalSerialize + + CanonicalDeserialize; /// A G2 element that has been preprocessed for use in a pairing. type G2Prepared: Default @@ -83,14 +87,18 @@ pub trait Pairing: Sized + 'static + Copy + Debug + Sync + Send + Eq { /// Computes the product of Miller loops for some number of (G1, G2) pairs. fn multi_miller_loop( - a: impl IntoIterator>, - b: impl IntoIterator>, + a: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, ) -> MillerLoopOutput; /// Computes the Miller loop over `a` and `b`. fn miller_loop( - a: impl Into, - b: impl Into, + a: impl Into + CanonicalSerialize + CanonicalDeserialize, + b: impl Into + CanonicalSerialize + CanonicalDeserialize, ) -> MillerLoopOutput { Self::multi_miller_loop([a], [b]) } @@ -101,16 +109,20 @@ pub trait Pairing: Sized + 'static + Copy + Debug + Sync + Send + Eq { /// Computes a "product" of pairings. fn multi_pairing( - a: impl IntoIterator>, - b: impl IntoIterator>, + a: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, + b: impl IntoIterator< + Item = impl Into + CanonicalSerialize + CanonicalDeserialize, + >, ) -> PairingOutput { Self::final_exponentiation(Self::multi_miller_loop(a, b)).unwrap() } /// Performs multiple pairing operations fn pairing( - p: impl Into, - q: impl Into, + p: impl Into + CanonicalSerialize + CanonicalDeserialize, + q: impl Into + CanonicalSerialize + CanonicalDeserialize, ) -> PairingOutput { Self::multi_pairing([p], [q]) } diff --git a/ff/src/fields/models/fp/montgomery_backend.rs b/ff/src/fields/models/fp/montgomery_backend.rs index 0b38ff7be..e494eaa8a 100644 --- a/ff/src/fields/models/fp/montgomery_backend.rs +++ b/ff/src/fields/models/fp/montgomery_backend.rs @@ -821,8 +821,7 @@ impl, const N: usize> Fp, N> { #[cfg(test)] mod test { - use ark_std::str::FromStr; - use ark_std::vec::Vec; + use ark_std::{str::FromStr, vec::Vec}; use ark_test_curves::secp256k1::Fr; use num_bigint::{BigInt, BigUint, Sign}; diff --git a/test-curves/src/bls12_381/g2.rs b/test-curves/src/bls12_381/g2.rs index f4c970910..63617c7a7 100644 --- a/test-curves/src/bls12_381/g2.rs +++ b/test-curves/src/bls12_381/g2.rs @@ -9,7 +9,6 @@ use ark_ec::{ AffineRepr, CurveGroup, Group, }; use ark_ff::{BigInt, Field, MontFp, Zero}; - pub type G2Affine = bls12::G2Affine; pub type G2Projective = bls12::G2Projective; diff --git a/test-templates/src/h2c/mod.rs b/test-templates/src/h2c/mod.rs index 520ad7979..c65391d23 100644 --- a/test-templates/src/h2c/mod.rs +++ b/test-templates/src/h2c/mod.rs @@ -29,8 +29,7 @@ macro_rules! test_h2c { fs::{read_dir, File}, io::BufReader, }; - use $crate::decode; - use $crate::Sha256; + use $crate::{decode, Sha256}; use $crate::json::SuiteVector; #[test] diff --git a/test-templates/src/pairing.rs b/test-templates/src/pairing.rs index 8386969ca..e0f50262b 100644 --- a/test-templates/src/pairing.rs +++ b/test-templates/src/pairing.rs @@ -45,7 +45,7 @@ macro_rules! test_pairing { let c = <$Pairing as Pairing>::G1::rand(rng).into_affine(); let d = <$Pairing as Pairing>::G2::rand(rng).into_affine(); let ans1 = <$Pairing>::pairing(a, b) + &<$Pairing>::pairing(c, d); - let ans2 = <$Pairing>::multi_pairing(&[a, c], &[b, d]); + let ans2 = <$Pairing>::multi_pairing([a, c], [b, d]); assert_eq!(ans1, ans2); } }