tests/fuzzers: update fuzzers to use new built-in fuzzing

This commit is contained in:
Marius van der Wijden 2023-10-16 15:13:18 +02:00
parent 509a64ffb9
commit 69d3d5cd42
39 changed files with 436 additions and 267 deletions

3
go.mod
View file

@ -76,6 +76,8 @@ require (
) )
require ( require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20221206110420-d395f97c4830 // indirect
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect
github.com/DataDog/zstd v1.4.5 // indirect github.com/DataDog/zstd v1.4.5 // indirect
@ -99,6 +101,7 @@ require (
github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/bavard v0.1.13 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20230601170251-1830d0757c80 // indirect github.com/crate-crypto/go-ipa v0.0.0-20230601170251-1830d0757c80 // indirect
github.com/cyphar/filepath-securejoin v0.2.3 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/deepmap/oapi-codegen v1.6.0 // indirect github.com/deepmap/oapi-codegen v1.6.0 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect github.com/dlclark/regexp2 v1.7.0 // indirect

6
go.sum
View file

@ -31,6 +31,10 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20221206110420-d395f97c4830 h1:u8scGKApGy+gXpYDw2f+nh60R0FqCfrpDRIQki+5o3U=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20221206110420-d395f97c4830/go.mod h1:VzwV+t+dZ9j/H867F1M2ziD+yLHtB46oM35FxxMJ4d0=
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 h1:59MxjQVfjXsBpLy+dbd2/ELV5ofnUkUZBvWSC85sheA=
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0/go.mod h1:OahwfttHWG6eJ0clwcfBAHoDI6X/LV/15hx/wlMZSrU=
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8= github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 h1:8q4SaHjFsClSvuVne0ID/5Ka8u3fcIHyqkLjcFpNRHQ= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0 h1:8q4SaHjFsClSvuVne0ID/5Ka8u3fcIHyqkLjcFpNRHQ=
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q= github.com/Azure/azure-sdk-for-go/sdk/azcore v1.7.0/go.mod h1:bjGvMhVMb+EEm3VRNQawDMUyMMjo+S5ewNjflkep/0Q=
@ -151,6 +155,8 @@ github.com/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uz
github.com/crate-crypto/go-kzg-4844 v0.3.0/go.mod h1:SBP7ikXEgDnUPONgm33HtuDZEDtWa3L4QtN1ocJSEQ4= github.com/crate-crypto/go-kzg-4844 v0.3.0/go.mod h1:SBP7ikXEgDnUPONgm33HtuDZEDtWa3L4QtN1ocJSEQ4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X51MTk3ycuNI=
github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View file

@ -1,5 +1,5 @@
#/bin/bash -eu #!/bin/bash -eu
# Copyright 2020 Google Inc. # Copyright 2022 Google LLC
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -15,77 +15,44 @@
# #
################################################################################ ################################################################################
# This file is for integration with Google OSS-Fuzz. function build_native_go_fuzzer() {
# The following ENV variables are available when executing on OSS-fuzz: fuzzer=$1
# function=$2
# /out/ $OUT Directory to store build artifacts (fuzz targets, dictionaries, options files, seed corpus archives). path=$3
# /src/ $SRC Directory to checkout source files. tags="-tags gofuzz"
# /work/ $WORK Directory to store intermediate files.
#
# $CC, $CXX, $CCC The C and C++ compiler binaries.
# $CFLAGS, $CXXFLAGS C and C++ compiler flags.
# $LIB_FUZZING_ENGINE C++ compiler argument to link fuzz target against the prebuilt engine library (e.g. libFuzzer).
# This sets the -coverpgk for the coverage report when the corpus is executed through go test if [[ $SANITIZER == *coverage* ]]; then
coverpkg="github.com/ethereum/go-ethereum/..." current_dir=$(pwd)
mkdir $OUT/rawfuzzers || true
cd $abs_file_dir
go test $tags -c -run $fuzzer -o $OUT/$fuzzer -cover
cp "${fuzzer_filename}" "${OUT}/rawfuzzers/${fuzzer}"
function coverbuild { fuzzed_repo=$(go list $tags -f {{.Module}} "$path")
path=$1 abspath_repo=`go list -m $tags -f {{.Dir}} $fuzzed_repo || go list $tags -f {{.Dir}} $fuzzed_repo`
function=$2 # give equivalence to absolute paths in another file, as go test -cover uses golangish pkg.Dir
fuzzer=$3 echo "s=$fuzzed_repo"="$abspath_repo"= > $OUT/$fuzzer.gocovpath
tags=""
if [[ $# -eq 4 ]]; then cd $current_dir
tags="-tags $4" else
fi go-118-fuzz-build $tags -o $fuzzer.a -func $function $path
cd $path $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer
fuzzed_package=`pwd | rev | cut -d'/' -f 1 | rev` fi
cp $GOPATH/ossfuzz_coverage_runner.go ./"${function,,}"_test.go
sed -i -e 's/FuzzFunction/'$function'/' ./"${function,,}"_test.go
sed -i -e 's/mypackagebeingfuzzed/'$fuzzed_package'/' ./"${function,,}"_test.go
sed -i -e 's/TestFuzzCorpus/Test'$function'Corpus/' ./"${function,,}"_test.go
cat << DOG > $OUT/$fuzzer
#/bin/sh
cd $OUT/$path
go test -run Test${function}Corpus -v $tags -coverprofile \$1 -coverpkg $coverpkg
DOG
chmod +x $OUT/$fuzzer
#echo "Built script $OUT/$fuzzer"
#cat $OUT/$fuzzer
cd -
} }
function compile_fuzzer { function compile_fuzzer() {
# Inputs:
# $1: The package to fuzz, within go-ethereum
# $2: The name of the fuzzing function
# $3: The name to give to the final fuzzing-binary
path=$GOPATH/src/github.com/ethereum/go-ethereum/$1 path=$GOPATH/src/github.com/ethereum/go-ethereum/$1
func=$2 function=$2
fuzzer=$3 fuzzer=$3
echo "Building $fuzzer" echo "Building $fuzzer"
# Do a coverage-build or a regular build # Test if file contains a line with "func $function" and "testing.F".
if [[ $SANITIZER = *coverage* ]]; then if [ $(grep -r "func $function" $path | grep "testing.F" | wc -l) -eq 1 ]
coverbuild $path $func $fuzzer $coverpkg
else
(cd $path && \
go-fuzz -func $func -o $WORK/$fuzzer.a . && \
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $WORK/$fuzzer.a -o $OUT/$fuzzer)
fi
## Check if there exists a seed corpus file
corpusfile="${path}/testdata/${fuzzer}_seed_corpus.zip"
if [ -f $corpusfile ]
then then
cp $corpusfile $OUT/ build_native_go_fuzzer $fuzzer $function $path
echo "Found seed corpus: $corpusfile" else
echo "Could not find the function: func ${function}(f *testing.F)"
fi fi
} }
@ -95,7 +62,7 @@ compile_fuzzer tests/fuzzers/bn256 FuzzMul fuzzBn256Mul
compile_fuzzer tests/fuzzers/bn256 FuzzPair fuzzBn256Pair compile_fuzzer tests/fuzzers/bn256 FuzzPair fuzzBn256Pair
compile_fuzzer tests/fuzzers/runtime Fuzz fuzzVmRuntime compile_fuzzer tests/fuzzers/runtime Fuzz fuzzVmRuntime
compile_fuzzer tests/fuzzers/keystore Fuzz fuzzKeystore compile_fuzzer tests/fuzzers/keystore Fuzz fuzzKeystore
compile_fuzzer tests/fuzzers/txfetcher Fuzz fuzzTxfetcher compile_fuzzer tests/fuzzers/txfetcher FuzzFetcher fuzzTxfetcher
compile_fuzzer tests/fuzzers/rlp Fuzz fuzzRlp compile_fuzzer tests/fuzzers/rlp Fuzz fuzzRlp
compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie compile_fuzzer tests/fuzzers/trie Fuzz fuzzTrie
compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie compile_fuzzer tests/fuzzers/stacktrie Fuzz fuzzStackTrie

View file

@ -153,7 +153,7 @@ func runFuzzer(input []byte) int {
return 0 return 0
} }
func Fuzz(input []byte) int { func FuzzAbi(input []byte) int {
return runFuzzer(input) return runFuzzer(input)
} }

View file

@ -41,3 +41,9 @@ func TestGenerateCorpus(t *testing.T) {
} }
*/ */
} }
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
FuzzAbi(data)
})
}

