Signature hash
Protocol and consensus12.4.15+

Signature hash

The sighash type byte and the two signature hash algorithms a Lotus transaction can use, SIGHASH_FORKID and SIGHASH_LOTUS, with their exact preimages.

A transaction signature signs a hash of parts of the spending transaction. The last byte of the signature, the sighash type, says which parts and which algorithm. Lotus accepts two algorithms: SIGHASH_FORKID and SIGHASH_LOTUS.

Sighash type byte #

BitsMaskMeaning
Base type0x030x01 ALL: sign all outputs. 0x02 NONE: sign no output. 0x03 SINGLE: sign the output with the same index as the input.
Unused0x1cMust be 0.
Algorithm0x600x40 SIGHASH_FORKID, 0x60 SIGHASH_LOTUS. 0x00 (legacy) and 0x20 (reserved) are refused.
Anyone can pay0x80Sign only this input; other inputs may be added.

The usual values are 0x41 (ALL with FORKID) and 0x61 (ALL with LOTUS). The node's wallet signs with 0x41.

A signature whose type is not one of these combinations fails with SIG_HASHTYPE; one that uses the legacy algorithm fails with MUST_USE_FORKID.

In the preimage the type is a 4-byte little-endian integer: the type byte in the low 8 bits and a 24-bit fork value above it. The fork value is 0.

Note

At the 1st Chronicles upgrade (median time past 1813587000, 21 June 2027, 14:10 UTC on mainnet) replay protection switches on and the fork value used in the preimage becomes 0xffdead. The signature byte itself does not change. See Network upgrades.

Which algorithm to use #

SpendAllowed
Pay to public key hash, pay to script hash, bare scriptsFORKID or LOTUS
Taproot key pathLOTUS only, with a Schnorr signature
Taproot script pathFORKID or LOTUS

SIGHASH_LOTUS signatures are valid since the 2nd Samuel upgrade (21 December 2025).

SIGHASH_FORKID #

The hash is the double SHA-256 of:

SizeField
4nVersion
32Double SHA-256 of all input outpoints; zeros with ANYONECANPAY
32Double SHA-256 of all input nSequence; zeros with ANYONECANPAY, NONE or SINGLE
36Outpoint of the input being signed
variableScript code, with its length prefix
8Amount of the output being spent
4nSequence of the input being signed
32ALL: double SHA-256 of all outputs. SINGLE: double SHA-256 of the output at the input's index, zeros if there is none. NONE: zeros
4nLockTime
4Sighash type with the fork value

The script code is the script being executed, from after the last executed OP_CODESEPARATOR.

SIGHASH_LOTUS #

SIGHASH_LOTUS commits to every output the transaction spends, not only the one being signed, and uses the same Merkle roots as the transaction id. For a given sighash type the preimage has a fixed length.

The hash is the double SHA-256 of these fields, in order. A field marked with a condition is left out when the condition is false.

SizeFieldPresent when
4Sighash type with the fork valuealways
32Input hash, see belowalways
4Code separator positionscript execution
32Executed script hashscript execution
4Index of the input being signednot ANYONECANPAY
32Merkle root of all spent outputsnot ANYONECANPAY
8Sum of all input amountsnot ANYONECANPAY
8Sum of all output amountsALL
4nVersionalways
32Merkle root of the inputsnot ANYONECANPAY
1Height of the inputs treenot ANYONECANPAY
32Double SHA-256 of the output at the input's indexSINGLE
32Merkle root of the outputsALL
1Height of the outputs treeALL
4nLockTimealways

Input hash #

The double SHA-256 of:

SizeField
1Spend type: 0 for a Taproot key path spend, 2 when a script is being executed
36Outpoint of the input being signed
4Its nSequence
variableThe output it spends: amount (8 bytes), script length, script

Script execution fields #

These two fields are present whenever the signature is checked by an opcode inside a script, so for every spend except the Taproot key path.

  • Code separator position: the position of the last executed OP_CODESEPARATOR, or 0xffffffff if none was executed. The first opcode of a script has position 0, a push counts as one opcode, and opcodes in branches that are not executed count too.
  • Executed script hash: for a Taproot script path, the tapleaf hash; otherwise the double SHA-256 of the whole script being executed (the output script, or the redeem script for pay to script hash).

Merkle roots #

  • The inputs root and the outputs root, with their heights, are the ones of the transaction id.
  • The spent outputs root is built the same way; each leaf is the double SHA-256 of one spent output (amount, script length, script), in input order.

Rules #

  • The base type must be ALL, NONE or SINGLE and the unused bits must be 0.
  • With SINGLE, an input that has no output at its index cannot be signed: the signature check fails.
  • The signer needs the output spent by every input of the transaction, not only its own.

Signature formats #

A signature of 64 bytes (plus the sighash byte) is verified as Schnorr; any other length as DER-encoded ECDSA. Both use secp256k1 keys.

Sign with the node #

signrawtransactionwithkey and signrawtransactionwithwallet take the sighash type as text, for example "ALL|FORKID" or "ALL|LOTUS", with |ANYONECANPAY appended where needed.

Source share/www/docs/sighash.md in the lotusd repository
Checked against src/script/sighashtype.h src/script/interpreter.cpp src/script/sigencoding.cpp src/script/script_exec_data.h src/policy/replayprotection.cpp