Review report

core: PR #36154

2 minor findings · 3 suggestions

Findings

Link

[minor] · Conflicting global xpub origins produce an unparseable PSBT

When an input PSBT and the wallet assign different origins to the same xpub, walletprocesspsbt can report success while returning a PSBT that Core cannot parse.

Location: src/wallet/scriptpubkeyman.cpp:1519 (head).

Details and suggested fix

AddGlobalXpubs deduplicates xpubs only within each origin. Serialization therefore writes two PSBT_GLOBAL_XPUB records with the same key when the input PSBT and wallet descriptor assign different origins to one xpub. Deserialization rejects the duplicate key, so the returned PSBT fails in decodepsbt, a later walletprocesspsbt or combinepsbt, and other BIP 174 parsers. This can arise, for example, when one PSBT records a bare xpub and a signer uses a descriptor with its full origin. Apply the cross-origin duplicate check used by MergeGlobalXPubs before inserting xpubs here, and add a round-trip test with conflicting origins. No production PSBT with conflicting origins was observed, so the frequency of this case is unconfirmed.


Link

[minor] · Global xpub records can have paths that do not match key depth

Descriptors with bare xpubs or partial origins produce nonconforming PSBT_GLOBAL_XPUB records; no parser that rejects them was verified.

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

Details and suggested fix

BIP 174 requires the derivation path length in a PSBT_GLOBAL_XPUB value to match the extended public key's depth. GetExtPubKeysWithOrigins does not check this: without a hardened step, it publishes the xpub with its own fingerprint and an empty path, whatever its depth; descriptor origins are prepended without checking the resulting path length. The new tests include empty paths for depth-4 and depth-1 keys, a one-element path for a depth-4 key, and a three-element path for a depth-7 key. AddGlobalXpubs counts these records toward its threshold, so a multisig imported with bare account xpubs can emit only nonconforming records. Core's decoder does not check the depth, and no rejecting external parser was verified. Skip entries whose complete origin path length differs from xpub.nDepth, and exclude them from the count. This avoids nonconforming output but loses metadata that tools using Core's own-fingerprint convention could match. Test absent, partial, and complete origins.


Optional improvements

Link

[suggestion] · Default global xpub disclosure cannot be disabled in several send paths

PSBTs from multi-key descriptors can reveal enough to derive all descriptor addresses, and send, sendall, psbtbumpfee, and the GUI provide no option to omit the xpubs.

Location: src/wallet/scriptpubkeyman.cpp:1492 (head).

Details and suggested fix

The published xpub is the root or the key at the last hardened step, including its chain code. Anyone holding the PSBT can derive every unhardened child; for example, [fp/48h/1h/0h/2h]xpub/0/* exposes both the /0/* and /1/* chains. Before this change, per-input and per-output derivations revealed only the pubkeys and paths actually used. Publication requires contributes_to_psbt && options.bip32_derivs; any wallet-owned output sets contributes_to_psbt, so processing another party's PSBT that only pays this wallet can add the descriptor's account xpubs. bip32derivs defaults to true, and send, sendall, psbtbumpfee, and the GUI hard-code it to true. Add a separate option, such as include_global_xpubs, and honor it in those callers if PSBTs should not disclose account xpubs by default. If disclosure by default is intended, document that recipients can derive all descriptor addresses and that these send paths always include the field. Co-signers who already hold the descriptor learn nothing new; the open question is whether PSBTs that may reach others should carry these xpubs by default.


Link

[suggestion] · MuSig comment misstates how ranged participant xpubs derive transaction keys

In musig() descriptors with ranged participants, participant xpubs derive keys listed in the PSBT, contrary to the comment's explanation for publishing none.

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

Details and suggested fix

The comment says derivation is applied to the aggregate key, not the participants. That applies only to the musig(...)/path/* form. In musig(xpubA/0/*,xpubB/0/*), MuSigPubkeyProvider::GetPubKey derives each participant at pos, records their origins in the signing provider, and aggregates the derived keys. Those participant xpubs therefore derive keys listed in the PSBT, consistent with BIP 174's definition of PSBT_GLOBAL_XPUB. Either narrow the comment to the derive-after-aggregate form and state that ranged participants are intentionally omitted, or forward the ranged participants. Add a unit test for the ranged-participant form.


Link

[suggestion] · Tests do not cover cache-only global xpub generation

The tests do not verify the cache path used to derive hardened xpubs when an encrypted wallet is locked, so a regression could silently omit the metadata.

Location: src/test/descriptor_tests.cpp:1438 (head).

Details and suggested fix

AddGlobalXpubs passes GetKeys() and the descriptor cache to the accessor. A locked encrypted wallet provides no keys, so a hardened descriptor such as xprv/48h/1h/0h/2h/0/* must obtain its hardened xpub from the cache; walletcreatefundedpsbt does not require unlocking. The new unit tests pass no cache, the PSBT wallet tests use unencrypted xprvs, and the functional tests use account xpubs without hardened suffixes. wallet_listdescriptors.py exercises the shared lookup through ToNormalizedString, not this accessor or the cache argument in AddGlobalXpubs. Add a cache-only unit case that expands a hardened descriptor using its private provider, then calls the accessor with an empty provider and the cache and checks the xpub bytes, version, and origin. A functional test using a locked encrypted multisig participant would also cover this path.


Coverage details