diff --git a/algebra/Cargo.toml b/algebra/Cargo.toml index e3864bb38..5a260186b 100644 --- a/algebra/Cargo.toml +++ b/algebra/Cargo.toml @@ -25,6 +25,7 @@ edition = "2018" byteorder = { version = "1" } rand = { version = "0.7" } derivative = { version = "1" } +num-traits = { version = "0.2.11"} colored = { version = "1", optional = true } rayon = { version = "1", optional = true } diff --git a/algebra/src/curves/bls12_377/g1.rs b/algebra/src/curves/bls12_377/g1.rs index 3805e6c8e..6b97f0838 100644 --- a/algebra/src/curves/bls12_377/g1.rs +++ b/algebra/src/curves/bls12_377/g1.rs @@ -4,9 +4,9 @@ use crate::{ curves::models::{ModelParameters, SWModelParameters}, fields::{ bls12_377::{Fq, Fr}, - Field, }, }; +use num_traits::Zero; #[derive(Copy, Clone, Default, PartialEq, Eq)] pub struct Bls12_377G1Parameters; diff --git a/algebra/src/curves/bls12_377/g2.rs b/algebra/src/curves/bls12_377/g2.rs index c1a613772..121782f58 100644 --- a/algebra/src/curves/bls12_377/g2.rs +++ b/algebra/src/curves/bls12_377/g2.rs @@ -5,9 +5,9 @@ use crate::{ curves::models::{ModelParameters, SWModelParameters}, fields::{ bls12_377::{Fq, Fq2, Fr}, - Field, }, }; +use num_traits::Zero; #[derive(Copy, Clone, Default, PartialEq, Eq)] pub struct Bls12_377G2Parameters; diff --git a/algebra/src/curves/bls12_377/tests.rs b/algebra/src/curves/bls12_377/tests.rs index b256018d9..653547a8e 100644 --- a/algebra/src/curves/bls12_377/tests.rs +++ b/algebra/src/curves/bls12_377/tests.rs @@ -14,6 +14,7 @@ use crate::{ }, groups::tests::group_test, }; +use num_traits::{One, Zero}; use std::ops::{AddAssign, MulAssign}; #[test] diff --git a/algebra/src/curves/bls12_381/g1.rs b/algebra/src/curves/bls12_381/g1.rs index 0271f32fc..65f04c224 100644 --- a/algebra/src/curves/bls12_381/g1.rs +++ b/algebra/src/curves/bls12_381/g1.rs @@ -9,9 +9,9 @@ use crate::{ }, fields::{ bls12_381::{Fq, Fq12, Fr}, - Field, }, }; +use num_traits::Zero; pub type G1Affine = Bls12G1Affine; pub type G1Projective = Bls12G1Projective; diff --git a/algebra/src/curves/bls12_381/g2.rs b/algebra/src/curves/bls12_381/g2.rs index 112e04096..ed01eb9d7 100644 --- a/algebra/src/curves/bls12_381/g2.rs +++ b/algebra/src/curves/bls12_381/g2.rs @@ -12,9 +12,9 @@ use crate::{ }, fields::{ bls12_381::{Fq, Fq12, Fq2, Fr}, - Field, }, }; +use num_traits::Zero; pub type G2Affine = Bls12G2Affine; pub type G2Projective = Bls12G2Projective; diff --git a/algebra/src/curves/bls12_381/tests.rs b/algebra/src/curves/bls12_381/tests.rs index 5c23947ae..910902c07 100644 --- a/algebra/src/curves/bls12_381/tests.rs +++ b/algebra/src/curves/bls12_381/tests.rs @@ -16,6 +16,7 @@ use crate::{ }, groups::tests::group_test, }; +use num_traits::{One, Zero}; use rand; use std::ops::{AddAssign, MulAssign}; diff --git a/algebra/src/curves/jubjub/tests.rs b/algebra/src/curves/jubjub/tests.rs index b3c58ef61..c038091dc 100644 --- a/algebra/src/curves/jubjub/tests.rs +++ b/algebra/src/curves/jubjub/tests.rs @@ -1,9 +1,13 @@ use crate::{ bytes::{FromBytes, ToBytes}, - curves::{jubjub::*, tests::curve_tests, AffineCurve, ProjectiveCurve, models::twisted_edwards_extended::tests::montgomery_conversion_test}, + curves::{ + jubjub::*, models::twisted_edwards_extended::tests::montgomery_conversion_test, + tests::curve_tests, AffineCurve, ProjectiveCurve, + }, fields::jubjub::fr::Fr, groups::tests::group_test, }; +use num_traits::Zero; use rand; use std::str::FromStr; diff --git a/algebra/src/curves/mnt6/mod.rs b/algebra/src/curves/mnt6/mod.rs index 08b05c199..e3396c25f 100644 --- a/algebra/src/curves/mnt6/mod.rs +++ b/algebra/src/curves/mnt6/mod.rs @@ -10,6 +10,7 @@ use crate::{ BitIterator, Field, FpParameters, }, }; +use num_traits::{One, Zero}; pub mod g1; pub mod g2; diff --git a/algebra/src/curves/mnt6/tests.rs b/algebra/src/curves/mnt6/tests.rs index e702daf48..88c6e4f14 100644 --- a/algebra/src/curves/mnt6/tests.rs +++ b/algebra/src/curves/mnt6/tests.rs @@ -7,6 +7,7 @@ use crate::{ fields::mnt6::fr::Fr, groups::tests::group_test, }; +use num_traits::One; use rand; #[test] diff --git a/algebra/src/curves/mod.rs b/algebra/src/curves/mod.rs index 3d295fb11..4f4f715df 100644 --- a/algebra/src/curves/mod.rs +++ b/algebra/src/curves/mod.rs @@ -4,6 +4,7 @@ use crate::{ groups::Group, }; use crate::UniformRand; +use num_traits::Zero; use std::{ fmt::{Debug, Display}, hash::Hash, @@ -126,9 +127,11 @@ pub trait ProjectiveCurve: + Debug + Display + UniformRand + + Zero + 'static + Neg + for<'a> Add<&'a Self, Output = Self> + + Add + for<'a> Sub<&'a Self, Output = Self> + for<'a> AddAssign<&'a Self> + for<'a> SubAssign<&'a Self> @@ -137,18 +140,10 @@ pub trait ProjectiveCurve: type BaseField: Field; type Affine: AffineCurve; - /// Returns the additive identity. - #[must_use] - fn zero() -> Self; - /// Returns a fixed generator of unknown exponent. #[must_use] fn prime_subgroup_generator() -> Self; - /// Determines if this point is the point at infinity. - #[must_use] - fn is_zero(&self) -> bool; - /// Normalizes a slice of projective elements so that /// conversion to affine is cheap. fn batch_normalization(v: &mut [Self]); @@ -205,6 +200,7 @@ pub trait AffineCurve: + Hash + Debug + Display + + Zero + Neg + 'static { @@ -212,19 +208,10 @@ pub trait AffineCurve: type BaseField: Field; type Projective: ProjectiveCurve; - /// Returns the additive identity. - #[must_use] - fn zero() -> Self; - /// Returns a fixed generator of unknown exponent. #[must_use] fn prime_subgroup_generator() -> Self; - /// Determines if this point represents the point at infinity; the - /// additive identity. - #[must_use] - fn is_zero(&self) -> bool; - /// Performs scalar multiplication of this element with mixed addition. #[must_use] fn mul::BigInt>>(&self, other: S) @@ -261,15 +248,6 @@ pub trait PairingCurve: AffineCurve { impl Group for C { type ScalarField = C::ScalarField; - #[must_use] - fn zero() -> Self { - ::zero() - } - - #[must_use] - fn is_zero(&self) -> bool { - ::is_zero(&self) - } #[inline] #[must_use] diff --git a/algebra/src/curves/models/bls12/g1.rs b/algebra/src/curves/models/bls12/g1.rs index d8bed2456..4f0494749 100644 --- a/algebra/src/curves/models/bls12/g1.rs +++ b/algebra/src/curves/models/bls12/g1.rs @@ -6,6 +6,7 @@ use crate::{ AffineCurve, }, }; +use num_traits::Zero; use std::io::{Result as IoResult, Write}; pub type G1Affine

= GroupAffine<

::G1Parameters>; diff --git a/algebra/src/curves/models/bls12/g2.rs b/algebra/src/curves/models/bls12/g2.rs index 3c4235f0c..03cd9a3e1 100644 --- a/algebra/src/curves/models/bls12/g2.rs +++ b/algebra/src/curves/models/bls12/g2.rs @@ -8,6 +8,7 @@ use crate::{ }, fields::{BitIterator, Field, Fp2}, }; +use num_traits::{One, Zero}; use std::io::{Result as IoResult, Write}; pub type G2Affine

= GroupAffine<

