github.1485827954.workers.dev/ethereum/go-ethereum@v1.14.3/oss-fuzz.sh (about) 1 #!/bin/bash -eu 2 # Copyright 2022 Google LLC 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 ################################################################################ 17 18 # This sets the -coverpgk for the coverage report when the corpus is executed through go test 19 coverpkg="github.com/ethereum/go-ethereum/..." 20 21 function coverbuild { 22 path=$1 23 function=$2 24 fuzzer=$3 25 tags="" 26 27 if [[ $# -eq 4 ]]; then 28 tags="-tags $4" 29 fi 30 cd $path 31 fuzzed_package=`pwd | rev | cut -d'/' -f 1 | rev` 32 cp $GOPATH/ossfuzz_coverage_runner.go ./"${function,,}"_test.go 33 sed -i -e 's/FuzzFunction/'$function'/' ./"${function,,}"_test.go 34 sed -i -e 's/mypackagebeingfuzzed/'$fuzzed_package'/' ./"${function,,}"_test.go 35 sed -i -e 's/TestFuzzCorpus/Test'$function'Corpus/' ./"${function,,}"_test.go 36 37 cat << DOG > $OUT/$fuzzer 38 #/bin/sh 39 40 cd $OUT/$path 41 go test -run Test${function}Corpus -v $tags -coverprofile \$1 -coverpkg $coverpkg 42 43 DOG 44 45 chmod +x $OUT/$fuzzer 46 #echo "Built script $OUT/$fuzzer" 47 #cat $OUT/$fuzzer 48 cd - 49 } 50 51 function compile_fuzzer() { 52 package=$1 53 function=$2 54 fuzzer=$3 55 file=$4 56 57 path=$GOPATH/src/$package 58 59 echo "Building $fuzzer" 60 cd $path 61 62 # Install build dependencies 63 go mod tidy 64 go get github.com/holiman/gofuzz-shim/testing 65 66 if [[ $SANITIZER == *coverage* ]]; then 67 coverbuild $path $function $fuzzer $coverpkg 68 else 69 gofuzz-shim --func $function --package $package -f $file -o $fuzzer.a 70 $CXX $CXXFLAGS $LIB_FUZZING_ENGINE $fuzzer.a -o $OUT/$fuzzer 71 fi 72 73 ## Check if there exists a seed corpus file 74 corpusfile="${path}/testdata/${fuzzer}_seed_corpus.zip" 75 if [ -f $corpusfile ] 76 then 77 cp $corpusfile $OUT/ 78 echo "Found seed corpus: $corpusfile" 79 fi 80 cd - 81 } 82 83 go install github.com/holiman/gofuzz-shim@latest 84 repo=$GOPATH/src/github.com/ethereum/go-ethereum 85 compile_fuzzer github.com/ethereum/go-ethereum/accounts/abi \ 86 FuzzABI fuzzAbi \ 87 $repo/accounts/abi/abifuzzer_test.go 88 89 compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil \ 90 FuzzEncoder fuzzBitutilEncoder \ 91 $repo/common/bitutil/compress_test.go 92 93 compile_fuzzer github.com/ethereum/go-ethereum/common/bitutil \ 94 FuzzDecoder fuzzBitutilDecoder \ 95 $repo/common/bitutil/compress_test.go 96 97 compile_fuzzer github.com/ethereum/go-ethereum/core/vm/runtime \ 98 FuzzVmRuntime fuzzVmRuntime\ 99 $repo/core/vm/runtime/runtime_fuzz_test.go 100 101 compile_fuzzer github.com/ethereum/go-ethereum/core/vm \ 102 FuzzPrecompiledContracts fuzzPrecompiledContracts\ 103 $repo/core/vm/contracts_fuzz_test.go,$repo/core/vm/contracts_test.go 104 105 compile_fuzzer github.com/ethereum/go-ethereum/core/types \ 106 FuzzRLP fuzzRlp \ 107 $repo/core/types/rlp_fuzzer_test.go 108 109 compile_fuzzer github.com/ethereum/go-ethereum/crypto/blake2b \ 110 Fuzz fuzzBlake2b \ 111 $repo/crypto/blake2b/blake2b_f_fuzz_test.go 112 113 compile_fuzzer github.com/ethereum/go-ethereum/accounts/keystore \ 114 FuzzPassword fuzzKeystore \ 115 $repo/accounts/keystore/keystore_fuzzing_test.go 116 117 pkg=$repo/trie/ 118 compile_fuzzer github.com/ethereum/go-ethereum/trie \ 119 FuzzTrie fuzzTrie \ 120 $pkg/trie_test.go,$pkg/database_test.go,$pkg/tracer_test.go,$pkg/proof_test.go,$pkg/iterator_test.go,$pkg/sync_test.go 121 122 compile_fuzzer github.com/ethereum/go-ethereum/trie \ 123 FuzzStackTrie fuzzStackTrie \ 124 $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 125 126 #compile_fuzzer tests/fuzzers/snap FuzzARange fuzz_account_range 127 compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ 128 FuzzARange fuzz_account_range \ 129 $repo/eth/protocols/snap/handler_fuzzing_test.go 130 131 compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ 132 FuzzSRange fuzz_storage_range \ 133 $repo/eth/protocols/snap/handler_fuzzing_test.go 134 135 compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ 136 FuzzByteCodes fuzz_byte_codes \ 137 $repo/eth/protocols/snap/handler_fuzzing_test.go 138 139 compile_fuzzer github.com/ethereum/go-ethereum/eth/protocols/snap \ 140 FuzzTrieNodes fuzz_trie_nodes\ 141 $repo/eth/protocols/snap/handler_fuzzing_test.go 142 143 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ 144 FuzzAdd fuzzBn256Add\ 145 $repo/tests/fuzzers/bn256/bn256_test.go 146 147 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ 148 FuzzMul fuzzBn256Mul \ 149 $repo/tests/fuzzers/bn256/bn256_test.go 150 151 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bn256 \ 152 FuzzPair fuzzBn256Pair \ 153 $repo/tests/fuzzers/bn256/bn256_test.go 154 155 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/txfetcher \ 156 Fuzz fuzzTxfetcher \ 157 $repo/tests/fuzzers/txfetcher/txfetcher_test.go 158 159 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 160 FuzzG1Add fuzz_g1_add\ 161 $repo/tests/fuzzers/bls12381/bls12381_test.go 162 163 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 164 FuzzG1Mul fuzz_g1_mul\ 165 $repo/tests/fuzzers/bls12381/bls12381_test.go 166 167 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 168 FuzzG1MultiExp fuzz_g1_multiexp \ 169 $repo/tests/fuzzers/bls12381/bls12381_test.go 170 171 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 172 FuzzG2Add fuzz_g2_add \ 173 $repo/tests/fuzzers/bls12381/bls12381_test.go 174 175 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 176 FuzzG2Mul fuzz_g2_mul\ 177 $repo/tests/fuzzers/bls12381/bls12381_test.go 178 179 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 180 FuzzG2MultiExp fuzz_g2_multiexp \ 181 $repo/tests/fuzzers/bls12381/bls12381_test.go 182 183 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 184 FuzzPairing fuzz_pairing \ 185 $repo/tests/fuzzers/bls12381/bls12381_test.go 186 187 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 188 FuzzMapG1 fuzz_map_g1\ 189 $repo/tests/fuzzers/bls12381/bls12381_test.go 190 191 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 192 FuzzMapG2 fuzz_map_g2 \ 193 $repo/tests/fuzzers/bls12381/bls12381_test.go 194 195 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 196 FuzzCrossG1Add fuzz_cross_g1_add \ 197 $repo/tests/fuzzers/bls12381/bls12381_test.go 198 199 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 200 FuzzCrossG1MultiExp fuzz_cross_g1_multiexp \ 201 $repo/tests/fuzzers/bls12381/bls12381_test.go 202 203 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 204 FuzzCrossG2Add fuzz_cross_g2_add \ 205 $repo/tests/fuzzers/bls12381/bls12381_test.go 206 207 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 208 FuzzCrossPairing fuzz_cross_pairing\ 209 $repo/tests/fuzzers/bls12381/bls12381_test.go 210 211 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 212 FuzzG1SubgroupChecks fuzz_g1_subgroup_checks\ 213 $repo/tests/fuzzers/bls12381/bls12381_test.go 214 215 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/bls12381 \ 216 FuzzG2SubgroupChecks fuzz_g2_subgroup_checks\ 217 $repo/tests/fuzzers/bls12381/bls12381_test.go 218 219 compile_fuzzer github.com/ethereum/go-ethereum/tests/fuzzers/secp256k1 \ 220 Fuzz fuzzSecp256k1\ 221 $repo/tests/fuzzers/secp256k1/secp_test.go 222 223 224 #compile_fuzzer tests/fuzzers/vflux FuzzClientPool fuzzClientPool 225 #compile_fuzzer tests/fuzzers/difficulty Fuzz fuzzDifficulty 226 #compile_fuzzer tests/fuzzers/les Fuzz fuzzLes 227