From 103d398e488971f7a3d2d0208f840bc547423782 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Tue, 17 Jun 2025 15:09:08 +0200 Subject: [PATCH] appease felix --- crypto/bn256/gnark/g1.go | 19 ++++++++++++------- crypto/bn256/gnark/g2.go | 8 +------- crypto/bn256/gnark/native_format_test.go | 8 ++------ 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/crypto/bn256/gnark/g1.go b/crypto/bn256/gnark/g1.go index c0400a7046..50c25212bf 100644 --- a/crypto/bn256/gnark/g1.go +++ b/crypto/bn256/gnark/g1.go @@ -44,13 +44,7 @@ func (g *G1) Unmarshal(buf []byte) (int, error) { } // Check if both coordinates are zero (point at infinity) - isZero := true - for i := 0; i < 64; i++ { - if buf[i] != 0 { - isZero = false - break - } - } + isZero := allZeroes(buf[0:64]) if isZero { g.inner.X.SetZero() g.inner.Y.SetZero() @@ -97,3 +91,14 @@ func (p *G1) Marshal() []byte { return output } + +func allZeroes(buf []byte) bool { + isZero := true + for i := 0; i < len(buf); i++ { + if buf[i] != 0 { + isZero = false + break + } + } + return isZero +} diff --git a/crypto/bn256/gnark/g2.go b/crypto/bn256/gnark/g2.go index 0fe4ffd00b..83a33c112a 100644 --- a/crypto/bn256/gnark/g2.go +++ b/crypto/bn256/gnark/g2.go @@ -32,13 +32,7 @@ func (g *G2) Unmarshal(buf []byte) (int, error) { } // Check if all coordinates are zero (point at infinity) - isZero := true - for i := 0; i < 128; i++ { - if buf[i] != 0 { - isZero = false - break - } - } + isZero := allZeroes(buf[0:128]) if isZero { g.inner.X.A0.SetZero() g.inner.X.A1.SetZero() diff --git a/crypto/bn256/gnark/native_format_test.go b/crypto/bn256/gnark/native_format_test.go index a34395c379..e2b6744932 100644 --- a/crypto/bn256/gnark/native_format_test.go +++ b/crypto/bn256/gnark/native_format_test.go @@ -21,14 +21,10 @@ func TestNativeGnarkFormatIncompatibility(t *testing.T) { func TestSerRoundTrip(t *testing.T) { _, _, g1Gen, g2Gen := bn254.Generators() - expectedG1 := G1{ - inner: g1Gen, - } + expectedG1 := G1{inner: g1Gen} bytesG1 := expectedG1.Marshal() - expectedG2 := G2{ - inner: g2Gen, - } + expectedG2 := G2{inner: g2Gen} bytesG2 := expectedG2.Marshal() var gotG1 G1