fuzz: add Silent Payments targets #37006

Open
devdavidejesus wants to merge 1 commit from fuzz-bip352 into master AGit
devdavidejesus commented 2026-11-28 16:34:31 +00:00 (Migrated from github.com)

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 #36776 across all four targets, without failures.
  • Ran an additional 180 seconds of fuzzing on the public key extraction target on top of #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.

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 #36776 across all four targets, without failures. * Ran an additional 180 seconds of fuzzing on the public key extraction target on top of #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.
DrahtBot commented 2026-11-28 16:34:41 +00:00 (Migrated from github.com)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/37006 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/37006.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/37006#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35793](https://github.com/bitcoin/bitcoin/pull/35793) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35793.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

🟠 Minor · The fuzz oracle rejects a valid point-at-infinity failure

A crafted spend key can make bip352_send_receive abort on the sender's documented point-at-infinity rejection even though the prevouts summary is valid.

Location: src/test/fuzz/bip352.cpp:542 (head).

Review coverage was incomplete.


Reviewed: 12b299133cf0 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:afedb19cca4c3b40d89514fb0c66b0c20e4f5d62 --> <!-- ralph-head:12b299133cf05018d4a4a8bbefbfcd7168a72872 --> <!-- ralph-case:08c49b03ed162b52c8c58f7fb263dbcb0c10e21b998d86575d5a518b05a3843c --> **🟠 Minor · The fuzz oracle rejects a valid point-at-infinity failure** A crafted spend key can make `bip352_send_receive` abort on the sender's documented point-at-infinity rejection even though the prevouts summary is valid. Location: [`src/test/fuzz/bip352.cpp:542`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/12b299133cf05018d4a4a8bbefbfcd7168a72872/src/test/fuzz/bip352.cpp#L542>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`12b299133cf0`](<https://git.fish.foo/bitcoin/bitcoin/commit/12b299133cf05018d4a4a8bbefbfcd7168a72872>) · [Review report](<https://review.fish.foo/report/37006-12b299133cf05018d4a4a8bbefbfcd7168a72872-3286-1.html>) · [Previous reports](<https://review.fish.foo/traces/37006/>) [permalink](<https://review.fish.foo/report/37006-12b299133cf05018d4a4a8bbefbfcd7168a72872-3286-1.html>)
devdavidejesus commented 2026-11-28 19:02:33 +00:00 (Migrated from github.com)

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.

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 in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!37006
No description provided.