Skip to content

Wallet derived from xprv is different for bdk>=0.20 #750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bonomat opened this issue Sep 12, 2022 · 2 comments
Closed

Wallet derived from xprv is different for bdk>=0.20 #750

bonomat opened this issue Sep 12, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@bonomat
Copy link
Contributor

bonomat commented Sep 12, 2022

Describe the bug

We generate our wallet from an extended private key (xprv) and realized that the resulting wallet is different when upgrading bdk from 0.19 to a version >=0.20.

To Reproduce

I've created a simple project to reproduce the behavior: https://github.com/bonomat/bdk-showcase

This project uses 4 different bdk versions and prints the resulting addresses/name and found balances.
It shows that the wallet created with <=0.19 is different to a wallet created with >=0.20

Expected behavior

Should be the same?

Build environment

  • BDK tag/commit: 0.20+
  • OS+version:
  • rustc 1.62.0 (a8314ef7d 2022-06-27)
  • cargo cargo 1.62.0 (a748cf5a3 2022-06-08)

Additional context

@afilini
Copy link
Member

afilini commented Sep 12, 2022

I think this is caused by #585 which fixed the derivation paths we use for BIP 44, 49 and 84 in testnet/regtest and it was first release as part of BDK 0.20.0 (see release notes). Mainnet is unaffected by that PR.

Originally we were using m/84'/0'/0' for all networks, while instead on testnet/regtest it should be m/84'/1'/0'. If you need to import older wallets you can write your own descriptor template that preserves the old behavior or you can just use the descriptor macro and hardcode the derivation path there. Something like this should work:

let external_desc = descriptor!(wpkh((xprv, DerivationPath::from_str("m/84'/0'/0'/0").unwrap())));
let internal_desc = descriptor!(wpkh((xprv, DerivationPath::from_str("m/84'/0'/0'/1").unwrap())));

@bonomat
Copy link
Contributor Author

bonomat commented Sep 13, 2022

Awesome. Thanks for pointing this out. We must have missed that in the release notes.

@bonomat bonomat closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants