Repository navigation
fuzz: add Silent Payments targets - #37006
devdavidejesus wants to merge 1 commit into
Conversation
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.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
Opened bitcoin-core/qa-assets#303 with a |

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 forsrc/common/bip352.cpp.The new fuzz targets are:
bip352_decode_address: testsDecodeSilentPaymentsAddressagainst 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: exercisesSilentPaymentsDestination::From, including invalid public keys.bip352_pubkey_from_input: testsGetPubKeyFromInputacross 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, fromGetSilentPaymentsPrevoutsSummarythroughGenerateSilentPaymentsTaprootDestinationstoSilentPaymentsReceiver::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 separatebitcoin-core/qa-assetsPR with these inputs underfuzz_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 ofSilentPaymentsLabel, 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:
src/.clang-tidywithout findings.Testing performed on macOS (Apple M3):
src/common/bip352.cppwere detected.No production code is modified.