This article explains the companion script scripts/fuzz.sh
and its configuration file scripts/tests.config.
The script wraps every step of the fuzz testing workflow — building, seeding the corpus, and running each target — into a single command.
# Clone Bitcoin Core if you haven't already
git clone https://github.com/bitcoin/bitcoin /path/to/bitcoin
# Run each target for 5 minutes
./scripts/fuzz.sh --bitcoin-dir /path/to/bitcoin --time 300The script performs these steps in order:
- Build the fuzz binary with
cmake --preset=libfuzzer - Clone or update the
bitcoin-core/qa-assetscorpus - Run the fuzzer on each target listed in
tests.config
scripts/tests.config controls which fuzz targets
are run.
# This is a comment
clusterlin_linearize
clusterlin_postlinearize
txgraph
- One target name per line, matching the
nameinFUZZ_TARGET(name)insidesrc/test/fuzz/ - Lines starting with
#and blank lines are ignored - Targets run in the order they appear in the file
Append the target name to the file:
echo "feefrac" >> scripts/tests.configUse --config to point at any config file, making it easy to maintain
multiple target lists for different scenarios:
# Test only txgraph
echo "txgraph" > /tmp/txgraph.config
./scripts/fuzz.sh --bitcoin-dir /path/to/bitcoin \
--config /tmp/txgraph.config --skip-build --time 120| Option | Default | Description |
|---|---|---|
--bitcoin-dir DIR |
$BITCOIN_DIR env var or auto-detected |
Bitcoin Core source root |
--build-dir DIR |
<bitcoin-dir>/build_fuzz |
Build output directory |
--corpus-dir DIR |
<bitcoin-dir>/fuzz_corpora |
Local corpus root |
--qa-assets DIR |
<bitcoin-dir>/qa-assets |
qa-assets directory |
--config FILE |
scripts/tests.config |
Fuzz target config file |
--nosan |
off | Build without sanitizers (higher throughput) |
--skip-build |
off | Skip compilation, use existing build |
--skip-qa-assets |
off | Do not clone/update qa-assets |
--time N |
0 (unlimited) | Stop each target after N seconds |
--runs N |
0 (unlimited) | Stop each target after N executions |
--jobs N |
nproc |
Parallel build jobs |
-h, --help |
— | Show help |
--time and --runs can be combined; the fuzzer stops at whichever limit
is reached first and then moves on to the next target.
./scripts/fuzz.sh \
--bitcoin-dir /path/to/bitcoin \
--skip-build \
--time 60./scripts/fuzz.sh \
--bitcoin-dir /path/to/bitcoin \
--nosan \
--runs 0 # run indefinitely; Ctrl-C to stop./scripts/fuzz.sh \
--bitcoin-dir /path/to/bitcoin \
--time 3600 # 1 hour per target./scripts/fuzz.sh \
--bitcoin-dir /path/to/bitcoin \
--corpus-dir ~/my_corpora \
--skip-qa-assets \
--time 300At the start of each target the script prints:
──────────────────────────────────────────
[INFO] ▶ 目标: clusterlin_linearize
[INFO] 语料库: /path/to/bitcoin/fuzz_corpora/clusterlin_linearize
If the fuzzer finds a crash, the script prints a reproduction command:
[WARN] [clusterlin_linearize] fuzzer exited abnormally (possible crash)
[INFO] Reproduce with: FUZZ=clusterlin_linearize build_fuzz/bin/fuzz crash-<hash>
Crash files (crash-* or leak-*) are written to the directory from which
the script was invoked.
scripts/fuzz.sh— the script itselfscripts/tests.config— default target list