Skip to content

Commit 88922d2

Browse files
authored
crypto/bn256: refactor to use bitutil.TestBytes (ethereum#32435)
1 parent ccf684f commit 88922d2

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

crypto/bn256/gnark/g1.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/big"
66

77
"github.com/consensys/gnark-crypto/ecc/bn254"
8+
"github.com/ethereum/go-ethereum/common/bitutil"
89
)
910

1011
// G1 is the affine representation of a G1 group element.
@@ -43,7 +44,7 @@ func (g *G1) Unmarshal(buf []byte) (int, error) {
4344
return 0, errors.New("invalid G1 point size")
4445
}
4546

46-
if allZeroes(buf[:64]) {
47+
if !bitutil.TestBytes(buf[:64]) {
4748
// point at infinity
4849
g.inner.X.SetZero()
4950
g.inner.Y.SetZero()
@@ -82,12 +83,3 @@ func (p *G1) Marshal() []byte {
8283

8384
return output
8485
}
85-
86-
func allZeroes(buf []byte) bool {
87-
for i := range buf {
88-
if buf[i] != 0 {
89-
return false
90-
}
91-
}
92-
return true
93-
}

crypto/bn256/gnark/g2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55

66
"github.com/consensys/gnark-crypto/ecc/bn254"
7+
"github.com/ethereum/go-ethereum/common/bitutil"
78
)
89

910
// G2 is the affine representation of a G2 group element.
@@ -31,7 +32,7 @@ func (g *G2) Unmarshal(buf []byte) (int, error) {
3132
return 0, errors.New("invalid G2 point size")
3233
}
3334

34-
if allZeroes(buf[:128]) {
35+
if !bitutil.TestBytes(buf[:128]) {
3536
// point at infinity
3637
g.inner.X.A0.SetZero()
3738
g.inner.X.A1.SetZero()

0 commit comments

Comments
 (0)