Fuzz Findings Management
The differential fuzzer lives in rust/tcl-fuzz. It generates Tcl programs
and runs each through a pair of engines, recording every divergence to a
findings registry. Three engines are available:
| Engine | What it is | Binary |
|---|---|---|
| tclvm | The native bytecode VM CLI | tcl-vm-cli's tclvm |
| tclsh | A reference C Tcl interpreter | tclsh9.0/tclsh on PATH |
| runtime-rust | runtime/rust's tree-walking interpreter | runtime/rust's run_script dev-tool example (cargo build --release --example run_script under runtime/rust; needs TCL_TOMMATH_DIR pointed at a libtommath source tree for expr/math to work — see "Building the runtime-rust engine" below) |
run --reference E1 --subject E2 pairs any two of these (default: tclsh
reference, tclvm subject). Findings are
keyed by their generating seed (so they replay exactly) and stored as a
JSON record (see rust/tcl-fuzz/src/findings.rs) plus the raw .tcl script
under the findings directory (default fuzz-findings/, override with
--findings DIR). A non-default pair is namespaced under
<findings>/<subject>-vs-<reference>/ so two pairs never collide on the same
seed; the default pair uses <findings>/ directly.
There is no separate "fixed/unfixed" state: the registry de-duplicates by seed
and categorises by the divergence kind. A finding is "fixed" when its seed no
longer reproduces — confirm that by replaying it (below).
Usage
Build once, then invoke the binary:
cargo run -q -p tcl-fuzz -- <command> [args...]
# or, after `cargo build -p tcl-fuzz`:
./target/debug/tcl-fuzz <command> [args...]
Global flags: --findings DIR (registry location), --timeout-ms MS
(per-script timeout), --tclvm PATH / --tclsh PATH / --runtime-rust PATH
(engine binaries; defaults are auto-located beside tcl-fuzz or on PATH),
and the two generator dials --malformed-expr-permille /
--word-shape-permille. Both dials are global rather than run-only because
replay has to generate a seed exactly as the recording campaign did.
Commands
| Command | Arguments | What it does |
|---|---|---|
| run | --iterations N [--seed S] [--verbose] [--reference E] [--subject E] [--compare-error-text] [--tcl-version X.Y] | Run a campaign over the pair; one release applies to every pinnable engine and an engine that cannot honour it stops the campaign |
| summary | [--reference E] [--subject E] [--tcl-version X.Y] | Print counts per release namespace. Without a release it includes unpinned and every tclX.Y registry; an explicit release selects only that registry |
| replay | SEED [--reference E] [--subject E] [--tcl-version X.Y] | Regenerate seed S, restoring its persisted release automatically. An explicit release selects that exact registry |
| wasm-check | --iterations N [--seed S] [--verbose] | WASM-runnability arm: compile each program to the eval-fallback WASM module and flag codegen panics / instantiation failures / traps |
| wasm-diff | --iterations N [--seed S] [--verbose] | WASM value-differential arm: compare compiled-WASM control flow (hosted by tcl-vm) against direct tcl-vm, isolating control-flow miscompiles |
| characterise | --iterations N [--seed S] [--verbose] [--compare-error-text] | Three-way campaign classifying tcl-vm and runtime/rust against C Tcl 9; agreement between the two Rust backends alone is never correctness |
| bpf-diff | --iterations N [--seed S] [--verbose] | eBPF arm: compare a generated BPF-Tcl socket filter's dialect contract against the real lowering, eBPF emitter, and userspace eBPF VM |
| linked-wasm-diff | --iterations N [--seed S] [--verbose] | Link a compiled user module against runtime/rust's WASM module and compare against C Tcl 9 |
Match the reference `tclsh`'s version, or read every finding twice
**A divergence is evidence of a bug only when both engines speak the same
version of Tcl.** A campaign against tclsh8.6 with a 9.0-era subject reports
deliberate language changes as findings. The usual culprits:
| Cause | Seeds | What differs |
|---|---|---|
| TIP 461 lt/gt/le/ge string-comparison operators (9.0+) | 90040, 90061, 90091, 90104, 90112 | 8.6 rejects expr {{a} lt {b}} as invalid bareword "lt" |
| TIP 521 isfinite()/isinf()/isnan() (9.0+) | 90119 | 8.6: invalid command name "tcl::mathfunc::isfinite" |
| Namespace-scope global fallback for relative variable names, removed in 9.0 (TIP 278) | 90022, 90188 | see the KCS note |
Every campaign prints both engines' releases before it starts and warns when
they differ; every finding records reference_version, subject_version and
version_skew. Check those before triaging.
To run version-matched against an older reference, pin the whole pair:
# runtime-rust and tclvm emulating 8.6
cargo run -q -p tcl-fuzz -- \
run --subject runtime-rust --reference tclvm --tcl-version 8.6 \
--iterations 200 --seed 90000
runtime-rust and tclvm receive the same --tcl-version argument. A fixed
release engine such as C tclsh is selected by its binary instead, then its
reported release is verified; no engine may silently ignore a pair pin.
--subject-tcl-version is an alias with the same pair-wide semantics. Pinned
findings live below tclX.Y/ and replay restores that line; the same seed at
8.6 and 9.0 is deliberately two separate records.
--compare-error-text (on run) additionally flags an ErrorTextMismatch
finding when both engines error but their stderr text differs — off by
default, since independent implementations legitimately word errors
differently (e.g. "wrong # args" phrasing); use it when hunting for an engine
reporting the wrong kind of error for a shared failure, not just "an error".
Building the `runtime-rust` engine
runtime/rust's expr/if/while/for/math commands are gated behind a
have_tommath cfg that only turns on when a libtommath C source tree is
found at build time ($TCL_TOMMATH_DIR, else tmp/tcl9.0.4/libtommath — see
runtime/rust/build.rs). Without it, run_script is missing most of the
generator's surface and a runtime-rust-paired campaign is dominated by
false "invalid command name" divergences that are a build gap, not a
runtime bug. Point TCL_TOMMATH_DIR at any libtommath ≥ 1.3.0 source
checkout (the version matters: 1.2.x's mp_expt_n is a deprecated wrapper
excluded by the build script's file filter; 1.3.0 defines it directly in
bn_mp_expt_n.c) before building:
# The Tcl 9.0.4 source tarball already ships libtommath 1.3.0 at
# tmp/tcl9.0.4/libtommath, so extracting it (which building a 9.0 oracle
# does anyway) is usually enough — check for that directory FIRST.
# Only if it is genuinely absent, a shallow tag checkout also works and
# needs no build of its own:
git clone --depth 1 --branch v1.3.0 \
https://github.com/libtom/libtommath tmp/libtommath-1.3.0
# `runtime/rust` is a standalone crate, excluded from the top-level
# workspace — build it from its own directory so it keeps its own target
# dir (do not export the workspace's CARGO_TARGET_DIR into it).
cd runtime/rust && TCL_TOMMATH_DIR="$PWD/../../tmp/libtommath-1.3.0" \
cargo build --release --example run_script
Verify with a quick smoke script (expr/if should both work, not error
with invalid command name) before trusting a campaign's findings.