Repository navigation
Commit 59391d5
Merge bitcoin#35984: sign: skip signing SIGHASH_SINGLE inputs with no corresponding output
8df006f wallet: skip signing SIGHASH_SINGLE inputs with no corresponding output (furszy)
Pull request description:
`SIGHASH_SINGLE` only commits to the output at the input's index. If the output at such
position doesn't exist, it commits to no output at all (legacy uses a fixed sighash of 1, segwit
v0 zeroes `hashOutputs`), which means the signature stays valid even when outputs are
swapped, which is a footgun that lets funds be redirected without the owner's consent.
`SignTransaction()` already skipped these inputs, but `SignPSBTInput()` did not, so
`walletprocesspsbt` signed them. This moves the check into the `CreateSig` so both
paths, and any future one, skip producing the detached signature.
Note: if there is a valid use for the segwit v0 case, I would rather re-allow it through
an explicit opt-in arg than by default, so it is always a deliberate choice.
Fixes bitcoin#35977
ACKs for top commit:
thomasbuilds:
ACK 8df006f
achow101:
ACK 8df006f
Tree-SHA512: ac1c9659910eae889475c65b8dde68e711c4d85d0d520af06411728591e573bf027b41a9ac6dd0f6e93de425841ac6c7d9e6c9f07936b9d8ae390941fbe6f1f1
BACKPORT NOTE:
- src/script/sign.cpp: Dash has no SignOptions or SIGHASH_DEFAULT, so the
check uses nHashType. Dash also has no SIGHASH_OUTPUT_MASK (added with
Taproot), so it tests (nHashType & 0x1f), the same test Dash's legacy
SignatureHash uses for SIGHASH_SINGLE. For every sighash the wallet can
sign with (ALL/NONE/SINGLE, optionally |ANYONECANPAY) this matches
upstream's (hashtype & SIGHASH_OUTPUT_MASK).
- test/functional/rpc_psbt.py, test_sighash_single():
- No loop over legacy/bech32/bech32m address types; Dash only has P2PKH.
Instead the test covers SINGLE, SINGLE|ANYONECANPAY and ALL (control),
and also checks signrawtransactionwithwallet, because this change
removes SignTransaction's own SIGHASH_SINGLE check and Dash had no test
for that path.
- It runs after test_input_confs_control; Dash has none of the sighash
tests upstream places it next to.
- Omitted: the test_psbt_roundtrip and test_psbt_version UTXO selection
changes; those tests (PSBTv2) do not exist in Dash.
Co-authored-by: Ava Chow <github@achow101.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent f35a24c commit 59391d5
2 files changed
Lines changed: 39 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
40 | 45 | | |
41 | 46 | | |
42 | 47 | | |
| |||
400 | 405 | | |
401 | 406 | | |
402 | 407 | | |
403 | | - | |
404 | | - | |
405 | 408 | | |
406 | 409 | | |
407 | 410 | | |
| |||
437 | 440 | | |
438 | 441 | | |
439 | 442 | | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
| 443 | + | |
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
111 | 143 | | |
112 | 144 | | |
113 | 145 | | |
| |||
441 | 473 | | |
442 | 474 | | |
443 | 475 | | |
| 476 | + | |
444 | 477 | | |
445 | 478 | | |
446 | 479 | | |
| |||
0 commit comments