2 minor findings · 4 suggestions
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · Reimporting an account-rooted descriptor can create a duplicate manager
After the wallet learns the master xprv, reimporting an account-rooted descriptor can create a second manager, so active=false may report success without deactivating the original.
Location: src/wallet/imports.cpp:134 (head).
Details and suggested fix
Suppose the wallet stores wpkh([fp/84h/1h/0h]acct_xprv/0/*) before it knows the master key. Later, the master xprv becomes known, for example through addhdkey or another import. Reimporting the descriptor then calls SubstituteMasterExtPubs, which rewrites it as master_xpub/84h/1h/0h/0/* before AddWalletDescriptor checks for an existing manager. Because canonical comparison does not equate these expressions, the wallet creates a second manager instead of updating the original. With active=false, deactivation targets the new manager, not the active original. Range updates also target the duplicate, bypassing the existing range-narrowing check. The base code did not rewrite the expression, so it matched and updated the existing manager. Before rewriting, look for an existing manager using the parsed descriptor; if one exists, preserve that expression and add only the derived signing keys. No current caller or test producing this later-master-key sequence was identified, so production frequency is unconfirmed.
[minor] · Odd-parity x-only Taproot keys are not matched to wallet-held private keys
Importing tr(X) for a key the wallet holds can fail for odd-Y keys because the x-only key is represented with even parity.
Location: src/wallet/imports.cpp:149 (head).
Details and suggested fix
A 32-byte key in tr() is parsed as 02||X. The wallet stores private keys under the real compressed pubkey, which is 03||X for an odd-Y key. Because GetKnownKeys and this lookup use exact CPubKey matches, the lookup misses and does not add the key. The import is then rejected with "Cannot import descriptor without private keys to a wallet with private keys enabled", or stored without that key with only the generic warning. This affects cases such as importing wpkh(WIF) followed by tr(X), reimporting the wallet's own tr(WIF) descriptor in the public x-only form printed by listdescriptors, and reloading a serialized tr(WIF) descriptor, which is stored as tr(X). ConstPubkeyProvider handles x-only keys with GetKeyByXOnly, which tries both parity IDs. Apply equivalent x-only lookup in both GetKnownKeys and this lookup, insert the key under key.GetPubKey().GetID(), and retain exact matching for non-x-only keys. The new test uses a 33-byte key in tr(), so it does not cover this path.
Optional improvements
[suggestion] · MuSig participants change gethdkeys results and HD-key defaulting
Including MuSig participant xpubs in GetPubKeys changes RPC results and can make createwalletdescriptor or derivehdkey unable to select a default key, but the change has no MuSig coverage, release note, or stated rationale.
Location: src/script/descriptor.cpp:1117 (head).
Details and suggested fix
GetPubKeys now returns the root keys of musig() participants. Since CWallet::GetHDPubKeys uses GetPubKeys, gethdkeys now lists participant xpubs for wallets with MuSig descriptors, including cosigner xpubs for which the wallet has no private key. Without an hdkey, createwalletdescriptor requires exactly one active xpub and derivehdkey allows at most one; with an active tr(musig(...)) descriptor, either RPC can fail with "Unable to determine which HD key to use from active descriptors". This matches how wsh(multi()) keys already appear and may be intended, but wallet_gethdkeys.py has no MuSig case and there is no release note or stated rationale. If this change is intended, add gethdkeys and createwalletdescriptor coverage with a MuSig descriptor and a release note. Otherwise, collect participants only in the import path.
[suggestion] · Batch imports repeatedly copy and decrypt wallet root keys
Each import request retrieves all wallet root keys while holding cs_wallet, so batch work grows with requests times root keys even when requests already contain their private keys.
Location: src/wallet/imports.cpp:124 (head).
Details and suggested fix
ImportDescriptor calls GetKnownKeys for every request, and ProcessDescriptorsImport processes each request while holding cs_wallet. GetKnownKeys walks every ScriptPubKeyMan and calls GetKey for each root key; on an unlocked encrypted wallet, each call decrypts the key. A batch therefore repeats work proportional to requests times root keys, even when the requests already include all their private keys. Migrated legacy wallets with one combo() descriptor per loose key are the largest case. In addition, SubstituteMasterExtPubs takes its xprv map by value, causing another full private-key-map copy for each parsed multipath expansion. Pass the map by const& and keep one key inventory for the batch, adding keys from each successful import so later requests can use them. This preserves the behavior that test_musig_private_key_warnings now relies on. The wall-clock cost has not been measured.
[suggestion] · MuSig missing-participant-key warnings are no longer covered
Removing two assertions leaves no test for the MuSig missing-participant-key warning, while the batch-key reuse behavior is also unasserted.
Location: test/functional/wallet_importdescriptors.py:296 (head).
Details and suggested fix
Request 0 imports acc_xprv2. The per-request GetKnownKeys call now includes MuSig participants, so requests 1 and 3 receive that key and no longer warn; the removed MISSING_KEYS_WARNING assertions were not replaced. The remaining checks for this warning use non-MuSig descriptors, and in the new test_import_noprivs cases it comes from the unknown internal key. Neither reuse of keys from earlier requests in the batch nor the original MuSig warning path is asserted. Assert that res[1] and res[3] have no warnings to cover batch reuse, and add requests using an unknown participant xpub, such as acc_xpub3, that assert MISSING_KEYS_WARNING.
[suggestion] · SubstituteMasterExtPubs comment misstates what the function does
The comment says the function replaces public keys with private keys, but it rewrites matching origin-and-xpub expressions to master-xpub expressions and adds no private keys.
Location: src/script/descriptor.h:215 (head).
Details and suggested fix
The function acts only on an OriginPubkeyProvider wrapping a BIP32PubkeyProvider. When a supplied master xprv has the origin fingerprint and derives to the xpub, it replaces the expression with a BIP32PubkeyProvider based on the master xpub and combined derivation path. It leaves single pubkeys unchanged and adds no private keys to the descriptor; ImportDescriptor adds those separately. The comment could therefore lead callers to assume the descriptor can produce private keys. Describe the actual expression rewrite and note that the function does not add private keys.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Define the scope of literal-key matching for wallet-held HD keys