wallet: Allow importing of descriptors without private keys when the wallet has the private keys #35377

Open
achow101 wants to merge 4 commits from importdescriptors-without-priv into master AGit
achow101 commented 2026-05-25 23:55:32 +00:00 (Migrated from github.com)

Currently importing a descriptor to a wallet that has private keys requires the descriptor to include the private keys. This is not ideal as it means exposing private key material. This PR makes it so that the wallet will lookup and substitute the private keys for their respective public keys in such descriptors, thus enabling importing of public descriptors into wallets with private keys.

The underlying mechanism is that the wallet retrieves all of the pubkeys from the descriptor and checks to see if any of them have private keys in any ScriptPubKeyMan. Additionally, if the descriptor has a xpub with key origin info, we will check if any xprvs known to the wallet have a matching fingerprint and derive to the specified xpub. If so, the origin + xpub are replaced with the single xprv with the origin derivation path prepended to the key expression's derivation path.

Possible future work is to allow the xpub substitution to work when the wallet has some child in the key origin, i.e. the wallet xprv has a key origin that is a prefix of the key origin specified for an xpub in the descriptor. Currently this kind of substitution is not being done, only root master xprvs will be substituted.

If a wallet does not have the private keys for a public descriptor, the import is still disallowed.

This PR is based on #34861 to avoid an annoying rebase.

Closes #27336

Currently importing a descriptor to a wallet that has private keys requires the descriptor to include the private keys. This is not ideal as it means exposing private key material. This PR makes it so that the wallet will lookup and substitute the private keys for their respective public keys in such descriptors, thus enabling importing of public descriptors into wallets with private keys. The underlying mechanism is that the wallet retrieves all of the pubkeys from the descriptor and checks to see if any of them have private keys in any `ScriptPubKeyMan`. Additionally, if the descriptor has a xpub with key origin info, we will check if any xprvs known to the wallet have a matching fingerprint and derive to the specified xpub. If so, the origin + xpub are replaced with the single xprv with the origin derivation path prepended to the key expression's derivation path. Possible future work is to allow the xpub substitution to work when the wallet has some child in the key origin, i.e. the wallet xprv has a key origin that is a prefix of the key origin specified for an xpub in the descriptor. Currently this kind of substitution is not being done, only root master xprvs will be substituted. If a wallet does not have the private keys for a public descriptor, the import is still disallowed. This PR is based on #34861 to avoid an annoying rebase. Closes #27336
DrahtBot commented 2026-05-25 23:55:40 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK rkrux, polespinasa, Sjors

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36885 (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc)
  • #36257 (qa: assert_equal -> assert_true/assert_false by hodlinator)
  • #36070 (wallet: Add deriveHDKey interface by PraneethGunas)
  • #34520 (refactor: Add nodiscard to functions returning bool+mutable ref by maflcko)

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.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • // Whether ' or h is used in harded derivation -> // Whether ' or h is used in hardened derivation [“harded” is misspelled]
  • self.log.info("Test import of descriptors without private keys that the wallet has the privkeys for") -> self.log.info("Test import of descriptors without private keys that the wallet has the private keys for") [“privkeys” is unclear/abbreviated in a way that may hinder comprehension]
  • # xpub substition -> # xpub substitution [“substition” is misspelled]

