From f2ad9059fb77d80f3f05a82e49d76dd7e2fae9ae Mon Sep 17 00:00:00 2001 From: Weiji Guo Date: Tue, 23 Jan 2024 15:18:24 +0800 Subject: [PATCH 1/2] exposed G2SqrtRatio for BLS12-381, to be used in gnark --- ecc/bls12-381/hash_to_g2.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ecc/bls12-381/hash_to_g2.go b/ecc/bls12-381/hash_to_g2.go index 4feafbfb14..e84064123f 100644 --- a/ecc/bls12-381/hash_to_g2.go +++ b/ecc/bls12-381/hash_to_g2.go @@ -194,6 +194,18 @@ func g2SqrtRatio(z *fptower.E2, u *fptower.E2, v *fptower.E2) uint64 { return isQNr } +func G2SqrtRatio(z0, z1, u0, u1, v0, v1 *fp.Element) uint64 { + var z fptower.E2 + u := fptower.E2 {A0: *u0, A1: *u1} + v := fptower.E2 {A0: *v0, A1: *v1} + ret := g2SqrtRatio(&z, &u, &v) + *z0 = z.A0 + *z1 = z.A1 + + return ret +} + + func g2NotOne(x *fptower.E2) uint64 { //Assuming hash is implemented for G1 and that the curve is over Fp From e9584bf28ef7ecf8cc36d7f5232b0664f65ada20 Mon Sep 17 00:00:00 2001 From: Weiji Guo Date: Wed, 31 Jan 2024 08:54:58 +0800 Subject: [PATCH 2/2] gofmt --- ecc/bls12-381/hash_to_g2.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ecc/bls12-381/hash_to_g2.go b/ecc/bls12-381/hash_to_g2.go index e84064123f..c2cc532911 100644 --- a/ecc/bls12-381/hash_to_g2.go +++ b/ecc/bls12-381/hash_to_g2.go @@ -196,8 +196,8 @@ func g2SqrtRatio(z *fptower.E2, u *fptower.E2, v *fptower.E2) uint64 { func G2SqrtRatio(z0, z1, u0, u1, v0, v1 *fp.Element) uint64 { var z fptower.E2 - u := fptower.E2 {A0: *u0, A1: *u1} - v := fptower.E2 {A0: *v0, A1: *v1} + u := fptower.E2{A0: *u0, A1: *u1} + v := fptower.E2{A0: *v0, A1: *v1} ret := g2SqrtRatio(&z, &u, &v) *z0 = z.A0 *z1 = z.A1 @@ -205,7 +205,6 @@ func G2SqrtRatio(z0, z1, u0, u1, v0, v1 *fp.Element) uint64 { return ret } - func g2NotOne(x *fptower.E2) uint64 { //Assuming hash is implemented for G1 and that the curve is over Fp