diff --git a/src/groth16/tests/dummy_engine.rs b/src/groth16/tests/dummy_engine.rs index 9fcecc0..ee141a7 100644 --- a/src/groth16/tests/dummy_engine.rs +++ b/src/groth16/tests/dummy_engine.rs @@ -1,6 +1,6 @@ use ff::{Field, PrimeField}; use group::{CurveAffine, CurveProjective, Group, PrimeGroup}; -use pairing::{Engine, MillerLoopResult, PairingCurveAffine}; +use pairing::{Engine, MillerLoopResult, MultiMillerLoop, PairingCurveAffine}; use rand_core::RngCore; use std::fmt; @@ -332,21 +332,26 @@ impl Engine for DummyEngine { type G2Affine = Fr; // TODO: This should be F_645131 or something. Doesn't matter for now. - type MillerLoopResult = Fr; type Gt = Fr; - fn miller_loop<'a, I>(i: I) -> Self::MillerLoopResult - where - I: IntoIterator< - Item = &'a ( - &'a ::Prepared, - &'a ::Prepared, - ), - >, - { + fn pairing(p: &Self::G1Affine, q: &Self::G2Affine) -> Self::Gt { + Self::multi_miller_loop(&[(p, &(q.prepare()))]).final_exponentiation() + } +} + +impl MultiMillerLoop for DummyEngine { + // TODO: This should be F_645131 or something. Doesn't matter for now. + type Result = Fr; + + fn multi_miller_loop( + terms: &[( + &Self::G1Affine, + &::Prepared, + )], + ) -> Self::Result { let mut acc = ::zero(); - for &(a, b) in i { + for &(a, b) in terms { let mut tmp = *a; MulAssign::mul_assign(&mut tmp, b); AddAssign::add_assign(&mut acc, &tmp); diff --git a/src/groth16/verifier.rs b/src/groth16/verifier.rs index 6f144fc..0825f4f 100644 --- a/src/groth16/verifier.rs +++ b/src/groth16/verifier.rs @@ -1,5 +1,5 @@ use group::{CurveAffine, CurveProjective}; -use pairing::{Engine, MillerLoopResult, PairingCurveAffine}; +use pairing::{Engine, MillerLoopResult, MultiMillerLoop, PairingCurveAffine}; use std::ops::{AddAssign, Neg}; use super::{PreparedVerifyingKey, Proof, VerifyingKey}; @@ -18,7 +18,7 @@ pub fn prepare_verifying_key(vk: &VerifyingKey) -> PreparedVerifyi } } -pub fn verify_proof<'a, E: Engine>( +pub fn verify_proof<'a, E: MultiMillerLoop>( pvk: &'a PreparedVerifyingKey, proof: &Proof, public_inputs: &[E::Fr], @@ -41,14 +41,11 @@ pub fn verify_proof<'a, E: Engine>( // A * B + inputs * (-gamma) + C * (-delta) = alpha * beta // which allows us to do a single final exponentiation. - Ok(E::miller_loop( - [ - (&proof.a.prepare(), &proof.b.prepare()), - (&acc.to_affine().prepare(), &pvk.neg_gamma_g2), - (&proof.c.prepare(), &pvk.neg_delta_g2), - ] - .iter(), - ) + Ok(E::multi_miller_loop(&[ + (&proof.a, &proof.b.prepare()), + (&acc.to_affine(), &pvk.neg_gamma_g2), + (&proof.c, &pvk.neg_delta_g2), + ]) .final_exponentiation() == pvk.alpha_g1_beta_g2) }