AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Low 49 Bitcoin

Merge bitcoin/bitcoin#35665: psbt: avoid duplicate global xpub keys when merging

Public commit record

What the developer wrote

Authored by Ava Chow

91/100 · Strong
Merge bitcoin/bitcoin#35665: psbt: avoid duplicate global xpub keys when merging

6d387af562fc85eee003a269dbea10963e941985 psbt: remove write-only global xpub tracking set (Thomas)
3b7051c7e3388727402eeffe15a0df86e3c0de3c test: check combinepsbt with conflicting global xpub origins (Thomas)
7c632c0e2a2ef604cc5bca682935ee519cfbad8e psbt: avoid duplicate global xpub keys when merging (Thomas)

Pull request description:

Global xpubs are stored in a map of key origin to set of xpubs, while the serialization writes one record per xpub, keyed by the xpub. `Merge` unions the map origin-by-origin, so when the combined PSBTs provide different key origins for the same xpub, the result serializes the same `PSBT_GLOBAL_XPUB` key twice. BIP 174 declares PSBTs with duplicate keys invalid and the deserializer rejects them, so `combinepsbt` returns a PSBT that no RPC can parse again. This affects all releases since the merge loop was added in #17034 (v23.0).

<details><summary>Reproduction on master</summary>

The PSBTs share the unsigned transaction and xpub, and differ only in the master fingerprint of the global xpub record (`00000000` vs `11111111`):

```
$ A=cHNidP8BADwCAAAAAaqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqAAAAAAD/////AQAAAAAAAAAAAAAAAABPAQQ1h88AAAAAAAAAAACHPf+BwC9SViP9H+UWfqw6VaBJ3j0xS7Qu4if/7TfVCAM5o2ATMBWX2u9B++WToCzFE9C1VSfsLfEFDi6P9JyFwgQAAAAAAAAA
$ B=cHNidP8BADwCAAAAAaqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqAAAAAAD/////AQAAAAAAAAAAAAAAAABPAQQ1h88AAAAAAAAAAACHPf+BwC9SViP9H+UWfqw6VaBJ3j0xS7Qu4if/7TfVCAM5o2ATMBWX2u9B++WToCzFE9C1VSfsLfEFDi6P9JyFwgQRERERAAAA
$ bitcoin-cli -regtest decodepsbt "$(bitcoin-cli -regtest combinepsbt "[\"$A\",\"$B\"]")"
error code: -22
error message:
TX decode failed Duplicate Key, global key "01043587cf00...9c85c2" already provided: iostream error
```

</details>

Deduplicate by xpub when merging, keeping the origin that is already present: BIP 174 lets the Combiner "pick arbitrarily when conflicts occur", and conflicting unknown and proprietary records are already resolved the same way. The logic is shared between `combinepsbt` and `joinpsbts` through a new `MergeGlobalXPubs` helper. The second commit adds a test that fails on master with the error above, and the last commit removes the `global_xpubs` tracking set in `Unserialize`, write-only since the generic duplicate key check introduced in #21283 (1e2d146b47) replaced the explicit one.

Note: the xpub loop in `joinpsbts` currently has no observable effect, since the collected xpubs never reach the returned PSBT. My #35516 fixes that, so this PR should land first: on its own, #35516 would make the same duplicate key issue reachable through `joinpsbts`, while with the shared helper in place it never becomes reachable. I will rebase #35516 on top afterwards.

ACKs for top commit:
Bicaru20:
tACK 6d387af562.
achow101:
ACK 6d387af562fc85eee003a269dbea10963e941985
winterrdog:
tACK 6d387af562fc85eee003a269dbea10963e941985

Tree-SHA512: e2a9e02617eeec22a9240d7cf9386ee880a5f3639b143df7de4d8ea3e7b808f8c123f0b0410ff4a22e9a564bd86b2335a5c4aa3b2281af47d111484a6f1fd108
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a bug in Bitcoin Core's PSBT (Partially Signed Bitcoin Transaction) merging code. When two PSBTs contained the same extended public key (xpub) but with different key origin metadata, the merge would create a result that serialized the same xpub key twice. Because the PSBT standard forbids duplicate keys, the merged PSBT could not be decoded by any Bitcoin Core RPC afterward. The fix deduplicates by xpub during merging, keeping the first origin encountered. It is a correctness/denial-of-service bug rather than a theft-of-funds vulnerability.

Recommended action

No immediate emergency action is required; this is a correctness bug, not a critical exploit. Users and downstream projects should apply the patch and ensure they are not relying on merged PSBTs that may have been rendered unparseable. Wallet and PSBT-tooling maintainers should review their own merge/deduplication logic for similar origin-vs-xpub mismatch issues.

Security signals we found

01

Fixes a bug that caused combinepsbt to produce an unparseable PSBT

02

BIP 174 duplicate-key violation in serialized output

03

Shared merge logic between combinepsbt and joinpsbts

04

Removal of dead duplicate-tracking code in deserialization

05

Functional test demonstrates real reproduction vector

Risk score

Why this scored 49/100

Our methodology →
Potential impact 12/30
Exploitability 8/25
Stealth signal 5/15
Affected reach 10/15
Confidence 9/10
Evidence quality 5/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.