We are running gnark-crypto against other bls implementations on oss-fuzz, and have found a crash. Essentially, the code which crashes it this (printouts added by me) :
// sample a random scalar
s, err := randomScalar(input, fp.Modulus())
if err != nil {
return nil, nil, err
}
fmt.Printf("Scalar: %x\n", s)
// compute a random point
cp := new(gnark.G1Affine)
_, _, g1Gen, _ := gnark.Generators()
cp.ScalarMultiplication(&g1Gen, s)
cpBytes := cp.Marshal()
fmt.Printf("Scalar mult, bytes: %x\n", cpBytes)
// marshal gnark point -> geth point
g1 := bls12381.NewG1()
kp, err := g1.FromBytes(cpBytes)
Scalar: 73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff0000000100000000000000
Scalar mult, bytes: 400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
panic: Could not marshal gnark.G1 -> geth.G1: must be less than modulus
goroutine 1 [running]:
github.com/ethereum/go-ethereum/tests/fuzzers/bls12381.getG1Points({0x709380, 0xc00002ecf0})
/home/user/go/src/github.com/ethereum/go-ethereum/tests/fuzzers/bls12381/bls12381_fuzz.go:205 +0x64b
I'm not sufficiently knowledgeable here to know what is happening or why, so would appreciate some help assessing this.
I did test this against the latest version of gnark-crypto also, but go the same result.