Skip to content

Commit 79deb4a

Browse files
committed
fuzz: update README.md
1 parent 524c395 commit 79deb4a

File tree

1 file changed

+22
-53
lines changed

1 file changed

+22
-53
lines changed

fuzz/README.md

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
# Fuzzing
22

3-
`miniscript` has a fuzzing harness setup for use with honggfuzz.
3+
`miniscript` has a fuzzing harness setup for use with cargo-fuzz.
44

55
To run the fuzz-tests as in CI -- briefly fuzzing every target -- simply
66
run
77

8-
./fuzz.sh
8+
RUSTUP_TOOLCHAIN=nightly ./fuzz.sh
99

1010
in this directory.
1111

12-
To build honggfuzz, you must have libunwind on your system, as well as
13-
libopcodes and libbfd from binutils **2.38** on your system. The most
14-
recently-released binutils 2.39 has changed their API in a breaking way.
12+
You need a nightly compiler to run the fuzz tests. You will also need
13+
`cargo-fuzz` installed:
1514

16-
On Nix, you can obtain these libraries, and disable some hardening flags
17-
which conflict with the way honggfuzz builds its targets, by running
15+
cargo install --force cargo-fuzz
1816

19-
nix-shell -p libopcodes_2_38 -p libunwind
20-
# In the nix-shell run these
21-
NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify/}
22-
NIX_HARDENING_ENABLE=''${NIX_HARDENING_ENABLE/fortify3/}
23-
24-
and then run fuzz.sh as above.
25-
26-
# Fuzzing with weak cryptography
17+
## Fuzzing with weak cryptography
2718

2819
You may wish to replace the hashing and signing code with broken crypto,
2920
which will be faster and enable the fuzzer to do otherwise impossible
@@ -46,7 +37,7 @@ secp256k1 library with broken cryptography.
4637
Needless to say, NEVER COMPILE REAL CODE WITH THESE FLAGS because if a
4738
fuzzer can break your crypto, so can anybody.
4839

49-
# Long-term fuzzing
40+
## Long-term fuzzing
5041

5142
To see the full list of targets, the most straightforward way is to run
5243

@@ -59,22 +50,19 @@ To run each of them for an hour, run
5950

6051
To run a single fuzztest indefinitely, run
6152

62-
cargo hfuzz run <target>
53+
cargo +nightly fuzz run <target>
6354

6455
`cycle.sh` uses the `chrt` utility to try to reduce the priority of the
6556
jobs. If you would like to run for longer, the most straightforward way
6657
is to edit `cycle.sh` before starting. To run the fuzz-tests in parallel,
6758
you will need to implement a custom harness.
6859

69-
# Adding fuzz tests
60+
## Adding fuzz tests
7061

7162
All fuzz tests can be found in the `fuzz_target/` directory. Adding a new
7263
one is as simple as copying an existing one and editing the `do_test`
7364
function to do what you want.
7465

75-
If your test clearly belongs to a specific crate, please put it in that
76-
crate's directory. Otherwise you can put it directly in `fuzz_target/`.
77-
7866
If you need to add dependencies, edit the file `generate-files.sh` to add
7967
it to the generated `Cargo.toml`.
8068

@@ -91,43 +79,24 @@ If it is working, you will see a rapid stream of data for many seconds
9179
(you can hit Ctrl+C to stop it early). If not, you should quickly see
9280
an error.
9381

94-
# Reproducing Failures
82+
## Computing code coverage
9583

96-
If a fuzztest fails, it will exit with a summary which looks something like
84+
Compute the code coverage of the corpus of a given target using the following command:
9785

98-
```
99-
...
100-
fuzzTarget : hfuzz_target/x86_64-unknown-linux-gnu/release/hashes_sha256
101-
CRASH:
102-
DESCRIPTION:
103-
ORIG_FNAME: 00000000000000000000000000000000.00000000.honggfuzz.cov
104-
FUZZ_FNAME: hfuzz_workspace/hashes_sha256/SIGABRT.PC.7ffff7c8abc7.STACK.18826d9b64.CODE.-6.ADDR.0.INSTR.mov____%eax,%ebp.fuzz
105-
...
106-
=====================================================================
107-
fff400610004
86+
```bash
87+
cargo fuzz coverage TARGET
10888
```
10989

110-
The final line is a hex-encoded version of the input that caused the crash. You
111-
can test this directly by editing the `duplicate_crash` test to copy/paste the
112-
hex output into the call to `extend_vec_from_hex`. Then run the test with
90+
Generate a human-readable HTML coverage report using a command as below. _The exact paths might differ depending on the target architecture._
11391

114-
cargo test
92+
The demangler `rustfilt` must be installed.
11593

116-
Note that if you set your `RUSTFLAGS` while fuzzing (see above) you must make
117-
sure they are set the same way when running `cargo test`.
94+
```bash
95+
cargo cov -- show -Xdemangler=rustfilt target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/TARGET -instr-profile=fuzz/coverage/TARGET/coverage.profdata -show-line-counts-or-regions -show-instantiations --format html --output-dir=OUTPUT_DIR -ignore-filename-regex="\.cargo"
96+
```
11897

119-
If the `duplicate_crash` function is not present, please add it. A template is
120-
as follows:
98+
More information is available in the [rustc book](https://doc.rust-lang.org/stable/rustc/instrument-coverage.html#running-the-instrumented-binary-to-generate-raw-coverage-profiling-data).
12199

122-
```
123-
#[cfg(test)]
124-
mod tests {
125-
use miniscript::bitcoin::hex::FromHex;
126-
127-
#[test]
128-
fn duplicate_crash() {
129-
let v = Vec::from_hex("abcd").unwrap();
130-
super::do_test(&v);
131-
}
132-
}
133-
```
100+
## Reproducing and Minimizing Failures
101+
102+
(todo -- wait for some failures to happen before filling in this section)

0 commit comments

Comments
 (0)