Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
Tested ACK 1291d0e on Windows. |
|
Approach ACK / tACK 1291d0e Good fix for the referenced issue. Tested on Ubuntu 24.04:
|
achow101
left a comment
There was a problem hiding this comment.
Please replace your unit tests with functional tests. We prefer functional tests for PSBTs.
| // so a taproot signature with an explicit SIGHASH_ALL is also accepted. | ||
| const auto sig_matches = [&](const std::vector<unsigned char>& sig) { | ||
| return sig.size() == 64 || (!sighash_specified && sig.size() == 65 && sig.back() == SIGHASH_ALL); | ||
| }; |
There was a problem hiding this comment.
In 1291d0e "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.
There was a problem hiding this comment.
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.
SignPSBTInput() checks that existing signatures use the input's sighash type. When neither PSBT_IN_SIGHASH_TYPE nor the sighash_type parameter was given, it checked them against an assumed default: 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, and asks a finalizer to fail on a mismatch only when it is present. So run the check only when the field or the parameter is given. This also lets non-taproot partial signatures use any sighash type in that case. RemoveUnnecessaryTransactions() looked only at the field to find SIGHASH_ANYONECANPAY. Without the field, also look at the taproot signatures, so that the non_witness_utxo is kept when one of them uses it. Fixes bitcoin#36507.
A finalized input is serialized without its sighash type field and its taproot signatures, so RemoveUnnecessaryTransactions dropped the non_witness_utxos once a PSBT with a finalized ANYONECANPAY taproot input was processed again, for example by utxoupdatepsbt or walletprocesspsbt. Also check the signatures in the final witness, which are among the items left once the annex and, for a script path, the script and the control block are removed. A control block can be 65 bytes long and end with a byte that has 0x80 set, so it is not read as a signature.
|
Once a taproot input is finalized, its sighash type field and its taproot signatures are no longer serialized, so a later |
|
🐙 This pull request conflicts with the target branch and needs rebase. |

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.