mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
psbt: check sig sighash only if a type is given #36577
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36577
Loading…
Reference in a new issue
No description provided.
Delete branch "psbt-taproot-sighash-absent"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
SignPSBTInput() checked existing signatures against an assumed sighash type when neither PSBT_IN_SIGHASH_TYPE nor the sighashtype parameter was given: SIGHASH_DEFAULT for taproot, SIGHASH_ALL otherwise. A PSBT holding a valid 65-byte SIGHASH_ALL taproot signature could then be neither finalized nor signed further.
BIP 174 lets a signer use any sighash type when the field is absent, so the check now runs only when the field or the parameter is given, for every input type. Without the field, RemoveUnnecessaryTransactions() now also looks at the taproot signatures for SIGHASH_ANYONECANPAY, so that the non_witness_utxo is kept. A functional test in rpc_psbt.py covers a taproot input signed with ALL, NONE and ALL|ANYONECANPAY without the field. A second commit also keeps the non_witness_utxo of a finalized taproot input, whose signatures are left only in the final witness, and tests it on a key path and a script path.
Fixes #36507.
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.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
encryptwalletRPC for encrypting existing wallets. by davidgumberg)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.
🔵 Suggestion · Missing signature masks DEFAULT-field finalizer rejection
The finalizer assertion uses a one-signature 2-of-2 PSBT, so it stays incomplete even if the DEFAULT-field mismatch check is bypassed.
Location:
test/functional/rpc_psbt.py:789(head).🔵 Suggestion · Fieldless non-ALL ECDSA signatures lack regression coverage
The new tests do not exercise acceptance of non-ALL ECDSA partial signatures when both the PSBT sighash field and RPC argument are absent.
Location:
test/functional/rpc_psbt.py:758(head).🔵 Suggestion · RPC help omits the explicit-default sighash distinction
For a fieldless, unfinalized PSBT, explicitly passing the usual signing default can reject a cosigner's signature that an omitted argument accepts, but neither processing RPC's help explains the distinction.
Location:
src/psbt.cpp:709(head).🔵 Suggestion · Fieldless unfinalized Taproot key signatures lack coverage
The key-path fixture finalizes its first signature, so reprocessing tests final-witness retention rather than the relaxed check or retention rule for an existing
m_tap_key_sig.Location:
test/functional/rpc_psbt.py:805(head).🔵 Suggestion · Final-witness tests never exercise annex removal
Core's signer produces annex-free witnesses, so deleting the new annex-stripping branch would not affect the added retention tests.
Location:
src/psbt.cpp:791(head).🔵 Suggestion · Second signer's DEFAULT sighash is not asserted
The mixed-sighash test would also accept signer2 copying signer1's type, including NONE, because it checks completion and mempool acceptance but not signer2's signature encoding.
Location:
test/functional/rpc_psbt.py:778(head).Review coverage was incomplete.
Reviewed:
f169a27f3adf· Full review report · Previous reportspermalink
Tested ACK
1291d0e389on Windows.Approach ACK / tACK 1291d0e
Good fix for the referenced issue.
When
sighash_typeis unset, accepting 65-byte Taproot signatures ending inSIGHASH_ALLis safe because it commits to the identical BIP-341 digest asSIGHASH_DEFAULT.Preserving rejection for other variants keeps Core's safety checks intact.
Tested on Ubuntu 24.04:
psbt_testspassed (including both new absent-field tests).rpc_psbt.pypassed cleanly too.Please replace your unit tests with functional tests. We prefer functional tests for PSBTs.
In
1291d0e389"psbt: accept taproot ALL sigs with sighash unset"I think it would be better to rewrite these checks to be dependent on the presence of the field and/or parameter, rather than assuming something about the sighash value. Allowing SIGHASH_ALL for a SIGHASH_DEFAULT seems like there is a possibility for another bug given that the sighash type is encoded into the signature message itself.
Done: existing signatures' sighash types are now checked only when PSBT_IN_SIGHASH_TYPE or the sighashtype parameter is given. Without either, any type is accepted, on non-taproot inputs too, as BIP 174 allows. As you suggest, this replaces the rule I argued for on #36558, which accepted only ALL besides DEFAULT. RemoveUnnecessaryTransactions also finds ANYONECANPAY in taproot signatures. The unit tests became a functional test.
Once a taproot input is finalized, its sighash type field and its taproot signatures are no longer serialized, so a later
utxoupdatepsbtorwalletprocesspsbtdrops its non_witness_utxo even when it was signed with ANYONECANPAY. The second commit also reads the signatures in the final witness, through the same check as the first commit.re-ACK
f169a27f3Verified range-diff against
1291d0e. The extra commit for finalized ANYONECANPAY witness signatures looks good, tests pass.🐙 This pull request conflicts with the target branch and needs rebase.