2026-09-30 18:06:49

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35377 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35377.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35377#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [rkrux](https://github.com/bitcoin/bitcoin/pull/35377#issuecomment-4630564472), [polespinasa](https://github.com/bitcoin/bitcoin/pull/35377#issuecomment-4647841954), [Sjors](https://github.com/bitcoin/bitcoin/pull/35377#issuecomment-5482654715) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36885](https://github.com/bitcoin/bitcoin/pull/36885) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36885.svg"></sub> (wallet, rpc: Add analyzedescriptor for multisig setups by pablomartin4btc) * [#36257](https://github.com/bitcoin/bitcoin/pull/36257) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36257.svg"></sub> (qa: assert_equal -> assert_true/assert_false by hodlinator) * [#36070](https://github.com/bitcoin/bitcoin/pull/36070) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36070.svg"></sub> (wallet: Add deriveHDKey interface by PraneethGunas) * [#34520](https://github.com/bitcoin/bitcoin/pull/34520) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34520.svg"></sub> (refactor: Add [[nodiscard]] to functions returning bool+mutable ref by maflcko) 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. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### LLM Linter (✨ experimental) Possible typos and grammar issues: - `// Whether ' or h is used in harded derivation` -> `// Whether ' or h is used in hardened derivation` [“harded” is misspelled] - `self.log.info("Test import of descriptors without private keys that the wallet has the privkeys for")` -> `self.log.info("Test import of descriptors without private keys that the wallet has the private keys for")` [“privkeys” is unclear/abbreviated in a way that may hinder comprehension] - `# xpub substition` -> `# xpub substitution` [“substition” is misspelled] <sup>2026-09-30 18:06:49</sup>
rkrux commented 2026-06-05 10:28:24 +00:00 (Migrated from github.com)

Definite Concept ACK 2e6d8d0 because it allows the users to not deal with private keys manually.

Definite Concept ACK 2e6d8d0 because it allows the users to not deal with private keys manually.
polespinasa commented 2026-06-08 10:15:16 +00:00 (Migrated from github.com)

seems like a good idea, concept ACK

Will review after #34861 is merged

seems like a good idea, concept ACK Will review after #34861 is merged
DrahtBot commented 2026-06-13 03:24:07 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/27453755862/job/81154189319
LLM reason (✨ experimental): CI failed because IWYU reported a header include issue (it modified src/script/descriptor.h and deliberately exited with “Failure generated from IWYU”).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/27453755862/job/81154189319</sub> <sub>LLM reason (✨ experimental): CI failed because IWYU reported a header include issue (it modified `src/script/descriptor.h` and deliberately exited with “Failure generated from IWYU”).</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
DrahtBot commented 2026-06-26 23:02:09 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-07-03 11:21:54 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-07-14 09:19:09 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-08-06 01:23:11 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/31056225146/job/92474198450
LLM reason (✨ experimental): CI failed due to a C++ build error in src/script/descriptor.cpp (invalid access to MuSigPubkeyProvider::m_participants plus a related std::equal compilation error).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `test ancestor commits`: https://github.com/bitcoin/bitcoin/actions/runs/31056225146/job/92474198450</sub> <sub>LLM reason (✨ experimental): CI failed due to a C++ build error in `src/script/descriptor.cpp` (invalid access to `MuSigPubkeyProvider::m_participants` plus a related `std::equal` compilation error).</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
DrahtBot commented 2026-08-11 11:58:07 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
Sjors commented 2026-08-31 18:24:53 +00:00 (Migrated from github.com)
Concept ACK, I've been using some version of this in https://github.com/Sjors/bitcoin/pull/91. I'll try to switch to exactly this PR after https://github.com/bitcoin/bitcoin/pull/34861 lands and you've rebased.
Sjors commented 2026-09-02 18:00:41 +00:00 (Migrated from github.com)

An alternative approach, using bits of #36133, is to give Parse access to the wallet's extended keys: 2026/09/parse-known-keys (2 commits)

Although it works fine when you give it all keys, I further simplified it by only considering hd keys.

An alternative approach, using bits of #36133, is to give `Parse` access to the wallet's extended keys: [2026/09/parse-known-keys](https://github.com/Sjors/bitcoin/commits/2026/09/parse-known-keys/) (2 commits) Although it works fine when you give it all keys, I further simplified it by only considering hd keys.
DrahtBot commented 2026-09-14 13:31:57 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
DrahtBot commented 2026-09-22 16:23:32 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
First-time contributor

5 additional verified findings in the full report.

🟠 Minor · Wallet-held odd-parity keys are missed for x-only Taproot imports

A public-only tr(X) import can be rejected despite the wallet holding its private key, because the new lookups match compressed pubkeys exactly and miss odd-Y keys.

Location: src/wallet/imports.cpp:149 (head).

🟠 Minor · Substitution prevents reimport from matching an account-rooted descriptor

Once the master xprv is known, reimporting an existing account-rooted descriptor creates a duplicate manager, so updates and deactivation miss the original.

