ark_models_ext/models/bls12/
mod.rs

1pub use ark_ec::models::bls12::TwistType;
2use ark_ec::{
3    models::CurveConfig,
4    pairing::{MillerLoopOutput, Pairing, PairingOutput},
5};
6use ark_ff::{
7    fields::{
8        fp12_2over3over2::{Fp12, Fp12Config},
9        fp2::Fp2Config,
10        fp6_3over2::Fp6Config,
11        Fp2,
12    },
13    PrimeField,
14};
15use ark_std::marker::PhantomData;
16use derivative::Derivative;
17
18use crate::models::short_weierstrass::SWCurveConfig;
19
20pub trait Bls12Config: 'static + Sized {
21    /// Parameterizes the BLS12 family.
22    const X: &'static [u64];
23    /// Is `Self::X` negative?
24    const X_IS_NEGATIVE: bool;
25    /// What kind of twist is this?
26    const TWIST_TYPE: TwistType;
27
28    type Fp: PrimeField + Into<<Self::Fp as PrimeField>::BigInt>;
29    type Fp2Config: Fp2Config<Fp = Self::Fp>;
30    type Fp6Config: Fp6Config<Fp2Config = Self::Fp2Config>;
31    type Fp12Config: Fp12Config<Fp6Config = Self::Fp6Config>;
32    type G1Config: SWCurveConfig<BaseField = Self::Fp>;
33    type G2Config: SWCurveConfig<
34        BaseField = Fp2<Self::Fp2Config>,
35        ScalarField = <Self::G1Config as CurveConfig>::ScalarField,
36    >;
37
38    fn multi_miller_loop(
39        a_vec: impl IntoIterator<Item = impl Into<G1Prepared<Self>>>,
40        b_vec: impl IntoIterator<Item = impl Into<G2Prepared<Self>>>,
41    ) -> MillerLoopOutput<Bls12<Self>>;
42
43    fn final_exponentiation(f: MillerLoopOutput<Bls12<Self>>)
44        -> Option<PairingOutput<Bls12<Self>>>;
45}
46
47pub mod g1;
48pub mod g2;
49
50pub use self::{
51    g1::{G1Affine, G1Prepared, G1Projective},
52    g2::{G2Affine, G2Prepared, G2Projective},
53};
54
55#[derive(Derivative)]
56#[derivative(Copy, Clone, PartialEq, Eq, Debug, Hash)]
57pub struct Bls12<P: Bls12Config>(PhantomData<fn() -> P>);
58
59impl<P: Bls12Config> Pairing for Bls12<P> {
60    type BaseField = <P::G1Config as CurveConfig>::BaseField;
61    type ScalarField = <P::G1Config as CurveConfig>::ScalarField;
62    type G1 = G1Projective<P>;
63    type G1Affine = G1Affine<P>;
64    type G1Prepared = G1Prepared<P>;
65    type G2 = G2Projective<P>;
66    type G2Affine = G2Affine<P>;
67    type G2Prepared = G2Prepared<P>;
68    type TargetField = Fp12<P::Fp12Config>;
69
70    fn multi_miller_loop(
71        a: impl IntoIterator<Item = impl Into<Self::G1Prepared>>,
72        b: impl IntoIterator<Item = impl Into<Self::G2Prepared>>,
73    ) -> MillerLoopOutput<Self> {
74        P::multi_miller_loop(a, b)
75    }
76
77    fn final_exponentiation(f: MillerLoopOutput<Self>) -> Option<PairingOutput<Self>> {
78        P::final_exponentiation(f)
79    }
80}