tests/fuzzers/bls12381: fix blst pairing (#25037)

* tests/fuzzers/bls12381: fix blst pairing

* tests/fuzzers/bls12381: only build on gofuzz

* tests/fuzzers/bls12381: remove unused code

* tests/fuzzers/bls12381: remove unused code
This commit is contained in:
Marius van der Wijden 2022-06-07 09:06:34 +02:00 committed by GitHub
parent 84b327244d
commit 5e8fa1da70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,20 +65,41 @@ func FuzzCrossPairing(data []byte) int {
panic("pairing mismatch gnark / geth ") panic("pairing mismatch gnark / geth ")
} }
var b []byte
ctx := blst.PairingCtx(false, b)
// compute pairing using blst // compute pairing using blst
blst.PairingRawAggregate(ctx, blG2, blG1) blstResult := blst.Fp12MillerLoop(blG2, blG1)
blstResult := blst.PairingAsFp12(ctx) blstResult.FinalExp()
if !(bytes.Equal(blstResult.ToBendian(), bls12381.NewGT().ToBytes(kResult))) { res := massageBLST(blstResult.ToBendian())
fmt.Printf("geth: %v\n", common.Bytes2Hex(bls12381.NewGT().ToBytes(kResult))) if !(bytes.Equal(res, bls12381.NewGT().ToBytes(kResult))) {
fmt.Printf("blst: %v\n", common.Bytes2Hex(blstResult.ToBendian()))
panic("pairing mismatch blst / geth") panic("pairing mismatch blst / geth")
} }
return 1 return 1
} }
func massageBLST(in []byte) []byte {
out := make([]byte, len(in))
len := 12 * 48
// 1
copy(out[0:], in[len-1*48:len])
copy(out[1*48:], in[len-2*48:len-1*48])
// 2
copy(out[6*48:], in[len-3*48:len-2*48])
copy(out[7*48:], in[len-4*48:len-3*48])
// 3
copy(out[2*48:], in[len-5*48:len-4*48])
copy(out[3*48:], in[len-6*48:len-5*48])
// 4
copy(out[8*48:], in[len-7*48:len-6*48])
copy(out[9*48:], in[len-8*48:len-7*48])
// 5
copy(out[4*48:], in[len-9*48:len-8*48])
copy(out[5*48:], in[len-10*48:len-9*48])
// 6
copy(out[10*48:], in[len-11*48:len-10*48])
copy(out[11*48:], in[len-12*48:len-11*48])
return out
}
func FuzzCrossG1Add(data []byte) int { func FuzzCrossG1Add(data []byte) int {
input := bytes.NewReader(data) input := bytes.NewReader(data)