Block header
The 160-byte Lotus block header, field by field, how its three hash layers give the block hash, and the rules a header must pass.
A Lotus block header is 160 bytes. Its hash is built in three layers, so a device can check the chain and the proof of work with a small part of the header.
Layout #
Fields are serialized in this order. Integers are little-endian.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 32 | hashPrevBlock | Hash of the parent block; all zeros for the genesis block. |
| 32 | 4 | nBits | Compact encoding of the target the block hash must meet. |
| 36 | 6 | nTime | Block time, Unix seconds. |
| 42 | 2 | nReserved | Must be 0. |
| 44 | 8 | nNonce | Nonce the miner changes. |
| 52 | 1 | nHeaderVersion | Version of the bytes that follow. Must be 1. |
| 53 | 7 | nSize | Size of the serialized block in bytes. |
| 60 | 4 | nHeight | Block height; the genesis block is 0. |
| 64 | 32 | hashEpochBlock | Epoch block hash, see below. |
| 96 | 32 | hashMerkleRoot | Merkle root of the block's transactions. |
| 128 | 32 | hashExtendedMetadata | Hash of the extended metadata, see below. |
Block hash #
The block hash is three nested single SHA-256 hashes:
layer3 = SHA256(nHeaderVersion || nSize || nHeight || hashEpochBlock || hashMerkleRoot || hashExtendedMetadata)
layer2 = SHA256(nBits || nTime || nReserved || nNonce || layer3)
hash = SHA256(hashPrevBlock || layer2)| Layer | Input size | Lets you check |
|---|---|---|
| 1, chain | 64 bytes | That blocks form a chain. |
| 2, proof of work | 52 bytes | The target, the time and the nonce: enough for proof of work and the difficulty adjustment. |
| 3, transactions | 108 bytes | Size, height, epoch, the transaction Merkle root and the metadata hash. |
A miner that changes only the nonce or the time rehashes layers 2 and 1; layer 3 stays fixed.
Epoch block hash #
Epochs are 5,040 blocks long (one week at 2-minute blocks). The rule is:
- when
nHeightis a multiple of 5,040,hashEpochBlockequalshashPrevBlock; - otherwise it equals the parent's
hashEpochBlock.
So every block of an epoch points to the last block of the previous epoch. A header with another value is rejected with bad-blk-epoch.
Merkle root #
Each leaf is the double SHA-256 of a transaction's hash followed by its transaction id. Leaves are hashed in pairs with double SHA-256 up to the root. A level with an odd number of hashes is completed with a 32-byte zero hash; the last hash is not duplicated.
Extended metadata #
After the header, a block carries a list of metadata fields, then its transactions:
| Type | Meaning |
|---|---|
| compact size | Number of fields. |
| field[] | The fields. |
Each field is:
| Type | Meaning |
|---|---|
| 4 bytes | Field id. |
| compact size | Length of the data. |
| bytes | Data. |
hashExtendedMetadata is the double SHA-256 of that serialized list. For an empty list it is the double SHA-256 of the single byte 0x00:
9a538906e6466ebd2617d321f71bc94e56056ce213d366773699e28158e00614A block carries either no field or exactly one field. The only defined fields hold a merged-mining proof:
| Field id | Parent proof |
|---|---|
| 1 | Scrypt parent, classic tag |
| 2 | SHA-256d parent, classic tag |
| 3 | Scrypt parent, positional anchor |
| 4 | SHA-256d parent, positional anchor |
Any other field, or more than one, makes the block invalid (bad-metadata).
On mainnet, a block with a metadata field is valid only from the Napoleon activation (median time past 1797886200, 21 December 2026, 20:50 UTC). Before it, a mainnet header whose own hash does not meet its target is rejected. See Merged mining.
Header rules #
| Rule | Reject reason |
|---|---|
nReserved is 0 | bad-blk-reserved |
nHeaderVersion is 1 | bad-blk-version |
nHeight is the parent's height plus one | bad-blk-height |
nBits is the value the difficulty algorithm gives | bad-diffbits |
nTime is later than the median time of the last 11 blocks | time-too-old |
nTime is at most 2 hours ahead of the node's clock | time-too-new |
hashEpochBlock follows the epoch rule | bad-blk-epoch |
hashExtendedMetadata matches the metadata | bad-metadata-hash |
nSize is not above the block size limit | bad-blk-size |
Genesis block #
| Mainnet | |
|---|---|
| Hash | 000000000abc0cde58ee7e919d3d4de183e6844add1fd5d14b4eac89d958f470 |
| Time | 1624246260 (2021-06-21 03:31:00 UTC) |
nBits | 0x1c100000 |
| Nonce | 7146261898250975403 |
| Merkle root | 37f392d88f70cdada6d366a25a7ef90b6711bf2d6b5ffea4f39727dcb90af34c |
| Size | 379 bytes |
| Coinbase message | John 1:1 In the beginning was the Logos |
Read a header #
lotus-cli getblockheader 000000000abc0cde58ee7e919d3d4de183e6844add1fd5d14b4eac89d958f470