From 56c75c0c8a499b812b2a017923cd576c6d7cf4c4 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sun, 7 May 2017 18:07:35 -0600 Subject: [PATCH] Rename Group to Curve. --- src/curves/bls381/ec.rs | 4 +-- src/curves/bls381/mod.rs | 24 ++++++------- src/curves/bls381/tests/mod.rs | 4 +-- src/curves/mod.rs | 28 +++++++-------- src/curves/tests/{groups.rs => curves.rs} | 16 ++++----- src/curves/tests/mod.rs | 12 +++---- src/groth16/mod.rs | 44 +++++++++++------------ 7 files changed, 66 insertions(+), 66 deletions(-) rename src/curves/tests/{groups.rs => curves.rs} (93%) diff --git a/src/curves/bls381/ec.rs b/src/curves/bls381/ec.rs index f0a7652..cdb8831 100644 --- a/src/curves/bls381/ec.rs +++ b/src/curves/bls381/ec.rs @@ -43,7 +43,7 @@ macro_rules! curve_impl { } } - impl GroupAffine<$engine, $name> for $name_affine { + impl CurveAffine<$engine, $name> for $name_affine { type Uncompressed = $name_uncompressed; fn is_valid(&self, e: &$engine) -> bool { @@ -118,7 +118,7 @@ macro_rules! curve_impl { } } - impl Group<$engine> for $name { + impl Curve<$engine> for $name { type Affine = $name_affine; type Prepared = $name_prepared; diff --git a/src/curves/bls381/mod.rs b/src/curves/bls381/mod.rs index d185e8c..fe74790 100644 --- a/src/curves/bls381/mod.rs +++ b/src/curves/bls381/mod.rs @@ -5,9 +5,9 @@ use std::borrow::Borrow; use super::{ WindowTable, Engine, - Group, - GroupAffine, - GroupRepresentation, + Curve, + CurveAffine, + CurveRepresentation, PrimeField, Field, SnarkField, @@ -334,7 +334,7 @@ impl<'a> Deserialize<'a> for G2Uncompressed { } } -impl GroupRepresentation for G1Uncompressed { +impl CurveRepresentation for G1Uncompressed { fn to_affine_unchecked(&self, e: &Bls381) -> Result { match self { &G1Uncompressed::Infinity => { @@ -365,7 +365,7 @@ impl GroupRepresentation for G1Uncompressed { } } -impl GroupRepresentation for G2Uncompressed { +impl CurveRepresentation for G2Uncompressed { fn to_affine_unchecked(&self, e: &Bls381) -> Result { match self { &G2Uncompressed::Infinity => { @@ -948,8 +948,8 @@ impl Engine for Bls381 { fn miller_loop<'a, I>(&self, i: I) -> Self::Fqk where I: IntoIterator>::Prepared, - &'a >::Prepared + &'a >::Prepared, + &'a >::Prepared )> { let mut pairs = vec![]; @@ -1009,7 +1009,7 @@ impl Engine for Bls381 { f } - fn batch_baseexp, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable>, s: S) -> Vec + fn batch_baseexp, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable>, s: S) -> Vec { use crossbeam; use num_cpus; @@ -1036,7 +1036,7 @@ impl Engine for Bls381 { ret } - fn multiexp>(&self, g: &[G::Affine], s: &[Fr]) -> Result { + fn multiexp>(&self, g: &[G::Affine], s: &[Fr]) -> Result { if g.len() != s.len() { return Err(()); } @@ -1063,7 +1063,7 @@ impl Engine for Bls381 { Ok(acc) }); - fn multiexp_inner>(engine: &Bls381, g: &[G::Affine], s: &[Fr]) -> G + fn multiexp_inner>(engine: &Bls381, g: &[G::Affine], s: &[Fr]) -> G { // This performs a multi-exponentiation calculation, i.e., multiplies // each group element by the corresponding scalar and adds all of the @@ -1196,7 +1196,7 @@ impl Engine for Bls381 { } } -impl, B: Borrow<[G]>> WindowTable { +impl, B: Borrow<[G]>> WindowTable { fn exp(&mut self, e: &Bls381, into: &mut G, mut c: >::Repr) { assert!(self.window > 1); @@ -1252,7 +1252,7 @@ impl, B: Borrow<[G]>> WindowTable { } // Performs optimal exponentiation -fn opt_exp>(e: &Bls381, base: &mut G, scalar: >::Repr, table: &mut WindowTable>) +fn opt_exp>(e: &Bls381, base: &mut G, scalar: >::Repr, table: &mut WindowTable>) { let bits = fr_arith::num_bits(&scalar); match G::optimal_window(e, bits) { diff --git a/src/curves/bls381/tests/mod.rs b/src/curves/bls381/tests/mod.rs index 99aca36..1a59782 100644 --- a/src/curves/bls381/tests/mod.rs +++ b/src/curves/bls381/tests/mod.rs @@ -3,7 +3,7 @@ extern crate bincode; use curves::*; use super::*; -fn test_vectors>(e: &E, expected: &[u8]) { +fn test_vectors>(e: &E, expected: &[u8]) { let mut bytes = vec![]; let mut acc = G::zero(e); let mut expected_reader = expected; @@ -11,7 +11,7 @@ fn test_vectors>(e: &E, expected: &[u8]) { for _ in 0..10000 { { let acc = acc.to_affine(e); - let exp: >::Uncompressed = + let exp: >::Uncompressed = bincode::deserialize_from(&mut expected_reader, bincode::Infinite).unwrap(); assert!(acc == exp.to_affine(e).unwrap()); diff --git a/src/curves/mod.rs b/src/curves/mod.rs index 536e21b..dc39e6a 100644 --- a/src/curves/mod.rs +++ b/src/curves/mod.rs @@ -15,8 +15,8 @@ pub trait Engine: Sized + Clone type Fr: SnarkField; type Fqe: SqrtField; type Fqk: Field; - type G1: Group + Convert<>::Affine, Self>; - type G2: Group + Convert<>::Affine, Self>; + type G1: Curve + Convert<>::Affine, Self>; + type G2: Curve + Convert<>::Affine, Self>; fn new() -> Self; @@ -24,8 +24,8 @@ pub trait Engine: Sized + Clone fn with FnOnce(&'a Self) -> R>(F) -> R; fn pairing(&self, p: &G1, q: &G2) -> Self::Fqk - where G1: Convert<>::Affine, Self>, - G2: Convert<>::Affine, Self> + where G1: Convert<>::Affine, Self>, + G2: Convert<>::Affine, Self> { self.final_exponentiation(&self.miller_loop( [( @@ -36,17 +36,17 @@ pub trait Engine: Sized + Clone } fn miller_loop<'a, I>(&self, I) -> Self::Fqk where I: IntoIterator>::Prepared, - &'a >::Prepared + &'a >::Prepared, + &'a >::Prepared )>; fn final_exponentiation(&self, &Self::Fqk) -> Self::Fqk; /// Perform multi-exponentiation. g and s must have the same length. - fn multiexp>(&self, g: &[G::Affine], s: &[Self::Fr]) -> Result; - fn batch_baseexp, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable>, scalars: S) -> Vec; + fn multiexp>(&self, g: &[G::Affine], s: &[Self::Fr]) -> Result; + fn batch_baseexp, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable>, scalars: S) -> Vec; } -pub trait Group: Sized + +pub trait Curve: Sized + Copy + Clone + Send + @@ -54,7 +54,7 @@ pub trait Group: Sized + fmt::Debug + 'static { - type Affine: GroupAffine; + type Affine: CurveAffine; type Prepared: Clone + Send + Sync + 'static; fn zero(&E) -> Self; @@ -78,7 +78,7 @@ pub trait Group: Sized + fn optimal_window_batch(&self, &E, scalars: usize) -> WindowTable>; } -pub trait GroupAffine>: Copy + +pub trait CurveAffine>: Copy + Clone + Sized + Send + @@ -88,7 +88,7 @@ pub trait GroupAffine>: Copy + Eq + 'static { - type Uncompressed: GroupRepresentation; + type Uncompressed: CurveRepresentation; fn to_jacobian(&self, &E) -> G; fn prepare(self, &E) -> G::Prepared; @@ -106,7 +106,7 @@ pub trait GroupAffine>: Copy + fn to_uncompressed(&self, &E) -> Self::Uncompressed; } -pub trait GroupRepresentation>: Serialize + for<'a> Deserialize<'a> +pub trait CurveRepresentation>: Serialize + for<'a> Deserialize<'a> { /// If the point representation is valid (lies on the curve, correct /// subgroup) this function will return it. @@ -207,7 +207,7 @@ pub struct WindowTable> { _marker: PhantomData<(E, G)> } -impl> WindowTable> { +impl> WindowTable> { fn new() -> Self { WindowTable { table: vec![], diff --git a/src/curves/tests/groups.rs b/src/curves/tests/curves.rs similarity index 93% rename from src/curves/tests/groups.rs rename to src/curves/tests/curves.rs index 52005e9..3682709 100644 --- a/src/curves/tests/groups.rs +++ b/src/curves/tests/curves.rs @@ -1,7 +1,7 @@ use rand; -use super::super::{Engine, Field, PrimeField, Group, GroupAffine}; +use super::super::{Engine, Field, PrimeField, Curve, CurveAffine}; -fn random_test_mixed_addition>(e: &E) +fn random_test_mixed_addition>(e: &E) { let rng = &mut rand::thread_rng(); @@ -78,7 +78,7 @@ fn random_test_mixed_addition>(e: &E) } } -fn random_test_addition>(e: &E) { +fn random_test_addition>(e: &E) { let rng = &mut rand::thread_rng(); for _ in 0..50 { @@ -111,7 +111,7 @@ fn random_test_addition>(e: &E) { } } -fn random_test_doubling>(e: &E) { +fn random_test_doubling>(e: &E) { let rng = &mut rand::thread_rng(); for _ in 0..50 { @@ -141,7 +141,7 @@ fn random_test_doubling>(e: &E) { } } -fn random_test_dh>(e: &E) { +fn random_test_dh>(e: &E) { let rng = &mut rand::thread_rng(); for _ in 0..50 { @@ -162,7 +162,7 @@ fn random_test_dh>(e: &E) { } } -fn random_mixed_addition>(e: &E) { +fn random_mixed_addition>(e: &E) { let rng = &mut rand::thread_rng(); for _ in 0..50 { @@ -179,7 +179,7 @@ fn random_mixed_addition>(e: &E) { } } -fn random_test_equality>(e: &E) { +fn random_test_equality>(e: &E) { let rng = &mut rand::thread_rng(); for _ in 0..50 { @@ -222,7 +222,7 @@ fn random_test_equality>(e: &E) { } } -pub fn test_group>(e: &E) { +pub fn test_curve>(e: &E) { { let rng = &mut rand::thread_rng(); let mut g = G::random(e, rng); diff --git a/src/curves/tests/mod.rs b/src/curves/tests/mod.rs index dec568f..33ba891 100644 --- a/src/curves/tests/mod.rs +++ b/src/curves/tests/mod.rs @@ -1,11 +1,11 @@ -use super::{Engine, Group, GroupAffine, Field, PrimeField}; +use super::{Engine, Curve, CurveAffine, Field, PrimeField}; use rand; mod fields; -mod groups; +mod curves; -fn test_multiexp>(e: &E) { - fn naiveexp>(e: &E, g: &[G::Affine], s: &[E::Fr]) -> G +fn test_multiexp>(e: &E) { + fn naiveexp>(e: &E, g: &[G::Affine], s: &[E::Fr]) -> G { assert!(g.len() == s.len()); @@ -112,8 +112,8 @@ pub fn test_engine() { fields::test_field::(&engine); fields::test_field::(&engine); - groups::test_group::(&engine); - groups::test_group::(&engine); + curves::test_curve::(&engine); + curves::test_curve::(&engine); test_bilinearity(&engine); test_multimiller(&engine); diff --git a/src/groth16/mod.rs b/src/groth16/mod.rs index bfdfd5e..3a9f5b6 100644 --- a/src/groth16/mod.rs +++ b/src/groth16/mod.rs @@ -4,34 +4,34 @@ use super::*; mod domain; pub struct ProvingKey { - a_inputs: Vec<>::Affine>, - b1_inputs: Vec<>::Affine>, - b2_inputs: Vec<>::Affine>, - a_aux: Vec<>::Affine>, - b1_aux: Vec<>::Affine>, - b2_aux: Vec<>::Affine>, - h: Vec<>::Affine>, - l: Vec<>::Affine>, - alpha_g1: >::Affine, - beta_g1: >::Affine, - beta_g2: >::Affine, - delta_g1: >::Affine, - delta_g2: >::Affine + a_inputs: Vec<>::Affine>, + b1_inputs: Vec<>::Affine>, + b2_inputs: Vec<>::Affine>, + a_aux: Vec<>::Affine>, + b1_aux: Vec<>::Affine>, + b2_aux: Vec<>::Affine>, + h: Vec<>::Affine>, + l: Vec<>::Affine>, + alpha_g1: >::Affine, + beta_g1: >::Affine, + beta_g2: >::Affine, + delta_g1: >::Affine, + delta_g2: >::Affine } pub struct VerifyingKey { - alpha_g1: >::Affine, - beta_g2: >::Affine, - gamma_g2: >::Affine, - delta_g2: >::Affine, - ic: Vec<>::Affine> + alpha_g1: >::Affine, + beta_g2: >::Affine, + gamma_g2: >::Affine, + delta_g2: >::Affine, + ic: Vec<>::Affine> } pub struct PreparedVerifyingKey { alpha_g1_beta_g2: E::Fqk, - neg_gamma_g2: >::Prepared, - neg_delta_g2: >::Prepared, - ic: Vec<>::Affine> + neg_gamma_g2: >::Prepared, + neg_delta_g2: >::Prepared, + ic: Vec<>::Affine> } pub struct Proof { @@ -317,7 +317,7 @@ pub fn verify, F: FnOnce(&mut ConstraintSystem) -> C>( struct VerifierInput<'a, E: Engine + 'a> { e: &'a E, acc: E::G1, - ic: &'a [>::Affine], + ic: &'a [>::Affine], insufficient_inputs: bool, num_inputs: usize, num_aux: usize