Location: src/wallet/imports.cpp:134 (head).

🟠 Minor · Failed origin derivation can still trigger substitution

An unsuccessful origin-path derivation still reaches the equality check and can replace an importable expression with an underivable path.

Location: src/script/descriptor.cpp:1201 (head).

🔵 Suggestion · Every import eagerly retrieves all wallet root keys

Each validated request enumerates every manager under cs_wallet, decrypting available roots in encrypted wallets, and every multipath expansion copies the complete xprv map.

Location: src/wallet/imports.cpp:124 (head).

🔵 Suggestion · MuSig participant enumeration also changes HD-key RPC defaults

Returning MuSig participants changes gethdkeys output and can make automatic HD-key selection ambiguous, beyond the import behavior this PR targets.

Location: src/script/descriptor.cpp:1117 (head).

🔵 Suggestion · Public reimports can reset and deactivate the wallet's default descriptor

Reimporting a public default descriptor string now reaches existing state-reset semantics, so omitted activation and index fields can deactivate it and permit address reuse after reactivation.

Location: src/wallet/imports.cpp:134 (head).

Review coverage was incomplete.


Reviewed: 44a26c1d2824 · Full review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:4d44b6ffa09c54db24f8f0ab27ae388beae06a733efcae741ca64db76bb1c938:7efd3c3ba41667382004cfa7a7db56605da7d8f9b7ab69bc483f27117390ba48 --> <!-- ralph-base:0e38ad26af922abdc0fc36c9379e17efd2a72b80 --> <!-- ralph-head:44a26c1d2824d0e7b33bb343c01310bddd316fa1 --> <!-- ralph-case:6b3b593840e18036483a841d9aa3db7709d152aeae1ea74fedbfbfdad00bebe0 --> [5 additional verified findings in the full report](<https://review.fish.foo/traces/35377-44a26c1d2824d0e7b33bb343c01310bddd316fa1-2192-6.html>). **🟠 Minor · Wallet-held odd-parity keys are missed for x-only Taproot imports** A public-only `tr(X)` import can be rejected despite the wallet holding its private key, because the new lookups match compressed pubkeys exactly and miss odd-Y keys. Location: [`src/wallet/imports.cpp:149`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/44a26c1d2824d0e7b33bb343c01310bddd316fa1/src/wallet/imports.cpp#L149>) (head). **🟠 Minor · Substitution prevents reimport from matching an account-rooted descriptor** Once the master xprv is known, reimporting an existing account-rooted descriptor creates a duplicate manager, so updates and deactivation miss the original. Location: [`src/wallet/imports.cpp:134`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/44a26c1d2824d0e7b33bb343c01310bddd316fa1/src/wallet/imports.cpp#L134>) (head). **🟠 Minor · Failed origin derivation can still trigger substitution** An unsuccessful origin-path derivation still reaches the equality check and can replace an importable expression with an underivable path. Location: [`src/script/descriptor.cpp:1201`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/44a26c1d2824d0e7b33bb343c01310bddd316fa1/src/script/descriptor.cpp#L1201>) (head). **🔵 Suggestion · Every import eagerly retrieves all wallet root keys** Each validated request enumerates every manager under `cs_wallet`, decrypting available roots in encrypted wallets, and every multipath expansion copies the complete xprv map. Location: [`src/wallet/imports.cpp:124`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/44a26c1d2824d0e7b33bb343c01310bddd316fa1/src/wallet/imports.cpp#L124>) (head). **🔵 Suggestion · MuSig participant enumeration also changes HD-key RPC defaults** Returning MuSig participants changes `gethdkeys` output and can make automatic HD-key selection ambiguous, beyond the import behavior this PR targets. Location: [`src/script/descriptor.cpp:1117`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/44a26c1d2824d0e7b33bb343c01310bddd316fa1/src/script/descriptor.cpp#L1117>) (head). **🔵 Suggestion · Public reimports can reset and deactivate the wallet's default descriptor** Reimporting a public default descriptor string now reaches existing state-reset semantics, so omitted activation and index fields can deactivate it and permit address reuse after reactivation. Location: [`src/wallet/imports.cpp:134`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/44a26c1d2824d0e7b33bb343c01310bddd316fa1/src/wallet/imports.cpp#L134>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`44a26c1d2824`](<https://git.fish.foo/bitcoin/bitcoin/commit/44a26c1d2824d0e7b33bb343c01310bddd316fa1>) · [Full review report](<https://review.fish.foo/traces/35377-44a26c1d2824d0e7b33bb343c01310bddd316fa1-2192-6.html>) · [Previous reports](<https://review.fish.foo/traces/35377/>) [permalink](<https://review.fish.foo/traces/35377-44a26c1d2824d0e7b33bb343c01310bddd316fa1-2192-6.html>)
polespinasa (Migrated from github.com) reviewed 2026-09-30 17:45:08 +00:00
polespinasa (Migrated from github.com) left a comment

did a first review, looks pretty good, I have a concept question/suggestion, left a comment below :)