View file

@ -24,7 +24,7 @@ import (
// Fuzz implements a go-fuzz fuzzer method to test various encoding method // Fuzz implements a go-fuzz fuzzer method to test various encoding method
// invocations. // invocations.
func Fuzz(data []byte) int { func FuzzBitutil(data []byte) int {
if len(data) == 0 { if len(data) == 0 {
return 0 return 0
} }

View file

@ -1,4 +1,4 @@
// Copyright 2020 The go-ethereum Authors // Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
// The go-ethereum library is free software: you can redistribute it and/or modify // The go-ethereum library is free software: you can redistribute it and/or modify
@ -14,25 +14,12 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package main package bitutil
import ( import "testing"
"fmt"
"os"
"github.com/ethereum/go-ethereum/tests/fuzzers/stacktrie" func Fuzz(f *testing.F) {
) f.Fuzz(func(t *testing.T, data []byte) {
FuzzBitutil(data)
func main() { })
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: debug <file>")
os.Exit(1)
}
crasher := os.Args[1]
data, err := os.ReadFile(crasher)
if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1)
}
stacktrie.Debug(data)
} }

View file

@ -14,9 +14,6 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//go:build gofuzz
// +build gofuzz
package bls package bls
import ( import (
@ -35,7 +32,7 @@ import (
blst "github.com/supranational/blst/bindings/go" blst "github.com/supranational/blst/bindings/go"
) )
func FuzzCrossPairing(data []byte) int { func fuzzCrossPairing(data []byte) int {
input := bytes.NewReader(data) input := bytes.NewReader(data)
// get random G1 points // get random G1 points
@ -101,7 +98,7 @@ func massageBLST(in []byte) []byte {
return out return out
} }
func FuzzCrossG1Add(data []byte) int { func fuzzCrossG1Add(data []byte) int {
input := bytes.NewReader(data) input := bytes.NewReader(data)
// get random G1 points // get random G1 points
@ -139,7 +136,7 @@ func FuzzCrossG1Add(data []byte) int {
return 1 return 1
} }
func FuzzCrossG2Add(data []byte) int { func fuzzCrossG2Add(data []byte) int {
input := bytes.NewReader(data) input := bytes.NewReader(data)
// get random G2 points // get random G2 points
@ -177,7 +174,7 @@ func FuzzCrossG2Add(data []byte) int {
return 1 return 1
} }
func FuzzCrossG1MultiExp(data []byte) int { func fuzzCrossG1MultiExp(data []byte) int {
var ( var (
input = bytes.NewReader(data) input = bytes.NewReader(data)
gethScalars []*big.Int gethScalars []*big.Int

View file

@ -0,0 +1,94 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package bls
import "testing"
func FuzzCrossPairing(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzCrossPairing(data)
})
}
func FuzzCrossG1Add(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzCrossG1Add(data)
})
}
func FuzzCrossG2Add(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzCrossG2Add(data)
})
}
func FuzzCrossG1MultiExp(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzCrossG1MultiExp(data)
})
}
func FuzzG1Add(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsG1Add, data)
})
}
func FuzzG1Mul(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsG1Mul, data)
})
}
func FuzzG1MultiExp(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsG1MultiExp, data)
})
}
func FuzzG2Add(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsG2Add, data)
})
}
func FuzzG2Mul(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsG2Mul, data)
})
}
func FuzzG2MultiExp(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsG2MultiExp, data)
})
}
func FuzzPairing(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsPairing, data)
})
}
func FuzzMapG1(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsMapG1, data)
})
}
func FuzzMapG2(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(blsMapG2, data)
})
}

