Skip to content

Commit d71692b

Browse files
committed
Get pairings to compile
1 parent 66e9073 commit d71692b

File tree

4 files changed

+68
-32
lines changed

4 files changed

+68
-32
lines changed

src/pairing/bls12/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
use ark_relations::r1cs::SynthesisError;
22

3-
use super::PairingVar as PG;
3+
use super::{PairingGadget as PG, PairingWithGadget};
44

55
use crate::{
6-
fields::{fp::FpVar, fp12::Fp12Var, fp2::Fp2Var, FieldVar},
6+
fields::{fp::FpVar, fp12::Fp12Var, fp2::Fp2Var, FieldVar, FieldWithVar},
77
groups::bls12::{G1AffineVar, G1PreparedVar, G1Var, G2PreparedVar, G2Var},
88
};
99
use ark_ec::bls12::{Bls12, Bls12Parameters, TwistType};
1010
use ark_ff::fields::BitIteratorBE;
1111
use core::marker::PhantomData;
1212

1313
/// Specifies the constraints for computing a pairing in a BLS12 bilinear group.
14-
pub struct PairingVar<P: Bls12Parameters>(PhantomData<P>);
14+
pub struct Bls12Gadget<P: Bls12Parameters>(PhantomData<P>);
1515

1616
type Fp2V<P> = Fp2Var<<P as Bls12Parameters>::Fp2Params>;
1717