did a first review, looks pretty good, I have a concept question/suggestion, left a comment below :)
polespinasa (Migrated from github.com) commented 2026-09-30 11:36:17 +00:00

in e59a2f2070 descriptor: Implement SubstituteMasterExtPubs

I think this should work and would be cleaner?

if (xpub.id_key_fingerprint() != origin_pub->m_origin.fingerprint) continue;
in e59a2f20702103562cfc6fe574d5470f496c88c2 descriptor: Implement SubstituteMasterExtPubs I think this should work and would be cleaner? ```c++ if (xpub.id_key_fingerprint() != origin_pub->m_origin.fingerprint) continue; ```
polespinasa (Migrated from github.com) commented 2026-09-30 17:34:52 +00:00

in e59a2f2070 descriptor: Implement SubstituteMasterExtPubs

Idk if what I am going to say makes sense but, shouldn't we only compare the pubkey? What if some metadata such as depth, fingerprint, etc. is missing (or is 0)? They key still a valid key but we would silently omit it.
Probably this with Core descriptors will not happen, but should we assume other wallets might miss this data?

in e59a2f20702103562cfc6fe574d5470f496c88c2 descriptor: Implement SubstituteMasterExtPubs Idk if what I am going to say makes sense but, shouldn't we only compare the pubkey? What if some metadata such as depth, fingerprint, etc. is missing (or is 0)? They key still a valid key but we would silently omit it. Probably this with Core descriptors will not happen, but should we assume other wallets might miss this data?
achow101 (Migrated from github.com) reviewed 2026-09-30 17:57:06 +00:00
achow101 (Migrated from github.com) commented 2026-09-30 17:57:06 +00:00

I think we want to be as specific as possible here to avoid any unexpected surprises. Given that changing any of the other fields in an xpub can drastically change how the xpub is encoded, I think it would be surprising to users if something very visually different to their private key magically gets a private key.

I think we want to be as specific as possible here to avoid any unexpected surprises. Given that changing any of the other fields in an xpub can drastically change how the xpub is encoded, I think it would be surprising to users if something very visually different to their private key magically gets a private key.
achow101 (Migrated from github.com) reviewed 2026-09-30 18:06:30 +00:00
achow101 (Migrated from github.com) commented 2026-09-30 18:06:30 +00:00

Done

