Skip to content

importdescriptors: multipath expansion silently reuses key material across branches #35985

Open

Description

@pythcoiner

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:

// 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():

// 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:

// 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:

// 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 importdescriptors and getdescriptorinfo.

Activity

  1. achow101 commented on Aug 17, 2026

    @achow101
    Member

    This is expected and intended behavior. We should not reject such descriptors. A warning would be sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions