Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pairing traits from crate #8

Merged
merged 3 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be done in a separate PR? If yes, can we file an issue for this task to keep a track?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have issues enabled on this repo and I cannot see a way for me to enable them. I assume I don't have the right permissions.

pub mod pairing;
pub mod serde;

Expand Down
Loading