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::{