diff --git a/crypto/blake2b/blake2b_f_fuzz.go b/crypto/blake2b/blake2b_f_fuzz.go
deleted file mode 100644
index aa124c1f40..0000000000
--- a/crypto/blake2b/blake2b_f_fuzz.go
+++ /dev/null
@@ -1,55 +0,0 @@
-package blake2b
-
-import (
- "encoding/binary"
-)
-
-func fuzz(data []byte) int {
- // Make sure the data confirms to the input model
- if len(data) != 211 {
- return 0
- }
- // Parse everything and call all the implementations
- var (
- rounds = binary.BigEndian.Uint16(data[0:2])
-
- h [8]uint64
- m [16]uint64
- t [2]uint64
- f uint64
- )
- for i := 0; i < 8; i++ {
- offset := 2 + i*8
- h[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
- }
- for i := 0; i < 16; i++ {
- offset := 66 + i*8
- m[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
- }
- t[0] = binary.LittleEndian.Uint64(data[194:202])
- t[1] = binary.LittleEndian.Uint64(data[202:210])
-
- if data[210]%2 == 1 { // Avoid spinning the fuzzer to hit 0/1
- f = 0xFFFFFFFFFFFFFFFF
- }
- // Run the blake2b compression on all instruction sets and cross reference
- want := h
- fGeneric(&want, &m, t[0], t[1], f, uint64(rounds))
-
- have := h
- fSSE4(&have, &m, t[0], t[1], f, uint64(rounds))
- if have != want {
- panic("SSE4 mismatches generic algo")
- }
- have = h
- fAVX(&have, &m, t[0], t[1], f, uint64(rounds))
- if have != want {
- panic("AVX mismatches generic algo")
- }
- have = h
- fAVX2(&have, &m, t[0], t[1], f, uint64(rounds))
- if have != want {
- panic("AVX2 mismatches generic algo")
- }
- return 1
-}
diff --git a/crypto/blake2b/blake2b_f_test.go b/crypto/blake2b/blake2b_f_test.go
index 16dbb3e56d..983c65a749 100644
--- a/crypto/blake2b/blake2b_f_test.go
+++ b/crypto/blake2b/blake2b_f_test.go
@@ -1,17 +1,12 @@
package blake2b
import (
+ "encoding/binary"
"fmt"
"reflect"
"testing"
)
-func Fuzz(f *testing.F) {
- f.Fuzz(func(t *testing.T, data []byte) {
- fuzz(data)
- })
-}
-
func TestF(t *testing.T) {
for i, test := range testVectorsF {
t.Run(fmt.Sprintf("test vector %v", i), func(t *testing.T) {
@@ -63,3 +58,60 @@ var testVectorsF = []testVector{
},
},
}
+
+func Fuzz(f *testing.F) {
+ f.Fuzz(func(t *testing.T, data []byte) {
+ fuzz(data)
+ })
+}
+
+func fuzz(data []byte) {
+ // Make sure the data confirms to the input model
+ if len(data) != 211 {
+ return
+ }
+ // Parse everything and call all the implementations
+ var (
+ rounds = binary.BigEndian.Uint16(data[0:2])
+
+ h [8]uint64
+ m [16]uint64
+ t [2]uint64
+ f uint64
+ )
+
+ for i := 0; i < 8; i++ {
+ offset := 2 + i*8
+ h[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
+ }
+ for i := 0; i < 16; i++ {
+ offset := 66 + i*8
+ m[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
+ }
+ t[0] = binary.LittleEndian.Uint64(data[194:202])
+ t[1] = binary.LittleEndian.Uint64(data[202:210])
+
+ if data[210]%2 == 1 { // Avoid spinning the fuzzer to hit 0/1
+ f = 0xFFFFFFFFFFFFFFFF
+ }
+
+ // Run the blake2b compression on all instruction sets and cross reference
+ want := h
+ fGeneric(&want, &m, t[0], t[1], f, uint64(rounds))
+
+ have := h
+ fSSE4(&have, &m, t[0], t[1], f, uint64(rounds))
+ if have != want {
+ panic("SSE4 mismatches generic algo")
+ }
+ have = h
+ fAVX(&have, &m, t[0], t[1], f, uint64(rounds))
+ if have != want {
+ panic("AVX mismatches generic algo")
+ }
+ have = h
+ fAVX2(&have, &m, t[0], t[1], f, uint64(rounds))
+ if have != want {
+ panic("AVX2 mismatches generic algo")
+ }
+}
diff --git a/tests/fuzzers/bitutil/compress_fuzz.go b/tests/fuzzers/bitutil/compress_fuzz.go
index 36ed06c8aa..9ddb63f5fb 100644
--- a/tests/fuzzers/bitutil/compress_fuzz.go
+++ b/tests/fuzzers/bitutil/compress_fuzz.go
@@ -22,7 +22,7 @@ import (
"github.com/ethereum/go-ethereum/common/bitutil"
)
-// Fuzz implements a go-fuzz fuzzer method to test various encoding method
+// FuzzBitutil implements a go-fuzz fuzzer method to test various encoding method
// invocations.
func FuzzBitutil(data []byte) int {
if len(data) == 0 {
diff --git a/tests/fuzzers/runtime/runtime_fuzz.go b/tests/fuzzers/runtime/runtime_fuzz.go
deleted file mode 100644
index 44c8ea1847..0000000000
--- a/tests/fuzzers/runtime/runtime_fuzz.go
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2017 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package runtime
-
-import (
- "github.com/ethereum/go-ethereum/core/vm/runtime"
-)
-
-// Fuzz is the basic entry point for the go-fuzz tool
-//
-// This returns 1 for valid parse:able/runnable code, 0
-// for invalid opcode.
-func fuzz(input []byte) int {
- _, _, err := runtime.Execute(input, input, &runtime.Config{
- GasLimit: 12000000,
- })
- // invalid opcode
- if err != nil && len(err.Error()) > 6 && err.Error()[:7] == "invalid" {
- return 0
- }
- return 1
-}
diff --git a/tests/fuzzers/runtime/runtime_test.go b/tests/fuzzers/runtime/runtime_test.go
index 7c4e58db8b..2d73a56ca1 100644
--- a/tests/fuzzers/runtime/runtime_test.go
+++ b/tests/fuzzers/runtime/runtime_test.go
@@ -16,10 +16,16 @@
package runtime
-import "testing"
+import (
+ "testing"
+
+ "github.com/ethereum/go-ethereum/core/vm/runtime"
+)
func Fuzz(f *testing.F) {
- f.Fuzz(func(t *testing.T, data []byte) {
- fuzz(data)
+ f.Fuzz(func(t *testing.T, code, input []byte) {
+ runtime.Execute(code, input, &runtime.Config{
+ GasLimit: 12000000,
+ })
})
}
diff --git a/tests/fuzzers/secp256k1/secp_fuzzer.go b/tests/fuzzers/secp256k1/secp_fuzzer.go
deleted file mode 100644
index b6200aeffa..0000000000
--- a/tests/fuzzers/secp256k1/secp_fuzzer.go
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2021 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// build +gofuzz
-
-package secp256k1
-
-import (
- "fmt"
-
- "github.com/btcsuite/btcd/btcec/v2"
- "github.com/ethereum/go-ethereum/crypto/secp256k1"
- gofuzz "github.com/google/gofuzz"
-)
-
-func fuzz(input []byte) int {
- var (
- fuzzer = gofuzz.NewFromGoFuzz(input)
- curveA = secp256k1.S256()
- curveB = btcec.S256()
- dataP1 []byte
- dataP2 []byte
- )
- // first point
- fuzzer.Fuzz(&dataP1)
- x1, y1 := curveB.ScalarBaseMult(dataP1)
- // second point
- fuzzer.Fuzz(&dataP2)
- x2, y2 := curveB.ScalarBaseMult(dataP2)
- resAX, resAY := curveA.Add(x1, y1, x2, y2)
- resBX, resBY := curveB.Add(x1, y1, x2, y2)
- if resAX.Cmp(resBX) != 0 || resAY.Cmp(resBY) != 0 {
- fmt.Printf("%s %s %s %s\n", x1, y1, x2, y2)
- panic(fmt.Sprintf("Addition failed: geth: %s %s btcd: %s %s", resAX, resAY, resBX, resBY))
- }
- return 0
-}
diff --git a/tests/fuzzers/secp256k1/secp_test.go b/tests/fuzzers/secp256k1/secp_test.go
index c4aa2c8bae..fbdd8e6ac2 100644
--- a/tests/fuzzers/secp256k1/secp_test.go
+++ b/tests/fuzzers/secp256k1/secp_test.go
@@ -16,15 +16,39 @@
package secp256k1
-import "testing"
+import (
+ "fmt"
+ "testing"
+
+ "github.com/btcsuite/btcd/btcec/v2"
+ "github.com/ethereum/go-ethereum/crypto/secp256k1"
+)
func TestFuzzer(t *testing.T) {
- test := "00000000N0000000/R00000000000000000U0000S0000000mkhP000000000000000U"
- fuzz([]byte(test))
+ a, b := "00000000N0000000/R0000000000000000", "0U0000S0000000mkhP000000000000000U"
+ fuzz([]byte(a), []byte(b))
}
func Fuzz(f *testing.F) {
- f.Fuzz(func(t *testing.T, data []byte) {
- fuzz(data)
+ f.Fuzz(func(t *testing.T, a, b []byte) {
+ fuzz(a, b)
})
}
+
+func fuzz(dataP1, dataP2 []byte) int {
+ var (
+ curveA = secp256k1.S256()
+ curveB = btcec.S256()
+ )
+ // first point
+ x1, y1 := curveB.ScalarBaseMult(dataP1)
+ // second points
+ x2, y2 := curveB.ScalarBaseMult(dataP2)
+ resAX, resAY := curveA.Add(x1, y1, x2, y2)
+ resBX, resBY := curveB.Add(x1, y1, x2, y2)
+ if resAX.Cmp(resBX) != 0 || resAY.Cmp(resBY) != 0 {
+ fmt.Printf("%s %s %s %s\n", x1, y1, x2, y2)
+ panic(fmt.Sprintf("Addition failed: geth: %s %s btcd: %s %s", resAX, resAY, resBX, resBY))
+ }
+ return 0
+}