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

Closed
brunoerg wants to merge 1 commit from 2026-04-external-signer into master AGit
brunoerg commented 2026-05-22 12:31:49 +00:00 (Migrated from github.com)

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.

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 commented 2026-05-22 12:31:56 +00:00 (Migrated from github.com)

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

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/35358 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/35358.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/35358#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. A summary of reviews will appear here. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36114](https://github.com/bitcoin/bitcoin/pull/36114) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36114.svg"></sub> (wallet: harden external signer psbt processing, revamp mock by Sjors) * [#35433](https://github.com/bitcoin/bitcoin/pull/35433) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35433.svg"></sub> (wallet: deprecate replaceable argument from transaction (and psbt) creation (and modification) RPCs by rkrux) * [#33112](https://github.com/bitcoin/bitcoin/pull/33112) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33112.svg"></sub> (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. <!--5faf32d7da4f0f540f40219e4f7537a3--> ### 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` <sup>2026-05-22 13:11:37</sup>
junbyjun1238 commented 2026-05-23 08:14:03 +00:00 (Migrated from github.com)

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?

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 commented 2026-05-27 21:45:04 +00:00 (Migrated from github.com)

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.

> 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 commented 2026-08-28 11:28:00 +00:00 (Migrated from github.com)

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

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

Base: cf80493e2367786ce9946c522eb8313a52c90557
Head: e5ca77ed5049ec273bb11a441ca86d9389507f66

No verified findings are available from this partial review.

Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review had incomplete evidence. Verifier output failed validation; no findings were published.

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> Base: `cf80493e2367786ce9946c522eb8313a52c90557` Head: `e5ca77ed5049ec273bb11a441ca86d9389507f66` No verified findings are available from this partial review. Review coverage was incomplete. The archaeology review had incomplete evidence. The adversarial review had incomplete evidence. The adversarial_glm review had incomplete evidence. Verifier output failed validation; no findings were published. [Full review report](<https://review.fish.foo/traces/35358-e5ca77ed5049ec273bb11a441ca86d9389507f66-454-1.html>)
sedited commented 2026-10-09 12:36:47 +00:00 (Migrated from github.com)

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

@brunoerg do you want to close this and continue in #36114? Or is the plan to work on this first?
brunoerg commented 2026-10-09 12:47:55 +00:00 (Migrated from github.com)

@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 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.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!35358
No description provided.