tests/fuzzers/bls12381: fix blst deserializing (#25036)

* tests/fuzzers/bls12381: fix blst deserializing

* tests/fuzzers/bls12381: fix blst deserializing
This commit is contained in:
Marius van der Wijden 2022-06-06 17:01:59 +02:00 committed by GitHub
parent 997f1c4f0a
commit d6b55749e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,6 +29,7 @@ import (
gnark "github.com/consensys/gnark-crypto/ecc/bls12-381" gnark "github.com/consensys/gnark-crypto/ecc/bls12-381"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fp" "github.com/consensys/gnark-crypto/ecc/bls12-381/fp"
"github.com/consensys/gnark-crypto/ecc/bls12-381/fr" "github.com/consensys/gnark-crypto/ecc/bls12-381/fr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/bls12381" "github.com/ethereum/go-ethereum/crypto/bls12381"
blst "github.com/supranational/blst/bindings/go" blst "github.com/supranational/blst/bindings/go"
) )
@ -70,7 +71,9 @@ func FuzzCrossPairing(data []byte) int {
blst.PairingRawAggregate(ctx, blG2, blG1) blst.PairingRawAggregate(ctx, blG2, blG1)
blstResult := blst.PairingAsFp12(ctx) blstResult := blst.PairingAsFp12(ctx)
if !(bytes.Equal(blstResult.ToBendian(), bls12381.NewGT().ToBytes(kResult))) { if !(bytes.Equal(blstResult.ToBendian(), bls12381.NewGT().ToBytes(kResult))) {
panic("pairing mismatch blst / geth ") fmt.Printf("geth: %v\n", common.Bytes2Hex(bls12381.NewGT().ToBytes(kResult)))
fmt.Printf("blst: %v\n", common.Bytes2Hex(blstResult.ToBendian()))
panic("pairing mismatch blst / geth")
} }
return 1 return 1
@ -227,10 +230,8 @@ func getG1Points(input io.Reader) (*bls12381.PointG1, *gnark.G1Affine, *blst.P1A
} }
// marshal gnark point -> blst point // marshal gnark point -> blst point
var p1 *blst.P1Affine scalar := new(blst.Scalar).FromBEndian(common.LeftPadBytes(s.Bytes(), 32))
var scalar *blst.Scalar p1 := new(blst.P1Affine).From(scalar)
scalar.Deserialize(s.Bytes())
p1.From(scalar)
if !bytes.Equal(p1.Serialize(), cpBytes) { if !bytes.Equal(p1.Serialize(), cpBytes) {
panic("bytes(blst.G1) != bytes(geth.G1)") panic("bytes(blst.G1) != bytes(geth.G1)")
} }
@ -262,10 +263,9 @@ func getG2Points(input io.Reader) (*bls12381.PointG2, *gnark.G2Affine, *blst.P2A
} }
// marshal gnark point -> blst point // marshal gnark point -> blst point
var p2 *blst.P2Affine // Left pad the scalar to 32 bytes
var scalar *blst.Scalar scalar := new(blst.Scalar).FromBEndian(common.LeftPadBytes(s.Bytes(), 32))
scalar.Deserialize(s.Bytes()) p2 := new(blst.P2Affine).From(scalar)
p2.From(scalar)
if !bytes.Equal(p2.Serialize(), cpBytes) { if !bytes.Equal(p2.Serialize(), cpBytes) {
panic("bytes(blst.G2) != bytes(geth.G2)") panic("bytes(blst.G2) != bytes(geth.G2)")
} }