::G2Parameters>; diff --git a/algebra/src/curves/models/bls12/mod.rs b/algebra/src/curves/models/bls12/mod.rs index bc3c22772..3fe24475d 100644 --- a/algebra/src/curves/models/bls12/mod.rs +++ b/algebra/src/curves/models/bls12/mod.rs @@ -10,6 +10,7 @@ use crate::{ BitIterator, Field, Fp2, PrimeField, SquareRootField, }, }; +use num_traits::One; use std::marker::PhantomData; diff --git a/algebra/src/curves/models/short_weierstrass_jacobian.rs b/algebra/src/curves/models/short_weierstrass_jacobian.rs index 728eb3cba..d9f9d379e 100644 --- a/algebra/src/curves/models/short_weierstrass_jacobian.rs +++ b/algebra/src/curves/models/short_weierstrass_jacobian.rs @@ -1,6 +1,7 @@ use crate::curves::models::SWModelParameters as Parameters; use rand::{Rng, distributions::{Standard, Distribution}}; use crate::UniformRand; +use num_traits::{One, Zero}; use std::{ fmt::{Display, Formatter, Result as FmtResult}, io::{Read, Result as IoResult, Write}, @@ -102,16 +103,43 @@ impl GroupAffine

{ } } +impl Zero for GroupAffine