18-
impl<P: Bls12Parameters> PairingVar<P> {
18+
impl<P: Bls12Parameters> Bls12Gadget<P>
19+
where
20+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
21+
{
1922
// Evaluate the line function at point p.
2023
#[tracing::instrument(target = "r1cs")]
2124
fn ell(
@@ -59,7 +62,17 @@ impl<P: Bls12Parameters> PairingVar<P> {
5962
}
6063
}
6164

62-
impl<P: Bls12Parameters> PG<Bls12<P>, P::Fp> for PairingVar<P> {
65+
impl<P: Bls12Parameters> PairingWithGadget for Bls12<P>
66+
where
67+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
68+
{
69+
type Gadget = Bls12Gadget<P>;
70+
}
71+
72+
impl<P: Bls12Parameters> PG<Bls12<P>> for Bls12Gadget<P>
73+
where
74+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
75+
{
6376
type G1Var = G1Var<P>;
6477
type G2Var = G2Var<P>;
6578
type G1PreparedVar = G1PreparedVar<P>;

src/pairing/mnt4/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use ark_relations::r1cs::SynthesisError;
22

3-
use super::PairingVar as PG;
3+
use super::{PairingGadget as PG, PairingWithGadget};
44

55
use crate::{
6-
fields::{fp::FpVar, fp2::Fp2Var, fp4::Fp4Var, FieldVar},
6+
fields::{fp::FpVar, fp2::Fp2Var, fp4::Fp4Var, FieldVar, FieldWithVar},
77
groups::mnt4::{
88
AteAdditionCoefficientsVar, AteDoubleCoefficientsVar, G1PreparedVar, G1Var, G2PreparedVar,
99
G2ProjectiveExtendedVar, G2Var,
@@ -15,14 +15,17 @@ use ark_ff::BitIteratorBE;
1515
use core::marker::PhantomData;
1616

1717
/// Specifies the constraints for computing a pairing in a MNT4 bilinear group.
18-
pub struct PairingVar<P: MNT4Parameters>(PhantomData<P>);
18+
pub struct MNT4Gadget<P: MNT4Parameters>(PhantomData<P>);
1919

2020
type Fp2G<P> = Fp2Var<<P as MNT4Parameters>::Fp2Params>;
2121
type Fp4G<P> = Fp4Var<<P as MNT4Parameters>::Fp4Params>;
2222
/// A variable corresponding to `ark_ec::mnt4::GT`.
2323
pub type GTVar<P> = Fp4G<P>;
2424

25-
impl<P: MNT4Parameters> PairingVar<P> {
25+
impl<P: MNT4Parameters> MNT4Gadget<P>
26+
where
27+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
28+
{
2629
#[tracing::instrument(target = "r1cs", skip(r))]
2730
pub(crate) fn doubling_step_for_flipped_miller_loop(
2831
r: &G2ProjectiveExtendedVar<P>,
@@ -186,7 +189,17 @@ impl<P: MNT4Parameters> PairingVar<P> {
186189
}
187190
}
188191

189-
impl<P: MNT4Parameters> PG<MNT4<P>, P::Fp> for PairingVar<P> {
192+
impl<P: MNT4Parameters> PairingWithGadget for MNT4<P>
193+
where
194+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
195+
{
196+
type Gadget = MNT4Gadget<P>;
197+
}
198+
199+
impl<P: MNT4Parameters> PG<MNT4<P>> for MNT4Gadget<P>
200+
where
201+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
202+
{
190203
type G1Var = G1Var<P>;
191204
type G2Var = G2Var<P>;
192205
type G1PreparedVar = G1PreparedVar<P>;

src/pairing/mnt6/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use ark_relations::r1cs::SynthesisError;
22

3-
use super::PairingVar as PG;
3+
use super::{PairingGadget as PG, PairingWithGadget};
44

55
use crate::{
6-
fields::{fp::FpVar, fp3::Fp3Var, fp6_2over3::Fp6Var, FieldVar},
6+
fields::{fp::FpVar, fp3::Fp3Var, fp6_2over3::Fp6Var, FieldVar, FieldWithVar},
77
groups::mnt6::{
88
AteAdditionCoefficientsVar, AteDoubleCoefficientsVar, G1PreparedVar, G1Var, G2PreparedVar,
99
G2ProjectiveExtendedVar, G2Var,
@@ -14,14 +14,17 @@ use ark_ff::fields::BitIteratorBE;
1414
use core::marker::PhantomData;
1515

1616
/// Specifies the constraints for computing a pairing in a MNT6 bilinear group.
17-
pub struct PairingVar<P: MNT6Parameters>(PhantomData<P>);
17+
pub struct MNT6Gadget<P: MNT6Parameters>(PhantomData<P>);
1818

1919
type Fp3G<P> = Fp3Var<<P as MNT6Parameters>::Fp3Params>;
2020
type Fp6G<P> = Fp6Var<<P as MNT6Parameters>::Fp6Params>;
2121
/// A variable corresponding to `ark_ec::mnt6::GT`.
2222
pub type GTVar<P> = Fp6G<P>;
2323

24-
impl<P: MNT6Parameters> PairingVar<P> {
24+
impl<P: MNT6Parameters> MNT6Gadget<P>
25+
where
26+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
27+
{
2528
#[tracing::instrument(target = "r1cs", skip(r))]
2629
pub(crate) fn doubling_step_for_flipped_miller_loop(
2730
r: &G2ProjectiveExtendedVar<P>,
@@ -181,7 +184,17 @@ impl<P: MNT6Parameters> PairingVar<P> {
181184
}
182185
}
183186

184-
impl<P: MNT6Parameters> PG<MNT6<P>, P::Fp> for PairingVar<P> {
187+
impl<P: MNT6Parameters> PairingWithGadget for MNT6<P>
188+
where
189+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
190+
{
191+
type Gadget = MNT6Gadget<P>;
192+
}
193+
194+
impl<P: MNT6Parameters> PG<MNT6<P>> for MNT6Gadget<P>
195+
where
196+
P::Fp: FieldWithVar<Var = FpVar<P::Fp>>,
197+
{
185198
type G1Var = G1Var<P>;
186199
type G2Var = G2Var<P>;
187200
type G1PreparedVar = G1PreparedVar<P>;

src/pairing/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::prelude::*;
22
use ark_ec::PairingEngine;
3-
use ark_ff::Field;
43
use ark_relations::r1cs::SynthesisError;
54
use core::fmt::Debug;
65

@@ -11,39 +10,37 @@ pub mod mnt4;
1110
/// This module implements pairings for MNT6 bilinear groups.
1211
pub mod mnt6;
1312

13+
pub trait PairingWithGadget: PairingEngine {
14+
type Gadget: PairingGadget<Self>;
15+
}
16+
1417
/// Specifies the constraints for computing a pairing in the yybilinear group
1518
/// `E`.
16-
pub trait PairingVar<E: PairingEngine, ConstraintF: Field = <E as PairingEngine>::Fq> {
19+
pub trait PairingGadget<E: PairingEngine> {
1720
/// An variable representing an element of `G1`.
1821
/// This is the R1CS equivalent of `E::G1Projective`.
19-
type G1Var: CurveVar<E::G1Projective, ConstraintF>
20-
+ AllocVar<E::G1Projective, ConstraintF>
21-
+ AllocVar<E::G1Affine, ConstraintF>;
22+
type G1Var: CurveVar<E::G1Projective, E::Fq>
23+
+ AllocVar<E::G1Projective, E::Fq>
24+
+ AllocVar<E::G1Affine, E::Fq>;
2225

2326
/// An variable representing an element of `G2`.
2427
/// This is the R1CS equivalent of `E::G2Projective`.
25-
type G2Var: CurveVar<E::G2Projective, ConstraintF>
26-
+ AllocVar<E::G2Projective, ConstraintF>
27-
+ AllocVar<E::G2Affine, ConstraintF>;
28+
type G2Var: CurveVar<E::G2Projective, E::Fq>
29+
+ AllocVar<E::G2Projective, E::Fq>
30+
+ AllocVar<E::G2Affine, E::Fq>;
2831

2932
/// An variable representing an element of `GT`.
3033
/// This is the R1CS equivalent of `E::GT`.
31-
type GTVar: FieldVar<E::Fqk, ConstraintF>;
34+
type GTVar: FieldVar<E::Fqk, E::Fq>;
3235

3336
/// An variable representing cached precomputation that can speed up
3437
/// pairings computations. This is the R1CS equivalent of
3538
/// `E::G1Prepared`.
36-
type G1PreparedVar: ToBytesGadget<ConstraintF>
37-
+ AllocVar<E::G1Prepared, ConstraintF>
38-
+ Clone
39-
+ Debug;
39+
type G1PreparedVar: ToBytesGadget<E::Fq> + AllocVar<E::G1Prepared, E::Fq> + Clone + Debug;
4040
/// An variable representing cached precomputation that can speed up
4141
/// pairings computations. This is the R1CS equivalent of
4242
/// `E::G2Prepared`.
43-
type G2PreparedVar: ToBytesGadget<ConstraintF>
44-
+ AllocVar<E::G2Prepared, ConstraintF>
45-
+ Clone
46-
+ Debug;
43+
type G2PreparedVar: ToBytesGadget<E::Fq> + AllocVar<E::G2Prepared, E::Fq> + Clone + Debug;
4744

4845
/// Computes a multi-miller loop between elements
4946
/// of `p` and `q`.

0 commit comments

Comments
 (0)