pairing: Separate associated types for MillerLoopResult and Gt
This commit is contained in:
parent
534c99327a
commit
c8bf2e9fb7
|
@ -400,7 +400,7 @@ impl<E: Engine> Parameters<E> {
|
||||||
|
|
||||||
pub struct PreparedVerifyingKey<E: Engine> {
|
pub struct PreparedVerifyingKey<E: Engine> {
|
||||||
/// Pairing result of alpha*beta
|
/// Pairing result of alpha*beta
|
||||||
alpha_g1_beta_g2: E::Fqk,
|
alpha_g1_beta_g2: E::Gt,
|
||||||
/// -gamma in G2
|
/// -gamma in G2
|
||||||
neg_gamma_g2: <E::G2Affine as PairingCurveAffine>::Prepared,
|
neg_gamma_g2: <E::G2Affine as PairingCurveAffine>::Prepared,
|
||||||
/// -delta in G2
|
/// -delta in G2
|
||||||
|
|
|
@ -335,9 +335,10 @@ impl Engine for DummyEngine {
|
||||||
type G2Affine = Fr;
|
type G2Affine = Fr;
|
||||||
|
|
||||||
// TODO: This should be F_645131 or something. Doesn't matter for now.
|
// TODO: This should be F_645131 or something. Doesn't matter for now.
|
||||||
type Fqk = Fr;
|
type MillerLoopResult = Fr;
|
||||||
|
type Gt = Fr;
|
||||||
|
|
||||||
fn miller_loop<'a, I>(i: I) -> Self::Fqk
|
fn miller_loop<'a, I>(i: I) -> Self::MillerLoopResult
|
||||||
where
|
where
|
||||||
I: IntoIterator<
|
I: IntoIterator<
|
||||||
Item = &'a (
|
Item = &'a (
|
||||||
|
@ -358,7 +359,7 @@ impl Engine for DummyEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Perform final exponentiation of the result of a miller loop.
|
/// Perform final exponentiation of the result of a miller loop.
|
||||||
fn final_exponentiation(this: &Self::Fqk) -> CtOption<Self::Fqk> {
|
fn final_exponentiation(this: &Self::MillerLoopResult) -> CtOption<Self::Gt> {
|
||||||
CtOption::new(*this, Choice::from(1))
|
CtOption::new(*this, Choice::from(1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,10 @@ impl Engine for Bls12 {
|
||||||
type G1Affine = G1Affine;
|
type G1Affine = G1Affine;
|
||||||
type G2 = G2;
|
type G2 = G2;
|
||||||
type G2Affine = G2Affine;
|
type G2Affine = G2Affine;
|
||||||
type Fqk = Fq12;
|
type MillerLoopResult = Fq12;
|
||||||
|
type Gt = Fq12;
|
||||||
|
|
||||||
fn miller_loop<'a, I>(i: I) -> Self::Fqk
|
fn miller_loop<'a, I>(i: I) -> Self::MillerLoopResult
|
||||||
where
|
where
|
||||||
I: IntoIterator<
|
I: IntoIterator<
|
||||||
Item = &'a (
|
Item = &'a (
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub trait Engine: ScalarEngine {
|
||||||
Scalar = Self::Fr,
|
Scalar = Self::Fr,
|
||||||
Projective = Self::G1,
|
Projective = Self::G1,
|
||||||
Pair = Self::G2Affine,
|
Pair = Self::G2Affine,
|
||||||
PairingResult = Self::Fqk,
|
PairingResult = Self::Gt,
|
||||||
> + From<Self::G1>
|
> + From<Self::G1>
|
||||||
+ Mul<Self::Fr, Output = Self::G1>
|
+ Mul<Self::Fr, Output = Self::G1>
|
||||||
+ for<'a> Mul<&'a Self::Fr, Output = Self::G1>;
|
+ for<'a> Mul<&'a Self::Fr, Output = Self::G1>;
|
||||||
|
@ -60,16 +60,19 @@ pub trait Engine: ScalarEngine {
|
||||||
Scalar = Self::Fr,
|
Scalar = Self::Fr,
|
||||||
Projective = Self::G2,
|
Projective = Self::G2,
|
||||||
Pair = Self::G1Affine,
|
Pair = Self::G1Affine,
|
||||||
PairingResult = Self::Fqk,
|
PairingResult = Self::Gt,
|
||||||
> + From<Self::G2>
|
> + From<Self::G2>
|
||||||
+ Mul<Self::Fr, Output = Self::G2>
|
+ Mul<Self::Fr, Output = Self::G2>
|
||||||
+ for<'a> Mul<&'a Self::Fr, Output = Self::G2>;
|
+ for<'a> Mul<&'a Self::Fr, Output = Self::G2>;
|
||||||
|
|
||||||
|
/// The type returned by `Engine::miller_loop`.
|
||||||
|
type MillerLoopResult;
|
||||||
|
|
||||||
/// The extension field that hosts the target group of the pairing.
|
/// The extension field that hosts the target group of the pairing.
|
||||||
type Fqk: Field;
|
type Gt: Field;
|
||||||
|
|
||||||
/// Perform a miller loop with some number of (G1, G2) pairs.
|
/// Perform a miller loop with some number of (G1, G2) pairs.
|
||||||
fn miller_loop<'a, I>(i: I) -> Self::Fqk
|
fn miller_loop<'a, I>(i: I) -> Self::MillerLoopResult
|
||||||
where
|
where
|
||||||
I: IntoIterator<
|
I: IntoIterator<
|
||||||
Item = &'a (
|
Item = &'a (
|
||||||
|
@ -79,10 +82,10 @@ pub trait Engine: ScalarEngine {
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Perform final exponentiation of the result of a miller loop.
|
/// Perform final exponentiation of the result of a miller loop.
|
||||||
fn final_exponentiation(_: &Self::Fqk) -> CtOption<Self::Fqk>;
|
fn final_exponentiation(_: &Self::MillerLoopResult) -> CtOption<Self::Gt>;
|
||||||
|
|
||||||
/// Performs a complete pairing operation `(p, q)`.
|
/// Performs a complete pairing operation `(p, q)`.
|
||||||
fn pairing<G1, G2>(p: G1, q: G2) -> Self::Fqk
|
fn pairing<G1, G2>(p: G1, q: G2) -> Self::Gt
|
||||||
where
|
where
|
||||||
G1: Into<Self::G1Affine>,
|
G1: Into<Self::G1Affine>,
|
||||||
G2: Into<Self::G2Affine>,
|
G2: Into<Self::G2Affine>,
|
||||||
|
|
|
@ -30,12 +30,12 @@ pub fn engine_tests<E: Engine>() {
|
||||||
let d = E::G2::random(&mut rng).to_affine().prepare();
|
let d = E::G2::random(&mut rng).to_affine().prepare();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
E::Fqk::one(),
|
E::Gt::one(),
|
||||||
E::final_exponentiation(&E::miller_loop(&[(&z1, &b)])).unwrap()
|
E::final_exponentiation(&E::miller_loop(&[(&z1, &b)])).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
E::Fqk::one(),
|
E::Gt::one(),
|
||||||
E::final_exponentiation(&E::miller_loop(&[(&a, &z2)])).unwrap()
|
E::final_exponentiation(&E::miller_loop(&[(&a, &z2)])).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue