Skip to content

Commit

Permalink
tests/fuzzers/bls12381: fix blst deserializing (ethereum#25036)
Browse files Browse the repository at this point in the history
* tests/fuzzers/bls12381: fix blst deserializing

* tests/fuzzers/bls12381: fix blst deserializing
  • Loading branch information
MariusVanDerWijden authored and blakehhuynh committed Oct 7, 2022
1 parent 1e72b6b commit 531ff17
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/fuzzers/bls12381/bls12381_fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
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/fr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/bls12381"
blst "github.com/supranational/blst/bindings/go"
)
Expand Down Expand Up @@ -70,7 +71,9 @@ func FuzzCrossPairing(data []byte) int {
blst.PairingRawAggregate(ctx, blG2, blG1)
blstResult := blst.PairingAsFp12(ctx)
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
Expand Down Expand Up @@ -227,10 +230,8 @@ func getG1Points(input io.Reader) (*bls12381.PointG1, *gnark.G1Affine, *blst.P1A
}

// marshal gnark point -> blst point
var p1 *blst.P1Affine
var scalar *blst.Scalar
scalar.Deserialize(s.Bytes())
p1.From(scalar)
scalar := new(blst.Scalar).FromBEndian(common.LeftPadBytes(s.Bytes(), 32))
p1 := new(blst.P1Affine).From(scalar)
if !bytes.Equal(p1.Serialize(), cpBytes) {
panic("bytes(blst.G1) != bytes(geth.G1)")
}
Expand Down Expand Up @@ -262,10 +263,9 @@ func getG2Points(input io.Reader) (*bls12381.PointG2, *gnark.G2Affine, *blst.P2A
}

// marshal gnark point -> blst point
var p2 *blst.P2Affine
var scalar *blst.Scalar
scalar.Deserialize(s.Bytes())
p2.From(scalar)
// Left pad the scalar to 32 bytes
scalar := new(blst.Scalar).FromBEndian(common.LeftPadBytes(s.Bytes(), 32))
p2 := new(blst.P2Affine).From(scalar)
if !bytes.Equal(p2.Serialize(), cpBytes) {
panic("bytes(blst.G2) != bytes(geth.G2)")
}
Expand Down

0 comments on commit 531ff17

Please sign in to comment.