Bitcoin Block Headers
- Version:
- Version 2: Height in Coinbase Input Script (BIP34)
- Version 3: Strict DER (BIP66)
- Version 4: CLTV support (BIP65)
- Merkle Root:
- Commits all transactions and their order.
- Timestamp:
- POSIX time:
- Must be higher than median of previous 11 blocks
- Cannot more than 2hrs higher than local peer clock
- Difficulty Bits:
- Defines target for POW
- Block hash must be below target
- Nonce:
- Block Hash:
- Double sha256 of serialised 80B header
Genesis Block
- Block header:
- No previous block hash.
- Timestamp:
- 6:15:05 PM, Jan 3rd, 2009
- Difficulty bits:
- Lowest accepted difficulty bits.
- Transactions:
- First TX is always coinbase.
- Coinbase input script:
- Version 1: Arbitrary data
- Genesis block:
- Difficulty bits.
- Times heading proves block originated afterwards.
- Difficulty Bits:
- Lowest accepted difficulty bits.
Difficulty & Target
- Valid Header Hash must be <= target
- Miner can iterate following data in block:
- Nonce.
- Unused version bits.
- Timestamp.
- Coinbase (Merkle Root).
- Version bits.
- Input script.
- Merkle root(TX set/order)
- Hashes required to achieve target:
- Example: 0x0800...00: Every 2nd Hash...
- Example: 0x0400...00: Every 4th Hash...
Difficulty Retargeting
- Difficulty Adjustment:
- Every 2016 blocks.
- Adjusted to maintain 10min block interval.
- Adjustment maximum bound: 4x.
- Inflation Bug:
- Considers interval between 2015 blocks.
- Slightly faster block/inflation schedule.
- Requires hardfork to fix.
Coinbase Transaction
- Single input script:
- V1: Arbitrary data.
- Beginning V2: Commits to blockheight (BIP30).
- Coinbase overwriting (identical txid).
- Up to 100B total.
- Output script:
- Witness block:
- Witness root and coinbase witness commitment.
- For witness root: coinbase wtxid = 0x00..00
- Non-witness block:
- No output commiting to witness root required.
- Multiple outputs possible:
- Fees from transactions.
- Block subsidy.
Block Size & Weight
- Transaction Weight (BIP141):
- Weight equals byte size sum of:
- 1 x TX serialised (BIP144, with witness).
- 3 x TX serialised (Pre-BIP144, no witness).
- Witness Blocks:
- Maximum weight of 4 Million.
- Actual data size depends on witness data ratio in block
- Examples:
- TX Data 1000B / Witness Data 0B:
- TX Weight: 1000 + 3000 = 4000
- TX Data 1000B / Witness Data 500B:
- TX Weight: 1000 + 1500 = 2500
- TX Data 1000B / Witness Data 900B:
- TX Weight: 1000 + 300 = 1300
- As Witness data size approaches total tx size,
effective block size approaches 4MB.
Merkle Root
- Merkle Root:
- Bitcoin256: dsha256 -> LE Encoding.
- At each level, duplicate last leaf if uneven.
- Merkle/Witness Root.
- TXID leaves -> merkle root (in block header).
- WTXID leaves -> witness root (in coinbase output)
Block Subsidy
- Genesis Block:
- Block reward adjustment:
- Halves every 210,000 blocks/~ 4 years.
- After 33 halvings, block reward is removed.
- Block subsidy vs fees
- As block rewards decrease, and usage increases, fee market emerges for block inclusion.
Chain Organisation
- Forks:
- Different valid blocks of equal height.
- All valid blocks are organised by node.
- Node follows chain with most POW.
- Orphan Blocks:
- Node will request headers/blocks
from peers to link to main chain.
- Checkpoints:
- Forks below checkpoint not organised into chain.
- Does not contribute to security model.
- Legacy: Prevent low-difficulty DOS blocks.
- Currently 13 hardcoded checkpoints.
- Latest at height 295000.
- Forks are costly.