Skip to content

external signer: verify PSBT is reliable after signing it - #35358

Closed
brunoerg wants to merge 1 commit into
bitcoin:masterfrom
brunoerg:2026-04-external-signer
Closed

brunoerg wants to merge 1 commit into
bitcoin:masterfrom
brunoerg:2026-04-external-signer

Conversation

@brunoerg

@brunoerg brunoerg commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Seeking Concept ACK

A compromised or "rogue" external signer could return a PSBT with silently altered outputs or use unsafe sighash types that do not commit to all outputs (perhaps unlikely, but a buggy signer could also change it). This PR adds a post-signing validation step in External::SignTransaction that compares the signed PSBT returned by the external signer against the original one before accepting it. Without these checks, it is not super friendly (e.g. using RPC) to manually verify the same.

Note: the added tests were partially vibe-coded.

@DrahtBot

DrahtBot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

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.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36114 (wallet: harden external signer psbt processing, revamp mock by Sjors)
  • #35433 (wallet: deprecate replaceable argument from transaction (and psbt) creation (and modification) RPCs by rkrux)
  • #33112 (wallet: relax external_signer flag constraints by Sjors)

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 places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • walletcreatefundedpsbt([], {dest: 0.5}, 0, {...}, True) in test/functional/wallet_signer.py

2026-05-22 13:11:37

@brunoerg
brunoerg force-pushed the 2026-04-external-signer branch from a87fd29 to e5ca77e Compare May 22, 2026 13:11
@junbyjun1238

Copy link
Copy Markdown
Contributor

Should SIGHASH_ALL | SIGHASH_ANYONECANPAY really be considered safe here?

The PR protects outputs, and ANYONECANPAY|ALL does commit to all
outputs. But ANYONECANPAY also means the signed input can be included
in a larger transaction with additional inputs that the wallet did not
authorize. If the expected sighash is SIGHASH_ALL (or SIGHASH_DEFAULT
for taproot), a rogue signer silently downgrading to ANYONECANPAY|ALL
would pass this check while producing a signature with strictly weaker
commitment.

Is allowing ANYONECANPAY an intentional design choice here, or should
the check require the returned sighash to match the PSBT's per-input
sighash field when present, and fall back to the default policy otherwise?

@achow101

achow101 commented May 27, 2026 •

Copy link
Copy Markdown
Member

Should SIGHASH_ALL | SIGHASH_ANYONECANPAY really be considered safe here?

Yes.

It is not a problem for us if someone else adds more inputs. We only care that the inputs we want spend and the outputs we want to send to are all in the transaction. If someone else adds more inputs, the inputs we want to spend are still there, and the outputs we want to create are still committed to. There is no effect to the wallet, hence it is safe.


Concept OK I guess

I think we generally assume an external signer to be more trusted/secure, so we don't really do checks on their output. An external signer can always leak private keys or steal the user's coins and there isn't much we can do about it.

@Sjors

Sjors commented Aug 28, 2026

Copy link
Copy Markdown
Member

I absorbed this into #36114, which revamps the external signer mock in a way that makes this stuff easier to test.

@sedited

sedited commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

@brunoerg do you want to close this and continue in #36114? Or is the plan to work on this first?

@brunoerg

brunoerg commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@brunoerg do you want to close this and continue in #36114? Or is the plan to work on this first?

Yes, I can close this and focus in #36114. I'm going to review that.

@brunoerg brunoerg closed this Oct 9, 2026
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.

6 participants