From 276e09f1fb6c11598a799b815702046de82e5e9f Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 6 Jul 2018 21:37:18 +0100 Subject: [PATCH] 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 26cb4f9..87a8240 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 6beaddd..42eccea 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 {