Skip to content

Commit

Permalink
Merge pull request #8 from scroll-tech/use_pairing
Browse files Browse the repository at this point in the history
Implement pairing traits from crate
  • Loading branch information
z2trillion authored Aug 15, 2024
2 parents 112f5b9 + 8e0020d commit 976ebc7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.63.0
1.70.0
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
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod arithmetic;
pub mod hash_to_curve;
// TODO: remove this and use traits defined in axiom_pairing instead.
pub mod pairing;
pub mod serde;

Expand Down

0 comments on commit 976ebc7

Please sign in to comment.