EIP-100 · Final · Core · 2016-04-28
EIP-100: Change difficulty adjustment to target mean block time including uncles
Changed proof-of-work difficulty adjustment to count uncles, so miners could not inflate ETH issuance by producing more uncle blocks.
What problem does it solve?
Under proof of work, Ethereum adjusted the mining difficulty after every block to keep block times steady. The old formula looked only at the time gap between a block and its parent.
Ethereum also paid rewards for uncles, which are valid blocks that lost the race but were still referenced by a later block. Uncles add new ETH, but the old formula ignored them. A miner could therefore raise total issuance by producing more uncles, and the difficulty would not respond. The proposal's references describe this as a consensus flaw ("uncle mining").
EIP-100 makes the difficulty target a steady average rate of blocks including uncles. Issuance then stays predictable and cannot be pushed up by manipulating the uncle rate.
How it works
The old adjustment factor was:
adj_factor = max(1 - ((timestamp - parent.timestamp) // 10), -99)
From the Byzantium fork on, it became:
adj_factor = max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) // 9), -99)
Two things changed:
- Uncle-aware target. If the parent block included any uncles, the base value is 2 instead of 1. Difficulty rises faster when uncles appear, as if the network had produced more blocks in that period.
- Denominator 10 → 9. This keeps the average block time about the same. The spec expects block times to drop by about 3% at the uncle rate of the time (about 7%).
The exact version would add len(parent.uncles), treating a block with k uncles as k + 1 blocks with the same timestamp. The spec instead uses only whether any uncles exist, because that can be checked from the header alone: compare the uncle hash with the hash of an empty list. Clients do not need the full block body.
Sample code
Simplified difficulty calculation after EIP-100 (difficulty bomb term omitted):
BLOCK_DIFF_FACTOR = 2048
EMPTY_UNCLE_HASH = keccak256(rlp_encode([]))
def calc_difficulty(parent, timestamp):
has_uncles = parent.uncles_hash != EMPTY_UNCLE_HASH
adj_factor = max((2 if has_uncles else 1) - (timestamp - parent.timestamp) // 9, -99)
return parent.difficulty + (parent.difficulty // BLOCK_DIFF_FACTOR) * adj_factor
# + difficulty bomb component
Things to know
- Activated in the Byzantium hard fork (EIP-609), together with the block reward cut and bomb delay in EIP-649.
- Only the parent header is needed. That keeps light and fast-sync clients simple.
- Since The Merge (EIP-3675), Ethereum uses proof of stake. Difficulty is fixed at 0 and uncles no longer exist, so this rule now matters only for the historical proof-of-work chain and for chains that still use Ethash.