Repository navigation
descriptors: check duplicate keys in all multipath Miniscript branches - #35742
yashbhutwala wants to merge 1 commit into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35742. 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. |
|
I ran this on master and on pr-35742, and this is what I got: On master {
"descriptor": "wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/2)))#kzwg47ay",
"multipath_expansion": [
"wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/0),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/2)))#kzwg47ay",
"wsh(or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1)))#jkt2efkp"
],
"checksum": "mn7hqkkh",
"isrange": false,
"issolvable": true,
"hasprivatekeys": false
}On branch I also checked using On master, the unsafe branch is added to the wallet: [
{
"success": true
}
]On the PR: [
{
"success": false,
"error": {
"code": -5,
"message": "or_i(pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1),pk(xpub6BgBgsespWvERF3LHQu6CnqdvfEvtMcQjYrcRzx53QJjSxarj2afYWcLteoGVky7D3UKDP9QyrLprQ3VCECoY49yfdDEHGCtMMj92pReUsQ/1)) is not sane: contains duplicate public keys"
}
}
]This shows how the PR fixes the silent passing on master |
|
Concept ACK, I also found the same issue - please rebase. |
560cfa2 to
5ced9e7
Compare
There was a problem hiding this comment.
#22838 :-}. This change aligns with BIP389. Hardcoding the 0th index assumes that there is always a single path/branch that contradicts the BIP imo. Reproduced the error.
Before PR
After PR
There was a problem hiding this comment.
I suggest splitting this into focused commits so reviewers can understand the old behavior and the problem before assessing the fix: test infrastructure and controls, characterization of the old behavior with TODOs explaining why those expectations are wrong, then the fix and updated expectations. See l0rinc#295 for how I split the same change.
We should also take this opportunity to add coverage for mixed single-path/multipath keys, wildcards, hardened paths with and without private keys, differing origins, nested errors, and valid key sharing across branches and Taproot leaves.
A functional test would demonstrate the wallet impact: these imports currently succeed but prevent reload. With the fix, rejected imports leave the descriptor set unchanged and the wallet reloadable.
Edit: please make the PR description less robotic, show us how you tested this manually for example
| // Duplicate keys were checked above for branch 0. Check every remaining branch now | ||
| // that all multipath key vectors have been expanded to the same length. | ||
| for (size_t i = 1; i < num_multipath; ++i) { | ||
| parser.m_multipath_index = i; | ||
| node->DuplicateKeyCheck(parser); | ||
| if (!node->CheckDuplicateKey()) { | ||
| const auto* insane_node = &node.value(); | ||
| if (const auto sub = node->FindInsaneSub()) insane_node = sub; | ||
| error = *insane_node->ToString(parser) + " is not sane: contains duplicate public keys"; | ||
| return {}; | ||
| } | ||
| } |
There was a problem hiding this comment.
Given that sane already checks for duplicates in
bitcoin/src/script/miniscript.h
Line 1699 in 1fdd208
| // Duplicate keys were checked above for branch 0. Check every remaining branch now | |
| // that all multipath key vectors have been expanded to the same length. | |
| for (size_t i = 1; i < num_multipath; ++i) { | |
| parser.m_multipath_index = i; | |
| node->DuplicateKeyCheck(parser); | |
| if (!node->CheckDuplicateKey()) { | |
| const auto* insane_node = &node.value(); | |
| if (const auto sub = node->FindInsaneSub()) insane_node = sub; | |
| error = *insane_node->ToString(parser) + " is not sane: contains duplicate public keys"; | |
| return {}; | |
| } | |
| } | |
| // Recheck duplicate keys after multipath expansion, since parsing checked only branch 0 | |
| for (size_t i{1}; i < num_multipath; ++i) { | |
| parser.m_multipath_index = i; | |
| node->DuplicateKeyCheck(parser); | |
| if (!node->CheckDuplicateKey()) { | |
| error = *node->FindInsaneSub()->ToString(parser) + " is not sane: contains duplicate public keys"; | |
| return {}; | |
| } | |
| } |
|
🐙 This pull request conflicts with the target branch and needs rebase. |
|
@yashbhutwala, I rebased l0rinc's split of this PR (l0rinc#295) onto current master: https://github.com/fametrano/bitcoin/tree/multipath-dupkeys-l0rinc The only conflict was in You can fetch it and force-push it over this branch, or cherry-pick the three commits onto your own rebase. Your call. |
|
Closing for now due to inactivity. A new pull can be opened, if this is still relevant. |
Fixes #35629.
Multipath Miniscript descriptors performed duplicate-key sanity checking while parsing the template, when key comparison used the first multipath branch. As a result, duplicate keys present only in a later branch were accepted.
Select each expanded multipath branch and rerun the existing duplicate-key check before constructing the final descriptors. If a branch contains a duplicate, report the offending concrete Miniscript expression.
The regression test covers:
wshcontrol;wshbranch;trbranches.Tested with: