BIP370 specifies a bit flag (bit 2) in PSBT_GLOBAL_TX_MODIFIABLE
field, that "indicates whether the transaction has a SIGHASH_SINGLE signature who's input and output pairing must be preserved" and "If the Has SIGHASH_SINGLE flag is True, then the Constructor must iterate through the inputs and find the inputs which have signatures that use SIGHASH_SINGLE. The same number of inputs and outputs must be added before those inputs and their corresponding outputs"
BIP370 does not specify how to handle this flag in other situations, when the inconsistency of the flag with other fields can indicate some problem and it may be best to somehow react to this problem rather than ignore it.
For example, the code that parses PSBTv2 may find that 'Has SIGHASH_SINGLE flag' is false in PSBT_GLOBAL_TX_MODIFIABLE
, but later, when processing the input fields, finds out that one of psbt inputs has SIGHASH_SINGLE
.
How the code should react to this ? This is obvious inconsistency, if this situation is ignored, and the 'Has SIGHASH_SINGLE flag' is considered false despite the presence of SIGHASH_SIGNGLE
in the inputs, the signatures can be invalidated when moving inputs or outputs.
Likewise, if the flag is true, but there are no inputs having SIGHASH_SINGLE
sighash types, should this be taken as an indication of inconsistent PSBT ?
Can we say "this flag is always equal to any(input.has_sighash_single() for input in psbt.inputs)
" (1) ?
PSBT_IN_SIGHASH_TYPE
is not required to be present, and if it is absent, signer "may use any sighash type they wish". But let's imagine that BIP text would state that PSBT_IN_SIGHASH_TYPE
must always be present if SIGHASH_SINGLE
is to be used. Will (1) be true in this case ? Would we even need this flag then ?
Should say that 'Has SIGHASH_SINGLE' flag is to be ignored if there are finalized inputs because any adding of inputs must have been done before finalization ?
How would it be possible to check the finalized inputs for the use of SIGHASH_SINGLE
signatures in case of finalized inputs when custom scripts are used with unknown format for the witness data ?
BIP174 says that on finalization, finalized scriptSig
and scriptWitness
should remain, and "All other data except the UTXO and unknown fields in the input key-value map should be cleared from the PSBT"*. If PSBT_IN_SIGHASH_TYPE
is cleared, there's no way to know in general if the witness has signatures with SIGHASH_SINGLE
, unless the code can somehow understand the format of the witness.
* By the way, this wording should include not only unknown fields, but proprietary fields, too should be preserved. Should I make PR to add this ?
PSBT_IN_PARTIAL_SIG
that has signatures that Constructor can look at.