Rename Group to Curve.

This commit is contained in:
Sean Bowe 2017-05-07 18:07:35 -06:00
parent d95a9b0b29
commit 56c75c0c8a
7 changed files with 66 additions and 66 deletions

View File

@ -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; type Uncompressed = $name_uncompressed;
fn is_valid(&self, e: &$engine) -> bool { 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 Affine = $name_affine;
type Prepared = $name_prepared; type Prepared = $name_prepared;

View File

@ -5,9 +5,9 @@ use std::borrow::Borrow;
use super::{ use super::{
WindowTable, WindowTable,
Engine, Engine,
Group, Curve,
GroupAffine, CurveAffine,
GroupRepresentation, CurveRepresentation,
PrimeField, PrimeField,
Field, Field,
SnarkField, SnarkField,
@ -334,7 +334,7 @@ impl<'a> Deserialize<'a> for G2Uncompressed {
} }
} }
impl GroupRepresentation<Bls381, G1> for G1Uncompressed { impl CurveRepresentation<Bls381, G1> for G1Uncompressed {
fn to_affine_unchecked(&self, e: &Bls381) -> Result<G1Affine, ()> { fn to_affine_unchecked(&self, e: &Bls381) -> Result<G1Affine, ()> {
match self { match self {
&G1Uncompressed::Infinity => { &G1Uncompressed::Infinity => {
@ -365,7 +365,7 @@ impl GroupRepresentation<Bls381, G1> for G1Uncompressed {
} }
} }
impl GroupRepresentation<Bls381, G2> for G2Uncompressed { impl CurveRepresentation<Bls381, G2> for G2Uncompressed {
fn to_affine_unchecked(&self, e: &Bls381) -> Result<G2Affine, ()> { fn to_affine_unchecked(&self, e: &Bls381) -> Result<G2Affine, ()> {
match self { match self {
&G2Uncompressed::Infinity => { &G2Uncompressed::Infinity => {
@ -948,8 +948,8 @@ impl Engine for Bls381 {
fn miller_loop<'a, I>(&self, i: I) -> Self::Fqk fn miller_loop<'a, I>(&self, i: I) -> Self::Fqk
where I: IntoIterator<Item=&'a ( where I: IntoIterator<Item=&'a (
&'a <Self::G1 as Group<Self>>::Prepared, &'a <Self::G1 as Curve<Self>>::Prepared,
&'a <Self::G2 as Group<Self>>::Prepared &'a <Self::G2 as Curve<Self>>::Prepared
)> )>
{ {
let mut pairs = vec![]; let mut pairs = vec![];
@ -1009,7 +1009,7 @@ impl Engine for Bls381 {
f f
} }
fn batch_baseexp<G: Group<Self>, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable<Self, G, Vec<G>>, s: S) -> Vec<G::Affine> fn batch_baseexp<G: Curve<Self>, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable<Self, G, Vec<G>>, s: S) -> Vec<G::Affine>
{ {
use crossbeam; use crossbeam;
use num_cpus; use num_cpus;
@ -1036,7 +1036,7 @@ impl Engine for Bls381 {
ret ret
} }
fn multiexp<G: Group<Self>>(&self, g: &[G::Affine], s: &[Fr]) -> Result<G, ()> { fn multiexp<G: Curve<Self>>(&self, g: &[G::Affine], s: &[Fr]) -> Result<G, ()> {
if g.len() != s.len() { if g.len() != s.len() {
return Err(()); return Err(());
} }
@ -1063,7 +1063,7 @@ impl Engine for Bls381 {
Ok(acc) Ok(acc)
}); });
fn multiexp_inner<G: Group<Bls381>>(engine: &Bls381, g: &[G::Affine], s: &[Fr]) -> G fn multiexp_inner<G: Curve<Bls381>>(engine: &Bls381, g: &[G::Affine], s: &[Fr]) -> G
{ {
// This performs a multi-exponentiation calculation, i.e., multiplies // This performs a multi-exponentiation calculation, i.e., multiplies
// each group element by the corresponding scalar and adds all of the // each group element by the corresponding scalar and adds all of the
@ -1196,7 +1196,7 @@ impl Engine for Bls381 {
} }
} }
impl<G: Group<Bls381>, B: Borrow<[G]>> WindowTable<Bls381, G, B> { impl<G: Curve<Bls381>, B: Borrow<[G]>> WindowTable<Bls381, G, B> {
fn exp(&mut self, e: &Bls381, into: &mut G, mut c: <Fr as PrimeField<Bls381>>::Repr) { fn exp(&mut self, e: &Bls381, into: &mut G, mut c: <Fr as PrimeField<Bls381>>::Repr) {
assert!(self.window > 1); assert!(self.window > 1);
@ -1252,7 +1252,7 @@ impl<G: Group<Bls381>, B: Borrow<[G]>> WindowTable<Bls381, G, B> {
} }
// Performs optimal exponentiation // Performs optimal exponentiation
fn opt_exp<G: Group<Bls381>>(e: &Bls381, base: &mut G, scalar: <Fr as PrimeField<Bls381>>::Repr, table: &mut WindowTable<Bls381, G, Vec<G>>) fn opt_exp<G: Curve<Bls381>>(e: &Bls381, base: &mut G, scalar: <Fr as PrimeField<Bls381>>::Repr, table: &mut WindowTable<Bls381, G, Vec<G>>)
{ {
let bits = fr_arith::num_bits(&scalar); let bits = fr_arith::num_bits(&scalar);
match G::optimal_window(e, bits) { match G::optimal_window(e, bits) {

View File

@ -3,7 +3,7 @@ extern crate bincode;
use curves::*; use curves::*;
use super::*; use super::*;
fn test_vectors<E: Engine, G: Group<E>>(e: &E, expected: &[u8]) { fn test_vectors<E: Engine, G: Curve<E>>(e: &E, expected: &[u8]) {
let mut bytes = vec![]; let mut bytes = vec![];
let mut acc = G::zero(e); let mut acc = G::zero(e);
let mut expected_reader = expected; let mut expected_reader = expected;
@ -11,7 +11,7 @@ fn test_vectors<E: Engine, G: Group<E>>(e: &E, expected: &[u8]) {
for _ in 0..10000 { for _ in 0..10000 {
{ {
let acc = acc.to_affine(e); let acc = acc.to_affine(e);
let exp: <G::Affine as GroupAffine<E, G>>::Uncompressed = let exp: <G::Affine as CurveAffine<E, G>>::Uncompressed =
bincode::deserialize_from(&mut expected_reader, bincode::Infinite).unwrap(); bincode::deserialize_from(&mut expected_reader, bincode::Infinite).unwrap();
assert!(acc == exp.to_affine(e).unwrap()); assert!(acc == exp.to_affine(e).unwrap());

View File

@ -15,8 +15,8 @@ pub trait Engine: Sized + Clone
type Fr: SnarkField<Self>; type Fr: SnarkField<Self>;
type Fqe: SqrtField<Self>; type Fqe: SqrtField<Self>;
type Fqk: Field<Self>; type Fqk: Field<Self>;
type G1: Group<Self> + Convert<<Self::G1 as Group<Self>>::Affine, Self>; type G1: Curve<Self> + Convert<<Self::G1 as Curve<Self>>::Affine, Self>;
type G2: Group<Self> + Convert<<Self::G2 as Group<Self>>::Affine, Self>; type G2: Curve<Self> + Convert<<Self::G2 as Curve<Self>>::Affine, Self>;
fn new() -> Self; fn new() -> Self;
@ -24,8 +24,8 @@ pub trait Engine: Sized + Clone
fn with<R, F: for<'a> FnOnce(&'a Self) -> R>(F) -> R; fn with<R, F: for<'a> FnOnce(&'a Self) -> R>(F) -> R;
fn pairing<G1, G2>(&self, p: &G1, q: &G2) -> Self::Fqk fn pairing<G1, G2>(&self, p: &G1, q: &G2) -> Self::Fqk
where G1: Convert<<Self::G1 as Group<Self>>::Affine, Self>, where G1: Convert<<Self::G1 as Curve<Self>>::Affine, Self>,
G2: Convert<<Self::G2 as Group<Self>>::Affine, Self> G2: Convert<<Self::G2 as Curve<Self>>::Affine, Self>
{ {
self.final_exponentiation(&self.miller_loop( self.final_exponentiation(&self.miller_loop(
[( [(
@ -36,17 +36,17 @@ pub trait Engine: Sized + Clone
} }
fn miller_loop<'a, I>(&self, I) -> Self::Fqk fn miller_loop<'a, I>(&self, I) -> Self::Fqk
where I: IntoIterator<Item=&'a ( where I: IntoIterator<Item=&'a (
&'a <Self::G1 as Group<Self>>::Prepared, &'a <Self::G1 as Curve<Self>>::Prepared,
&'a <Self::G2 as Group<Self>>::Prepared &'a <Self::G2 as Curve<Self>>::Prepared
)>; )>;
fn final_exponentiation(&self, &Self::Fqk) -> Self::Fqk; fn final_exponentiation(&self, &Self::Fqk) -> Self::Fqk;
/// Perform multi-exponentiation. g and s must have the same length. /// Perform multi-exponentiation. g and s must have the same length.
fn multiexp<G: Group<Self>>(&self, g: &[G::Affine], s: &[Self::Fr]) -> Result<G, ()>; fn multiexp<G: Curve<Self>>(&self, g: &[G::Affine], s: &[Self::Fr]) -> Result<G, ()>;
fn batch_baseexp<G: Group<Self>, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable<Self, G, Vec<G>>, scalars: S) -> Vec<G::Affine>; fn batch_baseexp<G: Curve<Self>, S: AsRef<[Self::Fr]>>(&self, table: &WindowTable<Self, G, Vec<G>>, scalars: S) -> Vec<G::Affine>;
} }
pub trait Group<E: Engine>: Sized + pub trait Curve<E: Engine>: Sized +
Copy + Copy +
Clone + Clone +
Send + Send +
@ -54,7 +54,7 @@ pub trait Group<E: Engine>: Sized +
fmt::Debug + fmt::Debug +
'static 'static
{ {
type Affine: GroupAffine<E, Self>; type Affine: CurveAffine<E, Self>;
type Prepared: Clone + Send + Sync + 'static; type Prepared: Clone + Send + Sync + 'static;
fn zero(&E) -> Self; fn zero(&E) -> Self;
@ -78,7 +78,7 @@ pub trait Group<E: Engine>: Sized +
fn optimal_window_batch(&self, &E, scalars: usize) -> WindowTable<E, Self, Vec<Self>>; fn optimal_window_batch(&self, &E, scalars: usize) -> WindowTable<E, Self, Vec<Self>>;
} }
pub trait GroupAffine<E: Engine, G: Group<E>>: Copy + pub trait CurveAffine<E: Engine, G: Curve<E>>: Copy +
Clone + Clone +
Sized + Sized +
Send + Send +
@ -88,7 +88,7 @@ pub trait GroupAffine<E: Engine, G: Group<E>>: Copy +
Eq + Eq +
'static 'static
{ {
type Uncompressed: GroupRepresentation<E, G>; type Uncompressed: CurveRepresentation<E, G>;
fn to_jacobian(&self, &E) -> G; fn to_jacobian(&self, &E) -> G;
fn prepare(self, &E) -> G::Prepared; fn prepare(self, &E) -> G::Prepared;
@ -106,7 +106,7 @@ pub trait GroupAffine<E: Engine, G: Group<E>>: Copy +
fn to_uncompressed(&self, &E) -> Self::Uncompressed; fn to_uncompressed(&self, &E) -> Self::Uncompressed;
} }
pub trait GroupRepresentation<E: Engine, G: Group<E>>: Serialize + for<'a> Deserialize<'a> pub trait CurveRepresentation<E: Engine, G: Curve<E>>: Serialize + for<'a> Deserialize<'a>
{ {
/// If the point representation is valid (lies on the curve, correct /// If the point representation is valid (lies on the curve, correct
/// subgroup) this function will return it. /// subgroup) this function will return it.
@ -207,7 +207,7 @@ pub struct WindowTable<E, G, Table: Borrow<[G]>> {
_marker: PhantomData<(E, G)> _marker: PhantomData<(E, G)>
} }
impl<E: Engine, G: Group<E>> WindowTable<E, G, Vec<G>> { impl<E: Engine, G: Curve<E>> WindowTable<E, G, Vec<G>> {
fn new() -> Self { fn new() -> Self {
WindowTable { WindowTable {
table: vec![], table: vec![],

View File

@ -1,7 +1,7 @@
use rand; use rand;
use super::super::{Engine, Field, PrimeField, Group, GroupAffine}; use super::super::{Engine, Field, PrimeField, Curve, CurveAffine};
fn random_test_mixed_addition<E: Engine, G: Group<E>>(e: &E) fn random_test_mixed_addition<E: Engine, G: Curve<E>>(e: &E)
{ {
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
@ -78,7 +78,7 @@ fn random_test_mixed_addition<E: Engine, G: Group<E>>(e: &E)
} }
} }
fn random_test_addition<E: Engine, G: Group<E>>(e: &E) { fn random_test_addition<E: Engine, G: Curve<E>>(e: &E) {
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
for _ in 0..50 { for _ in 0..50 {
@ -111,7 +111,7 @@ fn random_test_addition<E: Engine, G: Group<E>>(e: &E) {
} }
} }
fn random_test_doubling<E: Engine, G: Group<E>>(e: &E) { fn random_test_doubling<E: Engine, G: Curve<E>>(e: &E) {
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
for _ in 0..50 { for _ in 0..50 {
@ -141,7 +141,7 @@ fn random_test_doubling<E: Engine, G: Group<E>>(e: &E) {
} }
} }
fn random_test_dh<E: Engine, G: Group<E>>(e: &E) { fn random_test_dh<E: Engine, G: Curve<E>>(e: &E) {
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
for _ in 0..50 { for _ in 0..50 {
@ -162,7 +162,7 @@ fn random_test_dh<E: Engine, G: Group<E>>(e: &E) {
} }
} }
fn random_mixed_addition<E: Engine, G: Group<E>>(e: &E) { fn random_mixed_addition<E: Engine, G: Curve<E>>(e: &E) {
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
for _ in 0..50 { for _ in 0..50 {
@ -179,7 +179,7 @@ fn random_mixed_addition<E: Engine, G: Group<E>>(e: &E) {
} }
} }
fn random_test_equality<E: Engine, G: Group<E>>(e: &E) { fn random_test_equality<E: Engine, G: Curve<E>>(e: &E) {
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
for _ in 0..50 { for _ in 0..50 {
@ -222,7 +222,7 @@ fn random_test_equality<E: Engine, G: Group<E>>(e: &E) {
} }
} }
pub fn test_group<E: Engine, G: Group<E>>(e: &E) { pub fn test_curve<E: Engine, G: Curve<E>>(e: &E) {
{ {
let rng = &mut rand::thread_rng(); let rng = &mut rand::thread_rng();
let mut g = G::random(e, rng); let mut g = G::random(e, rng);

View File

@ -1,11 +1,11 @@
use super::{Engine, Group, GroupAffine, Field, PrimeField}; use super::{Engine, Curve, CurveAffine, Field, PrimeField};
use rand; use rand;
mod fields; mod fields;
mod groups; mod curves;
fn test_multiexp<E: Engine, G: Group<E>>(e: &E) { fn test_multiexp<E: Engine, G: Curve<E>>(e: &E) {
fn naiveexp<E: Engine, G: Group<E>>(e: &E, g: &[G::Affine], s: &[E::Fr]) -> G fn naiveexp<E: Engine, G: Curve<E>>(e: &E, g: &[G::Affine], s: &[E::Fr]) -> G
{ {
assert!(g.len() == s.len()); assert!(g.len() == s.len());
@ -112,8 +112,8 @@ pub fn test_engine<E: Engine>() {
fields::test_field::<E, E::Fqe>(&engine); fields::test_field::<E, E::Fqe>(&engine);
fields::test_field::<E, E::Fqk>(&engine); fields::test_field::<E, E::Fqk>(&engine);
groups::test_group::<E, E::G1>(&engine); curves::test_curve::<E, E::G1>(&engine);
groups::test_group::<E, E::G2>(&engine); curves::test_curve::<E, E::G2>(&engine);
test_bilinearity(&engine); test_bilinearity(&engine);
test_multimiller(&engine); test_multimiller(&engine);

View File

@ -4,34 +4,34 @@ use super::*;
mod domain; mod domain;
pub struct ProvingKey<E: Engine> { pub struct ProvingKey<E: Engine> {
a_inputs: Vec<<E::G1 as Group<E>>::Affine>, a_inputs: Vec<<E::G1 as Curve<E>>::Affine>,
b1_inputs: Vec<<E::G1 as Group<E>>::Affine>, b1_inputs: Vec<<E::G1 as Curve<E>>::Affine>,
b2_inputs: Vec<<E::G2 as Group<E>>::Affine>, b2_inputs: Vec<<E::G2 as Curve<E>>::Affine>,
a_aux: Vec<<E::G1 as Group<E>>::Affine>, a_aux: Vec<<E::G1 as Curve<E>>::Affine>,
b1_aux: Vec<<E::G1 as Group<E>>::Affine>, b1_aux: Vec<<E::G1 as Curve<E>>::Affine>,
b2_aux: Vec<<E::G2 as Group<E>>::Affine>, b2_aux: Vec<<E::G2 as Curve<E>>::Affine>,
h: Vec<<E::G1 as Group<E>>::Affine>, h: Vec<<E::G1 as Curve<E>>::Affine>,
l: Vec<<E::G1 as Group<E>>::Affine>, l: Vec<<E::G1 as Curve<E>>::Affine>,
alpha_g1: <E::G1 as Group<E>>::Affine, alpha_g1: <E::G1 as Curve<E>>::Affine,
beta_g1: <E::G1 as Group<E>>::Affine, beta_g1: <E::G1 as Curve<E>>::Affine,
beta_g2: <E::G2 as Group<E>>::Affine, beta_g2: <E::G2 as Curve<E>>::Affine,
delta_g1: <E::G1 as Group<E>>::Affine, delta_g1: <E::G1 as Curve<E>>::Affine,
delta_g2: <E::G2 as Group<E>>::Affine delta_g2: <E::G2 as Curve<E>>::Affine
} }
pub struct VerifyingKey<E: Engine> { pub struct VerifyingKey<E: Engine> {
alpha_g1: <E::G1 as Group<E>>::Affine, alpha_g1: <E::G1 as Curve<E>>::Affine,
beta_g2: <E::G2 as Group<E>>::Affine, beta_g2: <E::G2 as Curve<E>>::Affine,
gamma_g2: <E::G2 as Group<E>>::Affine, gamma_g2: <E::G2 as Curve<E>>::Affine,
delta_g2: <E::G2 as Group<E>>::Affine, delta_g2: <E::G2 as Curve<E>>::Affine,
ic: Vec<<E::G1 as Group<E>>::Affine> ic: Vec<<E::G1 as Curve<E>>::Affine>
} }
pub struct PreparedVerifyingKey<E: Engine> { pub struct PreparedVerifyingKey<E: Engine> {
alpha_g1_beta_g2: E::Fqk, alpha_g1_beta_g2: E::Fqk,
neg_gamma_g2: <E::G2 as Group<E>>::Prepared, neg_gamma_g2: <E::G2 as Curve<E>>::Prepared,
neg_delta_g2: <E::G2 as Group<E>>::Prepared, neg_delta_g2: <E::G2 as Curve<E>>::Prepared,
ic: Vec<<E::G1 as Group<E>>::Affine> ic: Vec<<E::G1 as Curve<E>>::Affine>
} }
pub struct Proof<E: Engine> { pub struct Proof<E: Engine> {
@ -317,7 +317,7 @@ pub fn verify<E: Engine, C: Input<E>, F: FnOnce(&mut ConstraintSystem<E>) -> C>(
struct VerifierInput<'a, E: Engine + 'a> { struct VerifierInput<'a, E: Engine + 'a> {
e: &'a E, e: &'a E,
acc: E::G1, acc: E::G1,
ic: &'a [<E::G1 as Group<E>>::Affine], ic: &'a [<E::G1 as Curve<E>>::Affine],
insufficient_inputs: bool, insufficient_inputs: bool,
num_inputs: usize, num_inputs: usize,
num_aux: usize num_aux: usize