@@ -3,10 +3,11 @@ Fuzz-testing Bitcoin Core
33
44A special test harness ` test_bitcoin_fuzzy ` is provided to provide an easy
55entry point for fuzzers and the like. In this document we'll describe how to
6- use it with AFL.
6+ use it with AFL and libFuzzer .
77
8- Building AFL
9- -------------
8+ ## AFL
9+
10+ ### Building AFL
1011
1112It is recommended to always use the latest version of afl:
1213```
1718export AFLPATH=$PWD
1819```
1920
20- Instrumentation
21- ----------------
21+ ### Instrumentation
2222
2323To build Bitcoin Core using AFL instrumentation (this assumes that the
2424` AFLPATH ` was set as above):
@@ -39,8 +39,7 @@ compiling using `afl-clang-fast`/`afl-clang-fast++` the resulting
3939features "persistent mode" and "deferred forkserver" can be used. See
4040https://github.com/mcarpenter/afl/tree/master/llvm_mode for details.
4141
42- Preparing fuzzing
43- ------------------
42+ ### Preparing fuzzing
4443
4544AFL needs an input directory with examples, and an output directory where it
4645will place examples that it found. These can be anywhere in the file system,
@@ -60,8 +59,7 @@ Example inputs are available from:
6059
6160Extract these (or other starting inputs) into the ` inputs ` directory before starting fuzzing.
6261
63- Fuzzing
64- --------
62+ ### Fuzzing
6563
6664To start the actual fuzzing use:
6765```
@@ -70,3 +68,21 @@ $AFLPATH/afl-fuzz -i ${AFLIN} -o ${AFLOUT} -m52 -- test/test_bitcoin_fuzzy
7068
7169You may have to change a few kernel parameters to test optimally - ` afl-fuzz `
7270will print an error and suggestion if so.
71+
72+ ## libFuzzer
73+
74+ A recent version of ` clang ` , the address sanitizer and libFuzzer is needed (all
75+ found in the ` compiler-rt ` runtime libraries package).
76+
77+ To build the ` test/test_bitcoin_fuzzy ` executable run
78+
79+ ```
80+ ./configure --disable-ccache --with-sanitizers=fuzzer,address CC=clang CXX=clang++
81+ make
82+ ```
83+
84+ The fuzzer needs some inputs to work on, but the inputs or seeds can be used
85+ interchangably between libFuzzer and AFL.
86+
87+ See https://llvm.org/docs/LibFuzzer.html#running on how to run the libFuzzer
88+ instrumented executable.
0 commit comments