Skip to content

Respect PSBT_GLOBAL_TX_MODIFIABLE in PSBT2.CoinJoin - #1364

Merged
NicolasDorier merged 1 commit into
MetacoSA:masterfrom
allenpiscitello:fix/psbt2-coinjoin-modifiable
Oct 27, 2026
Merged

NicolasDorier merged 1 commit into
MetacoSA:masterfrom
allenpiscitello:fix/psbt2-coinjoin-modifiable

Conversation

@allenpiscitello

Copy link
Copy Markdown
Contributor

BIP 370 says a Constructor must check PSBT_GLOBAL_TX_MODIFIABLE before adding inputs or outputs. PSBT2.CoinJoin adds both without checking, so it can merge into a PSBT whose flags say it is closed, for example after a SIGHASH_ALL signature.

CoinJoin now throws when it would add inputs while Inputs Modifiable is clear, or add outputs while Outputs Modifiable is clear. It uses the same messages as AddInput and AddOutput. Only the side that is actually added to is checked, so merging a PSBT with outputs but no inputs works when only outputs are open.

As in AddInput and AddOutput, a PSBT without the field is not restricted. BIP 370 allows that field to be omitted both while a single Constructor is still adding and to mark a PSBT closed, so I kept NBitcoin's existing reading. The SIGHASH_SINGLE pairing rule (bit 2) is not handled here.

New tests cover each flag and the case where nothing is added to the closed side. The PSBT, Miniscript and Taproot tests pass on net10.0, except the ones that download bitcoind, which fail the same way without this change.

🤖 Generated with Claude Code

BIP 370 requires a Constructor to check PSBT_GLOBAL_TX_MODIFIABLE before
adding inputs or outputs. PSBT2.CoinJoin added both without checking, so
it could merge into a PSBT whose flags say it is closed, for example
after a SIGHASH_ALL signature.

CoinJoin now throws when it would add inputs and Inputs Modifiable is
clear, or add outputs and Outputs Modifiable is clear, with the same
messages as AddInput and AddOutput. As in those methods, a PSBT without
the field is not restricted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NicolasDorier
NicolasDorier merged commit 2d69010 into MetacoSA:master Oct 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants