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
30 changes: 30 additions & 0 deletions ec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,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 @@ -324,3 +326,31 @@ where
Fq = <Self::E1 as PairingEngine>::Fr,
>;
}

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<
BaseField = <Self::E2 as AffineCurve>::ScalarField,
ScalarField = <Self::E2 as AffineCurve>::BaseField,
>;
type E2: AffineCurve;
}

pub trait PairingFriendlyCycle: CurveCycle {
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,
>;
}