mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:08:38 +00:00
fuzz: add a custom mutator for PSBT #36631
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36631
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-10-fuzz-psbt-custom-mutator"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The
partially_signed_transaction_deserializetarget feeds raw bytes to the PSBT parser. Byte-level mutations rarely produce well-formed key-value maps with valid keydata (pubkeys, xpubs, control blocks, DER signatures, etc), so most inputs are rejected early and the deeper per-field parsing is rarely reached.This PR adds a custom mutator for PSBT which is ported from bitcoinfuzz (with some changes). The mutator splits the input into global/input/output maps of key-value records, applies the mutations and serializes the result again. The first commit is a preparation to allow targets to provide a custom mutator by adding an optional
mutatorfield toFuzzTargetOptions.note: LLM assisted on porting the custom mutator.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
A summary of reviews will appear here.
Conflicts
Reviewers, this pull request conflicts with the following ones:
[[noreturn]]by fanquake)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
note: since we have one binary for everything, a custom mutator would disable -len_control even for targets that do not use it. This function solves it but libFuzzer will still log the disabling.
🔵 Suggestion · Oversized structured mutations can be truncated mid-record
When serialized output exceeds max_size, the PSBT fuzz mutator can cut off a required record or separator, preventing the parser from reaching the complete appended field.
Location:
src/test/fuzz/util/psbt.cpp:478(head).🔵 Suggestion · Remove the redundant
<pubkey.h>includepsbt.cpp:10 includes <pubkey.h>, but the file uses nothing it declares. Pubkeys are
_hex_u8literals, MUSIG2_PUBNONCE_SIZE comes from musig.h, and psbt.h already includes pubkey.h. Redundant include in a new file; maintenance only.Location:
src/test/fuzz/util/psbt.cpp:7(head).🔵 Suggestion · Map-removal mutation can delete the global map
psbt.cpp:450 erases maps[map_idx], and map_idx can be 0, so the global map can be deleted. The promoted input map has no version or unsigned tx, so Unserialize throws before reading inputs or outputs. Roughly 1 in 36 MutateMaps calls with three maps; quality only.
Location:
src/test/fuzz/util/psbt.cpp:410(head).Review coverage was incomplete.
Reviewed:
93dc3cfe09ed· Full review report · Previous reportspermalink
🚧 At least one of the CI tasks failed.
Task
NetBSD Cross: https://github.com/bitcoin/bitcoin/actions/runs/40009584622/job/120606204787LLM reason (✨ experimental): CI failed during the fuzz-test build because
g_custom_mutatorinsrc/test/fuzz/fuzz.cppis set but unused, triggering-Werror.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased
I think this will break fuzzing with afl++ in OSS-Fuzz. It defines
LLVMFuzzerMutateas a symbol here and then crashes here because of argv manipulation. You can reproduce with this:This doesn't happen on master (
6ed5aad061).The key gets erased if
FuzzDefaultMutatereturns 0 (which is the case forLLVMFuzzerMutatein afl++) . Is that expected to happen in this branch for key mutations?Yea, noticed this, I had tested only on libFuzzer. I've moved this to draft while fixing it.
this would only happen with AFL++'s weak stub when PROVIDE_FUZZ_CUSTOM_MUTATOR is defined, isn't it?
Ah yes, that is my understanding as well after seeing
#if defined(PROVIDE_FUZZ_CUSTOM_MUTATOR)at fuzz.cpp:224.Done.
Partial review. Left some nits and a remark wrt honggfuzz + suggestion from Claude. Will look into mutator effectiveness next.
nit: "which only libFuzzer provides" is inaccurate. Suggesting "provided by libFuzzer" instead:
I don't know how much we care about honggfuzz, but honggfuzz has a similar problem. It also defines
LLVMFuzzerMutateand throws a warning because of-len_control=100(no crash like AFL++). See reproduction which simulates appending-len_control=100to argv likerestore_default_len_control()would do:Claude suggested a configure-time opt-in. Then we wouldn't need to detect the engine and rewrite arguments, but the custom mutator would be off by default and I think if there's a custom mutator available, we never want to run without it. Sounds like a good trade-off to me, though.
nit: could move this check to the call site. I consider it control flow rather than part of this function's logic.
Well noticed, I don't use honggfuzz but since we support it, I should consider it. I would not go with a configure-time opt-in because it would require changes on some infra, including OSS-Fuzz.
Done.
Done. I just changed it to detect the real libFuzzer runtime instead of LLVMFuzzerMutate.
In case I'm going to touch it again, I can address it.
Force-pushed: