mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 15:14:39 +00:00
descriptor: compare x-only public keys in Tapscript Miniscript duplicate check #36420
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!36420
Loading…
Reference in a new issue
No description provided.
Delete branch "tr-miniscript-xonly-dupkeys"
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?
In Tapscript Miniscript descriptors (
tr()), public keys serialize as 32-byte x-only pubkeys per BIP-340, BIP-342, and BIP-379, discarding parity. However,KeyParser::KeyCompareinsrc/script/descriptor.cppcompared keys as full 33-byteCPubKeys, retaining the parity byte.When a descriptor contains public keys that differ only in parity prefix (such as
pk(X)alongsidepk(03X)whereXdefaults to02, orpk(02X)alongsidepk(03X)),KeyParser::KeyComparetreated them as distinct keys. Miniscript duplicate key checking passed, declaring the descriptor sane even though both branches serialize on-chain to<X> OP_CHECKSIG. Because a single signature satisfies both branches, third parties could malleate transactions by altering branch selectors without holding private keys, violating BIP-379 non-malleability invariants.This patch updates
KeyParser::KeyCompareinsrc/script/descriptor.cppandKeyConverter::KeyCompareinsrc/test/miniscript_tests.cppto compare keys asXOnlyPubKeywheneverminiscript::IsTapscript(m_script_ctx)evaluates true. Under Tapscript context, keys sharing identical x-coordinates compare equivalent (!comp(a, b) && !comp(b, a)), ensuringDuplicateKeyCheck()detects the collision and rejects the descriptor. Insrc/test/descriptor_tests.cpp, unit tests verify thattr()descriptors containing parity-differing duplicate keys (including public hex and private WIF formats) are rejected as not sane, whilewsh()descriptors continue to treat 33-byte compressed keys with differing parities as distinct.Fixes #36414.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
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.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, 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.
LLM Linter (✨ experimental)
Possible places where named args for integral literals may be used (e.g.
func(x, /*named_arg=*/0)in C++, andfunc(x, named_arg=0)in Python):src/wallet/test/walletload_tests.cpp:WalletDescriptor(std::make_shared<DummyDescriptor>(desc), 0, 0, 0, 0)2026-11-25 15:40:57
Earlier concerns neither republished nor resolved: 1 major finding · 1 suggestion. See the Run archive linked from the Review report for their assessments.
🟠 Minor · Persistence compatibility bypasses unrelated Miniscript checks
The persistence bypass now admits unrelated failures such as keyless
wsh(1), although no normal-workflow producer of these newly accepted stored descriptors was found.Location:
src/script/descriptor.cpp:2750(head).🔵 Suggestion · Legacy-descriptor regression test does not reach watch-only export
The new wallet test stops at
LOAD_OK, so it cannot catch removal of the separate compatibility parse inExportWatchOnlyWallet.Location:
src/wallet/export.cpp:95(head).🔵 Suggestion · The duplicate-key fix precedes its wallet-compatibility prerequisite
The intermediate tree at
53439006rejects previously loadable parity-duplicatetr()wallet records;4e549915restores loading, so the final tree is unaffected.Location: src/script/descriptor.cpp:2315 (commit).
🔵 Suggestion · Legacy parity-duplicate descriptors load without a warning
Wallets silently retain previously accepted parity-duplicate
tr()descriptors, althoughimportdescriptorsnow rejects the same strings.Location:
src/wallet/walletutil.h:143(head).🔵 Suggestion · Parity-duplicate keys are absent from
miniscript_testsCurrent
miniscript_testsassertions do not distinguish the new Tapscript x-only comparison from full-CPubKeycomparison.Location:
src/test/miniscript_tests.cpp:139(head).Review coverage was incomplete.
Reviewed:
4e549915cc7a· Review report · Previous reportspermalink
Tested at
cb85c2cdde.descriptor_testsfails on themulti_acheck because that descriptor parses: amulti_adirectly intr()is not Miniscript and has no duplicate-key check, so evenmulti_a(2,X,X)is accepted.wallet_taproot.pyrepeats a key inside onemulti_a, so refusing duplicates there would be a separate change. I suggest dropping the check here and in the description. The twoor_icases are refused with this change and accepted without it.Optional: the same case with the second key as a WIF whose public key is
03X. Without thedescriptor.cppchange this private descriptor is accepted, while its public form (two identical x-only keys) is already refused:This descriptor parses, so this check fails:
Good catch on
multi_aparsing directly asMultiADescriptorrather than Miniscript. Dropped that test and updated the PR description. Thanks for testing!ACK
a1c65a776cdescriptor_tests and miniscript_tests pass, and both new tr() checks fail without the descriptor.cpp change.
The optional WIF case in https://github.com/bitcoin/bitcoin/pull/36420#discussion_r4167758806 still adds coverage: without the fix its private form is accepted, and this PR's cases all use public keys.
Re-pushed
a1c65a7->0956ace45d:KeyConverter.Range-diff
Applied in
0956ace45d, thanks.reACK
0956ace45dOnly the WIF test case was added since
a1c65a77. descriptor_tests and miniscript_tests pass; without the descriptor.cpp change, the two tr() cases and the WIF case fail, the WIF one because its private form parses.Rebased on master (
6c01bd0b2). Range-diff is clean:In
28121591bb"descriptor: compare x-only public keys in Tapscript Miniscript duplicate check"Use
Check(for test cases that are supposed to succeed.Swapped for
Check(in53439006c.Rebased and switched the wsh test case to
Check(. Range-diff against28121591b:tACK
5343900On master:
On PR:
Concept ACK
53439006c6This blocks for me: an existing wallet that holds one of these descriptors no longer loads. On regtest, the base build (
6c01bd0b) importedtr(K,or_i(pk(02X),pk(03X))), with X one x-only key, into a watch-only wallet. With this head,loadwalleton that wallet fails with error -4, and the base build loads it again afterwards. The script and its output are in https://gist.github.com/fametrano/a763979702d860ff2824272ca87d465b/36113358b41d8c240ac95bf4846dd67eee313474.Should
WalletDescriptor::FromStreamdecouple stream deserialization fromIsSane()?In
walletutil.h,WalletDescriptor::FromStreamcallsParse(..., /*require_checksum=*/true). BecauseParseScriptunconditionally rejects!node->IsSane(), tightening duplicate-key detection for Tapscript x-only keys causes existing wallet records containing02X/03Xtwins to throw on load, even thoughnode->IsValid()holds and the script remains spendable.Allowing
Parseto acceptbool require_sane = trueand passingfalseinFromStreamwould preserve wallet loading while keepingIsSane()enforced acrossimportdescriptors,getdescriptorinfo, andderiveaddresses.Reproduced the
loadwallet-4failure under53439006c6and pushed4e549915ccon top to add arequire_sane = trueparameter toParseandParseScript.WalletDescriptor::FromStreamandExportWatchOnlyWalletpassrequire_sane = falsewhile keepingIsValidTopLevel()enforced, and imports and descriptor RPCs keep rejecting duplicate x-only Tapscript keys.Tested with
descriptor_tests,miniscript_tests,walletload_tests,wallet_tests,wallet_descriptor.py,wallet_exported_watchonly.py,wallet_taproot.py, and the regtestloadwalletandexportwatchonlywalletrepro.