Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple curve cycle trait for curve cycles #190

Merged
merged 13 commits into from
Feb 4, 2021
Prev Previous commit
Next Next commit
Update trait impl w/ feedback
  • Loading branch information
drewstone committed Feb 4, 2021
commit 77127e8f3a619735fb80c0d312808f11d361edc8
30 changes: 27 additions & 3 deletions ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ pub fn prepare_g2<E: PairingEngine>(g: impl Into<E::G2Affine>) -> E::G2Prepared
}

/// A cycle of pairing-friendly elliptic curves.
/// TODO: remove this once dependencies are
/// updated with new curve cycle traits
drewstone marked this conversation as resolved.
Show resolved Hide resolved
pub trait CycleEngine: Sized + 'static + Copy + Debug + Sync + Send
where
<Self::E2 as PairingEngine>::G1Projective: MulAssign<<Self::E1 as PairingEngine>::Fq>,
Expand All @@ -323,12 +325,34 @@ where
>;
}

/// A cycle of elliptic curves, unopinionated
pub trait SimpleCycleEngine: Sized + 'static + Copy + Debug + Sync + Send
pub trait CurveCycle
where
<Self::E1 as AffineCurve>::Projective: MulAssign<<Self::E2 as AffineCurve>::BaseField>,
<Self::E2 as AffineCurve>::Projective: MulAssign<<Self::E1 as AffineCurve>::BaseField>,
{
type E1: AffineCurve;
// Maybe these constraints are too tight and could cause rust's constraint solver
// error out due to cycles (heh); we remove the
// bounds on the associated types if that's the case.
type E1: AffineCurve<
BaseField = <Self::E2 as AffineCurve>::ScalarField,
ScalarField = <Self::E2 as AffineCurve>::BaseField,
>;
type E2: AffineCurve;
}

pub trait PairingFriendlyCycle: CurveCycle {
// add whatever extra bounds are necessary.
type Engine1: PairingEngine<
G1Affine = Self::E1,
G1Projective = <Self::E1 as AffineCurve>::Projective,
Fq = <Self::E1 as AffineCurve>::BaseField,
Fr = <Self::E1 as AffineCurve>::ScalarField,
>;

type Engine2: PairingEngine<
G2Affine = Self::E2,
G2Projective = <Self::E2 as AffineCurve>::Projective,
Fq = <Self::E2 as AffineCurve>::BaseField,
Fr = <Self::E2 as AffineCurve>::ScalarField,
>;
}