Skip to content

Commit 5e8fa1d

Browse files
tests/fuzzers/bls12381: fix blst pairing (ethereum#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
1 parent 84b3272 commit 5e8fa1d

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

tests/fuzzers/bls12381/bls12381_fuzz.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,41 @@ func FuzzCrossPairing(data []byte) int {
6565
panic("pairing mismatch gnark / geth ")
6666
}
6767

68-
var b []byte
69-
ctx := blst.PairingCtx(false, b)
7068
// compute pairing using blst
71-
blst.PairingRawAggregate(ctx, blG2, blG1)
72-
blstResult := blst.PairingAsFp12(ctx)
73-
if !(bytes.Equal(blstResult.ToBendian(), bls12381.NewGT().ToBytes(kResult))) {
74-
fmt.Printf("geth: %v\n", common.Bytes2Hex(bls12381.NewGT().ToBytes(kResult)))
75-
fmt.Printf("blst: %v\n", common.Bytes2Hex(blstResult.ToBendian()))
69+
blstResult := blst.Fp12MillerLoop(blG2, blG1)
70+
blstResult.FinalExp()
71+
res := massageBLST(blstResult.ToBendian())
72+
if !(bytes.Equal(res, bls12381.NewGT().ToBytes(kResult))) {
7673
panic("pairing mismatch blst / geth")
7774
}
7875

7976
return 1
8077
}
8178

79+
func massageBLST(in []byte) []byte {
80+
out := make([]byte, len(in))
81+
len := 12 * 48
82+
// 1
83+
copy(out[0:], in[len-1*48:len])
84+
copy(out[1*48:], in[len-2*48:len-1*48])
85+
// 2
86+
copy(out[6*48:], in[len-3*48:len-2*48])
87+
copy(out[7*48:], in[len-4*48:len-3*48])
88+
// 3
89+
copy(out[2*48:], in[len-5*48:len-4*48])
90+
copy(out[3*48:], in[len-6*48:len-5*48])
91+
// 4
92+
copy(out[8*48:], in[len-7*48:len-6*48])
93+
copy(out[9*48:], in[len-8*48:len-7*48])
94+
// 5
95+
copy(out[4*48:], in[len-9*48:len-8*48])
96+
copy(out[5*48:], in[len-10*48:len-9*48])
97+
// 6
98+
copy(out[10*48:], in[len-11*48:len-10*48])
99+
copy(out[11*48:], in[len-12*48:len-11*48])
100+
return out
101+
}
102+
82103
func FuzzCrossG1Add(data []byte) int {
83104
input := bytes.NewReader(data)
84105

0 commit comments

Comments
 (0)