From 9228d20862476f3784ba31c71631c899bb7a77a9 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Thu, 30 May 2019 18:14:18 +0300 Subject: [PATCH 1/7] prepare for gpu integration --- Cargo.toml | 6 ++++-- src/bls12_381/ec.rs | 16 ++++++++++++++-- src/bn256/ec.rs | 18 ++++++++++++++---- src/lib.rs | 20 ++++++++++++++------ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e7b64b3..22dbc56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,12 +15,14 @@ description = "Pairing-friendly elliptic curve library" documentation = "https://docs.rs/pairing/" homepage = "https://github.com/matter-labs/pairing" repository = "https://github.com/matter-labs/pairing" +edition = "2018" [dependencies] rand = "0.4" byteorder = "1" -ff_ce = {version = "0.6", features = ["derive"] } -#ff = { git = 'https://github.com/matterinc/ff', features = ["derive"], tag = "0.5"} +#ff_ce = {version = "0.6", features = ["derive"] } +#ff_ce = { git = 'https://github.com/matter-labs/ff', features = ["derive"], branch = "gpu"} +ff_ce = { path = '../ff', features = ["derive", "derive_serde"]} serde = "1.0.80" serde_derive = "1.0.80" serde_json = "1.0.33" diff --git a/src/bls12_381/ec.rs b/src/bls12_381/ec.rs index 5c0545f..d4e1131 100644 --- a/src/bls12_381/ec.rs +++ b/src/bls12_381/ec.rs @@ -626,7 +626,7 @@ pub mod g1 { use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField}; use rand::{Rand, Rng}; use std::fmt; - use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; + use crate::{RawEncodable, CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; curve_impl!( "G1", @@ -750,6 +750,18 @@ pub mod g1 { } } + impl RawEncodable for G1Affine { + fn into_raw_uncompressed_le(&self) -> Self::Uncompressed { + let mut res = Self::Uncompressed::empty(); + let mut writer = &mut res.0[..]; + + self.x.into_raw_repr().write_le(&mut writer).unwrap(); + self.y.into_raw_repr().write_le(&mut writer).unwrap(); + + res + } + } + #[derive(Copy, Clone)] pub struct G1Compressed([u8; 48]); @@ -1272,7 +1284,7 @@ pub mod g2 { use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField}; use rand::{Rand, Rng}; use std::fmt; - use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; + use crate::{CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; curve_impl!( "G2", diff --git a/src/bn256/ec.rs b/src/bn256/ec.rs index f4a3a63..ab58e29 100644 --- a/src/bn256/ec.rs +++ b/src/bn256/ec.rs @@ -190,9 +190,7 @@ macro_rules! curve_impl { fn into_projective(&self) -> $projective { (*self).into() } - } - // impl Rand for $projective { // fn rand(rng: &mut R) -> Self { // loop { @@ -630,7 +628,7 @@ pub mod g1 { use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField}; use rand::{Rand, Rng}; use std::fmt; - use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; + use crate::{RawEncodable, CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; curve_impl!( "G1", @@ -644,6 +642,18 @@ pub mod g1 { G2Affine ); + impl RawEncodable for G1Affine { + fn into_raw_uncompressed_le(&self) -> Self::Uncompressed { + let mut res = Self::Uncompressed::empty(); + let mut writer = &mut res.0[..]; + + self.x.into_raw_repr().write_le(&mut writer).unwrap(); + self.y.into_raw_repr().write_le(&mut writer).unwrap(); + + res + } + } + #[derive(Copy, Clone)] pub struct G1Uncompressed([u8; 64]); @@ -1013,7 +1023,7 @@ pub mod g2 { use ff::{BitIterator, Field, PrimeField, PrimeFieldRepr, SqrtField}; use rand::{Rand, Rng}; use std::fmt; - use {CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; + use crate::{CurveAffine, CurveProjective, EncodedPoint, Engine, GroupDecodingError}; curve_impl!( "G2", diff --git a/src/lib.rs b/src/lib.rs index f704b21..f6f1df6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,11 +22,13 @@ extern crate serde_derive; #[cfg(test)] pub mod tests; -extern crate ff_ce as imported_ff; +pub extern crate ff_ce as ff; -pub mod ff { - pub use imported_ff::*; -} +pub use ff::*; + +// pub mod ff { +// pub use ff::*; +// } pub mod bls12_381; pub mod bn256; @@ -60,7 +62,7 @@ pub trait Engine: ScalarEngine { Pair = Self::G2Affine, PairingResult = Self::Fqk, > - + From; + + From + RawEncodable; /// The projective representation of an element in G2. type G2: CurveProjective< @@ -102,7 +104,7 @@ pub trait Engine: ScalarEngine { >; /// Perform final exponentiation of the result of a miller loop. - fn final_exponentiation(&Self::Fqk) -> Option; + fn final_exponentiation(r: &Self::Fqk) -> Option; /// Performs a complete pairing operation `(p, q)`. fn pairing(p: G1, q: G2) -> Self::Fqk @@ -240,6 +242,12 @@ pub trait CurveAffine: } } +pub trait RawEncodable: CurveAffine { + /// Converts this element into its uncompressed encoding, so long as it's not + /// the point at infinity. Leaves coordinates in Montgommery form + fn into_raw_uncompressed_le(&self) -> Self::Uncompressed; +} + /// An encoded elliptic curve point, which should essentially wrap a `[u8; N]`. pub trait EncodedPoint: Sized + Send + Sync + AsRef<[u8]> + AsMut<[u8]> + Clone + Copy + 'static From 47948ef8a59605eb39e6ab0e1a79715f6df87085 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Sat, 1 Jun 2019 14:08:44 +0300 Subject: [PATCH 2/7] implement decoding from raw representation --- src/bls12_381/ec.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/bn256/ec.rs | 41 +++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 6 ++++++ 3 files changed, 86 insertions(+) diff --git a/src/bls12_381/ec.rs b/src/bls12_381/ec.rs index d4e1131..7eabb53 100644 --- a/src/bls12_381/ec.rs +++ b/src/bls12_381/ec.rs @@ -760,6 +760,45 @@ pub mod g1 { res } + + fn from_raw_uncompressed_le_unchecked( + encoded: &Self::Uncompressed, + _infinity: bool + ) -> Result { + let copy = encoded.0; + if copy.iter().all(|b| *b == 0) { + return Ok(Self::zero()); + } + + let mut x = FqRepr([0; 6]); + let mut y = FqRepr([0; 6]); + + { + let mut reader = ©[..]; + x.read_be(&mut reader).unwrap(); + y.read_be(&mut reader).unwrap(); + } + + Ok(G1Affine { + x: Fq::from_raw_repr(x).map_err(|e| { + GroupDecodingError::CoordinateDecodingError("x coordinate", e) + })?, + y: Fq::from_raw_repr(y).map_err(|e| { + GroupDecodingError::CoordinateDecodingError("y coordinate", e) + })?, + infinity: false, + }) + } + + fn from_raw_uncompressed_le(encoded: &Self::Uncompressed, _infinity: bool) -> Result { + let affine = Self::from_raw_uncompressed_le_unchecked(&encoded, _infinity)?; + + if !affine.is_on_curve() { + Err(GroupDecodingError::NotOnCurve) + } else { + Ok(affine) + } + } } #[derive(Copy, Clone)] diff --git a/src/bn256/ec.rs b/src/bn256/ec.rs index ab58e29..e60f757 100644 --- a/src/bn256/ec.rs +++ b/src/bn256/ec.rs @@ -652,6 +652,47 @@ pub mod g1 { res } + + /// Creates a point from raw encoded coordinates without checking on curve + fn from_raw_uncompressed_le_unchecked( + encoded: &Self::Uncompressed, + _infinity: bool + ) -> Result { + let copy = encoded.0; + + if copy.iter().all(|b| *b == 0) { + return Ok(Self::zero()); + } + + let mut x = FqRepr([0; 4]); + let mut y = FqRepr([0; 4]); + + { + let mut reader = ©[..]; + x.read_be(&mut reader).unwrap(); + y.read_be(&mut reader).unwrap(); + } + + Ok(G1Affine { + x: Fq::from_raw_repr(x).map_err(|e| { + GroupDecodingError::CoordinateDecodingError("x coordinate", e) + })?, + y: Fq::from_raw_repr(y).map_err(|e| { + GroupDecodingError::CoordinateDecodingError("y coordinate", e) + })?, + infinity: false, + }) + } + + fn from_raw_uncompressed_le(encoded: &Self::Uncompressed, _infinity: bool) -> Result { + let affine = Self::from_raw_uncompressed_le_unchecked(&encoded, _infinity)?; + + if !affine.is_on_curve() { + Err(GroupDecodingError::NotOnCurve) + } else { + Ok(affine) + } + } } #[derive(Copy, Clone)] diff --git a/src/lib.rs b/src/lib.rs index f6f1df6..8d7053f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -246,6 +246,12 @@ pub trait RawEncodable: CurveAffine { /// Converts this element into its uncompressed encoding, so long as it's not /// the point at infinity. Leaves coordinates in Montgommery form fn into_raw_uncompressed_le(&self) -> Self::Uncompressed; + + /// Creates a point from raw encoded coordinates without checking on curve + fn from_raw_uncompressed_le_unchecked(encoded: &Self::Uncompressed, infinity: bool) -> Result; + + /// Creates a point from raw encoded coordinates + fn from_raw_uncompressed_le(encoded: &Self::Uncompressed, infinity: bool) -> Result; } /// An encoded elliptic curve point, which should essentially wrap a `[u8; N]`. From b75da3d8dca5e3068fdaca872fa4f5e8e8531086 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Sun, 2 Jun 2019 16:55:34 +0300 Subject: [PATCH 3/7] fix BE to LE --- src/bls12_381/ec.rs | 4 ++-- src/bn256/ec.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bls12_381/ec.rs b/src/bls12_381/ec.rs index 7eabb53..3d505de 100644 --- a/src/bls12_381/ec.rs +++ b/src/bls12_381/ec.rs @@ -775,8 +775,8 @@ pub mod g1 { { let mut reader = ©[..]; - x.read_be(&mut reader).unwrap(); - y.read_be(&mut reader).unwrap(); + x.read_le(&mut reader).unwrap(); + y.read_le(&mut reader).unwrap(); } Ok(G1Affine { diff --git a/src/bn256/ec.rs b/src/bn256/ec.rs index e60f757..02fcbc0 100644 --- a/src/bn256/ec.rs +++ b/src/bn256/ec.rs @@ -669,8 +669,8 @@ pub mod g1 { { let mut reader = ©[..]; - x.read_be(&mut reader).unwrap(); - y.read_be(&mut reader).unwrap(); + x.read_le(&mut reader).unwrap(); + y.read_le(&mut reader).unwrap(); } Ok(G1Affine { From 76c2d3451ff26812a0a9a178bb9f1f956d481b11 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Sun, 2 Jun 2019 21:26:26 +0300 Subject: [PATCH 4/7] fix warning --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 8d7053f..a22b5b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,6 @@ extern crate rand; extern crate hex; extern crate serde; -#[macro_use] extern crate serde_derive; #[cfg(test)] From 1dae6b69dbde527af0762dd579c7c9a560ea0a12 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Fri, 12 Jul 2019 21:59:06 +0300 Subject: [PATCH 5/7] start migrating to edition 2018 --- Cargo.toml | 6 +--- src/bls12_381/ec.rs | 8 +++-- src/bn256/ec.rs | 71 +++++++++++++++++++++++++++++++-------------- src/lib.rs | 10 +------ 4 files changed, 56 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 22dbc56..485800f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,11 +22,7 @@ rand = "0.4" byteorder = "1" #ff_ce = {version = "0.6", features = ["derive"] } #ff_ce = { git = 'https://github.com/matter-labs/ff', features = ["derive"], branch = "gpu"} -ff_ce = { path = '../ff', features = ["derive", "derive_serde"]} -serde = "1.0.80" -serde_derive = "1.0.80" -serde_json = "1.0.33" -hex = "0.3.2" +ff = { path = '../ff', package = "ff_ce", features = ["derive"]} [features] unstable-features = ["expose-arith"] diff --git a/src/bls12_381/ec.rs b/src/bls12_381/ec.rs index 3d505de..54c02c2 100644 --- a/src/bls12_381/ec.rs +++ b/src/bls12_381/ec.rs @@ -753,10 +753,12 @@ pub mod g1 { impl RawEncodable for G1Affine { fn into_raw_uncompressed_le(&self) -> Self::Uncompressed { let mut res = Self::Uncompressed::empty(); - let mut writer = &mut res.0[..]; + { + let mut writer = &mut res.0[..]; - self.x.into_raw_repr().write_le(&mut writer).unwrap(); - self.y.into_raw_repr().write_le(&mut writer).unwrap(); + self.x.into_raw_repr().write_le(&mut writer).unwrap(); + self.y.into_raw_repr().write_le(&mut writer).unwrap(); + } res } diff --git a/src/bn256/ec.rs b/src/bn256/ec.rs index 02fcbc0..cb3ab13 100644 --- a/src/bn256/ec.rs +++ b/src/bn256/ec.rs @@ -645,10 +645,12 @@ pub mod g1 { impl RawEncodable for G1Affine { fn into_raw_uncompressed_le(&self) -> Self::Uncompressed { let mut res = Self::Uncompressed::empty(); - let mut writer = &mut res.0[..]; + { + let mut writer = &mut res.0[..]; - self.x.into_raw_repr().write_le(&mut writer).unwrap(); - self.y.into_raw_repr().write_le(&mut writer).unwrap(); + self.x.into_raw_repr().write_le(&mut writer).unwrap(); + self.y.into_raw_repr().write_le(&mut writer).unwrap(); + } res } @@ -1078,25 +1080,6 @@ pub mod g2 { G1Affine ); - // impl Rand for G2 { - // fn rand(rng: &mut R) -> Self { - - // let mut r = G2::one(); - // let k = Fr::rand(rng); - // r.mul_assign(k); - // return r; - // } - // } - - // impl Rand for G2Affine { - // fn rand(rng: &mut R) -> Self { - // let mut r = G2::one(); - // let k = Fr::rand(rng); - // r.mul_assign(k); - // return r.into_affine(); - // } - // } - impl Rand for G2 { fn rand(rng: &mut R) -> Self { loop { @@ -1471,6 +1454,50 @@ pub mod g2 { } } + #[test] + fn test_generate_g2_in_subgroup() { + use SqrtField; + + let mut x = Fq2::zero(); + loop { + // y^2 = x^3 + b + let mut rhs = x; + rhs.square(); + rhs.mul_assign(&x); + rhs.add_assign(&G2Affine::get_coeff_b()); + + if let Some(y) = rhs.sqrt() { + let mut negy = y; + negy.negate(); + + let p = G2Affine { + x: x, + y: if y < negy { y } else { negy }, + infinity: false, + }; + + let g2 = p.into_projective(); + let mut minus_one = Fr::one(); + minus_one.negate(); + + let mut expected_zero = p.mul(minus_one); + expected_zero.add_assign(&g2); + + if !expected_zero.is_zero() { + let p = expected_zero.into_affine(); + let scaled_by_cofactor = p.scale_by_cofactor(); + if scaled_by_cofactor.is_zero() { + let g2 = G2Affine::from(expected_zero); + println!("Invalid subgroup point = {}", g2); + return; + } + } + } + + x.add_assign(&Fq2::one()); + } + } + #[cfg(test)] use rand::{SeedableRng, XorShiftRng}; diff --git a/src/lib.rs b/src/lib.rs index a22b5b7..8c1a255 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,21 +14,13 @@ extern crate byteorder; extern crate rand; -extern crate hex; -extern crate serde; -extern crate serde_derive; - #[cfg(test)] pub mod tests; -pub extern crate ff_ce as ff; +pub extern crate ff; pub use ff::*; -// pub mod ff { -// pub use ff::*; -// } - pub mod bls12_381; pub mod bn256; From 2567aab84d5167879e01199e3100944e7ab0ea3e Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Fri, 12 Jul 2019 22:05:30 +0300 Subject: [PATCH 6/7] fix for edition 2018 --- benches/pairing_benches.rs | 2 +- src/bls12_381/ec.rs | 8 ++++---- src/bls12_381/fq.rs | 12 ++++++------ src/bls12_381/fq12.rs | 4 ++-- src/bls12_381/fq2.rs | 6 +++--- src/bls12_381/fq6.rs | 4 ++-- src/bls12_381/fr.rs | 12 ++++++------ src/bls12_381/mod.rs | 2 +- src/bls12_381/tests/mod.rs | 2 +- src/bn256/ec.rs | 8 ++++---- src/bn256/fq.rs | 10 +++++----- src/bn256/fq12.rs | 4 ++-- src/bn256/fq2.rs | 6 +++--- src/bn256/fq6.rs | 4 ++-- src/bn256/fr.rs | 16 +--------------- src/bn256/mod.rs | 6 +++--- src/tests/curve.rs | 4 ++-- src/tests/engine.rs | 2 +- 18 files changed, 49 insertions(+), 63 deletions(-) diff --git a/benches/pairing_benches.rs b/benches/pairing_benches.rs index ddfd04d..757865a 100644 --- a/benches/pairing_benches.rs +++ b/benches/pairing_benches.rs @@ -1,7 +1,7 @@ #![feature(test)] extern crate ff; -extern crate pairing; +extern crate pairing_ce; extern crate rand; extern crate test; diff --git a/src/bls12_381/ec.rs b/src/bls12_381/ec.rs index 54c02c2..d4be8cf 100644 --- a/src/bls12_381/ec.rs +++ b/src/bls12_381/ec.rs @@ -1314,8 +1314,8 @@ pub mod g1 { #[test] fn g1_curve_tests() { - ::tests::curve::curve_tests::(); - ::tests::curve::random_transformation_tests_with_cofactor::(); + crate::tests::curve::curve_tests::(); + crate::tests::curve::random_transformation_tests_with_cofactor::(); } } @@ -2068,8 +2068,8 @@ pub mod g2 { #[test] fn g2_curve_tests() { - ::tests::curve::curve_tests::(); - ::tests::curve::random_transformation_tests_with_cofactor::(); + crate::tests::curve::curve_tests::(); + crate::tests::curve::random_transformation_tests_with_cofactor::(); } } diff --git a/src/bls12_381/fq.rs b/src/bls12_381/fq.rs index fd0d416..601b503 100644 --- a/src/bls12_381/fq.rs +++ b/src/bls12_381/fq.rs @@ -1,5 +1,5 @@ use super::fq2::Fq2; -use ff::{Field, PrimeField, PrimeFieldDecodingError, PrimeFieldRepr}; +use ff::{Field, PrimeField, PrimeFieldRepr}; // B coefficient of BLS12-381 curve, 4. pub const B_COEFF: Fq = Fq(FqRepr([ @@ -2186,10 +2186,10 @@ fn test_fq_root_of_unity() { #[test] fn fq_field_tests() { - ::tests::field::random_field_tests::(); - ::tests::field::random_sqrt_tests::(); - ::tests::field::random_frobenius_tests::(Fq::char(), 13); - ::tests::field::from_str_tests::(); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_sqrt_tests::(); + crate::tests::field::random_frobenius_tests::(Fq::char(), 13); + crate::tests::field::from_str_tests::(); } #[test] @@ -2205,7 +2205,7 @@ fn test_fq_ordering() { #[test] fn fq_repr_tests() { - ::tests::repr::random_repr_tests::(); + crate::tests::repr::random_repr_tests::(); } #[test] diff --git a/src/bls12_381/fq12.rs b/src/bls12_381/fq12.rs index b24fcaa..b8744ca 100644 --- a/src/bls12_381/fq12.rs +++ b/src/bls12_381/fq12.rs @@ -184,6 +184,6 @@ fn test_fq12_mul_by_014() { fn fq12_field_tests() { use ff::PrimeField; - ::tests::field::random_field_tests::(); - ::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); } diff --git a/src/bls12_381/fq2.rs b/src/bls12_381/fq2.rs index 363439a..9737adf 100644 --- a/src/bls12_381/fq2.rs +++ b/src/bls12_381/fq2.rs @@ -904,7 +904,7 @@ fn test_fq2_mul_nonresidue() { fn fq2_field_tests() { use ff::PrimeField; - ::tests::field::random_field_tests::(); - ::tests::field::random_sqrt_tests::(); - ::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_sqrt_tests::(); + crate::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); } diff --git a/src/bls12_381/fq6.rs b/src/bls12_381/fq6.rs index 36c6e28..19b8316 100644 --- a/src/bls12_381/fq6.rs +++ b/src/bls12_381/fq6.rs @@ -369,6 +369,6 @@ fn test_fq6_mul_by_01() { fn fq6_field_tests() { use ff::PrimeField; - ::tests::field::random_field_tests::(); - ::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); } diff --git a/src/bls12_381/fr.rs b/src/bls12_381/fr.rs index 5e57631..bcecbaa 100644 --- a/src/bls12_381/fr.rs +++ b/src/bls12_381/fr.rs @@ -1,4 +1,4 @@ -use ff::{Field, PrimeField, PrimeFieldDecodingError, PrimeFieldRepr}; +use ff::{Field, PrimeField, PrimeFieldRepr}; #[derive(PrimeField)] #[PrimeFieldModulus = "52435875175126190479447740508185965837690552500527637822603658699938581184513"] @@ -974,13 +974,13 @@ fn test_fr_root_of_unity() { #[test] fn fr_field_tests() { - ::tests::field::random_field_tests::(); - ::tests::field::random_sqrt_tests::(); - ::tests::field::random_frobenius_tests::(Fr::char(), 13); - ::tests::field::from_str_tests::(); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_sqrt_tests::(); + crate::tests::field::random_frobenius_tests::(Fr::char(), 13); + crate::tests::field::from_str_tests::(); } #[test] fn fr_repr_tests() { - ::tests::repr::random_repr_tests::(); + crate::tests::repr::random_repr_tests::(); } diff --git a/src/bls12_381/mod.rs b/src/bls12_381/mod.rs index 106591e..005a772 100644 --- a/src/bls12_381/mod.rs +++ b/src/bls12_381/mod.rs @@ -365,5 +365,5 @@ impl G2Prepared { #[test] fn bls12_engine_tests() { - ::tests::engine::engine_tests::(); + crate::tests::engine::engine_tests::(); } diff --git a/src/bls12_381/tests/mod.rs b/src/bls12_381/tests/mod.rs index bf6c595..4f2e5b1 100644 --- a/src/bls12_381/tests/mod.rs +++ b/src/bls12_381/tests/mod.rs @@ -1,5 +1,5 @@ use super::*; -use *; +use crate::*; #[test] fn test_pairing_result_against_relic() { diff --git a/src/bn256/ec.rs b/src/bn256/ec.rs index cb3ab13..6413d6b 100644 --- a/src/bn256/ec.rs +++ b/src/bn256/ec.rs @@ -1055,8 +1055,8 @@ pub mod g1 { #[test] fn g1_curve_tests() { - ::tests::curve::curve_tests::(); - ::tests::curve::random_transformation_tests::(); + crate::tests::curve::curve_tests::(); + crate::tests::curve::random_transformation_tests::(); } } @@ -1532,8 +1532,8 @@ pub mod g2 { #[test] fn g2_curve_tests() { - ::tests::curve::curve_tests::(); - ::tests::curve::random_transformation_tests::(); + crate::tests::curve::curve_tests::(); + crate::tests::curve::random_transformation_tests::(); } #[test] diff --git a/src/bn256/fq.rs b/src/bn256/fq.rs index 19e55d3..9d40d3d 100644 --- a/src/bn256/fq.rs +++ b/src/bn256/fq.rs @@ -1,5 +1,5 @@ use super::fq2::Fq2; -use ff::{Field, PrimeField, PrimeFieldDecodingError, PrimeFieldRepr}; +use ff::{Field, PrimeField, PrimeFieldRepr}; #[derive(PrimeField)] #[PrimeFieldModulus = "21888242871839275222246405745257275088696311157297823662689037894645226208583"] @@ -572,8 +572,8 @@ fn test_fq_sqrt_2() { #[test] fn fq_field_tests() { - ::tests::field::random_field_tests::(); - ::tests::field::random_sqrt_tests::(); - ::tests::field::random_frobenius_tests::(Fq::char(), 13); - ::tests::field::from_str_tests::(); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_sqrt_tests::(); + crate::tests::field::random_frobenius_tests::(Fq::char(), 13); + crate::tests::field::from_str_tests::(); } \ No newline at end of file diff --git a/src/bn256/fq12.rs b/src/bn256/fq12.rs index 67fe6cb..79a68e7 100644 --- a/src/bn256/fq12.rs +++ b/src/bn256/fq12.rs @@ -216,6 +216,6 @@ fn test_squaring() { fn fq12_field_tests() { use ff::PrimeField; - ::tests::field::random_field_tests::(); - ::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); } diff --git a/src/bn256/fq2.rs b/src/bn256/fq2.rs index 98939f3..4a1f9b9 100644 --- a/src/bn256/fq2.rs +++ b/src/bn256/fq2.rs @@ -960,7 +960,7 @@ fn test_fq2_mul_nonresidue() { fn fq2_field_tests() { use ff::PrimeField; - ::tests::field::random_field_tests::(); - ::tests::field::random_sqrt_tests::(); - ::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_sqrt_tests::(); + crate::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); } diff --git a/src/bn256/fq6.rs b/src/bn256/fq6.rs index 412e4ab..d9e481e 100644 --- a/src/bn256/fq6.rs +++ b/src/bn256/fq6.rs @@ -395,6 +395,6 @@ fn test_fq6_mul_by_01() { fn fq6_field_tests() { use ff::PrimeField; - ::tests::field::random_field_tests::(); - ::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); + crate::tests::field::random_field_tests::(); + crate::tests::field::random_frobenius_tests::(super::fq::Fq::char(), 13); } diff --git a/src/bn256/fr.rs b/src/bn256/fr.rs index 97715d8..7f4d103 100644 --- a/src/bn256/fr.rs +++ b/src/bn256/fr.rs @@ -1,4 +1,4 @@ -use ff::{Field, PrimeField, PrimeFieldDecodingError, PrimeFieldRepr}; +use ff::{Field, PrimeField, PrimeFieldRepr}; #[derive(PrimeField)] #[PrimeFieldModulus = "21888242871839275222246405745257275088548364400416034343698204186575808495617"] @@ -28,20 +28,6 @@ fn test_fr_from_hex() { assert_eq!(fr, Fr::zero()); } -#[test] -fn test_fr_serialize() { - assert_eq!( - serde_json::to_string(&Fr::one()).unwrap(), - r#""0x0000000000000000000000000000000000000000000000000000000000000001""#); -} - -#[test] -fn test_fr_deserialize() { - let json = r#""0x0000000000000000000000000000000000000000000000000000000000000001""#; - let fr: Fr = serde_json::from_str(json).unwrap(); - assert_eq!(fr, Fr::one()); -} - #[test] fn test_roots_of_unity() { assert_eq!(Fr::S, 28); diff --git a/src/bn256/mod.rs b/src/bn256/mod.rs index 10f1a91..54087e1 100644 --- a/src/bn256/mod.rs +++ b/src/bn256/mod.rs @@ -473,7 +473,7 @@ use rand::{Rand, SeedableRng, XorShiftRng}; #[test] fn test_pairing() { - use {CurveProjective}; + use crate::{CurveProjective}; let mut g1 = G1::one(); let mut g2 = G2::one(); @@ -557,7 +557,7 @@ fn test_pairing() { #[test] fn random_bilinearity_tests() { - use {CurveProjective}; + use crate::{CurveProjective}; use ff::PrimeField; let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); @@ -600,5 +600,5 @@ fn random_bilinearity_tests() { #[test] fn bn256_engine_tests() { - ::tests::engine::engine_tests::(); + crate::tests::engine::engine_tests::(); } diff --git a/src/tests/curve.rs b/src/tests/curve.rs index a398a73..4663a42 100644 --- a/src/tests/curve.rs +++ b/src/tests/curve.rs @@ -1,7 +1,7 @@ use ff::Field; use rand::{Rand, Rng, SeedableRng, XorShiftRng}; -use {CurveAffine, CurveProjective, EncodedPoint}; +use crate::{CurveAffine, CurveProjective, EncodedPoint}; pub fn curve_tests() { let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); @@ -67,7 +67,7 @@ pub fn curve_tests() { fn random_wnaf_tests() { use ff::PrimeField; - use wnaf::*; + use crate::wnaf::*; let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); diff --git a/src/tests/engine.rs b/src/tests/engine.rs index 52ff4e0..5fc37c4 100644 --- a/src/tests/engine.rs +++ b/src/tests/engine.rs @@ -1,6 +1,6 @@ use rand::{Rand, SeedableRng, XorShiftRng}; -use {CurveAffine, CurveProjective, Engine, Field, PrimeField}; +use crate::{CurveAffine, CurveProjective, Engine, Field, PrimeField}; pub fn engine_tests() { let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); From bfb809c1cddd18e0cd9ac4a2c026c3a3ac24b158 Mon Sep 17 00:00:00 2001 From: Alex Vlasov Date: Sat, 13 Jul 2019 21:58:06 +0300 Subject: [PATCH 7/7] prepare to publish --- Cargo.toml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 485800f..8eaac3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "pairing_ce" # Remember to change version string in README.md. -version = "0.17.0" +version = "0.18.0" authors = [ "Sean Bowe ", "Jack Grigg ", @@ -20,11 +20,9 @@ edition = "2018" [dependencies] rand = "0.4" byteorder = "1" -#ff_ce = {version = "0.6", features = ["derive"] } -#ff_ce = { git = 'https://github.com/matter-labs/ff', features = ["derive"], branch = "gpu"} -ff = { path = '../ff', package = "ff_ce", features = ["derive"]} +ff = {package = "ff_ce", version = "0.7", features = ["derive"]} +#ff = { path = '../ff', package = "ff_ce", features = ["derive"]} [features] -unstable-features = ["expose-arith"] expose-arith = [] default = []