Skip to content

fuzz: add Silent Payments targets - #37006

Open
devdavidejesus wants to merge 1 commit into
bitcoin:masterfrom
devdavidejesus:fuzz-bip352
Open

devdavidejesus wants to merge 1 commit into
bitcoin:masterfrom
devdavidejesus:fuzz-bip352

Conversation

@devdavidejesus

Copy link
Copy Markdown

This PR adds fuzz testing for Silent Payments in src/test/fuzz/bip352.cpp, covering address decoding, destination creation, public key extraction from inputs, and end-to-end sending and receiving. There are currently no fuzz targets for src/common/bip352.cpp.

The new fuzz targets are:

  • bip352_decode_address: tests DecodeSilentPaymentsAddress against an independent validity model, covering Bech32m checksums, the network HRP, versions, payload sizes, and compressed public keys. Accepted addresses are also checked against the encoded version, keys, and extension.
  • bip352_destination_from: exercises SilentPaymentsDestination::From, including invalid public keys.
  • bip352_pubkey_from_input: tests GetPubKeyFromInput across P2TR, P2WPKH, P2SH-P2WPKH, and P2PKH inputs. Taproot cases include annex handling, NUMS_H, and control blocks at the maximum supported size and beyond.
  • bip352_send_receive: exercises the complete sending and receiving flow, from GetSilentPaymentsPrevoutsSummary through GenerateSilentPaymentsTaprootDestinations to SilentPaymentsReceiver::Scan. It also covers missing coins, unsupported SegWit versions, labels, outpoint ordering, and keys that cancel each other out.

The fuzz targets use independent models to check expected behavior rather than simply reproducing the implementation. For consensus-invalid inputs where more than one result would be acceptable, the expected result is left undetermined. Two cases follow the current implementation instead of an independent model: P2SH scriptSig evaluation, and Taproot script-path spends with a malformed control block, which are expected to yield no public key.

The final corpus was built from inputs minimized with libFuzzer's -merge=1, together with additional manually added seeds for cases that were not retained by corpus minimization. Some of the mutation results below depend on these added seeds, which do not add coverage and would not survive a new minimization. I will open a separate bitcoin-core/qa-assets PR with these inputs under fuzz_corpora/.

Mutation testing was performed against 55 mutations of src/common/bip352.cpp, replaying the final corpus without additional fuzzing. Eight mutations survive: three are equivalent to the original implementation, two only change which validation layer rejects an address without changing acceptance, and three concern copy-assignment of SilentPaymentsLabel, which is covered by the unit test proposed in #36995.

Additional mutations were also tested, covering address decoding, P2WPKH and P2SH-P2WPKH public key extraction, invalid padding, empty address data, transactions without eligible inputs, and sender input validation. The corpus detects all of them except three: one that only affects consensus-invalid spends, one where an invalid private key is passed to the sender, and one where the sender is called without any recipients.

Testing performed on Linux with libFuzzer, ASan, UBSan, and integer sanitizers:

  • Replayed the final corpus against the original implementation on all four targets without failures.
  • Ran additional fuzzing on the original implementation: 150 seconds for address decoding, 120 seconds for destination creation, 240 seconds for public key extraction, and 240 seconds for sending and receiving, without failures.
  • Replayed the corpus on top of the P2SH changes from bip352: match P2SH-P2WPKH instead of evaluating it #36776 across all four targets, without failures.
  • Ran an additional 180 seconds of fuzzing on the public key extraction target on top of bip352: match P2SH-P2WPKH instead of evaluating it #36776, without failures.
  • Tested stricter P2WPKH and P2SH-P2WPKH variants against the corpus, additional test inputs, and 200 seconds of fuzzing each, without failures.
  • Ran clang-tidy 18 using src/.clang-tidy without findings.
  • Compiled with clang-20 and the Bitcoin Core compiler flags without warnings.

Testing performed on macOS (Apple M3):

  • Built without a fuzzing engine and replayed the final corpus on all four targets without failures; four planted bugs in src/common/bip352.cpp were detected.

No production code is modified.

Add fuzz targets for Silent Payments address decoding, destination
creation, public key extraction from inputs, and end-to-end sending
and receiving.

The targets exercise address validation, supported input types,
Taproot script-path handling, prevouts processing, and receiver
scanning.

Register the new targets in src/test/fuzz/CMakeLists.txt.
@DrahtBot

DrahtBot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • #35793 (Implement BIP 54 (Consensus Cleanup) without mainnet activation by darosior)

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.

@devdavidejesus

Copy link
Copy Markdown
Author

Opened bitcoin-core/qa-assets#303 with a -set_cover_merge=1 -use_value_profile=0 reduction of the corpus, as suggested in its README. It keeps coverage but not every input the mutation results rely on: with the reduced inputs alone, 8 of the 47 detected mutations are no longer detected. These 8 are detected by the unit tests: 2 by those in master, and the other 6 by the tests proposed in #36995. The mutation results in the description were measured with the full corpus, which I can share on request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants