Skip to content

test: cover missing BIP352 cases - #36995

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

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

Conversation

@devdavidejesus

@devdavidejesus devdavidejesus commented Nov 27, 2026 •

Copy link
Copy Markdown

The existing BIP352 tests leave several cases insufficiently covered. To identify these gaps, I ran manual mutation testing against src/common/bip352.cpp, complemented by bcore-mutation. Out of 55 mutations, 33 survived with the existing tests.

With these tests, 52 of the 55 mutations are detected. The three remaining mutations are equivalent to the original implementation.

One mutation replaces the return std::nullopt with break when GetOp fails while scanning a P2PKH scriptSig. The function reaches the same return std::nullopt after the loop. Another removes the early return for the case where there are no eligible keys, checking only whether there are no inputs. With no keys, libsecp256k1 already returns a failure, so the result remains NOT_ELIGIBLE. The third mutation changes the P2PKH scriptSig scanning loop condition from pc < txin.scriptSig.end() to pc <= txin.scriptSig.end(). When pc reaches the end of the scriptSig, GetOp fails, and the function returns the same std::nullopt.

The new tests cover scan label reporting, P2PKH public key extraction when the scriptSig contains unrelated pushes, invalid public keys across supported input types, P2SH-P2WPKH eligibility, Taproot script-path spends, annex handling, control block validation, prevouts summary errors, Silent Payments destination validation, label copy assignment, maximum-size control block acceptance, and the behavior of Scan when none of the outputs is a valid x-only key.

The existing bip352_skips_transactions_spending_unknown_segwit_versions test is also extended to cover SegWit versions v2 through v16 and check the exact NOT_ELIGIBLE error. The address decoding tests also cover a v0 address with a valid Bech32m checksum but one extra data byte (67 instead of 66). The existing bip352_scan_skips_invalid_taproot_outputs test is extended to verify that Scan returns an empty list, rather than an error, when none of the outputs is a valid x-only key.

The changes are limited to src/test/bip352_tests.cpp. No production code is modified.

The tests also pass on top of the P2SH changes from #36776. The annex-related mutations are detected independently of #36992.

Using bcore-mutation with --one-mutant and the bip352_tests test suite, the mutation score improves from 83.93% (9 of 56 mutations surviving on master) to 91.07% (5 of 56 surviving with the first PR version) and finally to 98.21% (1 of 56 surviving with this version). The only remaining survivor is the equivalent P2PKH loop-boundary mutation described above.

src/common/bip352.cpp is not included in the continuous mutation-testing runs on corecheck, so these gaps are not covered by those runs.

@DrahtBot DrahtBot added the Tests label Nov 27, 2026
@DrahtBot

DrahtBot commented Nov 27, 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.

Add unit tests for BIP352 cases that are not adequately
covered by the existing test suite.
The tests cover scan labels, P2PKH public key extraction,
invalid public keys, P2SH input eligibility, Taproot
script-path spends, annex handling, prevouts summary
errors, invalid Silent Payments destinations, label copy
assignment, maximum-size control blocks, and scanning
transactions without valid x-only outputs.
These cases were identified through manual mutation
testing and bcore-mutation.
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