Skip to content

Commit 792b39f

Browse files
Explicitly deny multipath keys
Although there is *some* code to handle multipath keys inside bdk, it's all untested, and from a few quick tests it seems that it's pretty easy to find buggy edge cases. Better to deny multipath descs for now, and revisit the decision once we work on supporting multidescriptor wallets.
1 parent b73385d commit 792b39f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

crates/bdk/src/descriptor/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub enum Error {
2222
InvalidDescriptorChecksum,
2323
/// The descriptor contains hardened derivation steps on public extended keys
2424
HardenedDerivationXpub,
25+
/// The descriptor contains multipath keys
26+
MultiPath,
2527

2628
/// Error thrown while working with [`keys`](crate::keys)
2729
Key(crate::keys::KeyError),
@@ -64,6 +66,10 @@ impl fmt::Display for Error {
6466
f,
6567
"The descriptor contains hardened derivation steps on public extended keys"
6668
),
69+
Self::MultiPath => write!(
70+
f,
71+
"The descriptor contains multipath keys, which are not supported yet"
72+
),
6773
Self::Key(err) => write!(f, "Key error: {}", err),
6874
Self::Policy(err) => write!(f, "Policy error: {}", err),
6975
Self::InvalidDescriptorCharacter(char) => {

crates/bdk/src/descriptor/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ pub(crate) fn into_wallet_descriptor_checked<T: IntoWalletDescriptor>(
308308
return Err(DescriptorError::HardenedDerivationXpub);
309309
}
310310

311+
if descriptor.is_multipath() {
312+
return Err(DescriptorError::MultiPath);
313+
}
314+
311315
// Run miniscript's sanity check, which will look for duplicated keys and other potential
312316
// issues
313317
descriptor.sanity_check()?;
@@ -865,6 +869,12 @@ mod test {
865869

866870
assert_matches!(result, Err(DescriptorError::HardenedDerivationXpub));
867871

872+
let descriptor = "wpkh(tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/<0;1>/*)";
873+
let result = into_wallet_descriptor_checked(descriptor, &secp, Network::Testnet);
874+
875+
assert_matches!(result, Err(DescriptorError::MultiPath));
876+
877+
// repeated pubkeys
868878
let descriptor = "wsh(multi(2,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/0/*,tpubD6NzVbkrYhZ4XHndKkuB8FifXm8r5FQHwrN6oZuWCz13qb93rtgKvD4PQsqC4HP4yhV3tA2fqr2RbY5mNXfM7RxXUoeABoDtsFUq2zJq6YK/0/*))";
869879
let result = into_wallet_descriptor_checked(descriptor, &secp, Network::Testnet);
870880

0 commit comments

Comments
 (0)