Home Bitcoin signature – What’s the transaction hash preimage for various values of SIGHASH (not SIGHASH_ALL) in P2PKH?

signature – What’s the transaction hash preimage for various values of SIGHASH (not SIGHASH_ALL) in P2PKH?

0
signature – What’s the transaction hash preimage for various values of SIGHASH (not SIGHASH_ALL) in P2PKH?

[ad_1]

I’ve just a few questions concerning the transaction hash preimage when signing with completely different values of the SIGHASH flag within the case of the P2PKH script.

I do know what the transaction hash preimage appears like in case of SIGHASH_ALL, however what does it appear to be for different values of this flag.

So for instance our transaction has 3 inputs and 4 outputs and we are able to denote it as T(I1, I2, I3; O1, O2, O3, O4), the preimage within the case of SIGHASH_ALL might be as follows.

Let’s begin with the enter. We take all inputs as they’re (its full content material). After that, we clear the scriptSig area of all inputs and set the size of the scriptSig area in all inputs to zero (0x00). Then, only for the enter we’re signing, we set its scriptSig area to the scriptPubKey from the output (UTXO) that this enter factors to. Additionally, we’ll set the size of the scriptSig area on this enter to the size of this newly added script scriptPubKey. The size of the scriptSig area in different inputs stays zero (0x00), and the scriptSig area stays empty. On the subject of the outputs, we copy their full contents and add them to the beforehand described barely modified contents of the inputs. Lastly, we moreover append 0x01000000, which signifies that it’s a SIGHASH_ALL kind of signature.

That is the way it works within the case of SIGHASH_ALL, however how does it work for different values of this flag.

My assumption is that it’s precisely the identical course of, the one query is which inputs and outputs are taken under consideration. Due to this fact, the transaction hash preimages for the completely different values of the SIGHASH flag are as follows (I took under consideration the values outlined within the Grasp Bitcoin guide):

  1. NONE (0x02) – Signature applies to all inputs, not one of the outputs

    • for inputs, completely the identical story that I described for SIGHASH_ALL applies
    • outputs are usually not taken under consideration (they don’t seem to be a part of the transaction hash preimage, comparable as scriptSig area of different inputs can be not an element)
    • append 0x02000000 to the top
  2. SIGNLE (0x03) – Signature applies to all inputs however solely the one output with the identical index quantity because the signed enter

    • for inputs, completely the identical story that I described for SIGHASH_ALL applies
    • solely the content material of the output whose index corresponds to the enter index is taken under consideration (eg if we wish to signal I2, we’ll take inputs I1, I2 and I3, however solely output O2)
    • append 0x02000000 to the top
  3. ALL|ANYONECANPAY (0x81) – Signature applies to at least one enter and all outputs

    • solely the enter that we signal is included within the transaction hash preimage, the opposite inputs, i.e. their content material, are usually not a part of the transaction hash preimage in any type (we simply ignore the opposite inputs, the same state of affairs that we might have if the transaction had just one enter and the SIGHASH_ALL)
    • for outputs, completely the identical story that I described for SIGHASH_ALL applies (we take your complete content material of all outputs)
    • append 0x81000000 to the top
  4. NONE|ANYONECANPAY (0x82) – Signature applies to at least one enter, not one of the outputs

    • for inputs, completely the identical story that I described for 0x81 (ALL|ANYONECANPAY) applies
    • outputs are usually not taken under consideration (they don’t seem to be a part of the transaction hash preimage)
    • append 0x82000000 to the top
  5. SINGLE|ANYONECANPAY (0x83) – Signature applies to at least one enter and the output with the identical index quantity

    • for inputs, completely the identical story that I described for 0x81 (ALL|ANYONECANPAY) applies
    • for outputs, completely the identical story that I described for 0x03 (SIGNLE) applies
    • append 0x83000000 to the top

So my questions are:

1. Is that this the way it works?

2. Are there another values for the SIGHASH flag that I ought to cowl?

3. Is there some associated work/paper/commonplace that explains this (maybe for different scripts, like P2WPKH and so on.)?

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here