From 718b25c94991895eadbb09d4cf8b5d7e35e0d588 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 2 Jul 2018 16:43:17 +0100 Subject: [PATCH 1/6] Use ff crate for Field traits --- Cargo.toml | 6 +++++- src/domain.rs | 3 +-- src/groth16/generator.rs | 3 +-- src/groth16/mod.rs | 2 +- src/groth16/prover.rs | 3 +-- src/groth16/tests/dummy_engine.rs | 14 +++++++------- src/groth16/tests/mod.rs | 7 ++----- src/groth16/verifier.rs | 2 +- src/lib.rs | 4 +++- src/multiexp.rs | 19 ++++++++----------- tests/mimc.rs | 7 +++---- 11 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a9105f7c..86914bb4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,12 +11,16 @@ version = "0.1.0" [dependencies] rand = "0.4" bit-vec = "0.4.4" +ff = "0.4" futures = "0.1" futures-cpupool = "0.1" num_cpus = "1" crossbeam = "0.3" -pairing = "0.14" byteorder = "1" +[dependencies.pairing] +git = "https://github.com/ebfull/pairing" +rev = "183a64b08e9dc7067f78624ec161371f1829623e" + [features] default = [] diff --git a/src/domain.rs b/src/domain.rs index ff626e5d0..886b4644f 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -10,10 +10,9 @@ //! This allows us to perform polynomial operations in O(n) //! by performing an O(n log n) FFT over such a domain. +use ff::{Field, PrimeField}; use pairing::{ Engine, - Field, - PrimeField, CurveProjective }; diff --git a/src/groth16/generator.rs b/src/groth16/generator.rs index 1eed62db0..2b319ea46 100644 --- a/src/groth16/generator.rs +++ b/src/groth16/generator.rs @@ -2,10 +2,9 @@ use rand::Rng; use std::sync::Arc; +use ff::{Field, PrimeField}; use pairing::{ Engine, - PrimeField, - Field, Wnaf, CurveProjective, CurveAffine diff --git a/src/groth16/mod.rs b/src/groth16/mod.rs index 3b8d67148..a55b6c838 100644 --- a/src/groth16/mod.rs +++ b/src/groth16/mod.rs @@ -486,8 +486,8 @@ mod test_with_bls12_381 { use super::*; use {Circuit, SynthesisError, ConstraintSystem}; + use ff::Field; use rand::{Rand, thread_rng}; - use pairing::{Field}; use pairing::bls12_381::{Bls12, Fr}; #[test] diff --git a/src/groth16/prover.rs b/src/groth16/prover.rs index f21fcce90..7e53120e6 100644 --- a/src/groth16/prover.rs +++ b/src/groth16/prover.rs @@ -4,10 +4,9 @@ use std::sync::Arc; use futures::Future; +use ff::{Field, PrimeField}; use pairing::{ Engine, - PrimeField, - Field, CurveProjective, CurveAffine }; diff --git a/src/groth16/tests/dummy_engine.rs b/src/groth16/tests/dummy_engine.rs index 26c899650..c739f34d5 100644 --- a/src/groth16/tests/dummy_engine.rs +++ b/src/groth16/tests/dummy_engine.rs @@ -1,13 +1,10 @@ +use ff::{ + Field, LegendreSymbol, PrimeField, PrimeFieldDecodingError, + PrimeFieldRepr, ScalarEngine, SqrtField}; use pairing::{ Engine, - PrimeField, - PrimeFieldRepr, - Field, - SqrtField, - LegendreSymbol, CurveProjective, CurveAffine, - PrimeFieldDecodingError, GroupDecodingError, EncodedPoint }; @@ -263,8 +260,11 @@ impl PrimeField for Fr { #[derive(Clone)] pub struct DummyEngine; -impl Engine for DummyEngine { +impl ScalarEngine for DummyEngine { type Fr = Fr; +} + +impl Engine for DummyEngine { type G1 = Fr; type G1Affine = Fr; type G2 = Fr; diff --git a/src/groth16/tests/mod.rs b/src/groth16/tests/mod.rs index a8e291477..0e05c36ab 100644 --- a/src/groth16/tests/mod.rs +++ b/src/groth16/tests/mod.rs @@ -1,8 +1,5 @@ -use pairing::{ - Engine, - Field, - PrimeField -}; +use ff::{Field, PrimeField}; +use pairing::Engine; mod dummy_engine; use self::dummy_engine::*; diff --git a/src/groth16/verifier.rs b/src/groth16/verifier.rs index 083e1d025..a4e914bc3 100644 --- a/src/groth16/verifier.rs +++ b/src/groth16/verifier.rs @@ -1,8 +1,8 @@ +use ff::PrimeField; use pairing::{ Engine, CurveProjective, CurveAffine, - PrimeField }; use super::{ diff --git a/src/lib.rs b/src/lib.rs index fb8d0431b..2ddb4ac3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +extern crate ff; extern crate pairing; extern crate rand; extern crate num_cpus; @@ -12,7 +13,8 @@ mod multiexp; pub mod domain; pub mod groth16; -use pairing::{Engine, Field}; +use ff::Field; +use pairing::Engine; use std::ops::{Add, Sub}; use std::fmt; diff --git a/src/multiexp.rs b/src/multiexp.rs index b1dc1f1fc..2481d863e 100644 --- a/src/multiexp.rs +++ b/src/multiexp.rs @@ -1,10 +1,7 @@ +use ff::{Field, PrimeField, PrimeFieldRepr, ScalarEngine}; use pairing::{ CurveAffine, CurveProjective, - Engine, - PrimeField, - Field, - PrimeFieldRepr }; use std::sync::Arc; use std::io; @@ -141,7 +138,7 @@ fn multiexp_inner( pool: &Worker, bases: S, density_map: D, - exponents: Arc::Fr as PrimeField>::Repr>>, + exponents: Arc::Fr as PrimeField>::Repr>>, mut skip: u32, c: u32, handle_trivial: bool @@ -167,8 +164,8 @@ fn multiexp_inner( // Create space for the buckets let mut buckets = vec![::Projective::zero(); (1 << c) - 1]; - let zero = ::Fr::zero().into_repr(); - let one = ::Fr::one().into_repr(); + let zero = ::Fr::zero().into_repr(); + let one = ::Fr::one().into_repr(); // Sort the bases into buckets for (&exp, density) in exponents.iter().zip(density_map.as_ref().iter()) { @@ -211,7 +208,7 @@ fn multiexp_inner( skip += c; - if skip >= ::Fr::NUM_BITS { + if skip >= ::Fr::NUM_BITS { // There isn't another region. Box::new(this) } else { @@ -238,7 +235,7 @@ pub fn multiexp( pool: &Worker, bases: S, density_map: D, - exponents: Arc::Fr as PrimeField>::Repr>> + exponents: Arc::Fr as PrimeField>::Repr>> ) -> Box::Projective, Error=SynthesisError>> where for<'a> &'a Q: QueryDensity, D: Send + Sync + 'static + Clone + AsRef, @@ -280,12 +277,12 @@ fn test_with_bls12() { } use rand::{self, Rand}; - use pairing::bls12_381::Bls12; + use pairing::{bls12_381::Bls12, Engine}; const SAMPLES: usize = 1 << 14; let rng = &mut rand::thread_rng(); - let v = Arc::new((0..SAMPLES).map(|_| ::Fr::rand(rng).into_repr()).collect::>()); + let v = Arc::new((0..SAMPLES).map(|_| ::Fr::rand(rng).into_repr()).collect::>()); let g = Arc::new((0..SAMPLES).map(|_| ::G1::rand(rng).into_affine()).collect::>()); let naive = naive_multiexp(g.clone(), v.clone()); diff --git a/tests/mimc.rs b/tests/mimc.rs index d6ff72b7b..1d554a57d 100644 --- a/tests/mimc.rs +++ b/tests/mimc.rs @@ -1,4 +1,5 @@ extern crate bellman; +extern crate ff; extern crate pairing; extern crate rand; @@ -9,10 +10,8 @@ use rand::{thread_rng, Rng}; use std::time::{Duration, Instant}; // Bring in some tools for using pairing-friendly curves -use pairing::{ - Engine, - Field -}; +use ff::Field; +use pairing::Engine; // We're going to use the BLS12-381 pairing-friendly elliptic curve. use pairing::bls12_381::{ From 3e8f2f820253392415f61347d3435086732986a2 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 6 Jul 2018 21:24:03 +0100 Subject: [PATCH 2/6] Use group crate for curve traits and wNAF --- Cargo.toml | 5 +++-- src/domain.rs | 10 ++++------ src/groth16/generator.rs | 8 ++------ src/groth16/mod.rs | 8 ++++---- src/groth16/prover.rs | 7 ++----- src/groth16/tests/dummy_engine.rs | 30 ++++++++++++++---------------- src/groth16/verifier.rs | 7 ++----- src/lib.rs | 1 + src/multiexp.rs | 5 +---- 9 files changed, 33 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 86914bb4f..8abf83ee1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,13 +14,14 @@ bit-vec = "0.4.4" ff = "0.4" futures = "0.1" futures-cpupool = "0.1" +group = "0.1" num_cpus = "1" crossbeam = "0.3" byteorder = "1" [dependencies.pairing] -git = "https://github.com/ebfull/pairing" -rev = "183a64b08e9dc7067f78624ec161371f1829623e" +git = "https://github.com/str4d/pairing" +rev = "3d41ee5abaa4888ff3607689aba007be8856816d" [features] default = [] diff --git a/src/domain.rs b/src/domain.rs index 886b4644f..26cb4f948 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -10,11 +10,9 @@ //! This allows us to perform polynomial operations in O(n) //! by performing an O(n log n) FFT over such a domain. -use ff::{Field, PrimeField}; -use pairing::{ - Engine, - CurveProjective -}; +use ff::{Field, PrimeField, ScalarEngine}; +use group::CurveProjective; +use pairing::Engine; use super::{ SynthesisError @@ -188,7 +186,7 @@ impl> EvaluationDomain { } } -pub trait Group: Sized + Copy + Clone + Send + Sync { +pub trait Group: Sized + Copy + Clone + Send + Sync { fn group_zero() -> Self; fn group_mul_assign(&mut self, by: &E::Fr); fn group_add_assign(&mut self, other: &Self); diff --git a/src/groth16/generator.rs b/src/groth16/generator.rs index 2b319ea46..f3f3d3afd 100644 --- a/src/groth16/generator.rs +++ b/src/groth16/generator.rs @@ -3,12 +3,8 @@ use rand::Rng; use std::sync::Arc; use ff::{Field, PrimeField}; -use pairing::{ - Engine, - Wnaf, - CurveProjective, - CurveAffine -}; +use group::{CurveAffine, CurveProjective, Wnaf}; +use pairing::Engine; use super::{ Parameters, diff --git a/src/groth16/mod.rs b/src/groth16/mod.rs index a55b6c838..620f32edb 100644 --- a/src/groth16/mod.rs +++ b/src/groth16/mod.rs @@ -1,7 +1,7 @@ +use group::{CurveAffine, EncodedPoint}; use pairing::{ Engine, - CurveAffine, - EncodedPoint + PairingCurveAffine, }; use ::{ @@ -385,9 +385,9 @@ pub struct PreparedVerifyingKey { /// Pairing result of alpha*beta alpha_g1_beta_g2: E::Fqk, /// -gamma in G2 - neg_gamma_g2: ::Prepared, + neg_gamma_g2: ::Prepared, /// -delta in G2 - neg_delta_g2: ::Prepared, + neg_delta_g2: ::Prepared, /// Copy of IC from `VerifiyingKey`. ic: Vec } diff --git a/src/groth16/prover.rs b/src/groth16/prover.rs index 7e53120e6..c674622cf 100644 --- a/src/groth16/prover.rs +++ b/src/groth16/prover.rs @@ -5,11 +5,8 @@ use std::sync::Arc; use futures::Future; use ff::{Field, PrimeField}; -use pairing::{ - Engine, - CurveProjective, - CurveAffine -}; +use group::{CurveAffine, CurveProjective}; +use pairing::Engine; use super::{ ParameterSource, diff --git a/src/groth16/tests/dummy_engine.rs b/src/groth16/tests/dummy_engine.rs index c739f34d5..d5f37a971 100644 --- a/src/groth16/tests/dummy_engine.rs +++ b/src/groth16/tests/dummy_engine.rs @@ -1,13 +1,8 @@ use ff::{ Field, LegendreSymbol, PrimeField, PrimeFieldDecodingError, PrimeFieldRepr, ScalarEngine, SqrtField}; -use pairing::{ - Engine, - CurveProjective, - CurveAffine, - GroupDecodingError, - EncodedPoint -}; +use group::{CurveAffine, CurveProjective, EncodedPoint, GroupDecodingError}; +use pairing::{Engine, PairingCurveAffine}; use std::cmp::Ordering; use std::fmt; @@ -277,8 +272,8 @@ impl Engine for DummyEngine { fn miller_loop<'a, I>(i: I) -> Self::Fqk where I: IntoIterator::Prepared, - &'a ::Prepared + &'a ::Prepared, + &'a ::Prepared )> { let mut acc = ::zero(); @@ -401,11 +396,8 @@ impl EncodedPoint for FakePoint { } impl CurveAffine for Fr { - type Pair = Fr; - type PairingResult = Fr; type Compressed = FakePoint; type Uncompressed = FakePoint; - type Prepared = Fr; type Projective = Fr; type Base = Fr; type Scalar = Fr; @@ -437,6 +429,16 @@ impl CurveAffine for Fr { res } + fn into_projective(&self) -> Self::Projective { + *self + } +} + +impl PairingCurveAffine for Fr { + type Prepared = Fr; + type Pair = Fr; + type PairingResult = Fr; + fn prepare(&self) -> Self::Prepared { *self } @@ -444,8 +446,4 @@ impl CurveAffine for Fr { fn pairing_with(&self, other: &Self::Pair) -> Self::PairingResult { self.mul(*other) } - - fn into_projective(&self) -> Self::Projective { - *self - } } diff --git a/src/groth16/verifier.rs b/src/groth16/verifier.rs index a4e914bc3..71c747837 100644 --- a/src/groth16/verifier.rs +++ b/src/groth16/verifier.rs @@ -1,9 +1,6 @@ use ff::PrimeField; -use pairing::{ - Engine, - CurveProjective, - CurveAffine, -}; +use group::{CurveAffine, CurveProjective}; +use pairing::{Engine, PairingCurveAffine}; use super::{ Proof, diff --git a/src/lib.rs b/src/lib.rs index 2ddb4ac3b..6beaddd7f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ extern crate ff; +extern crate group; extern crate pairing; extern crate rand; extern crate num_cpus; diff --git a/src/multiexp.rs b/src/multiexp.rs index 2481d863e..cea13f342 100644 --- a/src/multiexp.rs +++ b/src/multiexp.rs @@ -1,8 +1,5 @@ use ff::{Field, PrimeField, PrimeFieldRepr, ScalarEngine}; -use pairing::{ - CurveAffine, - CurveProjective, -}; +use group::{CurveAffine, CurveProjective}; use std::sync::Arc; use std::io; use bit_vec::{self, BitVec}; From 276e09f1fb6c11598a799b815702046de82e5e9f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 6 Jul 2018 21:37:18 +0100 Subject: [PATCH 3/6] Use ff:ScalarEngine instead of pairing::Engine in bellman core --- src/domain.rs | 27 +++++++++++++-------------- src/lib.rs | 37 ++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/domain.rs b/src/domain.rs index 26cb4f948..87a824084 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -12,7 +12,6 @@ use ff::{Field, PrimeField, ScalarEngine}; use group::CurveProjective; -use pairing::Engine; use super::{ SynthesisError @@ -20,7 +19,7 @@ use super::{ use super::multicore::Worker; -pub struct EvaluationDomain> { +pub struct EvaluationDomain> { coeffs: Vec, exp: u32, omega: E::Fr, @@ -29,7 +28,7 @@ pub struct EvaluationDomain> { minv: E::Fr } -impl> EvaluationDomain { +impl> EvaluationDomain { pub fn as_ref(&self) -> &[G] { &self.coeffs } @@ -224,23 +223,23 @@ impl Group for Point { } } -pub struct Scalar(pub E::Fr); +pub struct Scalar(pub E::Fr); -impl PartialEq for Scalar { +impl PartialEq for Scalar { fn eq(&self, other: &Scalar) -> bool { self.0 == other.0 } } -impl Copy for Scalar { } +impl Copy for Scalar { } -impl Clone for Scalar { +impl Clone for Scalar { fn clone(&self) -> Scalar { *self } } -impl Group for Scalar { +impl Group for Scalar { fn group_zero() -> Self { Scalar(E::Fr::zero()) } @@ -255,7 +254,7 @@ impl Group for Scalar { } } -fn best_fft>(a: &mut [T], worker: &Worker, omega: &E::Fr, log_n: u32) +fn best_fft>(a: &mut [T], worker: &Worker, omega: &E::Fr, log_n: u32) { let log_cpus = worker.log_num_cpus(); @@ -266,7 +265,7 @@ fn best_fft>(a: &mut [T], worker: &Worker, omega: &E::Fr, } } -fn serial_fft>(a: &mut [T], omega: &E::Fr, log_n: u32) +fn serial_fft>(a: &mut [T], omega: &E::Fr, log_n: u32) { fn bitreverse(mut n: u32, l: u32) -> u32 { let mut r = 0; @@ -311,7 +310,7 @@ fn serial_fft>(a: &mut [T], omega: &E::Fr, log_n: u32) } } -fn parallel_fft>( +fn parallel_fft>( a: &mut [T], worker: &Worker, omega: &E::Fr, @@ -377,7 +376,7 @@ fn polynomial_arith() { use pairing::bls12_381::Bls12; use rand::{self, Rand}; - fn test_mul(rng: &mut R) + fn test_mul(rng: &mut R) { let worker = Worker::new(); @@ -424,7 +423,7 @@ fn fft_composition() { use pairing::bls12_381::Bls12; use rand; - fn test_comp(rng: &mut R) + fn test_comp(rng: &mut R) { let worker = Worker::new(); @@ -463,7 +462,7 @@ fn parallel_fft_consistency() { use rand::{self, Rand}; use std::cmp::min; - fn test_consistency(rng: &mut R) + fn test_consistency(rng: &mut R) { let worker = Worker::new(); diff --git a/src/lib.rs b/src/lib.rs index 6beaddd7f..42eccea07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,7 @@ mod multiexp; pub mod domain; pub mod groth16; -use ff::Field; -use pairing::Engine; +use ff::{Field, ScalarEngine}; use std::ops::{Add, Sub}; use std::fmt; @@ -27,7 +26,7 @@ use std::marker::PhantomData; /// rank-1 quadratic constraint systems. The `Circuit` trait represents a /// circuit that can be synthesized. The `synthesize` method is called during /// CRS generation and during proving. -pub trait Circuit { +pub trait Circuit { /// Synthesize the circuit into a rank-1 quadratic constraint system fn synthesize>( self, @@ -64,21 +63,21 @@ pub enum Index { /// This represents a linear combination of some variables, with coefficients /// in the scalar field of a pairing-friendly elliptic curve group. #[derive(Clone)] -pub struct LinearCombination(Vec<(Variable, E::Fr)>); +pub struct LinearCombination(Vec<(Variable, E::Fr)>); -impl AsRef<[(Variable, E::Fr)]> for LinearCombination { +impl AsRef<[(Variable, E::Fr)]> for LinearCombination { fn as_ref(&self) -> &[(Variable, E::Fr)] { &self.0 } } -impl LinearCombination { +impl LinearCombination { pub fn zero() -> LinearCombination { LinearCombination(vec![]) } } -impl Add<(E::Fr, Variable)> for LinearCombination { +impl Add<(E::Fr, Variable)> for LinearCombination { type Output = LinearCombination; fn add(mut self, (coeff, var): (E::Fr, Variable)) -> LinearCombination { @@ -88,7 +87,7 @@ impl Add<(E::Fr, Variable)> for LinearCombination { } } -impl Sub<(E::Fr, Variable)> for LinearCombination { +impl Sub<(E::Fr, Variable)> for LinearCombination { type Output = LinearCombination; fn sub(self, (mut coeff, var): (E::Fr, Variable)) -> LinearCombination { @@ -98,7 +97,7 @@ impl Sub<(E::Fr, Variable)> for LinearCombination { } } -impl Add for LinearCombination { +impl Add for LinearCombination { type Output = LinearCombination; fn add(self, other: Variable) -> LinearCombination { @@ -106,7 +105,7 @@ impl Add for LinearCombination { } } -impl Sub for LinearCombination { +impl Sub for LinearCombination { type Output = LinearCombination; fn sub(self, other: Variable) -> LinearCombination { @@ -114,7 +113,7 @@ impl Sub for LinearCombination { } } -impl<'a, E: Engine> Add<&'a LinearCombination> for LinearCombination { +impl<'a, E: ScalarEngine> Add<&'a LinearCombination> for LinearCombination { type Output = LinearCombination; fn add(mut self, other: &'a LinearCombination) -> LinearCombination { @@ -126,7 +125,7 @@ impl<'a, E: Engine> Add<&'a LinearCombination> for LinearCombination { } } -impl<'a, E: Engine> Sub<&'a LinearCombination> for LinearCombination { +impl<'a, E: ScalarEngine> Sub<&'a LinearCombination> for LinearCombination { type Output = LinearCombination; fn sub(mut self, other: &'a LinearCombination) -> LinearCombination { @@ -138,7 +137,7 @@ impl<'a, E: Engine> Sub<&'a LinearCombination> for LinearCombination { } } -impl<'a, E: Engine> Add<(E::Fr, &'a LinearCombination)> for LinearCombination { +impl<'a, E: ScalarEngine> Add<(E::Fr, &'a LinearCombination)> for LinearCombination { type Output = LinearCombination; fn add(mut self, (coeff, other): (E::Fr, &'a LinearCombination)) -> LinearCombination { @@ -152,7 +151,7 @@ impl<'a, E: Engine> Add<(E::Fr, &'a LinearCombination)> for LinearCombination } } -impl<'a, E: Engine> Sub<(E::Fr, &'a LinearCombination)> for LinearCombination { +impl<'a, E: ScalarEngine> Sub<(E::Fr, &'a LinearCombination)> for LinearCombination { type Output = LinearCombination; fn sub(mut self, (coeff, other): (E::Fr, &'a LinearCombination)) -> LinearCombination { @@ -222,7 +221,7 @@ impl fmt::Display for SynthesisError { /// Represents a constraint system which can have new variables /// allocated and constrains between them formed. -pub trait ConstraintSystem: Sized { +pub trait ConstraintSystem: Sized { /// Represents the type of the "root" of this constraint system /// so that nested namespaces can minimize indirection. type Root: ConstraintSystem; @@ -294,9 +293,9 @@ pub trait ConstraintSystem: Sized { /// This is a "namespaced" constraint system which borrows a constraint system (pushing /// a namespace context) and, when dropped, pops out of the namespace context. -pub struct Namespace<'a, E: Engine, CS: ConstraintSystem + 'a>(&'a mut CS, PhantomData); +pub struct Namespace<'a, E: ScalarEngine, CS: ConstraintSystem + 'a>(&'a mut CS, PhantomData); -impl<'cs, E: Engine, CS: ConstraintSystem> ConstraintSystem for Namespace<'cs, E, CS> { +impl<'cs, E: ScalarEngine, CS: ConstraintSystem> ConstraintSystem for Namespace<'cs, E, CS> { type Root = CS::Root; fn one() -> Variable { @@ -359,7 +358,7 @@ impl<'cs, E: Engine, CS: ConstraintSystem> ConstraintSystem for Namespace< } } -impl<'a, E: Engine, CS: ConstraintSystem> Drop for Namespace<'a, E, CS> { +impl<'a, E: ScalarEngine, CS: ConstraintSystem> Drop for Namespace<'a, E, CS> { fn drop(&mut self) { self.get_root().pop_namespace() } @@ -367,7 +366,7 @@ impl<'a, E: Engine, CS: ConstraintSystem> Drop for Namespace<'a, E, CS> { /// Convenience implementation of ConstraintSystem for mutable references to /// constraint systems. -impl<'cs, E: Engine, CS: ConstraintSystem> ConstraintSystem for &'cs mut CS { +impl<'cs, E: ScalarEngine, CS: ConstraintSystem> ConstraintSystem for &'cs mut CS { type Root = CS::Root; fn one() -> Variable { From 4272cfa5b0dceac471bef115955e1534be84a018 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 6 Jul 2018 21:51:22 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Make=20pairing=20and=20groth16=20optional?= =?UTF-8?q?=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 9 ++++++++- src/domain.rs | 3 +++ src/lib.rs | 2 ++ src/multiexp.rs | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8abf83ee1..3a77feabc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,13 @@ byteorder = "1" [dependencies.pairing] git = "https://github.com/str4d/pairing" rev = "3d41ee5abaa4888ff3607689aba007be8856816d" +optional = true [features] -default = [] +groth16 = ["pairing"] +default = ["groth16"] + +[[test]] +name = "mimc" +path = "tests/mimc.rs" +required-features = ["groth16"] diff --git a/src/domain.rs b/src/domain.rs index 87a824084..4606ce5a2 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -371,6 +371,7 @@ fn parallel_fft>( // Test multiplying various (low degree) polynomials together and // comparing with naive evaluations. +#[cfg(feature = "pairing")] #[test] fn polynomial_arith() { use pairing::bls12_381::Bls12; @@ -418,6 +419,7 @@ fn polynomial_arith() { test_mul::(rng); } +#[cfg(feature = "pairing")] #[test] fn fft_composition() { use pairing::bls12_381::Bls12; @@ -456,6 +458,7 @@ fn fft_composition() { test_comp::(rng); } +#[cfg(feature = "pairing")] #[test] fn parallel_fft_consistency() { use pairing::bls12_381::Bls12; diff --git a/src/lib.rs b/src/lib.rs index 42eccea07..f6d716399 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ extern crate ff; extern crate group; +#[cfg(feature = "pairing")] extern crate pairing; extern crate rand; extern crate num_cpus; @@ -12,6 +13,7 @@ extern crate byteorder; pub mod multicore; mod multiexp; pub mod domain; +#[cfg(feature = "groth16")] pub mod groth16; use ff::{Field, ScalarEngine}; diff --git a/src/multiexp.rs b/src/multiexp.rs index cea13f342..d24572bf6 100644 --- a/src/multiexp.rs +++ b/src/multiexp.rs @@ -255,6 +255,7 @@ pub fn multiexp( multiexp_inner(pool, bases, density_map, exponents, 0, c, true) } +#[cfg(feature = "pairing")] #[test] fn test_with_bls12() { fn naive_multiexp( From 2e35a322d5080d372283a164b617e3af93b15ee0 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 11 Nov 2018 10:52:08 +1300 Subject: [PATCH 5/6] Update sapling-crypto crate to use ff crate --- Cargo.toml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a77feabc..6812a7fe3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,13 +17,9 @@ futures-cpupool = "0.1" group = "0.1" num_cpus = "1" crossbeam = "0.3" +pairing = { path = "../pairing", optional = true } byteorder = "1" -[dependencies.pairing] -git = "https://github.com/str4d/pairing" -rev = "3d41ee5abaa4888ff3607689aba007be8856816d" -optional = true - [features] groth16 = ["pairing"] default = ["groth16"] From 12f93f2fc25d79ca65e587305ff2547e1160452e Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 6 Jan 2019 09:50:07 +0000 Subject: [PATCH 6/6] Add ff and group crates to Cargo workspace --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6812a7fe3..9ba6de490 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,10 @@ version = "0.1.0" [dependencies] rand = "0.4" bit-vec = "0.4.4" -ff = "0.4" +ff = { path = "../ff" } futures = "0.1" futures-cpupool = "0.1" -group = "0.1" +group = { path = "../group" } num_cpus = "1" crossbeam = "0.3" pairing = { path = "../pairing", optional = true }