mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:11:37 +00:00
wallet: Allow importing of descriptors without private keys when the wallet has the private keys #35377
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!35377
Loading…
Reference in a new issue
No description provided.
Delete branch "importdescriptors-without-priv"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
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.
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:
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
Definite Concept ACK 2e6d8d0 because it allows the users to not deal with private keys manually.
seems like a good idea, concept ACK
Will review after #34861 is merged
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/27453755862/job/81154189319LLM reason (✨ experimental): CI failed because IWYU reported a header include issue (it modified
src/script/descriptor.hand 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.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/31056225146/job/92474198450LLM reason (✨ experimental): CI failed due to a C++ build error in
src/script/descriptor.cpp(invalid access toMuSigPubkeyProvider::m_participantsplus a relatedstd::equalcompilation 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.
🐙 This pull request conflicts with the target branch and needs rebase.
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.
An alternative approach, using bits of #36133, is to give
Parseaccess 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.
🐙 This pull request conflicts with the target branch and needs rebase.
🐙 This pull request conflicts with the target branch and needs rebase.
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
gethdkeysoutput 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 reportspermalink
did a first review, looks pretty good, I have a concept question/suggestion, left a comment below :)
in
e59a2f2070descriptor: Implement SubstituteMasterExtPubsI think this should work and would be cleaner?
in
e59a2f2070descriptor: Implement SubstituteMasterExtPubsIdk 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?
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.
Done
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/36756207544/job/110026972644LLM 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.
Could turn into draft while CI is red?
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 andwsh(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/*), thenpkh(xprvM/0/*). Importing thatwpkhagain, public or private, storeswpkh(xprvM/84h/1h/0h/0/*). Its descriptor ID is new, solistdescriptorslists the same public descriptor twice. With the master imported first, the first privatewpkhimport 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 newKeyFingerprintcomparison needs#include <array>indescriptor.cpp. The vectors and script are available.same
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.