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

Fix Ethereum compatibility for infinite G1Affine and G2Affine coordinates #31

Closed
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
20 changes: 18 additions & 2 deletions src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl From<G1> for G1Affine {
fn from(src: G1) -> G1Affine {
let x: Fq = u256_to_point(src.x);
let y: Fq = u256_to_point(src.y);
let inf = x.is_zero() && y.is_zero();
let inf = x.is_zero() || y.is_zero();
G1Affine::new(x, y, inf)
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ impl From<G2> for G2Affine {
let c1 = u256_to_point(src.y[1]);
let y = Fq2::new(c0, c1);

let inf = x.is_zero() && y.is_zero();
let inf = x.is_zero() || y.is_zero();
G2Affine::new(x, y, inf)
}
}
Expand Down Expand Up @@ -236,6 +236,14 @@ mod tests {
assert_eq!(el2, el4);
}

#[test]
fn convert_infinity_g1() {
let g1 = G1Affine::default();
let g1_eth = G1::from(&g1);
let g1_2 = G1Affine::from(g1_eth);
assert_eq!(g1, g1_2);
}

#[test]
fn convert_g2() {
let el = g2();
Expand All @@ -246,6 +254,14 @@ mod tests {
assert_eq!(el2, el4);
}

#[test]
fn convert_infinity_g2() {
let g2 = G2Affine::default();
let g2_eth = G2::from(&g2);
let g2_2 = G2Affine::from(g2_eth);
assert_eq!(g2, g2_2);
}

#[test]
fn convert_vk() {
let vk = ark_groth16::VerifyingKey::<Bn254> {
Expand Down