Repository navigation
fuzz targets for the join laws and the scrubber - #84
yuval-block wants to merge 4 commits into
Conversation
The fuzzing setup worked out for the original crate exercised input and output set joins through an _internal feature. The crate on main only exposes Join, JoinMut and PartialJoin, so recreate the harnesses against those instead: assert that join is idempotent, commutative and associative on JoinResult, Option, BTreeMap and HashMap, the result-domain collections it provides joins for, with operands that already carry conflicts. The targets live in a library of their own so that the libFuzzer, honggfuzz and AFL++ frontends are each a one-line wrapper over the same code, and a crash input found by one reproduces under the others. crash_test is the positive control those frontends' checks use to confirm a fuzzer's coverage feedback actually works. The library is a workspace of its own, outside the root one, as each frontend will be. That keeps the frontends independent of one another: adding one touches no manifest or lock file another shares. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The root clippy check covers only the root workspace, so the fuzz targets crate gets one of its own. This also lays down what the fuzzer checks build on: nix/fuzz imports every module in the directory, so each fuzzer adds a file there rather than an entry in a list the others edit too, and fuzzArgs gives the crane arguments for building one of the fuzz workspaces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| fuzzArgs "targets" | ||
| // { | ||
| RUSTFLAGS = "--cfg fuzzer_verify_crash"; | ||
| pnameSuffix = "-fuzz-targets-clippy"; |
There was a problem hiding this comment.
Fuzz clippy check reuses root clippy derivation name
cargoClippy sets pnameSuffix = "-clippy" after merging its arguments, so the -fuzz-targets-clippy value here is discarded; the check evaluates as concurrent-psbt-clippy-0.1.0, the same derivation name as checks.clippy. The check still runs, but its name no longer identifies it as the fuzz-targets lint.
oak · automated · 3e7c10e
The scrubber parses untrusted bytes and decides what is safe to share, so a fuzzer should look at it too, not only at the join laws. The target scrubs either the raw input or a PSBT of version 0 or 2 assembled from it, and checks that scrub: - never panics; - is idempotent; - emits maps whose keys are strictly increasing, holding only pairs from the corresponding input map, the first of any duplicate key; - keeps the number of maps, and of inputs and outputs; - drops the fields BIP 174 and BIP 371 define as derivations, keys, preimages and proprietary data; - accepts every PSBT that psbt-v2 accepts, and turns it into one psbt-v2 still accepts, with as many inputs and outputs. None of this uses the scrubber's allow-lists or decoder, so that a bug in either cannot hide itself. The sensitive fields are a floor, not the allow-list: they are the fields whose meaning is settled. Bounded model checking reaches only a few bytes of scrub's input, so this covers longer inputs and the v0 path, which the Kani harnesses do not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Shared ground for fuzzing the crate with libFuzzer, honggfuzz and AFL++, each of which follows in a PR of its own stacked on this one. lattice_laws asserts that join is idempotent, commutative and associative on JoinResult, Option, BTreeMap and HashMap, with operands that already carry conflicts. scrub feeds the scrubber raw bytes and assembled v0 and v2 PSBTs, and checks it against properties stated without its own allow-lists or decoder: no panics, idempotence, output pairs drawn from the matching input map, preserved input and output counts, no derivations, keys, preimages or proprietary fields left, and agreement with psbt-v2 on which PSBTs are valid. crash_test is a positive control: it only panics under --cfg fuzzer_verify_crash, and each fuzzer's verification run asserts that the fuzzer finds it, which it only does with working coverage feedback. The targets crate and every frontend are workspaces of their own, and nix/fuzz imports whatever modules are in it, so the three fuzzer PRs touch no file in common and can land in any order. The BIP 371 (Vec<TapLeafHash>, KeySource) join is left out of the targets for now: it keeps the left operand's leaf order, so it is not commutative under structural equality. #76 sorts the leaves, after which it can join the others here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3e7c10e to
f23a148
Compare
range-diff for force push 3e7c10e5fa → f23a1484f3
|
| let scrubbed = match scrubber::scrub(psbt) { | ||
| Ok(scrubbed) => scrubbed, | ||
| Err(e) => { | ||
| assert!( |
There was a problem hiding this comment.
Fuzzer treats a trailing empty map as a scrubber failure
psbt-v2 v0 and v2 stop after the declared maps and ignore trailing bytes, so a valid PSBT plus an extra empty map is accepted as the reference while scrub intentionally rejects it with UnexpectedTrailingBytes (see unexpected_eof_trailing_bytes).
The assertion at line 70 then panics, so the fuzzer reports a false crash instead of a scrubber defect.
Test that fails on this commit
}
#[cfg(test)]
mod trailing_test {
use super::*;
#[test]
fn trailing_empty_map_is_accepted_by_reference_but_rejected_by_scrub() {
let mut tx = 2u32.to_le_bytes().to_vec();
tx.push(1);
tx.extend([0u8; 36]);
tx.push(0);
tx.extend([0xff; 4]);
tx.push(0);
tx.extend([0u8; 4]);
let mut psbt = MAGIC.to_vec();
encode_pair(&mut psbt, 0x00, &[], &tx);
psbt.extend([0, 0, 0]);
check(&psbt, None);
}cargo test --manifest-path fuzz/targets/Cargo.toml -p concurrent-psbt-fuzz-targets trailing_empty_map_is_accepted_by_reference_but_rejected_by_scrub
oak · automated · f23a148
| /// The numbers of inputs and outputs, if psbt-v2 accepts the bytes as a PSBT | ||
| /// of either version. | ||
| fn reference_counts(psbt: &[u8]) -> Option<(usize, usize)> { | ||
| if let Ok(p) = psbt_v2::v2::Psbt::deserialize(psbt) { |
There was a problem hiding this comment.
Huge declared count aborts fuzz target
The scrub target panics with capacity overflow in psbt-v2's v2 decoder on a raw PSBT declaring a huge input count before scrubber::scrub runs; is that a psbt-v2 finding you want the fuzzer to report, or should the target guard the reference decode?
oak · automated · f23a148
There was a problem hiding this comment.
honggfuzz finds in <1 min a v0 PSBT that psbt-v2 accepts but scrub rejects:
70736274ff01000a0000000000000000000000
its tx has 0 inputs, and scrub.rs#L143 decodes it as segwit (BIP 174 requires non-witness)
so every fuzz run hits this check
| const MAGIC: &[u8] = b"psbt\xff"; | ||
|
|
||
| /// Fields that identify the wallet or hold secrets, which a scrubbed PSBT must | ||
| /// not carry. This is a floor, not the scrubber's allow-list: it only names |
There was a problem hiding this comment.
the floor misses fields the scrubber draft lists as sensitive (e.g. TAP_MERKLE_ROOT, OUT_TAP_TREE, output redeem/witness scripts, MuSig2, silent payments) and unregistered types
assert against the draft's insensitive list instead?
Shared ground for fuzzing the crate with libFuzzer, honggfuzz and AFL++,
each of which follows in a PR of its own stacked on this one.
lattice_laws asserts that join is idempotent, commutative and
associative on JoinResult, Option, BTreeMap and HashMap, with operands
that already carry conflicts.
scrub feeds the scrubber raw bytes and assembled v0 and v2 PSBTs, and
checks it against properties stated without its own allow-lists or
decoder: no panics, idempotence, output pairs drawn from the matching
input map, preserved input and output counts, no derivations, keys,
preimages or proprietary fields left, and agreement with psbt-v2 on
which PSBTs are valid.
psbt-v2 0.3.0 is asked about the input with its pairs sorted and
deduplicated, because its answer depends on pair order: it tracks four
required v2 fields by sentinel values, so it accepts a duplicate when the
first copy holds the sentinel and rejects zero-value outputs. libFuzzer
found this within seconds. rust-psbt master already fixes it.
crash_test is a positive control: it only panics under
--cfg fuzzer_verify_crash, and each fuzzer's verification run asserts
that the fuzzer finds it, which it only does with working coverage
feedback.
The targets crate and every frontend are workspaces of their own, and
nix/fuzz imports whatever modules are in it, so the three fuzzer PRs
touch no file in common and can land in any order.
The BIP 371 (Vec, KeySource) join is left out of the
targets for now: it keeps the left operand's leaf order, so it is not
commutative under structural equality. #76 sorts the leaves, after
which it can join the others here.
🤖 Generated with Claude Code