Sighash Flags
Last updated
Last updated
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 flag combinations 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.
NOTE: Currently all BitcoinSV transactions require an additional SIGHASH flag called SIGHASH_FORKID which is 0x40
Flag
Value including SIGHASH_FORKID HEX / BINARY
Value excluding SIGHASH_FORKID HEX / BINARY
Functional Meaning
SIGHASH_ALL
0x41 / 0100 0001
0x01 / 0000 0001
Sign all inputs and outputs
SIGHASH_NONE
0x42 / 0100 0010
0x02 / 0000 0010
Sign all inputs and no output
SIGHASH_SINGLE
0x43 / 0100 0011
0x03 / 0000 0011
Sign all inputs and the output with the same index
SIGHASH_ALL | ANYONECANPAY
0xC1 / 1100 0001
0x81 / 1000 0001
Sign its own input and all outputs
SIGHASH_NONE | ANYONECANPAY
0xC2 / 1100 0010
0x82 / 1000 0010
Sign its own input and no output
SIGHASH_SINGLE | ANYONECANPAY
0xC3 / 1100 0011
0x83 / 1000 0011
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 as well as the version of the protocol that the transaction is being evaluated under and the locktime being applied to the transaction.
Unlocking scripts are never signed
SIGHASH_ALL signs all inputs and outputs used to build the transaction. Once an input signed with SIGHASH_ALL is added to a transaction, the transaction's details cannot be changed without that signature being invalidated.
SIGHASH_SINGLE signs all inputs and the output that shares the same index as the input being signed. If that output or any inputs are changed that signature becomes invalidated.
SIGHASH_NONE signs all inputs and no outputs. Any output can be changed without invalidating the signature however if any inputs are changed that signature becomes invalidated.
`Once an input signed with SIGHASH_ALL|ANYONECANPAY is added to a transaction outputs cannot be changed or added without that signature being invalidated.
SIGHASH_SINGLE|ANYONECANPAY signs the input being signed and the output that shares the same index. If that output is changed that signature becomes invalidated.
SIGHASH_NONE|ANYONECANPAY signs a single inputs and no outputs. This type of signature can be used to easily assign funds to a person or smart-contract without creating an on-chain action.
SIGHASH flags are useful when constructing smart contracts and negotiable transactions in payment channels.
Using ALL | ANYONECANPAY allows a transaction to have a fixed output or fixed outputs while keeping the input list open. That is, anyone can add their input with their signature to the transaction without invalidating all existing signatures.
Using NONE allows anyone to add their desired outputs to the transaction to claim the funds in the input.
Using SINGLE | ANYONECANPAY modularises a transaction. Any number of these transactions can be combined into one transaction.
Please note that after the Chronicle release, the BSV Blockchain will support both the original TDA and the BIP143 Algorithm (with SIGHASH_FORKID), allowing flexibility for devs and users. It means that users will be able to decide how to sign transactions