{ + #[inline] + fn zero() -> Self { + Self::new(P::BaseField::zero(), P::BaseField::one(), true) + } + + #[inline] + fn is_zero(&self) -> bool { + self.infinity + } +} + +impl Add for GroupAffine

{ + type Output = Self; + fn add(self, other: Self) -> Self { + let mut copy = self; + copy += &other; + copy + } +} + +impl<'a, P: Parameters> AddAssign<&'a Self> for GroupAffine

{ + fn add_assign(&mut self, other: &'a Self) { + let lambda = (other.y - &self.y) / &(other.x - &self.y); + let x3 = lambda * lambda - &self.x - &other.x; + let y3 = (self.x - &x3) * lambda - &self.y; + + self.x = x3; + self.y = y3; + } +} + impl AffineCurve for GroupAffine

{ type BaseField = P::BaseField; type ScalarField = P::ScalarField; type Projective = GroupProjective

; - #[inline] - fn zero() -> Self { - Self::new(Self::BaseField::zero(), Self::BaseField::one(), true) - } - #[inline] fn prime_subgroup_generator() -> Self { Self::new( @@ -121,11 +149,6 @@ impl AffineCurve for GroupAffine

{ ) } - #[inline] - fn is_zero(&self) -> bool { - self.infinity - } - #[inline] fn mul::BigInt>>(&self, by: S) -> GroupProjective

{ let bits = BitIterator::new(by.into()); @@ -238,8 +261,6 @@ impl Distribution> for Standard { } } - - impl ToBytes for GroupProjective

{ #[inline] fn write(&self, mut writer: W) -> IoResult<()> { @@ -277,11 +298,7 @@ impl GroupProjective

{ } } -impl ProjectiveCurve for GroupProjective

{ - type BaseField = P::BaseField; - type ScalarField = P::ScalarField; - type Affine = GroupAffine

; - +impl Zero for GroupProjective

{ // The point at infinity is always represented by // Z = 0. #[inline] @@ -293,17 +310,23 @@ impl ProjectiveCurve for GroupProjective

{ ) } - #[inline] - fn prime_subgroup_generator() -> Self { - GroupAffine::prime_subgroup_generator().into() - } - // The point at infinity is always represented by // Z = 0. #[inline] fn is_zero(&self) -> bool { self.z.is_zero() } +} + +impl ProjectiveCurve for GroupProjective

{ + type BaseField = P::BaseField; + type ScalarField = P::ScalarField; + type Affine = GroupAffine

; + + #[inline] + fn prime_subgroup_generator() -> Self { + GroupAffine::prime_subgroup_generator().into() + } #[inline] fn is_normalized(&self) -> bool { @@ -557,13 +580,13 @@ impl Neg for GroupProjective

{ } } -impl<'a, P: Parameters> Add<&'a Self> for GroupProjective

{ +impl Add for GroupProjective

{ type Output = Self; #[inline] - fn add(self, other: &'a Self) -> Self { + fn add(self, other: Self) -> Self { let mut copy = self; - copy += other; + copy += &other; copy } } diff --git a/algebra/src/curves/models/short_weierstrass_projective.rs b/algebra/src/curves/models/short_weierstrass_projective.rs index 97ac508af..18f749894 100644 --- a/algebra/src/curves/models/short_weierstrass_projective.rs +++ b/algebra/src/curves/models/short_weierstrass_projective.rs @@ -1,6 +1,7 @@ use crate::curves::models::SWModelParameters as Parameters; use rand::{Rng, distributions::{Standard, Distribution}}; use crate::UniformRand; +use num_traits::{One, Zero}; use std::{ fmt::{Display, Formatter, Result as FmtResult}, io::{Read, Result as IoResult, Write}, @@ -107,15 +108,41 @@ impl GroupAffine

{ } } +impl Zero for GroupAffine

{ + fn zero() -> Self { + Self::new(P::BaseField::zero(), P::BaseField::one(), true) + } + + fn is_zero(&self) -> bool { + self.infinity + } +} + +impl Add for GroupAffine

{ + type Output = Self; + fn add(self, other: Self) -> Self { + let mut copy = self; + copy += &other; + copy + } +} + +impl<'a, P: Parameters> AddAssign<&'a Self> for GroupAffine

{ + fn add_assign(&mut self, other: &'a Self) { + let lambda = (other.y - &self.y) / &(other.x - &self.y); + let x3 = lambda * lambda - &self.x - &other.x; + let y3 = (self.x - &x3) * lambda - &self.y; + + self.x = x3; + self.y = y3; + } +} + impl AffineCurve for GroupAffine

{ type BaseField = P::BaseField; type ScalarField = P::ScalarField; type Projective = GroupProjective

; - fn zero() -> Self { - Self::new(Self::BaseField::zero(), Self::BaseField::one(), true) - } - fn prime_subgroup_generator() -> Self { Self::new( P::AFFINE_GENERATOR_COEFFS.0, @@ -124,10 +151,6 @@ impl AffineCurve for GroupAffine

{ ) } - fn is_zero(&self) -> bool { - self.infinity - } - fn mul::BigInt>>(&self, by: S) -> GroupProjective

{ let bits = BitIterator::new(by.into()); self.mul_bits(bits) @@ -231,9 +254,6 @@ impl Distribution> for Standard { } } - - - impl ToBytes for GroupProjective

{ #[inline] fn write(&self, mut writer: W) -> IoResult<()> { @@ -271,11 +291,7 @@ impl GroupProjective

{ } } -impl ProjectiveCurve for GroupProjective

{ - type BaseField = P::BaseField; - type ScalarField = P::ScalarField; - type Affine = GroupAffine

; - +impl Zero for GroupProjective

{ // The point at infinity is always represented by Z = 0. #[inline] fn zero() -> Self { @@ -286,17 +302,23 @@ impl ProjectiveCurve for GroupProjective

{ ) } - #[inline] - fn prime_subgroup_generator() -> Self { - GroupAffine::prime_subgroup_generator().into() - } - // The point at infinity is always represented by // Z = 0. #[inline] fn is_zero(&self) -> bool { self.z.is_zero() } +} + +impl ProjectiveCurve for GroupProjective

{ + type BaseField = P::BaseField; + type ScalarField = P::ScalarField; + type Affine = GroupAffine

; + + #[inline] + fn prime_subgroup_generator() -> Self { + GroupAffine::prime_subgroup_generator().into() + } #[inline] fn is_normalized(&self) -> bool { @@ -466,11 +488,11 @@ impl Neg for GroupProjective

{ } } -impl<'a, P: Parameters> Add<&'a Self> for GroupProjective

{ +impl Add for GroupProjective

{ type Output = Self; - fn add(self, other: &'a Self) -> Self { + fn add(self, other: Self) -> Self { let mut copy = self; - copy += other; + copy += &other; copy } } diff --git a/algebra/src/curves/models/twisted_edwards_extended/mod.rs b/algebra/src/curves/models/twisted_edwards_extended/mod.rs index 1ca2531a8..dd82860a4 100644 --- a/algebra/src/curves/models/twisted_edwards_extended/mod.rs +++ b/algebra/src/curves/models/twisted_edwards_extended/mod.rs @@ -1,5 +1,6 @@ use rand::{Rng, distributions::{Standard, Distribution}}; use crate::UniformRand; +use num_traits::{One, Zero}; use std::{ fmt::{Display, Formatter, Result as FmtResult}, io::{Read, Result as IoResult, Write}, @@ -105,23 +106,25 @@ impl GroupAffine

{ } } +impl Zero for GroupAffine

{ + fn zero() -> Self { + Self::new(P::BaseField::zero(), P::BaseField::one()) + } + + fn is_zero(&self) -> bool { + self.x.is_zero() & self.y.is_one() + } +} + impl AffineCurve for GroupAffine

{ type BaseField = P::BaseField; type ScalarField = P::ScalarField; type Projective = GroupProjective

; - fn zero() -> Self { - Self::new(Self::BaseField::zero(), Self::BaseField::one()) - } - fn prime_subgroup_generator() -> Self { Self::new(P::AFFINE_GENERATOR_COEFFS.0, P::AFFINE_GENERATOR_COEFFS.1) } - fn is_zero(&self) -> bool { - self.x.is_zero() & self.y.is_one() - } - fn mul::BigInt>>(&self, by: S) -> GroupProjective

{ self.mul_bits(BitIterator::new(by.into())) } @@ -147,6 +150,15 @@ impl Neg for GroupAffine

{ } } +impl Add for GroupAffine

{ + type Output = Self; + fn add(self, other: Self) -> Self { + let mut copy = self; + copy += &other; + copy + } +} + impl<'a, P: Parameters> Add<&'a Self> for GroupAffine

{ type Output = Self; fn add(self, other: &'a Self) -> Self { @@ -188,11 +200,11 @@ impl<'a, P: Parameters> SubAssign<&'a Self> for GroupAffine

{ } } -impl<'a, P: Parameters> Mul<&'a P::ScalarField> for GroupAffine

{ +impl Mul for GroupAffine

{ type Output = Self; - fn mul(self, other: &'a P::ScalarField) -> Self { + fn mul(self, other: P::ScalarField) -> Self { let mut copy = self; - copy *= other; + copy *= &other; copy } } @@ -247,13 +259,6 @@ mod group_impl { impl Group for GroupAffine

{ type ScalarField = P::ScalarField; - fn zero() -> Self { - ::zero() - } - - fn is_zero(&self) -> bool { - ::is_zero(&self) - } #[inline] #[must_use] @@ -367,11 +372,7 @@ impl GroupProjective

{ } } -impl ProjectiveCurve for GroupProjective

{ - type BaseField = P::BaseField; - type ScalarField = P::ScalarField; - type Affine = GroupAffine

; - +impl Zero for GroupProjective

{ fn zero() -> Self { Self::new( P::BaseField::zero(), @@ -381,13 +382,19 @@ impl ProjectiveCurve for GroupProjective

{ ) } - fn prime_subgroup_generator() -> Self { - GroupAffine::prime_subgroup_generator().into() - } - fn is_zero(&self) -> bool { self.x.is_zero() && self.y == self.z && !self.y.is_zero() && self.t.is_zero() } +} + +impl ProjectiveCurve for GroupProjective

{ + type BaseField = P::BaseField; + type ScalarField = P::ScalarField; + type Affine = GroupAffine

; + + fn prime_subgroup_generator() -> Self { + GroupAffine::prime_subgroup_generator().into() + } fn is_normalized(&self) -> bool { self.z.is_one() @@ -511,11 +518,11 @@ impl Neg for GroupProjective

{ } } -impl<'a, P: Parameters> Add<&'a Self> for GroupProjective

{ +impl Add for GroupProjective

{ type Output = Self; - fn add(self, other: &'a Self) -> Self { + fn add(self, other: Self) -> Self { let mut copy = self; - copy += other; + copy += &other; copy } } @@ -652,4 +659,3 @@ impl MontgomeryGroupAffine

{ } } } - diff --git a/algebra/src/curves/models/twisted_edwards_extended/tests.rs b/algebra/src/curves/models/twisted_edwards_extended/tests.rs index 148d82db2..8817aa1b9 100644 --- a/algebra/src/curves/models/twisted_edwards_extended/tests.rs +++ b/algebra/src/curves/models/twisted_edwards_extended/tests.rs @@ -1,4 +1,5 @@ use crate::{fields::Field, TEModelParameters, MontgomeryModelParameters}; +use num_traits::One; pub(crate) fn montgomery_conversion_test

() where diff --git a/algebra/src/curves/sw6/mod.rs b/algebra/src/curves/sw6/mod.rs index aa4a673bd..38f861de3 100644 --- a/algebra/src/curves/sw6/mod.rs +++ b/algebra/src/curves/sw6/mod.rs @@ -10,6 +10,7 @@ use crate::{ BitIterator, Field, FpParameters, }, }; +use num_traits::One; pub mod g1; pub use self::g1::{G1Affine, G1Projective}; diff --git a/algebra/src/curves/sw6/tests.rs b/algebra/src/curves/sw6/tests.rs index ad15d74cc..7dc4dcd69 100644 --- a/algebra/src/curves/sw6/tests.rs +++ b/algebra/src/curves/sw6/tests.rs @@ -6,6 +6,7 @@ use crate::{ }, groups::tests::group_test, }; +use num_traits::One; #[test] fn test_g1_projective_curve() { diff --git a/algebra/src/curves/tests.rs b/algebra/src/curves/tests.rs index da555165d..fcf3c5a27 100644 --- a/algebra/src/curves/tests.rs +++ b/algebra/src/curves/tests.rs @@ -1,8 +1,9 @@ use crate::{ curves::{AffineCurve, ProjectiveCurve}, - fields::{Field, PrimeField}, + fields::PrimeField, }; use crate::UniformRand; +use num_traits::Zero; use rand::SeedableRng; use rand_xorshift::XorShiftRng; diff --git a/algebra/src/fields/bls12_377/fq6.rs b/algebra/src/fields/bls12_377/fq6.rs index 366b1ef2f..5eec974ca 100644 --- a/algebra/src/fields/bls12_377/fq6.rs +++ b/algebra/src/fields/bls12_377/fq6.rs @@ -193,8 +193,9 @@ impl Fp6Parameters for Fq6Parameters { #[cfg(test)] mod test { use super::*; - use crate::fields::Field; + use crate::UniformRand; + use num_traits::{One, Zero}; use rand::SeedableRng; use rand_xorshift::XorShiftRng; diff --git a/algebra/src/fields/bls12_377/tests.rs b/algebra/src/fields/bls12_377/tests.rs index e519e710b..2bc8725b8 100644 --- a/algebra/src/fields/bls12_377/tests.rs +++ b/algebra/src/fields/bls12_377/tests.rs @@ -8,6 +8,7 @@ use crate::{ }, }; use crate::UniformRand; +use num_traits::{One, Zero}; use rand::SeedableRng; use rand_xorshift::XorShiftRng; use std::{ diff --git a/algebra/src/fields/bls12_381/fq12.rs b/algebra/src/fields/bls12_381/fq12.rs index fd32a2c18..408818910 100644 --- a/algebra/src/fields/bls12_381/fq12.rs +++ b/algebra/src/fields/bls12_381/fq12.rs @@ -210,9 +210,9 @@ mod test { use super::*; use crate::fields::{ bls12_381::{fq2::Fq2, fq6::Fq6}, - Field, }; use crate::UniformRand; + use num_traits::{One, Zero}; use rand::SeedableRng; use rand_xorshift::XorShiftRng; diff --git a/algebra/src/fields/bls12_381/tests.rs b/algebra/src/fields/bls12_381/tests.rs index 7b946ac84..c128fe062 100644 --- a/algebra/src/fields/bls12_381/tests.rs +++ b/algebra/src/fields/bls12_381/tests.rs @@ -11,6 +11,7 @@ use crate::{ }, }; use crate::UniformRand; +use num_traits::{One, Zero}; use rand::SeedableRng; use rand_xorshift::XorShiftRng; use std::{ diff --git a/algebra/src/fields/jubjub/tests.rs b/algebra/src/fields/jubjub/tests.rs index 7212175a7..f314e2a3c 100644 --- a/algebra/src/fields/jubjub/tests.rs +++ b/algebra/src/fields/jubjub/tests.rs @@ -9,6 +9,7 @@ use crate::{ PrimeField, SquareRootField, }, }; +use num_traits::{One, Zero}; use std::str::FromStr; #[test] diff --git a/algebra/src/fields/mod.rs b/algebra/src/fields/mod.rs index e44bddf91..9c1c65c5a 100644 --- a/algebra/src/fields/mod.rs +++ b/algebra/src/fields/mod.rs @@ -3,6 +3,7 @@ use crate::{ bytes::{FromBytes, ToBytes}, UniformRand, }; +use num_traits::{One, Zero}; use std::{ fmt::{Debug, Display}, hash::Hash, @@ -64,9 +65,11 @@ pub trait Field: + Sync + 'static + Eq + + One + Ord + Neg + UniformRand + + Zero + Sized + Hash + From @@ -75,26 +78,16 @@ pub trait Field: + From + From + for<'a> Add<&'a Self, Output = Self> + + Add + for<'a> Sub<&'a Self, Output = Self> + for<'a> Mul<&'a Self, Output = Self> + + Mul + for<'a> Div<&'a Self, Output = Self> + for<'a> AddAssign<&'a Self> + for<'a> SubAssign<&'a Self> + for<'a> MulAssign<&'a Self> + for<'a> DivAssign<&'a Self> { - /// Returns the zero element of the field, the additive identity. - fn zero() -> Self; - - /// Returns true if and only if `self == Self::zero()`. - fn is_zero(&self) -> bool; - - /// Returns the one element of the field, a field generator. - fn one() -> Self; - - /// Returns true if and only if `self == Self::one()`. - fn is_one(&self) -> bool; - /// Returns the characteristic of the field. fn characteristic<'a>() -> &'a [u64]; diff --git a/algebra/src/fields/models/fp12_2over3over2.rs b/algebra/src/fields/models/fp12_2over3over2.rs index 1ab1f9147..f396ff5ec 100644 --- a/algebra/src/fields/models/fp12_2over3over2.rs +++ b/algebra/src/fields/models/fp12_2over3over2.rs @@ -1,5 +1,6 @@ use rand::{Rng, distributions::{Standard, Distribution}}; use crate::UniformRand; +use num_traits::{One, Zero}; use std::{ cmp::Ordering, io::{Read, Result as IoResult, Write}, @@ -216,23 +217,26 @@ impl Distribution> for Standard { } } -impl Field for Fp12

{ +impl Zero for Fp12

{ fn zero() -> Self { Self::new(Fp6::zero(), Fp6::zero()) } - fn one() -> Self { - Self::new(Fp6::one(), Fp6::zero()) - } - fn is_zero(&self) -> bool { self.c0.is_zero() && self.c1.is_zero() } +} +impl One for Fp12

{ + fn one() -> Self { + Self::new(Fp6::one(), Fp6::zero()) + } fn is_one(&self) -> bool { self.c0.is_one() && self.c1.is_zero() } +} +impl Field for Fp12

{ #[inline] fn characteristic<'a>() -> &'a [u64] { Fp6::::characteristic() diff --git a/algebra/src/fields/models/fp2.rs b/algebra/src/fields/models/fp2.rs index 9b6b953ef..446ebe44d 100644 --- a/algebra/src/fields/models/fp2.rs +++ b/algebra/src/fields/models/fp2.rs @@ -1,4 +1,5 @@ use crate::UniformRand; +use num_traits::{One, Zero}; use rand::{ distributions::{Distribution, Standard}, Rng, @@ -73,7 +74,7 @@ impl Fp2

{ } } -impl Field for Fp2

{ +impl Zero for Fp2

{ fn zero() -> Self { Fp2::new(P::Fp::zero(), P::Fp::zero()) } @@ -81,7 +82,9 @@ impl Field for Fp2

{ fn is_zero(&self) -> bool { self.c0.is_zero() && self.c1.is_zero() } +} +impl One for Fp2

{ fn one() -> Self { Fp2::new(P::Fp::one(), P::Fp::zero()) } @@ -89,7 +92,9 @@ impl Field for Fp2

{ fn is_one(&self) -> bool { self.c0.is_one() && self.c1.is_zero() } +} +impl Field for Fp2

{ #[inline] fn characteristic<'a>() -> &'a [u64] { P::Fp::characteristic() diff --git a/algebra/src/fields/models/fp3.rs b/algebra/src/fields/models/fp3.rs index 7f7b87fc2..dfbaef361 100644 --- a/algebra/src/fields/models/fp3.rs +++ b/algebra/src/fields/models/fp3.rs @@ -1,4 +1,5 @@ use crate::UniformRand; +use num_traits::{One, Zero}; use rand::{ distributions::{Distribution, Standard}, Rng, @@ -91,7 +92,7 @@ impl Fp3

{ } } -impl Field for Fp3

{ +impl Zero for Fp3

{ fn zero() -> Self { Fp3 { c0: P::Fp::zero(), @@ -104,7 +105,9 @@ impl Field for Fp3

{ fn is_zero(&self) -> bool { self.c0.is_zero() && self.c1.is_zero() && self.c2.is_zero() } +} +impl One for Fp3

{ fn one() -> Self { Fp3 { c0: P::Fp::one(), @@ -117,7 +120,9 @@ impl Field for Fp3

{ fn is_one(&self) -> bool { self.c0.is_one() && self.c1.is_zero() && self.c2.is_zero() } +} +impl Field for Fp3

{ #[inline] fn characteristic<'a>() -> &'a [u64] { P::Fp::characteristic() diff --git a/algebra/src/fields/models/fp6_2over3.rs b/algebra/src/fields/models/fp6_2over3.rs index bf8962136..ac8a7b4ee 100644 --- a/algebra/src/fields/models/fp6_2over3.rs +++ b/algebra/src/fields/models/fp6_2over3.rs @@ -1,4 +1,5 @@ use crate::UniformRand; +use num_traits::{One, Zero}; use rand::{ distributions::{Distribution, Standard}, Rng, @@ -99,7 +100,7 @@ impl Fp6

{ } } -impl Field for Fp6

{ +impl Zero for Fp6

{ fn zero() -> Self { Fp6 { c0: Fp3::zero(), @@ -111,7 +112,9 @@ impl Field for Fp6

{ fn is_zero(&self) -> bool { self.c0.is_zero() && self.c1.is_zero() } +} +impl One for Fp6

{ fn one() -> Self { Fp6 { c0: Fp3::one(), @@ -123,7 +126,9 @@ impl Field for Fp6

{ fn is_one(&self) -> bool { self.c0.is_one() && self.c1.is_zero() } +} +impl Field for Fp6

{ #[inline] fn characteristic<'a>() -> &'a [u64] { Fp3::::characteristic() diff --git a/algebra/src/fields/models/fp6_3over2.rs b/algebra/src/fields/models/fp6_3over2.rs index 119063d6e..f54c0f16f 100644 --- a/algebra/src/fields/models/fp6_3over2.rs +++ b/algebra/src/fields/models/fp6_3over2.rs @@ -1,4 +1,5 @@ use crate::UniformRand; +use num_traits::{One, Zero}; use rand::{ distributions::{Distribution, Standard}, Rng, @@ -144,7 +145,7 @@ impl Fp6

{ } } -impl Field for Fp6

{ +impl Zero for Fp6

{ fn zero() -> Self { Self::new(Fp2::zero(), Fp2::zero(), Fp2::zero()) } @@ -152,7 +153,9 @@ impl Field for Fp6

{ fn is_zero(&self) -> bool { self.c0.is_zero() && self.c1.is_zero() && self.c2.is_zero() } +} +impl One for Fp6

{ fn one() -> Self { Self::new(Fp2::one(), Fp2::zero(), Fp2::zero()) } @@ -160,7 +163,9 @@ impl Field for Fp6

{ fn is_one(&self) -> bool { self.c0.is_one() && self.c1.is_zero() && self.c2.is_zero() } +} +impl Field for Fp6

{ #[inline] fn characteristic<'a>() -> &'a [u64] { Fp2::::characteristic() diff --git a/algebra/src/fields/models/fp_256.rs b/algebra/src/fields/models/fp_256.rs index f47593f1d..2f8a379fc 100644 --- a/algebra/src/fields/models/fp_256.rs +++ b/algebra/src/fields/models/fp_256.rs @@ -1,3 +1,4 @@ +use num_traits::{One, Zero}; use std::{ cmp::{Ord, Ordering, PartialOrd}, fmt::{Display, Formatter, Result as FmtResult}, @@ -105,7 +106,7 @@ impl Fp256

{ } } -impl Field for Fp256

{ +impl Zero for Fp256

{ #[inline] fn zero() -> Self { Fp256::

(BigInteger::from(0), PhantomData) @@ -115,7 +116,21 @@ impl Field for Fp256

{ fn is_zero(&self) -> bool { self.0.is_zero() } +} + +impl One for Fp256

{ + #[inline] + fn one() -> Self { + Fp256::

(P::R, PhantomData) + } + + #[inline] + fn is_one(&self) -> bool { + self == &Self::one() + } +} +impl Field for Fp256

{ #[inline] fn double(&self) -> Self { let mut temp = *self; @@ -132,16 +147,6 @@ impl Field for Fp256

{ self } - #[inline] - fn one() -> Self { - Fp256::

(P::R, PhantomData) - } - - #[inline] - fn is_one(&self) -> bool { - self == &Self::one() - } - #[inline] fn characteristic<'a>() -> &'a [u64] { P::MODULUS.as_ref() diff --git a/algebra/src/fields/models/fp_320.rs b/algebra/src/fields/models/fp_320.rs index 28c3956bc..fcd06b14f 100644 --- a/algebra/src/fields/models/fp_320.rs +++ b/algebra/src/fields/models/fp_320.rs @@ -1,3 +1,4 @@ +use num_traits::{One, Zero}; use std::{ cmp::{Ord, Ordering, PartialOrd}, fmt::{Display, Formatter, Result as FmtResult}, @@ -121,7 +122,7 @@ impl Fp320

{ } } -impl Field for Fp320

{ +impl Zero for Fp320

{ #[inline] fn zero() -> Self { Fp320::

(BigInteger::from(0), PhantomData) @@ -131,7 +132,21 @@ impl Field for Fp320

{ fn is_zero(&self) -> bool { self.0.is_zero() } +} + +impl One for Fp320

{ + #[inline] + fn one() -> Self { + Fp320::

(P::R, PhantomData) + } + + #[inline] + fn is_one(&self) -> bool { + self.0 == P::R + } +} +impl Field for Fp320

{ #[inline] fn double(&self) -> Self { let mut temp = *self; @@ -148,16 +163,6 @@ impl Field for Fp320

{ self } - #[inline] - fn one() -> Self { - Fp320::

(P::R, PhantomData) - } - - #[inline] - fn is_one(&self) -> bool { - self.0 == P::R - } - #[inline] fn characteristic<'a>() -> &'a [u64] { P::MODULUS.as_ref() diff --git a/algebra/src/fields/models/fp_384.rs b/algebra/src/fields/models/fp_384.rs index 7191ffdc2..aa657e09c 100644 --- a/algebra/src/fields/models/fp_384.rs +++ b/algebra/src/fields/models/fp_384.rs @@ -1,3 +1,4 @@ +use num_traits::{One, Zero}; use std::{ cmp::{Ord, Ordering, PartialOrd}, fmt::{Display, Formatter, Result as FmtResult}, @@ -139,7 +140,7 @@ impl Fp384

{ } } -impl Field for Fp384

{ +impl Zero for Fp384

{ #[inline] fn zero() -> Self { Fp384::

(BigInteger::from(0), PhantomData) @@ -149,7 +150,21 @@ impl Field for Fp384

{ fn is_zero(&self) -> bool { self.0.is_zero() } +} + +impl One for Fp384

{ + #[inline] + fn one() -> Self { + Fp384::

(P::R, PhantomData) + } + + #[inline] + fn is_one(&self) -> bool { + self.0 == P::R + } +} +impl Field for Fp384

{ #[inline] fn double(&self) -> Self { let mut temp = *self; @@ -166,16 +181,6 @@ impl Field for Fp384

{ self } - #[inline] - fn one() -> Self { - Fp384::

(P::R, PhantomData) - } - - #[inline] - fn is_one(&self) -> bool { - self.0 == P::R - } - #[inline] fn characteristic<'a>() -> &'a [u64] { P::MODULUS.as_ref() diff --git a/algebra/src/fields/models/fp_768.rs b/algebra/src/fields/models/fp_768.rs index ea7a44b00..ccd97b631 100644 --- a/algebra/src/fields/models/fp_768.rs +++ b/algebra/src/fields/models/fp_768.rs @@ -1,3 +1,4 @@ +use num_traits::{One, Zero}; use std::{ cmp::{Ord, Ordering, PartialOrd}, fmt::{Display, Formatter, Result as FmtResult}, @@ -284,7 +285,7 @@ impl Fp768

{ } } -impl Field for Fp768

{ +impl Zero for Fp768

{ #[inline] fn zero() -> Self { Fp768::

(BigInteger::from(0), PhantomData) @@ -294,7 +295,21 @@ impl Field for Fp768

{ fn is_zero(&self) -> bool { self.0.is_zero() } +} + +impl One for Fp768

{ + #[inline] + fn one() -> Self { + Fp768::

(P::R, PhantomData) + } + + #[inline] + fn is_one(&self) -> bool { + self.0 == P::R + } +} +impl Field for Fp768

{ #[inline] fn double(&self) -> Self { let mut temp = *self; @@ -311,16 +326,6 @@ impl Field for Fp768

{ self } - #[inline] - fn one() -> Self { - Fp768::

(P::R, PhantomData) - } - - #[inline] - fn is_one(&self) -> bool { - self.0 == P::R - } - #[inline] fn characteristic<'a>() -> &'a [u64] { P::MODULUS.as_ref() diff --git a/algebra/src/fields/models/fp_832.rs b/algebra/src/fields/models/fp_832.rs index eb4ab2b08..f960b7969 100644 --- a/algebra/src/fields/models/fp_832.rs +++ b/algebra/src/fields/models/fp_832.rs @@ -3,6 +3,7 @@ use crate::{ bytes::{FromBytes, ToBytes}, fields::{Field, FpParameters, LegendreSymbol, PrimeField, SquareRootField}, }; +use num_traits::{One, Zero}; use std::{ cmp::{Ord, Ordering, PartialOrd}, fmt::{Display, Formatter, Result as FmtResult}, @@ -315,7 +316,7 @@ impl Fp832

{ } } -impl Field for Fp832

{ +impl Zero for Fp832

{ #[inline] fn zero() -> Self { Fp832::

(BigInteger::from(0), PhantomData) @@ -325,7 +326,21 @@ impl Field for Fp832

{ fn is_zero(&self) -> bool { self.0.is_zero() } +} + +impl One for Fp832

{ + #[inline] + fn one() -> Self { + Fp832::

(P::R, PhantomData) + } + + #[inline] + fn is_one(&self) -> bool { + self.0 == P::R + } +} +impl Field for Fp832

{ #[inline] fn double(&self) -> Self { let mut temp = *self; @@ -342,16 +357,6 @@ impl Field for Fp832

{ self } - #[inline] - fn one() -> Self { - Fp832::

(P::R, PhantomData) - } - - #[inline] - fn is_one(&self) -> bool { - self.0 == P::R - } - #[inline] fn characteristic<'a>() -> &'a [u64] { P::MODULUS.as_ref() diff --git a/algebra/src/groups/mod.rs b/algebra/src/groups/mod.rs index 0004fa589..883014c0f 100644 --- a/algebra/src/groups/mod.rs +++ b/algebra/src/groups/mod.rs @@ -1,5 +1,6 @@ use crate::BitIterator; use crate::UniformRand; +use num_traits::Zero; use std::{ fmt::{Debug, Display}, hash::Hash, @@ -29,19 +30,14 @@ pub trait Group: + Hash + Neg + UniformRand - + for<'a> Add<&'a Self, Output = Self> + + Zero + + Add + for<'a> Sub<&'a Self, Output = Self> + for<'a> AddAssign<&'a Self> + for<'a> SubAssign<&'a Self> { type ScalarField: PrimeField + Into<::BigInt>; - /// Returns the additive identity. - fn zero() -> Self; - - /// Returns `self == zero`. - fn is_zero(&self) -> bool; - /// Returns `self + self`. #[must_use] fn double(&self) -> Self; diff --git a/algebra/src/groups/tests.rs b/algebra/src/groups/tests.rs index 38c548ce2..1c1cf13d1 100644 --- a/algebra/src/groups/tests.rs +++ b/algebra/src/groups/tests.rs @@ -1,6 +1,6 @@ use super::Group; -use crate::fields::Field; use crate::UniformRand; +use num_traits::{One, Zero}; use rand::SeedableRng; use rand_xorshift::XorShiftRng; diff --git a/algebra/src/msm/variable_base.rs b/algebra/src/msm/variable_base.rs index 8fd72395d..f1dac526b 100644 --- a/algebra/src/msm/variable_base.rs +++ b/algebra/src/msm/variable_base.rs @@ -1,8 +1,8 @@ use crate::{ - AffineCurve, BigInteger, Field, FpParameters, PrimeField, + AffineCurve, BigInteger, FpParameters, PrimeField, ProjectiveCurve, }; -#[cfg(feature = "parallel")] +use num_traits::{One, Zero}; use rayon::prelude::*; pub struct VariableBaseMSM; @@ -84,7 +84,7 @@ impl VariableBaseMSM { total.double_in_place(); } total - }) + lowest + }) + *lowest } pub fn multi_scalar_mul( @@ -135,7 +135,6 @@ mod test { assert_eq!(naive.into_affine(), fast.into_affine()); } - #[test] fn test_with_bls12_unequal_numbers() { const SAMPLES: usize = 1 << 10; diff --git a/crypto-primitives/Cargo.toml b/crypto-primitives/Cargo.toml index 3b937c80b..4d3566d5b 100644 --- a/crypto-primitives/Cargo.toml +++ b/crypto-primitives/Cargo.toml @@ -32,6 +32,7 @@ bench-utils = { path = "../bench-utils" } digest = "0.7" blake2 = "0.7" +num-traits = { version = "0.2.11" } rand = { version = "0.7" } derivative = "1" rayon = "1" diff --git a/crypto-primitives/src/merkle_tree/mod.rs b/crypto-primitives/src/merkle_tree/mod.rs index df65dd07d..ea1f8dfe8 100644 --- a/crypto-primitives/src/merkle_tree/mod.rs +++ b/crypto-primitives/src/merkle_tree/mod.rs @@ -372,6 +372,7 @@ mod test { merkle_tree::*, }; use algebra::curves::jubjub::JubJubAffine as JubJub; + use num_traits::Zero; use rand::SeedableRng; use rand_xorshift::XorShiftRng; @@ -419,7 +420,6 @@ mod test { } fn bad_merkle_tree_verify(leaves: &[L]) -> () { - use algebra::groups::Group; let mut rng = XorShiftRng::seed_from_u64(13423423u64); let crh_parameters = Rc::new(H::setup(&mut rng).unwrap()); diff --git a/crypto-primitives/src/nizk/mod.rs b/crypto-primitives/src/nizk/mod.rs index 048c51c7f..1c30bc767 100644 --- a/crypto-primitives/src/nizk/mod.rs +++ b/crypto-primitives/src/nizk/mod.rs @@ -59,7 +59,8 @@ mod test { #[test] fn test_gm17() { use crate::nizk::{gm17::Gm17, NIZK}; - use algebra::{curves::bls12_381::Bls12_381, fields::bls12_381::Fr, Field}; + use algebra::{curves::bls12_381::Bls12_381, fields::bls12_381::Fr}; + use num_traits::One; use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError}; #[derive(Copy, Clone)] diff --git a/crypto-primitives/src/signature/schnorr/mod.rs b/crypto-primitives/src/signature/schnorr/mod.rs index 29a8c2581..9e03e0599 100644 --- a/crypto-primitives/src/signature/schnorr/mod.rs +++ b/crypto-primitives/src/signature/schnorr/mod.rs @@ -6,6 +6,7 @@ use algebra::{ to_bytes, ToConstraintField, UniformRand, }; use digest::Digest; +use num_traits::{One, Zero}; use rand::Rng; use std::{ hash::Hash, diff --git a/ff-fft/Cargo.toml b/ff-fft/Cargo.toml index 4fbe727b3..48b1696c0 100644 --- a/ff-fft/Cargo.toml +++ b/ff-fft/Cargo.toml @@ -20,6 +20,7 @@ license = "MIT/Apache-2.0" edition = "2018" [dependencies] +num-traits = { version = "0.2.11" } rand = { version = "0.7" } algebra = { path = "../algebra", features = [ "parallel" ] } rayon = { version = "1" } diff --git a/ff-fft/src/domain.rs b/ff-fft/src/domain.rs index 83a628558..e47ad6a97 100644 --- a/ff-fft/src/domain.rs +++ b/ff-fft/src/domain.rs @@ -42,7 +42,6 @@ impl fmt::Debug for EvaluationDomain { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Multiplicative subgroup of size {}", self.size) } - } impl EvaluationDomain { @@ -59,7 +58,6 @@ impl EvaluationDomain { t } - /// Construct a domain that is large enough for evaluations of a polynomial /// having `num_coeffs` coefficients. pub fn new(num_coeffs: usize) -> Option { @@ -442,6 +440,7 @@ mod tests { use algebra::Field; use algebra::fields::bls12_381::fr::Fr; use rand::{Rng, thread_rng}; + use num_traits::Zero; #[test] fn vanishing_polynomial_evaluation() { diff --git a/ff-fft/src/polynomial/dense.rs b/ff-fft/src/polynomial/dense.rs index 9803e45f1..4f9ccd693 100644 --- a/ff-fft/src/polynomial/dense.rs +++ b/ff-fft/src/polynomial/dense.rs @@ -181,7 +181,6 @@ impl<'a, 'b, F: Field> AddAssign<&'a DensePolynomial> for DensePolynomial self.coeffs.truncate(0); self.coeffs.extend_from_slice(&other.coeffs); } else if other.is_zero() { - } else if self.degree() >= other.degree() { for (a, b) in self.coeffs.iter_mut().zip(&other.coeffs) { *a += b @@ -298,7 +297,6 @@ impl<'a, 'b, F: Field> SubAssign<&'a DensePolynomial> for DensePolynomial self.coeffs[i] -= coeff; } } else if other.is_zero() { - } else if self.degree() >= other.degree() { for (a, b) in self.coeffs.iter_mut().zip(&other.coeffs) { *a -= b @@ -351,6 +349,7 @@ mod tests { use crate::polynomial::*; use algebra::fields::{bls12_381::fr::Fr, Field}; use algebra::UniformRand; + use num_traits::{One, Zero}; use rand::thread_rng; #[test] diff --git a/ff-fft/src/polynomial/mod.rs b/ff-fft/src/polynomial/mod.rs index 5465ab92d..530b34917 100644 --- a/ff-fft/src/polynomial/mod.rs +++ b/ff-fft/src/polynomial/mod.rs @@ -34,7 +34,6 @@ impl<'a, F: 'a + Field> From<&'a DensePolynomial> for DenseOrSparsePolynomial } } - impl From> for DenseOrSparsePolynomial<'_, F> { fn from(other: SparsePolynomial) -> Self { SPolynomial(Cow::Owned(other)) @@ -47,7 +46,6 @@ impl<'a, F: Field> From<&'a SparsePolynomial> for DenseOrSparsePolynomial<'a, } } - impl Into> for DenseOrSparsePolynomial<'_, F> { fn into(self) -> DensePolynomial { match self { diff --git a/ff-fft/src/polynomial/sparse.rs b/ff-fft/src/polynomial/sparse.rs index 776a763b1..3b75b4cc9 100644 --- a/ff-fft/src/polynomial/sparse.rs +++ b/ff-fft/src/polynomial/sparse.rs @@ -129,7 +129,7 @@ impl Into> for SparsePolynomial { mod tests { use crate::{EvaluationDomain, DensePolynomial, SparsePolynomial}; use algebra::fields::bls12_381::fr::Fr; - use algebra::Field; + use num_traits::One; #[test] fn evaluate_over_domain() { diff --git a/gm17/Cargo.toml b/gm17/Cargo.toml index e2ff2261a..db63c6d22 100644 --- a/gm17/Cargo.toml +++ b/gm17/Cargo.toml @@ -27,6 +27,7 @@ ff-fft = { path = "../ff-fft" } r1cs-core = { path = "../r1cs-core" } bench-utils = { path = "../bench-utils" } +num-traits = { version = "0.2.11" } rand = { version = "0.7" } rayon = { version = "1" } smallvec = { version = "0.6" } diff --git a/gm17/examples/snark-scalability/gm17.rs b/gm17/examples/snark-scalability/gm17.rs index 08cfa34b8..55ca79a7b 100644 --- a/gm17/examples/snark-scalability/gm17.rs +++ b/gm17/examples/snark-scalability/gm17.rs @@ -27,6 +27,7 @@ use csv; +use num_traits::One; // For randomness (during paramgen and proof generation) use rand::thread_rng; @@ -39,7 +40,7 @@ use std::{ // Bring in some tools for using pairing-friendly curves // We're going to use the BLS12-377 pairing-friendly elliptic curve. use algebra::curves::bls12_377::Bls12_377; -use algebra::fields::{bls12_377::fr::Fr, Field}; +use algebra::fields::bls12_377::fr::Fr; // We're going to use the Groth-Maller 17 proving system. use gm17::{ diff --git a/gm17/src/generator.rs b/gm17/src/generator.rs index dd1010d14..0500e9860 100644 --- a/gm17/src/generator.rs +++ b/gm17/src/generator.rs @@ -4,6 +4,7 @@ use algebra::{ AffineCurve, Field, PairingEngine, PrimeField, ProjectiveCurve, }; +use num_traits::{One, Zero}; use rand::Rng; use rayon::prelude::*; use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable}; @@ -298,8 +299,6 @@ where ); end_timer!(b_time); - - end_timer!(proving_key_time); // Generate R1CS verification key diff --git a/gm17/src/prover.rs b/gm17/src/prover.rs index 76e81c954..4a65ac696 100644 --- a/gm17/src/prover.rs +++ b/gm17/src/prover.rs @@ -2,7 +2,7 @@ use rand::Rng; use rayon::prelude::*; use algebra::{ - UniformRand, msm::VariableBaseMSM, AffineCurve, Field, PairingEngine, PrimeField, ProjectiveCurve, + UniformRand, msm::VariableBaseMSM, AffineCurve, PairingEngine, PrimeField, ProjectiveCurve, }; use crate::{Parameters, Proof}; @@ -10,6 +10,7 @@ use crate::r1cs_to_sap::R1CStoSAP; use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable}; +use num_traits::{One, Zero}; use smallvec::SmallVec; use std::{ diff --git a/gm17/src/r1cs_to_sap.rs b/gm17/src/r1cs_to_sap.rs index bce87cb83..5c439880d 100644 --- a/gm17/src/r1cs_to_sap.rs +++ b/gm17/src/r1cs_to_sap.rs @@ -2,6 +2,7 @@ use ff_fft::EvaluationDomain; use algebra::{Field, PairingEngine}; use crate::{generator::KeypairAssembly, prover::ProvingAssignment}; +use num_traits::{One, Zero}; use r1cs_core::{Index, SynthesisError}; use rayon::prelude::*; @@ -227,7 +228,7 @@ impl R1CStoSAP { tmp.double_in_place(); let assignment = full_input_assignment[extra_var_offset2 + i]; - c[extra_constr_offset + 2 * i - 1] = tmp + &assignment; + c[extra_constr_offset + 2 * i - 1] = tmp + assignment; c[extra_constr_offset + 2 * i] = assignment; } diff --git a/gm17/src/test.rs b/gm17/src/test.rs index f3d796f84..f10894666 100644 --- a/gm17/src/test.rs +++ b/gm17/src/test.rs @@ -1,5 +1,7 @@ -use algebra::Field; +use algebra::fields::Field; +use num_traits::Zero; use r1cs_core::{ConstraintSynthesizer, ConstraintSystem, SynthesisError}; + struct MySillyCircuit { a: Option, b: Option, @@ -79,7 +81,7 @@ mod sw6 { use rand::thread_rng; - use algebra::{UniformRand, curves::sw6::SW6, fields::sw6::Fr as SW6Fr, Field}; + use algebra::{UniformRand, curves::sw6::SW6, fields::sw6::Fr as SW6Fr}; #[test] fn prove_and_verify() { diff --git a/gm17/src/verifier.rs b/gm17/src/verifier.rs index dc853b927..900208e4b 100644 --- a/gm17/src/verifier.rs +++ b/gm17/src/verifier.rs @@ -1,4 +1,5 @@ -use algebra::{AffineCurve, Field, PairingCurve, PairingEngine, PrimeField, ProjectiveCurve}; +use algebra::{AffineCurve, PairingCurve, PairingEngine, PrimeField, ProjectiveCurve}; +use num_traits::One; use super::{PreparedVerifyingKey, Proof, VerifyingKey}; diff --git a/groth16/Cargo.toml b/groth16/Cargo.toml index 717ae5529..fc1f1f735 100644 --- a/groth16/Cargo.toml +++ b/groth16/Cargo.toml @@ -28,6 +28,7 @@ ff-fft = { path = "../ff-fft" } r1cs-core = { path = "../r1cs-core" } bench-utils = { path = "../bench-utils" } +num-traits = { version = "0.2.11" } rand = { version = "0.7" } rayon = { version = "1" } smallvec = { version = "0.6" } diff --git a/groth16/examples/snark-scalability/groth16.rs b/groth16/examples/snark-scalability/groth16.rs index 9caef8eda..ec06cacf4 100644 --- a/groth16/examples/snark-scalability/groth16.rs +++ b/groth16/examples/snark-scalability/groth16.rs @@ -40,7 +40,7 @@ use std::{ // We're going to use the BLS12-377 pairing-friendly elliptic curve. use algebra::{ curves::bls12_377::Bls12_377, - fields::{bls12_377::fr::Fr, Field}, + fields::bls12_377::fr::Fr, }; // We're going to use the Groth 16 proving system. @@ -48,6 +48,7 @@ use groth16::{ create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, }; +use num_traits::One; use std::{env, fs::OpenOptions, path::PathBuf, process}; mod constraints; diff --git a/groth16/src/generator.rs b/groth16/src/generator.rs index 6c217ebe5..65d96891f 100644 --- a/groth16/src/generator.rs +++ b/groth16/src/generator.rs @@ -4,6 +4,7 @@ use algebra::{ }; use ff_fft::EvaluationDomain; +use num_traits::{One, Zero}; use r1cs_core::{ ConstraintSynthesizer, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable, }; diff --git a/groth16/src/prover.rs b/groth16/src/prover.rs index a9b847604..cd297c4ff 100644 --- a/groth16/src/prover.rs +++ b/groth16/src/prover.rs @@ -2,11 +2,12 @@ use rand::Rng; use rayon::prelude::*; use algebra::{ - groups::Group, msm::VariableBaseMSM, AffineCurve, Field, PairingEngine, PrimeField, + groups::Group, msm::VariableBaseMSM, AffineCurve, PairingEngine, PrimeField, ProjectiveCurve, UniformRand, }; use crate::{r1cs_to_qap::R1CStoQAP, Parameters, Proof}; +use num_traits::{One, Zero}; use r1cs_core::{ ConstraintSynthesizer, ConstraintSystem, Index, LinearCombination, SynthesisError, Variable, diff --git a/groth16/src/r1cs_to_qap.rs b/groth16/src/r1cs_to_qap.rs index ac95ab2b8..d5805be3c 100644 --- a/groth16/src/r1cs_to_qap.rs +++ b/groth16/src/r1cs_to_qap.rs @@ -1,7 +1,8 @@ -use algebra::{Field, PairingEngine}; +use algebra::PairingEngine; use ff_fft::EvaluationDomain; use crate::{generator::KeypairAssembly, prover::ProvingAssignment}; +use num_traits::{One, Zero}; use r1cs_core::{Index, SynthesisError}; use rayon::prelude::*; diff --git a/groth16/src/test.rs b/groth16/src/test.rs index 86bdc89c7..4d36df4bf 100644 --- a/groth16/src/test.rs +++ b/groth16/src/test.rs @@ -82,10 +82,10 @@ mod sw6 { create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof, }; + use algebra::{curves::sw6::SW6, fields::sw6::Fr as SW6Fr, UniformRand}; + use num_traits::Zero; use rand::thread_rng; - use algebra::{curves::sw6::SW6, fields::sw6::Fr as SW6Fr, Field, UniformRand}; - #[test] fn prove_and_verify() { let rng = &mut thread_rng(); diff --git a/r1cs-std/Cargo.toml b/r1cs-std/Cargo.toml index a79739826..b72a8f055 100644 --- a/r1cs-std/Cargo.toml +++ b/r1cs-std/Cargo.toml @@ -25,6 +25,7 @@ edition = "2018" algebra = { path = "../algebra" } r1cs-core = { path = "../r1cs-core" } derivative = "1" +num-traits = { version = "0.2.11" } radix_trie = "0.1" [dev-dependencies] diff --git a/r1cs-std/src/bits/boolean.rs b/r1cs-std/src/bits/boolean.rs index 0bcbacf6e..64f9f4402 100644 --- a/r1cs-std/src/bits/boolean.rs +++ b/r1cs-std/src/bits/boolean.rs @@ -832,13 +832,12 @@ impl CondSelectGadget for Boolean { } } - - #[cfg(test)] mod test { use super::{AllocatedBit, Boolean}; use crate::{prelude::*, test_constraint_system::TestConstraintSystem}; use algebra::{fields::bls12_381::Fr, BitIterator, Field, PrimeField, UniformRand}; + use num_traits::{One, Zero}; use r1cs_core::ConstraintSystem; use rand::SeedableRng; use rand_xorshift::XorShiftRng; @@ -903,8 +902,8 @@ mod test { assert_eq!(c.value.unwrap(), *a_val | *b_val); assert!(cs.is_satisfied()); - assert!(cs.get("a/boolean") == if *a_val { Field::one() } else { Field::zero() }); - assert!(cs.get("b/boolean") == if *b_val { Field::one() } else { Field::zero() }); + assert!(cs.get("a/boolean") == if *a_val { Fr::one() } else { Fr::zero() }); + assert!(cs.get("b/boolean") == if *b_val { Fr::one() } else { Fr::zero() }); } } } @@ -920,14 +919,14 @@ mod test { assert_eq!(c.value.unwrap(), *a_val & *b_val); assert!(cs.is_satisfied()); - assert!(cs.get("a/boolean") == if *a_val { Field::one() } else { Field::zero() }); - assert!(cs.get("b/boolean") == if *b_val { Field::one() } else { Field::zero() }); + assert!(cs.get("a/boolean") == if *a_val { Fr::one() } else { Fr::zero() }); + assert!(cs.get("b/boolean") == if *b_val { Fr::one() } else { Fr::zero() }); assert!( cs.get("and result") == if *a_val & *b_val { - Field::one() + Fr::one() } else { - Field::zero() + Fr::zero() } ); @@ -935,9 +934,9 @@ mod test { cs.set( "and result", if *a_val & *b_val { - Field::zero() + Fr::zero() } else { - Field::one() + Fr::one() }, ); assert!(!cs.is_satisfied()); @@ -956,14 +955,14 @@ mod test { assert_eq!(c.value.unwrap(), *a_val & !*b_val); assert!(cs.is_satisfied()); - assert!(cs.get("a/boolean") == if *a_val { Field::one() } else { Field::zero() }); - assert!(cs.get("b/boolean") == if *b_val { Field::one() } else { Field::zero() }); + assert!(cs.get("a/boolean") == if *a_val { Fr::one() } else { Fr::zero() }); + assert!(cs.get("b/boolean") == if *b_val { Fr::one() } else { Fr::zero() }); assert!( cs.get("and not result") == if *a_val & !*b_val { - Field::one() + Fr::one() } else { - Field::zero() + Fr::zero() } ); @@ -971,9 +970,9 @@ mod test { cs.set( "and not result", if *a_val & !*b_val { - Field::zero() + Fr::zero() } else { - Field::one() + Fr::one() }, ); assert!(!cs.is_satisfied()); @@ -992,14 +991,14 @@ mod test { assert_eq!(c.value.unwrap(), !*a_val & !*b_val); assert!(cs.is_satisfied()); - assert!(cs.get("a/boolean") == if *a_val { Field::one() } else { Field::zero() }); - assert!(cs.get("b/boolean") == if *b_val { Field::one() } else { Field::zero() }); + assert!(cs.get("a/boolean") == if *a_val { Fr::one() } else { Fr::zero() }); + assert!(cs.get("b/boolean") == if *b_val { Fr::one() } else { Fr::zero() }); assert!( cs.get("nor result") == if !*a_val & !*b_val { - Field::one() + Fr::one() } else { - Field::zero() + Fr::zero() } ); @@ -1007,9 +1006,9 @@ mod test { cs.set( "nor result", if !*a_val & !*b_val { - Field::zero() + Fr::zero() } else { - Field::one() + Fr::one() }, ); assert!(!cs.is_satisfied()); @@ -1235,7 +1234,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1243,7 +1242,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1251,7 +1250,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1259,7 +1258,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, @@ -1270,7 +1269,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1278,7 +1277,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1286,7 +1285,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1294,7 +1293,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, @@ -1305,7 +1304,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1313,7 +1312,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1321,7 +1320,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1329,7 +1328,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, @@ -1340,7 +1339,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1348,7 +1347,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Not(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1356,7 +1355,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::one()); + assert!(cs.get("xor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1364,7 +1363,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("xor result") == Field::zero()); + assert!(cs.get("xor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, @@ -1732,7 +1731,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("and result") == Field::one()); + assert!(cs.get("and result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1740,7 +1739,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("and result") == Field::zero()); + assert!(cs.get("and result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1748,7 +1747,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::zero()); + assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1756,7 +1755,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::one()); + assert!(cs.get("and not result") == Fr::one()); assert_eq!(v.value, Some(true)); }, @@ -1768,7 +1767,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("and result") == Field::zero()); + assert!(cs.get("and result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1776,7 +1775,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("and result") == Field::zero()); + assert!(cs.get("and result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1784,7 +1783,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::zero()); + assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1792,7 +1791,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::zero()); + assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, @@ -1807,7 +1806,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::zero()); + assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1815,7 +1814,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::zero()); + assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1823,7 +1822,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("nor result") == Field::zero()); + assert!(cs.get("nor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1831,7 +1830,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("nor result") == Field::zero()); + assert!(cs.get("nor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, @@ -1846,7 +1845,7 @@ mod test { OperandType::AllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::one()); + assert!(cs.get("and not result") == Fr::one()); assert_eq!(v.value, Some(true)); }, ( @@ -1854,7 +1853,7 @@ mod test { OperandType::AllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("and not result") == Field::zero()); + assert!(cs.get("and not result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1862,7 +1861,7 @@ mod test { OperandType::NegatedAllocatedTrue, Boolean::Is(ref v), ) => { - assert!(cs.get("nor result") == Field::zero()); + assert!(cs.get("nor result") == Fr::zero()); assert_eq!(v.value, Some(false)); }, ( @@ -1870,7 +1869,7 @@ mod test { OperandType::NegatedAllocatedFalse, Boolean::Is(ref v), ) => { - assert!(cs.get("nor result") == Field::one()); + assert!(cs.get("nor result") == Fr::one()); assert_eq!(v.value, Some(true)); }, diff --git a/r1cs-std/src/bits/uint32.rs b/r1cs-std/src/bits/uint32.rs index 8349df67a..eb42a32f1 100644 --- a/r1cs-std/src/bits/uint32.rs +++ b/r1cs-std/src/bits/uint32.rs @@ -344,7 +344,8 @@ impl ConditionalEqGadget for UInt32 { mod test { use super::UInt32; use crate::{bits::boolean::Boolean, test_constraint_system::TestConstraintSystem}; - use algebra::fields::{bls12_381::Fr, Field}; + use algebra::fields::bls12_381::Fr; + use num_traits::{One, Zero}; use r1cs_core::ConstraintSystem; use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; @@ -500,9 +501,9 @@ mod test { // Flip a bit_gadget and see if the addition constraint still works if cs.get("addition/result bit_gadget 0/boolean").is_zero() { - cs.set("addition/result bit_gadget 0/boolean", Field::one()); + cs.set("addition/result bit_gadget 0/boolean", Fr::one()); } else { - cs.set("addition/result bit_gadget 0/boolean", Field::zero()); + cs.set("addition/result bit_gadget 0/boolean", Fr::zero()); } assert!(!cs.is_satisfied()); diff --git a/r1cs-std/src/fields/fp12.rs b/r1cs-std/src/fields/fp12.rs index 22f5be856..1ae353abf 100644 --- a/r1cs-std/src/fields/fp12.rs +++ b/r1cs-std/src/fields/fp12.rs @@ -8,6 +8,7 @@ use algebra::{ }, BitIterator, Field, PrimeField, }; +use num_traits::One; use std::{borrow::Borrow, marker::PhantomData}; use crate::{prelude::*, Assignment}; diff --git a/r1cs-std/src/groups/curves/short_weierstrass/bls12/mod.rs b/r1cs-std/src/groups/curves/short_weierstrass/bls12/mod.rs index 88f333aec..7c5ee8b7e 100644 --- a/r1cs-std/src/groups/curves/short_weierstrass/bls12/mod.rs +++ b/r1cs-std/src/groups/curves/short_weierstrass/bls12/mod.rs @@ -3,6 +3,7 @@ use algebra::{ fields::Field, BitIterator, ProjectiveCurve, }; +use num_traits::One; use r1cs_core::{ConstraintSystem, SynthesisError}; use crate::{ diff --git a/r1cs-std/src/groups/curves/short_weierstrass/mod.rs b/r1cs-std/src/groups/curves/short_weierstrass/mod.rs index 55ad019b3..77801b021 100644 --- a/r1cs-std/src/groups/curves/short_weierstrass/mod.rs +++ b/r1cs-std/src/groups/curves/short_weierstrass/mod.rs @@ -5,6 +5,7 @@ use algebra::{ }, AffineCurve, BitIterator, Field, PrimeField, ProjectiveCurve, }; +use num_traits::{One, Zero}; use r1cs_core::{ConstraintSystem, SynthesisError}; use std::{borrow::Borrow, marker::PhantomData, ops::Neg}; diff --git a/r1cs-std/src/groups/curves/twisted_edwards/mod.rs b/r1cs-std/src/groups/curves/twisted_edwards/mod.rs index 4951131cd..720a8d964 100644 --- a/r1cs-std/src/groups/curves/twisted_edwards/mod.rs +++ b/r1cs-std/src/groups/curves/twisted_edwards/mod.rs @@ -5,6 +5,7 @@ use algebra::{ }, BitIterator, Field, }; +use num_traits::{One, Zero}; use r1cs_core::{ConstraintSystem, SynthesisError}; @@ -38,7 +39,7 @@ pub struct MontgomeryAffineGadget< mod montgomery_affine_impl { use super::*; use crate::Assignment; - use algebra::{twisted_edwards_extended::GroupAffine, AffineCurve, Field}; + use algebra::{twisted_edwards_extended::GroupAffine, Field}; use std::ops::{AddAssign, MulAssign, SubAssign}; impl> diff --git a/r1cs-std/src/pairing/mod.rs b/r1cs-std/src/pairing/mod.rs index e1ad84cdc..353dab3fc 100644 --- a/r1cs-std/src/pairing/mod.rs +++ b/r1cs-std/src/pairing/mod.rs @@ -60,6 +60,7 @@ mod test { // use rand; use crate::test_constraint_system::TestConstraintSystem; use algebra::{BitIterator, Field}; + use num_traits::One; use r1cs_core::ConstraintSystem; #[test]