Repository navigation
Description
when a descriptor mixes multipath key expressions with a non-multipath one, ParseScript clones the single-path provider into every multipath branch instead of rejecting or warning:
bitcoin/src/script/descriptor.cpp
Lines 2440 to 2451 in c90c23d
| // Make sure all vecs are of the same length, or exactly length 1 | |
| // For length 1 vectors, clone key providers until vector is the same length | |
| for (auto& vec : providers) { | |
| if (vec.size() == 1) { | |
| for (size_t i = 1; i < max_providers_len; ++i) { | |
| vec.emplace_back(vec.at(0)->Clone()); | |
| } | |
| } else if (vec.size() != max_providers_len) { | |
| error = strprintf("multi(): Multipath derivation paths have mismatched lengths"); | |
| return {}; | |
| } | |
| } |
same pattern for tr():
bitcoin/src/script/descriptor.cpp
Lines 2586 to 2597 in c90c23d
| // Make sure all vecs are of the same length, or exactly length 1 | |
| // For length 1 vectors, clone subdescs until vector is the same length | |
| for (auto& vec : subscripts) { | |
| if (vec.size() == 1) { | |
| for (size_t i = 1; i < max_providers_len; ++i) { | |
| vec.emplace_back(vec.at(0)->Clone()); | |
| } | |
| } else if (vec.size() != max_providers_len) { | |
| error = strprintf("tr(): Multipath subscripts have mismatched lengths"); | |
| return {}; | |
| } | |
| } |
miniscript:
bitcoin/src/script/descriptor.cpp
Lines 2720 to 2736 in c90c23d
| // Make sure all vecs are of the same length, or exactly length 1 | |
| // For length 1 vectors, clone subdescs until vector is the same length | |
| size_t num_multipath = std::max_element(parser.m_keys.begin(), parser.m_keys.end(), | |
| [](const std::vector<std::unique_ptr<PubkeyProvider>>& a, const std::vector<std::unique_ptr<PubkeyProvider>>& b) { | |
| return a.size() < b.size(); | |
| })->size(); | |
| for (auto& vec : parser.m_keys) { | |
| if (vec.size() == 1) { | |
| for (size_t i = 1; i < num_multipath; ++i) { | |
| vec.emplace_back(vec.at(0)->Clone()); | |
| } | |
| } else if (vec.size() != num_multipath) { | |
| error = strprintf("Miniscript: Multipath derivation paths have mismatched lengths"); | |
| return {}; | |
| } | |
| } |
and musig:
bitcoin/src/script/descriptor.cpp
Lines 2112 to 2125 in c90c23d
| // Makes sure that all providers vectors in providers are the given length, or exactly length 1 | |
| // Length 1 vectors have the single provider cloned until it matches the given length. | |
| const auto& clone_providers = [&providers](size_t length) -> bool { | |
| for (auto& multipath_providers : providers) { | |
| if (multipath_providers.size() == 1) { | |
| for (size_t i = 1; i < length; ++i) { | |
| multipath_providers.emplace_back(multipath_providers.at(0)->Clone()); | |
| } | |
| } else if (multipath_providers.size() != length) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| }; |
so wsh(multi(2,A/<0;1>/*,B/0/*)) imports as:
external: wsh(multi(2,A/0/*,B/0/*))
internal: wsh(multi(2,A/1/*,B/0/*))
B/0/i is the exact same pubkey in the receive script and in the change script at the same index. this seems intended & is covered by test vectors, what bothers me is the privacy impact:
once a receive output at index i and a change output at index i are both spent, the two witness scripts contain an identical pubkey. that is a hard link between the two utxos for any observer, similar to an address reuse but only after both coins has been spent.
it gets worse when the cloned key is not ranged at all, a bare pubkey or a fixed B/0/0, then the same pubkey appears in every script the wallet ever produces, receive and change, at every index.
i see two options to this:
- reject it in Parse() by default, with an opt-in flag on importdescriptors for anyone who already funded such a descriptor.
- or keep accepting it and emit a warning, from
importdescriptorsandgetdescriptorinfo.
Activity
achow101 commentedon Aug 17, 2026
This is expected and intended behavior. We should not reject such descriptors. A warning would be sufficient.