diff --git a/src/domain.rs b/src/domain.rs index e1dc229..098b0ed 100644 --- a/src/domain.rs +++ b/src/domain.rs @@ -12,7 +12,7 @@ //! [Groth16]: https://eprint.iacr.org/2016/260 use ff::PrimeField; -use group::CofactorCurve; +use group::cofactor::CofactorCurve; use super::SynthesisError; diff --git a/src/groth16/generator.rs b/src/groth16/generator.rs index e84fc12..084e7a3 100644 --- a/src/groth16/generator.rs +++ b/src/groth16/generator.rs @@ -3,7 +3,7 @@ use std::ops::{AddAssign, MulAssign}; use std::sync::Arc; use ff::{Field, PrimeField}; -use group::{CurveAffine, CofactorCurve, Group, Wnaf}; +use group::{cofactor::CofactorCurveAffine, Curve, Group, Wnaf}; use pairing::Engine; use super::{Parameters, VerifyingKey}; diff --git a/src/groth16/mod.rs b/src/groth16/mod.rs index 2602bc7..7c97197 100644 --- a/src/groth16/mod.rs +++ b/src/groth16/mod.rs @@ -2,7 +2,7 @@ //! //! [Groth16]: https://eprint.iacr.org/2016/260 -use group::{CurveAffine, GroupEncoding, UncompressedEncoding}; +use group::{cofactor::CofactorCurveAffine, GroupEncoding, UncompressedEncoding}; use pairing::{Engine, MultiMillerLoop}; use crate::SynthesisError; diff --git a/src/groth16/prover.rs b/src/groth16/prover.rs index 293cad2..cbe883a 100644 --- a/src/groth16/prover.rs +++ b/src/groth16/prover.rs @@ -5,7 +5,7 @@ use std::sync::Arc; use futures::Future; use ff::{Field, PrimeField}; -use group::{CurveAffine, CofactorCurve}; +use group::{cofactor::CofactorCurveAffine, Curve}; use pairing::Engine; use super::{ParameterSource, Proof}; diff --git a/src/groth16/tests/dummy_engine.rs b/src/groth16/tests/dummy_engine.rs index 01e8b82..17e0043 100644 --- a/src/groth16/tests/dummy_engine.rs +++ b/src/groth16/tests/dummy_engine.rs @@ -1,5 +1,9 @@ use ff::{Field, PrimeField}; -use group::{CurveAffine, CofactorCurve, Group, GroupEncoding, PrimeGroup, UncompressedEncoding}; +use group::{ + cofactor::{CofactorCurve, CofactorCurveAffine, CofactorGroup}, + prime::PrimeGroup, + Curve, Group, GroupEncoding, UncompressedEncoding, +}; use pairing::{Engine, MillerLoopResult, MultiMillerLoop, PairingCurveAffine}; use rand_core::RngCore; @@ -367,7 +371,6 @@ impl MillerLoopResult for Fr { } impl Group for Fr { - type Subgroup = Fr; type Scalar = Fr; fn random(rng: &mut R) -> Self { @@ -393,8 +396,20 @@ impl Group for Fr { impl PrimeGroup for Fr {} -impl CofactorCurve for Fr { - type Affine = Fr; +impl CofactorGroup for Fr { + type Subgroup = Fr; + + fn mul_by_cofactor(&self) -> Self::Subgroup { + *self + } + + fn into_subgroup(self) -> CtOption { + CtOption::new(self, Choice::from(1)) + } +} + +impl Curve for Fr { + type AffineRepr = Fr; fn to_affine(&self) -> Fr { *self @@ -409,6 +424,10 @@ impl CofactorCurve for Fr { } } +impl CofactorCurve for Fr { + type Affine = Fr; +} + #[derive(Copy, Clone, Default)] pub struct FakePoint; @@ -424,7 +443,7 @@ impl AsRef<[u8]> for FakePoint { } } -impl CurveAffine for Fr { +impl CofactorCurveAffine for Fr { type Curve = Fr; type Scalar = Fr; diff --git a/src/groth16/verifier.rs b/src/groth16/verifier.rs index 5758d5d..0fe8c94 100644 --- a/src/groth16/verifier.rs +++ b/src/groth16/verifier.rs @@ -1,4 +1,4 @@ -use group::{CurveAffine, CofactorCurve}; +use group::{cofactor::CofactorCurveAffine, Curve}; use pairing::{MillerLoopResult, MultiMillerLoop}; use std::ops::{AddAssign, Neg}; diff --git a/src/multiexp.rs b/src/multiexp.rs index fea10c6..8fdbc70 100644 --- a/src/multiexp.rs +++ b/src/multiexp.rs @@ -2,7 +2,7 @@ use super::multicore::Worker; use bit_vec::{self, BitVec}; use ff::{Endianness, Field, PrimeField}; use futures::Future; -use group::{CofactorCurve, CurveAffine}; +use group::cofactor::{CofactorCurve, CofactorCurveAffine}; use std::io; use std::iter; use std::ops::AddAssign; @@ -11,14 +11,14 @@ use std::sync::Arc; use super::SynthesisError; /// An object that builds a source of bases. -pub trait SourceBuilder: Send + Sync + 'static + Clone { +pub trait SourceBuilder: Send + Sync + 'static + Clone { type Source: Source; fn new(self) -> Self::Source; } /// A source of bases, like an iterator. -pub trait Source { +pub trait Source { fn next(&mut self) -> Result<&G, SynthesisError>; /// Skips `amt` elements from the source, avoiding deserialization. @@ -37,7 +37,7 @@ pub trait AddAssignFromSource: CofactorCurve { } impl AddAssignFromSource for G where G: CofactorCurve {} -impl SourceBuilder for (Arc>, usize) { +impl SourceBuilder for (Arc>, usize) { type Source = (Arc>, usize); fn new(self) -> (Arc>, usize) { @@ -45,7 +45,7 @@ impl SourceBuilder for (Arc>, usize) { } } -impl Source for (Arc>, usize) { +impl Source for (Arc>, usize) { fn next(&mut self) -> Result<&G, SynthesisError> { if self.0.len() <= self.1 { return Err(io::Error::new( @@ -311,7 +311,7 @@ fn test_with_bls12() { acc } - use group::Group; + use group::{Curve, Group}; use pairing::{ bls12_381::{Bls12, Fr}, Engine,