Skip to content

Commit

Permalink
impl traits from pairing crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason Liang committed Jun 22, 2024
1 parent 112f5b9 commit 1a1fdf2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ rand_core = { version = "0.6", default-features = false }
lazy_static = "1.4.0"
num-bigint = "0.4.3"
num-traits = "0.2"
axiom-pairing = { package = "pairing", version = "0.23" }
paste = "1.0.11"
serde = { version = "1.0", default-features = false, optional = true }
serde_arrays = { version = "0.1.0", optional = true }
Expand Down
47 changes: 47 additions & 0 deletions src/bn256/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ impl PairingCurveAffine for G1Affine {
}
}

impl axiom_pairing::PairingCurveAffine for G1Affine {
type Pair = G2Affine;
type PairingResult = Gt;

fn pairing_with(&self, other: &Self::Pair) -> Self::PairingResult {
pairing(self, other)
}
}

impl PairingCurveAffine for G2Affine {
type Pair = G1Affine;
type PairingResult = Gt;
Expand All @@ -57,6 +66,15 @@ impl PairingCurveAffine for G2Affine {
}
}

impl axiom_pairing::PairingCurveAffine for G2Affine {
type Pair = G1Affine;
type PairingResult = Gt;

fn pairing_with(&self, other: &Self::Pair) -> Self::PairingResult {
pairing(other, self)
}
}

#[derive(Copy, Clone, Debug, Default)]
pub struct Gt(pub(crate) Fq12);

Expand Down Expand Up @@ -559,6 +577,13 @@ impl MillerLoopResult for Gt {
}
}

impl axiom_pairing::MillerLoopResult for Gt {
type Gt = Gt;
fn final_exponentiation(&self) -> Self {
MillerLoopResult::final_exponentiation(self)
}
}

pub fn multi_miller_loop(terms: &[(&G1Affine, &G2Prepared)]) -> Gt {
let mut pairs = vec![];
for &(p, q) in terms {
Expand Down Expand Up @@ -654,6 +679,28 @@ impl MultiMillerLoop for Bn256 {
}
}

impl axiom_pairing::Engine for Bn256 {
type Fr = Fr;
type G1 = G1;
type G1Affine = G1Affine;
type G2 = G2;
type G2Affine = G2Affine;
type Gt = Gt;

fn pairing(p: &Self::G1Affine, q: &Self::G2Affine) -> Self::Gt {
pairing(p, q)
}
}

impl axiom_pairing::MultiMillerLoop for Bn256 {
type G2Prepared = G2Prepared;
type Result = Gt;

fn multi_miller_loop(terms: &[(&Self::G1Affine, &Self::G2Prepared)]) -> Self::Result {
multi_miller_loop(terms)
}
}

#[cfg(test)]
use rand::SeedableRng;
#[cfg(test)]
Expand Down

0 comments on commit 1a1fdf2

Please sign in to comment.