Skip to main content
Last updated

Block header binary encoding

The binary format for chain graphs of degree three is defined in Chainweb.BlockHeader.

SizeBytesValue
80-7flags
88-15time
3216-47parent
11048-157adjacents
32158-189target
32190-221payload
4222-225chain
32226-257weight
8258-265height
4266-269version
8270-277epoch start
8278-285nonce
32286-317hash

total: 318 bytes

Adjacent parents record

The binary format for adjacent parents (length 3):

BytesValue
0-1length
2-109adjacents

total: 110 bytes

Adjacent parent

BytesValue
0-3chain
4-35hash

total: 36 bytes

Proof of work and field values

Arithmetic operations and comparisons on parent, target, weight, and hash interpret the value as unsigned 256-bit integral numbers in little endian encoding. All operations are performed using rational arithmetic of unlimited precision and the final result is rounded. For details about how the result is rounded, consult the source code directly.

Time stamps

The time and epoch start values are a little endian twos complement encoded integral numbers that count SI microseconds since the start of the POSIX/UNIX epoch (leap seconds are ignored). These numbers are always positive (highest bit is 0).

Numbers

The height is a little endian encoded unsigned integral 64 bit number. The length is a little endian encoded unsigned integral 16 bit number.

Version

The version field identifies the Chainweb version. It is a 32 bit value in little endian encoding. Values up to 0x0000FFFF are reserved for production versions, including includes development and testnets.

ValueVersion
0x00000005mainnet01
0x00000001development
0x00000007testnet04

Other

The nonce is any sequence of 8 bytes that is only compared for equality. The chain is any sequence of 4 bytes that identifies a chain and can be compared for equality. The payload is any sequence of 32 bytes that is a cryptographic hash of the payload associated with the block and can be compared for equality. flags are eight bytes of value 0x0 that are reserved for future use.

Work header binary encoding

The work bytes received from the /miner/work endpoint is slightly different than the above header format. These headers do not include the block hash, instead prefixing the header above (without hash) with chain id and hash target bytes.

The first 36 bytes are informational. Only the bytes from position 36 to the end are the subject of the proof of work hash computation.

The final 8 bytes are the nonce. The creation time is encoded in bytes 44-52 (see above for details of the encoding). Miners are allowed, but not required, to update the time to reflect the solve time for the block more closely. A larger value for the creation time increases the accuracy of the difficulty adjustment which is in the interest of miners. The high difficulty guarantees that the outcome of the race of winning blocks is determined by actual hash power. However, blocks that are predated (that is, have a creation time that is in the future) are rejected during block header validation. Leaving the time unchanged is a valid choice.

Miners must not change or make any assumptions about the content of the "reserved" bytes.

Defined in Chainweb.Miner.Core:

SizeBytesWork bytesValue
40-3NAchain
324-35NAhash-target
836-430-7reserved
844-518-15time
29852-31316-277reserved
8314-321278-285nonce

total: 322 bytes

For arithmetic comparisons the hash-target is interpreted as unsigned 256 bit integral number in little endian encoding.

The time is a little endian twos complement encoded integral number that counts SI microseconds since the start of the POSIX/UNIX epoch (leap seconds are ignored). The value is always positive (highest bit is 0).