3 **A WebAssembly test case generator.**
5 [![](https://docs.rs/wasm-smith/badge.svg)](https://docs.rs/wasm-smith/)
6 [![](https://img.shields.io/crates/v/wasm-smith.svg)](https://crates.io/crates/wasm-smith)
7 [![](https://img.shields.io/crates/d/wasm-smith.svg)](https://crates.io/crates/wasm-smith)
9 * [Features](#features)
11 * [With `cargo fuzz` and `libfuzzer-sys`](#with-cargo-fuzz-and-libfuzzer-sys)
12 * [As a Command Line Tool](#as-a-command-line-tool)
16 * **Always valid:** All generated Wasm modules pass validation. `wasm-smith`
17 gets past your wasm parser and validator, exercising the guts of your Wasm
18 compiler, runtime, or tool.
20 * **Supports the full WebAssembly language:** Doesn't have blind spots or
21 unimplemented instructions.
24 [`Arbitrary`](https://docs.rs/arbitrary/*/arbitrary/trait.Arbitrary.html)
25 trait**: Easy to use with [`cargo
26 fuzz`](https://github.com/rust-fuzz/cargo-fuzz) and
27 [`libfuzzer-sys`](https://github.com/rust-fuzz/libfuzzer)!
29 * **Deterministic:** Given the same input seed, always generates the same output
30 Wasm module, so you can always reproduce test failures.
32 * **Plays nice with mutation-based fuzzers:** Small changes to the input tend to
33 produce small changes to the output Wasm module. Larger inputs tend to
34 generate larger Wasm modules.
38 ### With `cargo fuzz` and `libfuzzer-sys`
40 First, use `cargo fuzz` to define a new fuzz target:
43 $ cargo fuzz add my_wasm_smith_fuzz_target
46 Next, add `wasm-smith` to your dependencies:
49 $ cargo add wasm-smith
52 Then, define your fuzz target so that it takes arbitrary `wasm_smith::Module`s
53 as an argument, convert the module into serialized Wasm bytes via the `to_bytes`
54 method, and then feed it into your system:
57 // fuzz/fuzz_targets/my_wasm_smith_fuzz_target.rs
61 use libfuzzer_sys::fuzz_target;
62 use wasm_smith::Module;
64 fuzz_target!(|module: Module| {
65 let wasm_bytes = module.to_bytes();
71 Finally, start fuzzing:
74 $ cargo fuzz run my_wasm_smith_fuzz_target
77 > **Note:** Also check out [the `validate` fuzz
78 > target](https://github.com/bytecodealliance/wasm-tools/blob/main/fuzz/src/validate.rs)
79 > defined in this repository. Using the `wasmparser` crate, it checks that every
80 > module generated by `wasm-smith` validates successfully.
82 ### As a Command Line Tool
84 Install the CLI tool via `cargo`:
87 $ cargo install wasm-tools
90 Convert some arbitrary input into a valid Wasm module:
93 $ head -c 100 /dev/urandom | wasm-tools smith -o test.wasm
96 Finally, run your tool on the generated Wasm module:
99 $ my-wasm-tool test.wasm