Repository navigation
Conversation
|
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.
If your review is incorrectly listed, please copy-paste 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. LLM Linter (✨ experimental)Possible places where named args for integral literals may be used (e.g.
2026-11-25 15:40:57 |
fametrano
left a comment
There was a problem hiding this comment.
Tested at cb85c2c. descriptor_tests fails on the multi_a check because that descriptor parses: a multi_a directly in tr() is not Miniscript and has no duplicate-key check, so even multi_a(2,X,X) is accepted. wallet_taproot.py repeats a key inside one multi_a, so refusing duplicates there would be a separate change. I suggest dropping the check here and in the description. The two or_i cases are refused with this change and accepted without it.
| CheckUnparsable("tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,multi_a(2,6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4,036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4))", | ||
| "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,multi_a(2,6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4,036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4))", | ||
| "multi_a(2,6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4,036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4) is not sane: contains duplicate public keys"); |
There was a problem hiding this comment.
This descriptor parses, so this check fails:
| CheckUnparsable("tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,multi_a(2,6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4,036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4))", | |
| "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,multi_a(2,6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4,036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4))", | |
| "multi_a(2,6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4,036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4) is not sane: contains duplicate public keys"); |
| "or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys"); | ||
| CheckUnparsable("tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))", | ||
| "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))", | ||
| "or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys"); |
There was a problem hiding this comment.
Optional: the same case with the second key as a WIF whose public key is 03X. Without the descriptor.cpp change this private descriptor is accepted, while its public form (two identical x-only keys) is already refused:
| "or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys"); | |
| "or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys"); | |
| CheckUnparsable("tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(KztWktoNG1biXs3GSD6M7YDEynGaQPgjLguiWhMXiJM7sDA5vZFt)))", | |
| "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))", | |
| "or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys"); |
cb85c2c to
a1c65a7
Compare
|
Good catch on |
|
ACK a1c65a7 descriptor_tests and miniscript_tests pass, and both new tr() checks fail without the descriptor.cpp change. The optional WIF case in #36420 (comment) still adds coverage: without the fix its private form is accepted, and this PR's cases all use public keys. |
a1c65a7 to
0956ace
Compare
|
Re-pushed
Range-diff1: a1c65a776c ! 1: 0956ace45d descriptor: compare x-only public keys in Tapscript Miniscript duplicate check
@@ src/test/descriptor_tests.cpp: BOOST_AUTO_TEST_CASE(descriptor_test)
+ CheckUnparsable("tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))",
+ "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))",
+ "or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys");
++ CheckUnparsable("tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(KztWktoNG1biXs3GSD6M7YDEynGaQPgjLguiWhMXiJM7sDA5vZFt)))",
++ "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))",
++ "or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys");
+ // But in wsh(), keys differing only in parity are distinct 33-byte compressed pubkeys and not duplicate.
+ {
+ FlatSigningProvider keys; |
0956ace to
2812159
Compare
|
Rebased on master (6c01bd0). Range-diff is clean: |
| { | ||
| FlatSigningProvider keys; | ||
| std::string error; | ||
| auto parsed = Parse("wsh(or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))", keys, error); |
There was a problem hiding this comment.
In 2812159 "descriptor: compare x-only public keys in Tapscript Miniscript duplicate check"
Use Check( for test cases that are supposed to succeed.
There was a problem hiding this comment.
Swapped for Check( in 53439006c.
…ate check In Tapscript Miniscript descriptors (inside tr()), public keys serialize as 32-byte x-only pubkeys (BIP-340 / BIP-342 / BIP-379), discarding parity. However, KeyParser::KeyCompare compared keys as full 33-byte CPubKeys, causing keys that differ only in parity (such as pk(X) and pk(03X), or pk(02X) and pk(03X)) to be treated as distinct. As a result, DuplicateKeyCheck() passed and marked the script sane, even though both branches serialize to the same script on-chain (<X> OP_CHECKSIG). This violates BIP-379 malleability requirements and enables third parties to malleate transactions by flipping branch selectors with a single signature. Fix this by comparing keys as XOnlyPubKey when miniscript::IsTapscript(m_script_ctx) in KeyParser::KeyCompare and KeyConverter::KeyCompare. In Tapscript, keys with matching x-coordinates evaluate as equivalent, correctly failing duplicate-key checks, while P2WSH (wsh()) continues to distinguish 33-byte compressed keys. Fixes bitcoin#36414.
2812159 to
5343900
Compare
|
Rebased and switched the wsh test case to 1: 28121591b ! 1: 53439006c descriptor: compare x-only public keys in Tapscript Miniscript duplicate check
@@ src/test/descriptor_tests.cpp: BOOST_AUTO_TEST_CASE(descriptor_test)
+ "tr(a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))",
+ "or_i(pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(6116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)) is not sane: contains duplicate public keys");
+ // But in wsh(), keys differing only in parity are distinct 33-byte compressed pubkeys and not duplicate.
-+ {
-+ FlatSigningProvider keys;
-+ std::string error;
-+ auto parsed = Parse("wsh(or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))", keys, error);
-+ BOOST_CHECK_MESSAGE(!parsed.empty(), error);
-+ }
++ Check("wsh(or_i(pk(L28YBaopjVrcu8N9hGMAVC6aye5oGETqqx5daUGQxqCjRzw7MNko),pk(KztWktoNG1biXs3GSD6M7YDEynGaQPgjLguiWhMXiJM7sDA5vZFt)))",
++ "wsh(or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))",
++ "wsh(or_i(pk(026116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4),pk(036116733562ba4df653e4ec6b98c904c8dd3c677428264d33f4ae0089b72abaa4)))",
++ SIGNABLE, {{"00206d30950aa674b28b0fbf4cc43f70244c6bdbac4d8cd4ace43dc6fdf6d303d20e"}}, OutputType::BECH32);
// Valid with extended keys.
Check("wsh(and_v(v:ripemd160(095ff41131e5946f3c85f79e44adbcf8e27e080e),multi(1,xprvA1RpRA33e1JQ7ifknakTFpgNXPmW2YvmhqLQYMmrj4xJXXWYpDPS3xz7iAxn8L39njGVyuoseXzU6rcxFLJ8HFsTjSyQbLYnMpCqE2VbFWc,xprv9uPDJpEQgRQfDcW7BkF7eTya6RPxXeJCqCJGHuCJ4GiRVLzkTXBAJMu2qaMWPrS7AANYqdq6vcBcBUdJCVVFceUvJFjaPdGZ2y9WACViL4L/0)))", "wsh(and_v(v:ripemd160(095ff41131e5946f3c85f79e44adbcf8e27e080e),multi(1,xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0)))", "wsh(and_v(v:ripemd160(095ff41131e5946f3c85f79e44adbcf8e27e080e),multi(1,xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL,xpub68NZiKmJWnxxS6aaHmn81bvJeTESw724CRDs6HbuccFQN9Ku14VQrADWgqbhhTHBaohPX4CjNLf9fq9MYo6oDaPPLPxSb7gwQN3ih19Zm4Y/0)))", DEFAULT, {{"0020acf425291b98a1d7e0d4690139442abc289175be32ef1f75945e339924246d73"}}, OutputType::BECH32, /*op_compat_desc_hash=*/uint256{"0634b326edc66f9e2660562564d7a8fcca55f91dc4555ce0a51883cc72e0fa41"}, {{},{0}});
// Valid under sh(wsh()) and with a mix of xpubs and raw keys. |
|
tACK 5343900
On PR:
|
fametrano
left a comment
There was a problem hiding this comment.
Concept ACK 5343900
This blocks for me: an existing wallet that holds one of these descriptors no longer loads. On regtest, the base build (6c01bd0) imported tr(K,or_i(pk(02X),pk(03X))), with X one x-only key, into a watch-only wallet. With this head, loadwallet on 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 In Allowing |
…iptors Existing wallets created before enforcing Tapscript x-only duplicate-key checks may store descriptors such as tr(K,or_i(pk(02X),pk(03X))) that now fail IsSane(), causing loadwallet to fail with error -4. Add a require_sane = true parameter to Parse() and ParseScript() so callers deserializing or exporting already-persisted wallet descriptors (WalletDescriptor::FromStream and ExportWatchOnlyWallet) can opt out of Miniscript sanity checks while keeping IsValidTopLevel() enforced and leaving require_sane = true for imports and descriptor RPCs.
|
Reproduced the Tested with |



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.