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 #
| Bits | Mask | Meaning |
|---|---|---|
| Base type | 0x03 | 0x01 ALL: sign all outputs. 0x02 NONE: sign no output. 0x03 SINGLE: sign the output with the same index as the input. |
| Unused | 0x1c | Must be 0. |
| Algorithm | 0x60 | 0x40 SIGHASH_FORKID, 0x60 SIGHASH_LOTUS. 0x00 (legacy) and 0x20 (reserved) are refused. |
| Anyone can pay | 0x80 | Sign 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.
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 #
| Spend | Allowed |
|---|---|
| Pay to public key hash, pay to script hash, bare scripts | FORKID or LOTUS |
| Taproot key path | LOTUS only, with a Schnorr signature |
| Taproot script path | FORKID 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:
| Size | Field |
|---|---|
| 4 | nVersion |
| 32 | Double SHA-256 of all input outpoints; zeros with ANYONECANPAY |
| 32 | Double SHA-256 of all input nSequence; zeros with ANYONECANPAY, NONE or SINGLE |
| 36 | Outpoint of the input being signed |
| variable | Script code, with its length prefix |
| 8 | Amount of the output being spent |
| 4 | nSequence of the input being signed |
| 32 | ALL: 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 |
| 4 | nLockTime |
| 4 | Sighash 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.
| Size | Field | Present when |
|---|---|---|
| 4 | Sighash type with the fork value | always |
| 32 | Input hash, see below | always |
| 4 | Code separator position | script execution |
| 32 | Executed script hash | script execution |
| 4 | Index of the input being signed | not ANYONECANPAY |
| 32 | Merkle root of all spent outputs | not ANYONECANPAY |
| 8 | Sum of all input amounts | not ANYONECANPAY |
| 8 | Sum of all output amounts | ALL |
| 4 | nVersion | always |
| 32 | Merkle root of the inputs | not ANYONECANPAY |
| 1 | Height of the inputs tree | not ANYONECANPAY |
| 32 | Double SHA-256 of the output at the input's index | SINGLE |
| 32 | Merkle root of the outputs | ALL |
| 1 | Height of the outputs tree | ALL |
| 4 | nLockTime | always |
Input hash #
The double SHA-256 of:
| Size | Field |
|---|---|
| 1 | Spend type: 0 for a Taproot key path spend, 2 when a script is being executed |
| 36 | Outpoint of the input being signed |
| 4 | Its nSequence |
| variable | The 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, or0xffffffffif 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.
