Skip to content

fuzz targets for the join laws and the scrubber - #84

Draft
yuval-block wants to merge 4 commits into
mainfrom
fuzz-targets
Draft

yuval-block wants to merge 4 commits into
mainfrom
fuzz-targets

Conversation

@yuval-block

@yuval-block yuval-block commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

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

nothingmuch and others added 2 commits November 12, 2026 16:20
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>
@yuval-block yuval-block mentioned this pull request Nov 12, 2026
@github-code-quality

github-code-quality Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 227c7b5 fuzz-targets f23a148 +/-
100% 100% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated November 13, 2026 06:50 UTC

Comment thread nix/fuzz/targets.nix
fuzzArgs "targets"
// {
RUSTFLAGS = "--cfg fuzzer_verify_crash";
pnameSuffix = "-fuzz-targets-clippy";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

nothingmuch and others added 2 commits November 13, 2026 06:50
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>
@github-actions

Copy link
Copy Markdown
range-diff for force push 3e7c10e5fa → f23a1484f3 November 13, 2026 06:29 UTC: 2 unchanged, 1 dropped, 2 added; 3 → 4 commits; same base 5346f2b34e

reproduce: git range-diff 5346f2b..3e7c10e 5346f2b..f23a148

1:  0b778f899e +391 -0 4f = 1:  0b778f899e +391 -0 4f fuzz: lattice-law targets shared by every fuzzer
2:  41b852519a  +54 -0 4f = 2:  41b852519a  +54 -0 4f nix: lint the fuzz targets
3:  3e7c10e5fa   +0 -0 0f < -:  ----------            fuzz targets for the join laws
-:  ----------            > 3:  6e6998afe6 +323 -0 4f fuzz: scrub target
-:  ----------            > 4:  f23a1484f3   +0 -0 0f fuzz targets for the join laws and the scrubber

@yuval-block yuval-block changed the title fuzz targets for the join laws 🤖 fuzz targets for the join laws and the scrubber Nov 13, 2026
@yuval-block yuval-block changed the title 🤖 fuzz targets for the join laws and the scrubber fuzz targets for the join laws and the scrubber Nov 13, 2026
Comment thread fuzz/targets/src/scrub.rs
let scrubbed = match scrubber::scrub(psbt) {
Ok(scrubbed) => scrubbed,
Err(e) => {
assert!(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread fuzz/targets/src/scrub.rs
/// 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bc1cindy bc1cindy left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@bc1cindy bc1cindy mentioned this pull request Nov 14, 2026
Comment thread fuzz/targets/src/scrub.rs
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

This was referenced Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants