Skip to content

Add fuzz target for the v1 payjoin roundtrip - #1872

Open
caarloshenriq wants to merge 1 commit into
payjoin:masterfrom
caarloshenriq:feat/fuzz-roundtrip-v1
Open

Add fuzz target for the v1 payjoin roundtrip#1872
caarloshenriq wants to merge 1 commit into
payjoin:masterfrom
caarloshenriq:feat/fuzz-roundtrip-v1

Conversation

@caarloshenriq

Copy link
Copy Markdown
Contributor

Summary

Adds a libFuzzer target covering the full v1 payjoin roundtrip: sender builds a request, receiver walks the typestate chain, sender parses the proposal that comes back.

What is covered

The target exercises both sides of the exchange and the handoff between them:

Sender: SenderBuilder::new, build_non_incentivizing, create_v1_post_request, V1Context::process_response

Receiver: UncheckedOriginalPayload::from_request, check_inputs_not_owned, check_no_inputs_seen_before,
identify_receiver_outputs, commit_outputs, commit_inputs, apply_fee_range, finalize_proposal

The receiver's ownership checks answer unconditionally: a real receiver's answers depend on its own UTXO set, which is not what this target is exercising. The goal is the state machine's robustness against attacker-controlled input, not wallet logic.

Mutator design

The input is [len:2][psbt][query]. The custom mutator keeps the PSBT section intact and mutates the query, where the BIP 78 parameters live. 25% of mutations pass straight to fuzzer_mutate, which is also the only path that reaches the PSBT bytes and so doubles as coverage of the sender builder's rejection paths.

Seeding a valid PSBT is what makes the target work. Measured over 200k runs with raw input, roughly 4% deserialize as a PSBT at all and none of those survive build_non_incentivizing, which needs funded inputs, an output paying the URI address and consistent values. Without the seed the target only exercises the rust-bitcoin PSBT parser. The seed is the
BIP 78 test vector already used by payjoin-test-utils, and the URI address is derived from its output 1 rather than hardcoded, so the two cannot drift apart.

Fuzzing results

From an empty corpus on x86_64 Linux, 6 forks, 61 seconds:

Metric Value
Coverage counters reached 3260
Feature edges 6558
Corpus size 619 inputs
Crashes / OOM / Timeouts 0 / 0 / 0

Addresses part of #1267.

Disclosure: co-authored by Claude Opus 5

Pull Request Checklist

Please confirm the following before requesting review:

Walk the full v1 exchange: the sender builds a request from an
original PSBT, the receiver runs it through the typestate chain,
and the sender parses the resulting proposal.

A custom mutator keeps a known-good original PSBT intact and
spends the mutation budget on the BIP 78 query parameters, where
the attacker-controlled values live. Raw inputs cannot reach the
receiver: the sender builder needs funded inputs, an output
paying the URI address and consistent values, so seeding a valid
PSBT is what puts the state machine rather than the PSBT parser
under test.

The receiver's checks all answer unconditionally, since a real
receiver's answers depend on its own UTXO set.
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 34401726297

Coverage remained the same at 86.646%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 16549
Covered Lines: 14339
Line Coverage: 86.65%
Coverage Strength: 341.82 hits per line

💛 - Coveralls

@benalleng benalleng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TACK 6b3cb7c

Nice work! I had created a limited v1 sender builder but I think this does more with the same efficiency on exec/s

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.

3 participants