@@ -29,6 +29,7 @@ import (
2929 gnark "github.com/consensys/gnark-crypto/ecc/bls12-381"
3030 "github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
3131 "github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
32+ "github.com/ethereum/go-ethereum/common"
3233 "github.com/ethereum/go-ethereum/crypto/bls12381"
3334 blst "github.com/supranational/blst/bindings/go"
3435)
@@ -70,7 +71,9 @@ func FuzzCrossPairing(data []byte) int {
7071 blst .PairingRawAggregate (ctx , blG2 , blG1 )
7172 blstResult := blst .PairingAsFp12 (ctx )
7273 if ! (bytes .Equal (blstResult .ToBendian (), bls12381 .NewGT ().ToBytes (kResult ))) {
73- panic ("pairing mismatch blst / geth " )
74+ fmt .Printf ("geth: %v\n " , common .Bytes2Hex (bls12381 .NewGT ().ToBytes (kResult )))
75+ fmt .Printf ("blst: %v\n " , common .Bytes2Hex (blstResult .ToBendian ()))
76+ panic ("pairing mismatch blst / geth" )
7477 }
7578
7679 return 1
@@ -227,10 +230,8 @@ func getG1Points(input io.Reader) (*bls12381.PointG1, *gnark.G1Affine, *blst.P1A
227230 }
228231
229232 // marshal gnark point -> blst point
230- var p1 * blst.P1Affine
231- var scalar * blst.Scalar
232- scalar .Deserialize (s .Bytes ())
233- p1 .From (scalar )
233+ scalar := new (blst.Scalar ).FromBEndian (common .LeftPadBytes (s .Bytes (), 32 ))
234+ p1 := new (blst.P1Affine ).From (scalar )
234235 if ! bytes .Equal (p1 .Serialize (), cpBytes ) {
235236 panic ("bytes(blst.G1) != bytes(geth.G1)" )
236237 }
@@ -262,10 +263,9 @@ func getG2Points(input io.Reader) (*bls12381.PointG2, *gnark.G2Affine, *blst.P2A
262263 }
263264
264265 // marshal gnark point -> blst point
265- var p2 * blst.P2Affine
266- var scalar * blst.Scalar
267- scalar .Deserialize (s .Bytes ())
268- p2 .From (scalar )
266+ // Left pad the scalar to 32 bytes
267+ scalar := new (blst.Scalar ).FromBEndian (common .LeftPadBytes (s .Bytes (), 32 ))
268+ p2 := new (blst.P2Affine ).From (scalar )
269269 if ! bytes .Equal (p2 .Serialize (), cpBytes ) {
270270 panic ("bytes(blst.G2) != bytes(geth.G2)" )
271271 }
0 commit comments