Use group crate for curve traits and wNAF

This commit is contained in:
Jack Grigg
2018-07-06 21:24:03 +01:00
parent 718b25c949
commit 3e8f2f8202
9 changed files with 33 additions and 48 deletions

View File

@@ -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 = []

View File

@@ -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<E: Engine, G: Group<E>> EvaluationDomain<E, G> {
}
}
pub trait Group<E: Engine>: Sized + Copy + Clone + Send + Sync {
pub trait Group<E: ScalarEngine>: 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);

View File

@@ -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,

View File

@@ -1,7 +1,7 @@
use group::{CurveAffine, EncodedPoint};
use pairing::{
Engine,
CurveAffine,
EncodedPoint
PairingCurveAffine,
};
use ::{
@@ -385,9 +385,9 @@ pub struct PreparedVerifyingKey<E: Engine> {
/// Pairing result of alpha*beta
alpha_g1_beta_g2: E::Fqk,
/// -gamma in G2
neg_gamma_g2: <E::G2Affine as CurveAffine>::Prepared,
neg_gamma_g2: <E::G2Affine as PairingCurveAffine>::Prepared,
/// -delta in G2
neg_delta_g2: <E::G2Affine as CurveAffine>::Prepared,
neg_delta_g2: <E::G2Affine as PairingCurveAffine>::Prepared,
/// Copy of IC from `VerifiyingKey`.
ic: Vec<E::G1Affine>
}

View File

@@ -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,

View File

@@ -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<Item=&'a (
&'a <Self::G1Affine as CurveAffine>::Prepared,
&'a <Self::G2Affine as CurveAffine>::Prepared
&'a <Self::G1Affine as PairingCurveAffine>::Prepared,
&'a <Self::G2Affine as PairingCurveAffine>::Prepared
)>
{
let mut acc = <Fr as Field>::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
}
}

View File

@@ -1,9 +1,6 @@
use ff::PrimeField;
use pairing::{
Engine,
CurveProjective,
CurveAffine,
};
use group::{CurveAffine, CurveProjective};
use pairing::{Engine, PairingCurveAffine};
use super::{
Proof,

View File

@@ -1,4 +1,5 @@
extern crate ff;
extern crate group;
extern crate pairing;
extern crate rand;
extern crate num_cpus;

View File

@@ -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};