View file

@ -36,16 +36,6 @@ const (
blsMapG2 = byte(18) blsMapG2 = byte(18)
) )
func FuzzG1Add(data []byte) int { return fuzz(blsG1Add, data) }
func FuzzG1Mul(data []byte) int { return fuzz(blsG1Mul, data) }
func FuzzG1MultiExp(data []byte) int { return fuzz(blsG1MultiExp, data) }
func FuzzG2Add(data []byte) int { return fuzz(blsG2Add, data) }
func FuzzG2Mul(data []byte) int { return fuzz(blsG2Mul, data) }
func FuzzG2MultiExp(data []byte) int { return fuzz(blsG2MultiExp, data) }
func FuzzPairing(data []byte) int { return fuzz(blsPairing, data) }
func FuzzMapG1(data []byte) int { return fuzz(blsMapG1, data) }
func FuzzMapG2(data []byte) int { return fuzz(blsMapG2, data) }
func checkInput(id byte, inputLen int) bool { func checkInput(id byte, inputLen int) bool {
switch id { switch id {
case blsG1Add: case blsG1Add:

View file

@ -14,9 +14,6 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
//go:build gofuzz
// +build gofuzz
package bn256 package bn256
import ( import (
@ -64,8 +61,8 @@ func getG2Points(input io.Reader) (*cloudflare.G2, *google.G2, *bn254.G2Affine)
return xc, xg, xs return xc, xg, xs
} }
// FuzzAdd fuzzez bn256 addition between the Google and Cloudflare libraries. // fuzzAdd fuzzez bn256 addition between the Google and Cloudflare libraries.
func FuzzAdd(data []byte) int { func fuzzAdd(data []byte) int {
input := bytes.NewReader(data) input := bytes.NewReader(data)
xc, xg, xs := getG1Points(input) xc, xg, xs := getG1Points(input)
if xc == nil { if xc == nil {
@ -97,9 +94,9 @@ func FuzzAdd(data []byte) int {
return 1 return 1
} }
// FuzzMul fuzzez bn256 scalar multiplication between the Google and Cloudflare // fuzzMul fuzzez bn256 scalar multiplication between the Google and Cloudflare
// libraries. // libraries.
func FuzzMul(data []byte) int { func fuzzMul(data []byte) int {
input := bytes.NewReader(data) input := bytes.NewReader(data)
pc, pg, ps := getG1Points(input) pc, pg, ps := getG1Points(input)
if pc == nil { if pc == nil {
@ -139,7 +136,7 @@ func FuzzMul(data []byte) int {
return 1 return 1
} }
func FuzzPair(data []byte) int { func fuzzPair(data []byte) int {
input := bytes.NewReader(data) input := bytes.NewReader(data)
pc, pg, ps := getG1Points(input) pc, pg, ps := getG1Points(input)
if pc == nil { if pc == nil {

View file

@ -1,4 +1,4 @@
// Copyright 2020 The go-ethereum Authors // Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
// The go-ethereum library is free software: you can redistribute it and/or modify // The go-ethereum library is free software: you can redistribute it and/or modify
@ -14,25 +14,24 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package main package bn256
import ( import "testing"
"fmt"
"os"
"github.com/ethereum/go-ethereum/tests/fuzzers/snap" func FuzzAdd(f *testing.F) {
) f.Fuzz(func(t *testing.T, data []byte) {
fuzzAdd(data)
func main() { })
if len(os.Args) != 2 { }
fmt.Fprintf(os.Stderr, "Usage: debug <file>\n")
os.Exit(1) func FuzzMul(f *testing.F) {
} f.Fuzz(func(t *testing.T, data []byte) {
crasher := os.Args[1] fuzzMul(data)
data, err := os.ReadFile(crasher) })
if err != nil { }
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1) func FuzzPair(f *testing.F) {
} f.Fuzz(func(t *testing.T, data []byte) {
snap.FuzzTrieNodes(data) fuzzPair(data)
})
} }

View file

@ -75,7 +75,7 @@ func (f *fuzzer) readBool() bool {
// - 0 otherwise // - 0 otherwise
// //
// other values are reserved for future use. // other values are reserved for future use.
func Fuzz(data []byte) int { func fuzz(data []byte) int {
f := fuzzer{ f := fuzzer{
input: bytes.NewReader(data), input: bytes.NewReader(data),
exhausted: false, exhausted: false,

View file

@ -1,4 +1,4 @@
// Copyright 2020 The go-ethereum Authors // Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
// The go-ethereum library is free software: you can redistribute it and/or modify // The go-ethereum library is free software: you can redistribute it and/or modify
@ -14,25 +14,12 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package main package difficulty
import ( import "testing"
"fmt"
"os"
"github.com/ethereum/go-ethereum/tests/fuzzers/difficulty" func Fuzz(f *testing.F) {
) f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
func main() { })
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: debug <file>")
os.Exit(1)
}
crasher := os.Args[1]
data, err := os.ReadFile(crasher)
if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1)
}
difficulty.Fuzz(data)
} }

View file

@ -22,7 +22,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
) )
func Fuzz(input []byte) int { func fuzz(input []byte) int {
ks := keystore.NewKeyStore("/tmp/ks", keystore.LightScryptN, keystore.LightScryptP) ks := keystore.NewKeyStore("/tmp/ks", keystore.LightScryptN, keystore.LightScryptP)
a, err := ks.NewAccount(string(input)) a, err := ks.NewAccount(string(input))

View file

@ -1,4 +1,4 @@
// Copyright 2020 The go-ethereum Authors // Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
// The go-ethereum library is free software: you can redistribute it and/or modify // The go-ethereum library is free software: you can redistribute it and/or modify
@ -14,27 +14,12 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package main package keystore
import ( import "testing"
"fmt"
"os"
"github.com/ethereum/go-ethereum/tests/fuzzers/les" func Fuzz(f *testing.F) {
) f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
func main() { })
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: debug <file>\n")
fmt.Fprintf(os.Stderr, "Example\n")
fmt.Fprintf(os.Stderr, " $ debug ../crashers/4bbef6857c733a87ecf6fd8b9e7238f65eb9862a\n")
os.Exit(1)
}
crasher := os.Args[1]
data, err := os.ReadFile(crasher)
if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1)
}
les.Fuzz(data)
} }

View file

@ -279,7 +279,7 @@ func (f *fuzzer) doFuzz(msgCode uint64, packet interface{}) {
fn(f, peer, func() bool { return true }) fn(f, peer, func() bool { return true })
} }
func Fuzz(input []byte) int { func fuzz(input []byte) int {
// We expect some large inputs // We expect some large inputs
if len(input) < 100 { if len(input) < 100 {
return -1 return -1

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package les
import "testing"
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
}

View file

@ -1,40 +0,0 @@
// Copyright 2020 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 <http://www.gnu.org/licenses/>.
package main
import (
"fmt"
"os"
"github.com/ethereum/go-ethereum/tests/fuzzers/rangeproof"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: debug <file>\n")
fmt.Fprintf(os.Stderr, "Example\n")
fmt.Fprintf(os.Stderr, " $ debug ../crashers/4bbef6857c733a87ecf6fd8b9e7238f65eb9862a\n")
os.Exit(1)
}
crasher := os.Args[1]
data, err := os.ReadFile(crasher)
if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err)
os.Exit(1)
}
rangeproof.Fuzz(data)
}

View file

@ -185,7 +185,7 @@ func (f *fuzzer) fuzz() int {
// - 0 otherwise // - 0 otherwise
// //
// other values are reserved for future use. // other values are reserved for future use.
func Fuzz(input []byte) int { func fuzz(input []byte) int {
if len(input) < 100 { if len(input) < 100 {
return 0 return 0
} }

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package rangeproof
import "testing"
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
}

View file

@ -38,7 +38,7 @@ func decodeEncode(input []byte, val interface{}, i int) {
} }
} }
func Fuzz(input []byte) int { func fuzz(input []byte) int {
if len(input) == 0 { if len(input) == 0 {
return 0 return 0
} }

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package rlp
import "testing"
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
}

View file

@ -24,7 +24,7 @@ import (
// //
// This returns 1 for valid parse:able/runnable code, 0 // This returns 1 for valid parse:able/runnable code, 0
// for invalid opcode. // for invalid opcode.
func Fuzz(input []byte) int { func fuzz(input []byte) int {
_, _, err := runtime.Execute(input, input, &runtime.Config{ _, _, err := runtime.Execute(input, input, &runtime.Config{
GasLimit: 12000000, GasLimit: 12000000,
}) })

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package runtime
import "testing"
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
}

View file

@ -23,12 +23,12 @@ import (
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/ethereum/go-ethereum/crypto/secp256k1" "github.com/ethereum/go-ethereum/crypto/secp256k1"
fuzz "github.com/google/gofuzz" gofuzz "github.com/google/gofuzz"
) )
func Fuzz(input []byte) int { func fuzz(input []byte) int {
var ( var (
fuzzer = fuzz.NewFromGoFuzz(input) fuzzer = gofuzz.NewFromGoFuzz(input)
curveA = secp256k1.S256() curveA = secp256k1.S256()
curveB = btcec.S256() curveB = btcec.S256()
dataP1 []byte dataP1 []byte

View file

@ -20,5 +20,11 @@ import "testing"
func TestFuzzer(t *testing.T) { func TestFuzzer(t *testing.T) {
test := "00000000N0000000/R00000000000000000U0000S0000000mkhP000000000000000U" test := "00000000N0000000/R00000000000000000U0000S0000000mkhP000000000000000U"
Fuzz([]byte(test)) fuzz([]byte(test))
}
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
} }

View file

@ -141,20 +141,3 @@ func doFuzz(input []byte, obj interface{}, code int) int {
} }
return 1 return 1
} }
// To run a fuzzer, do
// $ CGO_ENABLED=0 go-fuzz-build -func FuzzTrieNodes
// $ go-fuzz
func FuzzARange(input []byte) int {
return doFuzz(input, &snap.GetAccountRangePacket{}, snap.GetAccountRangeMsg)
}
func FuzzSRange(input []byte) int {
return doFuzz(input, &snap.GetStorageRangesPacket{}, snap.GetStorageRangesMsg)
}
func FuzzByteCodes(input []byte) int {
return doFuzz(input, &snap.GetByteCodesPacket{}, snap.GetByteCodesMsg)
}
func FuzzTrieNodes(input []byte) int {
return doFuzz(input, &snap.GetTrieNodesPacket{}, snap.GetTrieNodesMsg)
}

View file

@ -1,4 +1,4 @@
// Copyright 2020 The go-ethereum Authors // Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
// The go-ethereum library is free software: you can redistribute it and/or modify // The go-ethereum library is free software: you can redistribute it and/or modify
@ -14,30 +14,34 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package main package snap
import ( import (
"fmt" "testing"
"os"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/eth/protocols/snap"
"github.com/ethereum/go-ethereum/tests/fuzzers/vflux"
) )
func main() { func FuzzARange(f *testing.F) {
log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) f.Fuzz(func(t *testing.T, data []byte) {
doFuzz(data, &snap.GetAccountRangePacket{}, snap.GetAccountRangeMsg)
if len(os.Args) != 2 { })
fmt.Fprintf(os.Stderr, "Usage: debug <file>\n") }
fmt.Fprintf(os.Stderr, "Example\n")
fmt.Fprintf(os.Stderr, " $ debug ../crashers/4bbef6857c733a87ecf6fd8b9e7238f65eb9862a\n") func FuzzSRange(f *testing.F) {
os.Exit(1) f.Fuzz(func(t *testing.T, data []byte) {
} doFuzz(data, &snap.GetStorageRangesPacket{}, snap.GetStorageRangesMsg)
crasher := os.Args[1] })
data, err := os.ReadFile(crasher) }
if err != nil {
fmt.Fprintf(os.Stderr, "error loading crasher %v: %v", crasher, err) func FuzzByteCodes(f *testing.F) {
os.Exit(1) f.Fuzz(func(t *testing.T, data []byte) {
} doFuzz(data, &snap.GetByteCodesPacket{}, snap.GetByteCodesMsg)
vflux.FuzzClientPool(data) })
}
func FuzzTrieNodes(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
doFuzz(data, &snap.GetTrieNodesPacket{}, snap.GetTrieNodesMsg)
})
} }

View file

@ -115,7 +115,7 @@ type kv struct {
// - 0 otherwise // - 0 otherwise
// //
// other values are reserved for future use. // other values are reserved for future use.
func Fuzz(data []byte) int { func fuzz(data []byte) int {
f := fuzzer{ f := fuzzer{
input: bytes.NewReader(data), input: bytes.NewReader(data),
exhausted: false, exhausted: false,

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package stacktrie
import "testing"
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
}

View file

@ -1 +0,0 @@
asdlfkjasf23oiejfasdfadkfqlkjfasdlkfjalwk4jfalsdkfjawlefkjsadlfkjasldkfjwalefkjasdlfkjM

View file

@ -130,7 +130,7 @@ func Generate(input []byte) randTest {
// - 0 otherwise // - 0 otherwise
// //
// other values are reserved for future use. // other values are reserved for future use.
func Fuzz(input []byte) int { func fuzz(input []byte) int {
program := Generate(input) program := Generate(input)
if len(program) == 0 { if len(program) == 0 {
return 0 return 0

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package trie
import "testing"
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
}

View file

@ -48,7 +48,7 @@ func init() {
} }
} }
func Fuzz(input []byte) int { func fuzz(input []byte) int {
// Don't generate insanely large test cases, not much value in them // Don't generate insanely large test cases, not much value in them
if len(input) > 16*1024 { if len(input) > 16*1024 {
return 0 return 0

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package trie
import "testing"
func Fuzz(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzz(data)
})
}

View file

@ -214,7 +214,7 @@ func (f *fuzzer) atomicBalanceOp(balance vfs.AtomicBalanceOperator, id enode.ID)
} }
} }
func FuzzClientPool(input []byte) int { func fuzzClientPool(input []byte) int {
if len(input) > 10000 { if len(input) > 10000 {
return -1 return -1
} }

View file

@ -0,0 +1,25 @@
// Copyright 2023 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 <http://www.gnu.org/licenses/>.
package vflux
import "testing"
func FuzzClientPool(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
fuzzClientPool(data)
})
}