From 3e8f2f820253392415f61347d3435086732986a2 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 6 Jul 2018 21:24:03 +0100 Subject: [PATCH] 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 86914bb..8abf83e 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 886b464..26cb4f9 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 2b319ea..f3f3d3a 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 a55b6c8..620f32e 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 7e53120..c674622 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 c739f34..d5f37a9 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 a4e914b..71c7478 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 2ddb4ac..6beaddd 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 2481d86..cea13f3 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};