Done
DrahtBot commented 2026-09-30 19:04:58 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task iwyu: https://github.com/bitcoin/bitcoin/actions/runs/36756207544/job/110026972644
LLM reason (✨ experimental): CI failed because the IWYU lint step (Fixing #includes) detected missing/incorrect includes and returned a failure (“Failure generated from IWYU”).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `iwyu`: https://github.com/bitcoin/bitcoin/actions/runs/36756207544/job/110026972644</sub> <sub>LLM reason (✨ experimental): CI failed because the IWYU lint step (Fixing #includes) detected missing/incorrect includes and returned a failure (“Failure generated from IWYU”).</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
DrahtBot commented 2026-10-07 12:46:20 +00:00 (Migrated from github.com)

Could turn into draft while CI is red?

Could turn into draft while CI is red?
fametrano commented 2026-10-22 08:35:31 +00:00 (Migrated from github.com)

Tested b58383aca6: with the master key in the wallet, re-importing a descriptor the wallet already holds adds a duplicate.

I computed 20 vectors with a separate BIP32 implementation and imported them on regtest. They cover hardened, unhardened and mixed origins, the master as origin, a wrong fingerprint, the right fingerprint with a wrong path, <0;1>, hardened steps after the xpub, tr() script paths and wsh(multi) with a foreign key. 19 succeed or fail as expected, and their substituted descriptors derive the addresses I computed. The 20th led to the case below.

A wallet imports wpkh([fpM/84h/1h/0h]xprvA/0/*), then pkh(xprvM/0/*). Importing that wpkh again, public or private, stores wpkh(xprvM/84h/1h/0h/0/*). Its descriptor ID is new, so listdescriptors lists the same public descriptor twice. With the master imported first, the first private wpkh import is already stored that way. Either way the private export carries the master key where the user gave an account key. Matching the wallet's exact xpub before the master would avoid the duplicate. Keeping the origin with the derived xprv would also keep the descriptor as given. The IWYU failure is this PR's: the new KeyFingerprint comparison needs #include <array> in descriptor.cpp. The vectors and script are available.

Tested b58383aca6: with the master key in the wallet, re-importing a descriptor the wallet already holds adds a duplicate. I computed 20 vectors with a separate BIP32 implementation and imported them on regtest. They cover hardened, unhardened and mixed origins, the master as origin, a wrong fingerprint, the right fingerprint with a wrong path, `<0;1>`, hardened steps after the xpub, `tr()` script paths and `wsh(multi)` with a foreign key. 19 succeed or fail as expected, and their substituted descriptors derive the addresses I computed. The 20th led to the case below. A wallet imports `wpkh([fpM/84h/1h/0h]xprvA/0/*)`, then `pkh(xprvM/0/*)`. Importing that `wpkh` again, public or private, stores `wpkh(xprvM/84h/1h/0h/0/*)`. Its descriptor ID is new, so `listdescriptors` lists the same public descriptor twice. With the master imported first, the first private `wpkh` import is already stored that way. Either way the private export carries the master key where the user gave an account key. Matching the wallet's exact xpub before the master would avoid the duplicate. Keeping the origin with the derived xprv would also keep the descriptor as given. The IWYU failure is this PR's: the new `KeyFingerprint` comparison needs `#include <array>` in `descriptor.cpp`. The vectors and script are available.
DrahtBot (Migrated from github.com) reviewed 2026-11-04 07:49:24 +00:00
DrahtBot (Migrated from github.com) commented 2026-11-04 07:47:24 +00:00
  • harded derivation -> hardened derivation [“harded” is misspelled]
* harded derivation -> hardened derivation [“harded” is misspelled]
DrahtBot (Migrated from github.com) commented 2026-11-04 07:48:20 +00:00
  • xpub substition -> # xpub substitution [“substition” is misspelled]
* xpub substition -> # xpub substitution [“substition” is misspelled]
DrahtBot (Migrated from github.com) commented 2026-11-04 07:48:23 +00:00

same

same
achow101 commented 2026-11-05 00:29:01 +00:00 (Migrated from github.com)

A wallet imports wpkh([fpM/84h/1h/0h]xprvA/0/), then pkh(xprvM/0/). Importing that wpkh again, public or private, stores wpkh(xprvM/84h/1h/0h/0/*)

While we do our best to avoid importing duplicates, importing a duplicate is not world ending and this sort of duplication issue is one that we are not interested in solving. There are a variety of ways that a single descriptor can be textually represented and we cannot cover all cases where there may be duplication.

> A wallet imports wpkh([fpM/84h/1h/0h]xprvA/0/*), then pkh(xprvM/0/*). Importing that wpkh again, public or private, stores wpkh(xprvM/84h/1h/0h/0/*) While we do our best to avoid importing duplicates, importing a duplicate is not world ending and this sort of duplication issue is one that we are not interested in solving. There are a variety of ways that a single descriptor can be textually represented and we cannot cover all cases where there may be duplication.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35377
No description provided.