chore: document and format oss-fuzz build script

Made the OSS-Fuzz script more readable and added explanations of how it is used
This commit is contained in:
LumenSolutions 2025-12-08 19:58:56 +01:00 committed by GitHub
parent 66134b35df
commit 87cf119285
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,6 +13,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# Helper script used by OSS-Fuzz to build fuzzers and coverage wrappers
# for various go-ethereum packages.
#
################################################################################ ################################################################################
# This sets the -coverpgk for the coverage report when the corpus is executed through go test # This sets the -coverpgk for the coverage report when the corpus is executed through go test
@ -27,24 +30,25 @@ function coverbuild {
if [[ $# -eq 4 ]]; then if [[ $# -eq 4 ]]; then
tags="-tags $4" tags="-tags $4"
fi fi
cd $path
fuzzed_package=`pwd | rev | cut -d'/' -f 1 | rev`
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 cd "$path"
fuzzed_package=$(pwd | rev | cut -d'/' -f 1 | rev)
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 #/bin/sh
cd "$OUT/$path"
cd $OUT/$path go test -run Test${function}Corpus -v $tags -coverprofile \$1 -coverpkg $coverpkg
go test -run Test${function}Corpus -v $tags -coverprofile \$1 -coverpkg $coverpkg
DOG DOG
chmod +x $OUT/$fuzzer chmod +x "$OUT/$fuzzer"
#echo "Built script $OUT/$fuzzer" # echo "Built script $OUT/$fuzzer"
#cat $OUT/$fuzzer # cat "$OUT/$fuzzer"
cd - cd -
} }
@ -54,178 +58,180 @@ function compile_fuzzer() {
fuzzer=$3 fuzzer=$3
file=$4 file=$4
path=$GOPATH/src/$package path="$GOPATH/src/$package"
echo "Building $fuzzer" echo "Building $fuzzer"
cd $path
cd "$path"
# Install build dependencies # Install build dependencies
go mod tidy go mod tidy
go get github.com/holiman/gofuzz-shim/testing go get github.com/holiman/gofuzz-shim/testing
if [[ $SANITIZER == *coverage* ]]; then if [[ $SANITIZER == *coverage* ]]; then
coverbuild $path $function $fuzzer $coverpkg coverbuild "$path" "$function" "$fuzzer" "$coverpkg"
else else
gofuzz-shim --func $function --package $package -f $file -o $fuzzer.a gofuzz-shim --func "$function" --package "$package" -f "$file" -o "$fuzzer.a"
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer $CXX $CXXFLAGS $LIB_FUZZING_ENGINE "$fuzzer.a" -o "$OUT/$fuzzer"
fi fi
## Check if there exists a seed corpus file ## Check if there exists a seed corpus file
corpusfile="${path}/testdata/${fuzzer}_seed_corpus.zip" corpusfile="${path}/testdata/${fuzzer}_seed_corpus.zip"
if [ -f $corpusfile ] if [ -f "$corpusfile" ]; then
then cp "$corpusfile" "$OUT/"
cp $corpusfile $OUT/
echo "Found seed corpus: $corpusfile" echo "Found seed corpus: $corpusfile"
fi fi
cd - cd -
} }
go install github.com/holiman/gofuzz-shim@latest go install github.com/holiman/gofuzz-shim@latest
repo=$GOPATH/src/github.com/ethereum/go-ethereum
repo="$GOPATH/src/github.com/ethereum/go-ethereum"
compile_fuzzer github.com/ethereum/go-ethereum/accounts/abi \ compile_fuzzer github.com/ethereum/go-ethereum/accounts/abi \
FuzzABI fuzzAbi \ FuzzABI fuzzAbi \
$repo/accounts/abi/abifuzzer_test.go "$repo/accounts/abi/abifuzzer_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil \ compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil \
FuzzEncoder fuzzBitutilEncoder \ FuzzEncoder fuzzBitutilEncoder \
$repo/common/bitutil/compress_test.go "$repo/common/bitutil/compress_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil \ compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil \
FuzzDecoder fuzzBitutilDecoder \ FuzzDecoder fuzzBitutilDecoder \
$repo/common/bitutil/compress_test.go "$repo/common/bitutil/compress_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/core/vm/runtime \ compile_fuzzer github.com/ethereum/go-ethereum/core/vm/runtime \
FuzzVmRuntime fuzzVmRuntime\ FuzzVmRuntime fuzzVmRuntime \
$repo/core/vm/runtime/runtime_fuzz_test.go "$repo/core/vm/runtime/runtime_fuzz_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/core/vm \ compile_fuzzer github.com/ethereum/go-ethereum/core/vm \
FuzzPrecompiledContracts fuzzPrecompiledContracts\ FuzzPrecompiledContracts fuzzPrecompiledContracts \
$repo/core/vm/contracts_fuzz_test.go,$repo/core/vm/contracts_test.go "$repo/core/vm/contracts_fuzz_test.go,$repo/core/vm/contracts_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/core/types \ compile_fuzzer github.com/ethereum/go-ethereum/core/types \
FuzzRLP fuzzRlp \ FuzzRLP fuzzRlp \
$repo/core/types/rlp_fuzzer_test.go "$repo/core/types/rlp_fuzzer_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/crypto/blake2b \ compile_fuzzer github.com/ethereum/go-ethereum/crypto/blake2b \
Fuzz fuzzBlake2b \ Fuzz fuzzBlake2b \
$repo/crypto/blake2b/blake2b_f_fuzz_test.go "$repo/crypto/blake2b/blake2b_f_fuzz_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/accounts/keystore \ compile_fuzzer github.com/ethereum/go-ethereum/accounts/keystore \
FuzzPassword fuzzKeystore \ FuzzPassword fuzzKeystore \
$repo/accounts/keystore/keystore_fuzzing_test.go "$repo/accounts/keystore/keystore_fuzzing_test.go"
pkg="$repo/trie/"
pkg=$repo/trie/
compile_fuzzer github.com/ethereum/go-ethereum/trie \ compile_fuzzer github.com/ethereum/go-ethereum/trie \
FuzzTrie fuzzTrie \ FuzzTrie fuzzTrie \
$pkg/trie_test.go,$pkg/database_test.go,$pkg/tracer_test.go,$pkg/proof_test.go,$pkg/iterator_test.go,$pkg/sync_test.go "$pkg/trie_test.go,$pkg/database_test.go,$pkg/tracer_test.go,$pkg/proof_test.go,$pkg/iterator_test.go,$pkg/sync_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/trie \ compile_fuzzer github.com/ethereum/go-ethereum/trie \
FuzzStackTrie fuzzStackTrie \ FuzzStackTrie fuzzStackTrie \
$pkg/stacktrie_fuzzer_test.go,$pkg/iterator_test.go,$pkg/trie_test.go,$pkg/database_test.go,$pkg/tracer_test.go,$pkg/proof_test.go,$pkg/sync_test.go "$pkg/stacktrie_fuzzer_test.go,$pkg/iterator_test.go,$pkg/trie_test.go,$pkg/database_test.go,$pkg/tracer_test.go,$pkg/proof_test.go,$pkg/sync_test.go"
# compile_fuzzer tests/fuzzers/snap FuzzARange fuzz_account_range
#compile_fuzzer tests/fuzzers/snap FuzzARange fuzz_account_range
compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \
FuzzARange fuzz_account_range \ FuzzARange fuzz_account_range \
$repo/eth/protocols/snap/handler_fuzzing_test.go "$repo/eth/protocols/snap/handler_fuzzing_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \
FuzzSRange fuzz_storage_range \ FuzzSRange fuzz_storage_range \
$repo/eth/protocols/snap/handler_fuzzing_test.go "$repo/eth/protocols/snap/handler_fuzzing_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \
FuzzByteCodes fuzz_byte_codes \ FuzzByteCodes fuzz_byte_codes \
$repo/eth/protocols/snap/handler_fuzzing_test.go "$repo/eth/protocols/snap/handler_fuzzing_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \
FuzzTrieNodes fuzz_trie_nodes\ FuzzTrieNodes fuzz_trie_nodes \
$repo/eth/protocols/snap/handler_fuzzing_test.go "$repo/eth/protocols/snap/handler_fuzzing_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \
FuzzAdd fuzzBn256Add\ FuzzAdd fuzzBn256Add \
$repo/tests/fuzzers/bn256/bn256_test.go "$repo/tests/fuzzers/bn256/bn256_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \
FuzzMul fuzzBn256Mul \ FuzzMul fuzzBn256Mul \
$repo/tests/fuzzers/bn256/bn256_test.go "$repo/tests/fuzzers/bn256/bn256_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \
FuzzPair fuzzBn256Pair \ FuzzPair fuzzBn256Pair \
$repo/tests/fuzzers/bn256/bn256_test.go "$repo/tests/fuzzers/bn256/bn256_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \
FuzzUnmarshalG1 fuzzBn256UnmarshalG1 \ FuzzUnmarshalG1 fuzzBn256UnmarshalG1 \
$repo/tests/fuzzers/bn256/bn256_test.go "$repo/tests/fuzzers/bn256/bn256_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \
FuzzUnmarshalG2 fuzzBn256UnmarshalG2 \ FuzzUnmarshalG2 fuzzBn256UnmarshalG2 \
$repo/tests/fuzzers/bn256/bn256_test.go "$repo/tests/fuzzers/bn256/bn256_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/txfetcher \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/txfetcher \
Fuzz fuzzTxfetcher \ Fuzz fuzzTxfetcher \
$repo/tests/fuzzers/txfetcher/txfetcher_test.go "$repo/tests/fuzzers/txfetcher/txfetcher_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG1Add fuzz_g1_add\ FuzzG1Add fuzz_g1_add \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG1MultiExp fuzz_g1_multiexp \ FuzzG1MultiExp fuzz_g1_multiexp \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG2Add fuzz_g2_add \ FuzzG2Add fuzz_g2_add \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG2MultiExp fuzz_g2_multiexp \ FuzzG2MultiExp fuzz_g2_multiexp \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzPairing fuzz_pairing \ FuzzPairing fuzz_pairing \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzMapG1 fuzz_map_g1\ FuzzMapG1 fuzz_map_g1 \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzMapG2 fuzz_map_g2 \ FuzzMapG2 fuzz_map_g2 \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzCrossG1Add fuzz_cross_g1_add \ FuzzCrossG1Add fuzz_cross_g1_add \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzCrossG1MultiExp fuzz_cross_g1_multiexp \ FuzzCrossG1MultiExp fuzz_cross_g1_multiexp \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzCrossG2Add fuzz_cross_g2_add \ FuzzCrossG2Add fuzz_cross_g2_add \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzCrossG2MultiExp fuzz_cross_g2_multiexp \ FuzzCrossG2MultiExp fuzz_cross_g2_multiexp \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzCrossPairing fuzz_cross_pairing\ FuzzCrossPairing fuzz_cross_pairing \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG1SubgroupChecks fuzz_g1_subgroup_checks\ FuzzG1SubgroupChecks fuzz_g1_subgroup_checks \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \
FuzzG2SubgroupChecks fuzz_g2_subgroup_checks\ FuzzG2SubgroupChecks fuzz_g2_subgroup_checks \
$repo/tests/fuzzers/bls12381/bls12381_test.go "$repo/tests/fuzzers/bls12381/bls12381_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/secp256k1 \ compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/secp256k1 \
Fuzz fuzzSecp256k1\ Fuzz fuzzSecp256k1 \
$repo/tests/fuzzers/secp256k1/secp_test.go "$repo/tests/fuzzers/secp256k1/secp_test.go"
compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/eth \ compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/eth \
FuzzEthProtocolHandlers fuzz_eth_protocol_handlers \ FuzzEthProtocolHandlers fuzz_eth_protocol_handlers \
$repo/eth/protocols/eth/handler_test.go,$repo/eth/protocols/eth/peer_test.go "$repo/eth/protocols/eth/handler_test.go,$repo/eth/protocols/eth/peer_test.go"