Difference between revisions of "SIGHASH flags"

Line 69: Line 69:
 
|style="font-style: italic;"|Outpoint N
 
|style="font-style: italic;"|Outpoint N
 
|.....Sig PN, Tx.....
 
|.....Sig PN, Tx.....
 +
|XN BSV
 +
|[ChecksigPm]
 +
|}
 +
 +
==Items that are ''never'' signed==
 +
 +
Unlocking scripts are ''never'' signed
 +
 +
{| class="wikitable" style="text-align: center;"
 +
|colspan="4" style="font-style: italic; width: 600px;"|TxID
 +
|-
 +
|colspan="4"|Version
 +
|-
 +
|colspan="4"|Locktime
 +
|-
 +
|colspan="2" style="width: 50%;"|Inputs
 +
|colspan="2" style="width: 50%;"|Outputs
 +
|-
 +
|
 +
|style="font-style: italic;"|Unlocking Script
 +
|
 +
|style="font-style: italic;"|Locking Script
 +
|- style="height: 7em;"
 +
|style="font-style: italic;"|Outpoint A
 +
|style="background: #f5b7b1;"|.....Sig Pa, Tx.....
 +
|Xa BSV
 +
|[ChecksigP1]
 +
|- style="height: 7em;"
 +
|style="font-style: italic;"|Outpoint B
 +
|style="background: #f5b7b1;"|.....Sig Pb, Tx.....
 +
|Xb BSV
 +
|[ChecksigP2]
 +
|-
 +
|colspan="2" style="font-style: bold; |...
 +
|colspan="2" style="font-style: bold; |...
 +
|- style="height: 7em;"
 +
|style="font-style: italic;"|Outpoint N
 +
|style="background: #f5b7b1;"|.....Sig PN, Tx.....
 
|XN BSV
 
|XN BSV
 
|[ChecksigPm]
 
|[ChecksigPm]

Revision as of 23:21, 30 December 2019

A SIGHASH flag is used to indicate which part of the transaction is signed by the ECDSA signature. The mechanism provides a flexibility in constructing transactions. There are in total 6 different flags that can be added to a digital signature in a transaction. Note that different inputs can use different SIGHASH flags enabling complex compositions of spending conditions.

Flag Value Functional Meaning
SIGHASH_ALL 0x00000001 Sign all inputs and outputs
SIGHASH_NONE 0x00000002 Sign all inputs and no output
SIGHASH_SINGLE 0x00000003 Sign all inputs and the output with the same index
SIGHASH_ALL | ANYONECANPAY 0x00000081 Sign its own input and all outputs
SIGHASH_NONE | ANYONECANPAY 0x00000082 Sign its own input and no output
SIGHASH_SINGLE | ANYONECANPAY 0x00000083 Sign its own input and the output with the same index


The tables below illustrate what is signed and what is not signed in an ECDSA siganture depending on the SIGHASH type used.

Items that are always signed

The signature on any input always signs the TXID and VOUT that comprise the Outpoint being spent.

TxID
Version
Locktime
Inputs Outputs
Unlocking Script Locking Script
Outpoint A .....Sig Pa, Tx..... Xa BSV [ChecksigP1]
Outpoint B .....Sig Pb, Tx..... Xb BSV [ChecksigP2]
... ...
Outpoint N .....Sig PN, Tx..... XN BSV [ChecksigPm]

Items that are never signed

Unlocking scripts are never signed

TxID
Version
Locktime
Inputs Outputs
Unlocking Script Locking Script
Outpoint A .....Sig Pa, Tx..... Xa BSV [ChecksigP1]
Outpoint B .....Sig Pb, Tx..... Xb BSV [ChecksigP2]
... ...
Outpoint N .....Sig PN, Tx..... XN BSV [ChecksigPm]

SIGHASH_ALL

TxID
Version
Locktime
Inputs Outputs
Unlocking Script Locking Script
Outpoint A .....Sig Pa, Tx..... Xa BSV [ChecksigP1]
Outpoint B .....Sig Pb, Tx..... Xb BSV [ChecksigP2]
... ...
Outpoint N .....Sig PN, Tx..... XN BSV [ChecksigPm]


SIGHASH flags are useful when constructing smart contracts and negotiable transactions in payment channels.


Use Case 1 - Crowdfunding

Using ALL | ANYONECANPAY allows a transaction to have a fixed output or fixed outputs while keep the input list open. That is, anyone can add their input with their signature to the transaction without invalidating all existing signatures.


Use Case 2 - Blank Check

Using NONE allows any miner to add their desired outputs to the transaction to claim the fund in the input.


Use Case 3 - Modular Transaction

Using SINGLE | ANYONECANPAY modularises a transaction. Any number of these transactions can be combined into one transaction.

References

https://github.com/bitcoin-sv/bitcoin-sv/blob/master/src/script/sighashtype.h