2024-01-06 06:18:28 +00:00
|
|
|
# beacon_chain
|
|
|
|
# Copyright (c) 2020-2024 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
import std/os except dirExists
|
2024-10-30 14:56:45 +00:00
|
|
|
import std/strformat
|
|
|
|
import confutils
|
2020-06-11 16:41:43 +00:00
|
|
|
import testutils/fuzzing_engines
|
2020-05-19 17:48:52 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
gitRoot = thisDir() / ".."
|
2021-03-13 20:51:39 +00:00
|
|
|
fixturesDir = gitRoot / "vendor" / "nim-eth2-scenarios" / "tests-v1.0.1" / "mainnet" / "phase0" / "ssz_static"
|
2020-05-19 17:48:52 +00:00
|
|
|
|
|
|
|
fuzzingTestsDir = gitRoot / "tests" / "fuzzing"
|
|
|
|
fuzzingCorpusesDir = fuzzingTestsDir / "corpus"
|
|
|
|
|
|
|
|
cli do (testname {.argument.}: string,
|
2020-06-11 16:41:43 +00:00
|
|
|
fuzzer = defaultFuzzingEngine):
|
2020-05-19 17:48:52 +00:00
|
|
|
|
|
|
|
if not dirExists(fixturesDir):
|
2021-10-12 11:36:52 +00:00
|
|
|
echo "Please run `make test` first in order to download the consensus spec ETH2 test vectors"
|
2020-05-19 17:48:52 +00:00
|
|
|
quit 1
|
|
|
|
|
|
|
|
if not dirExists(fixturesDir / testname):
|
|
|
|
echo testname, " is not a recognized SSZ type name (type names are case-sensitive)"
|
|
|
|
quit 1
|
|
|
|
|
|
|
|
let corpusDir = fuzzingCorpusesDir / testname
|
|
|
|
|
|
|
|
rmDir corpusDir
|
|
|
|
mkDir corpusDir
|
|
|
|
|
|
|
|
var inputIdx = 0
|
|
|
|
template nextInputName: string =
|
|
|
|
inc inputIdx
|
|
|
|
"input" & $inputIdx
|
|
|
|
|
|
|
|
for file in walkDirRec(fixturesDir / testname):
|
|
|
|
if splitFile(file).ext == ".ssz":
|
|
|
|
# TODO Can we create hard links here?
|
|
|
|
cpFile file, corpusDir / nextInputName()
|
|
|
|
|
|
|
|
let testProgram = fuzzingTestsDir / &"ssz_decode_{testname}.nim"
|
2020-06-11 16:41:43 +00:00
|
|
|
exec &"""ntu fuzz --fuzzer={fuzzer} --corpus="{corpusDir}" "{testProgram}" """
|