EIP-225 · Final · Core · 2017-03-06
EIP-225: Clique proof-of-authority consensus protocol
Clique is a simple proof-of-authority consensus in which a voted list of signers seals blocks, built to fit Ethereum's existing header format so clients could adopt it easily.
What problem does it solve?
A proof-of-work testnet is only as secure as the hash power behind it, and testnet ether is worth nothing. In early 2017, attackers took over the Ropsten testnet cheaply. They pushed the block gas limit up to about 9 billion and then flooded the network with huge transactions. Restarting the testnet would not help, because the same attack could be repeated.
Clique replaces mining with a set of trusted signers. Its main design goal is to fit into Ethereum's existing data structures, so any client can add it with little effort and fast and light sync keep working.
How it works
Clique reuses existing header fields instead of adding new ones:
extraDatais 32 bytes of free "vanity" data, then a 65-byte secp256k1 signature that seals the header. On checkpoint blocks, the current signer list (N × 20 bytes, sorted) sits between the two.miner/beneficiaryis normally zero. A signer sets it to the address it wants to vote on.nonceis0xffffffffffffffffto vote to add that address and0x0000000000000000to vote to remove it.difficultyis 2 if the signer is "in turn" (block_number % signer_count == signer_index) and 1 otherwise. The chain with more in-turn blocks wins.mixHashis zero, andommersHashis always the hash of an empty uncle list.
Rules:
- Each signer may seal at most one block in any
floor(N/2) + 1consecutive blocks. A single bad or compromised signer cannot dominate the chain. Censoring a vote requires a majority. - A vote takes effect as soon as a majority of signers agree. Every
EPOCH_LENGTHblocks (suggested 30,000), all pending votes are discarded and a checkpoint header records the full signer list. Clients can sync from a checkpoint without earlier state. - Blocks must be at least
BLOCK_PERIODapart (suggested 15 s). Out-of-turn signers are advised to wait a random delay so the in-turn signer usually wins. - Votes do not cascade. Only the address voted on in the current block can change, even if removing a signer would push other proposals past the majority.
Sample code
Clique section of a Geth-style genesis file:
{
"config": {
"chainId": 1337,
"clique": { "period": 15, "epoch": 30000 }
},
"difficulty": "1",
"gasLimit": "8000000",
"extraData": "0x<32 zero bytes><signer addresses, 20 bytes each><65 zero bytes>"
}
Recovering the signer of a header (pseudocode):
seal = header.extra_data[-65:]
unsigned = header.copy(extra_data=header.extra_data[:-65])
sighash = keccak256(rlp_encode(unsigned)) # all header fields, in yellow-paper order
signer = ecrecover(sighash, seal)
assert signer in authorized_signers and not signed_recently(signer)
Things to know
- Clique was used for public testnets such as Rinkeby and Görli, both of which have since been shut down, and it is widely used for private and dev networks.
- Because
minerholds a vote target, theCOINBASEopcode and transaction fees must use the actual block signer recovered fromextraData. - Short forks can still occur when out-of-turn signers race. The heavier in-turn difficulty decides between competing blocks.
- Ethereum mainnet uses proof of stake (EIP-3675), not Clique.