The consensus layer is a key part of Ethereum, ensuring that all participants agree on the blockchain's current state. It verifies transactions, adds them in order, and secures the chain without needing a central authority. Ethereum uses Proof of Stake (PoS), where validators confirm transactions and create new blocks. This article explains the features of the consensus layer and how it keeps Ethereum secure and efficient.
When a transaction is created in Ethereum, it is first broadcast to the network using a peer-to-peer protocol. This means the transaction is shared with other Ethereum nodes, which are computers running the Ethereum software. These nodes communicate with each other to ensure that the transaction is known across the network. Once a node receives the transaction, it places it in a temporary storage area called the mempool, which holds all unconfirmed transactions. Validators, which are responsible for confirming transactions, continuously monitor the mempool to pick up valid transactions. They check that the transaction follows the correct rules, like ensuring the sender has enough funds and the transaction is signed correctly. After validating a transaction, the validator groups it with others and proposes a new block that includes these transactions. This block is then sent to other validators for approval. Once enough validators agree that the block is correct, it is added to the blockchain, and the transaction is finalized. The transaction is now part of the Ethereum ledger, and the sender’s balance is updated. We will explore this process in more detail in the following sections.
The Beacon Chain is a crucial part of Ethereum's system that helps manage the network’s consensus (agreement) on which transactions are valid. It operates using slots and epochs:
The genesis block (the first block on the Beacon Chain) is at Slot 0, and the first 32 slots make up Epoch 0.
While each slot is like a scheduled time to add a block, not every slot will have a block, as validators (who are responsible for adding blocks) might not always be ready to do so. Validators also need to stay roughly in sync with the system's time to ensure things run smoothly.
In Ethereum’s Proof of Stake (PoS) system, validators replace miners (as in Proof of Work) and help run the network’s consensus. Instead of using computers to solve complex puzzles, validators are like "virtual miners" who participate by staking ETH. Their job is to verify transactions and propose new blocks to be added to the blockchain.
In Ethereum’s Proof of Stake system, validators are like virtual workers, powered by ETH that people stake. Instead of using expensive hardware like in Proof of Work, anyone can stake ETH to activate and control a validator. For every 32 ETH staked, one validator is created. The more ETH you stake, the more validators you can run.
Validators operate through special software called validator clients, which interact with the beacon node that tracks the Ethereum blockchain. The validator client uses this information to propose new blocks or vote on transactions. Once a node deposits 32 ETH into the staking contract (also known as the deposit contract), it becomes activated and starts acting as a validator on the Ethereum network, helping to secure the network.
You can manage or act as multiple validator identities through the same node by staking more ETH. For every 32 ETH staked, one validator is activated. So, if you stake 64 ETH, you can manage two validators, and with 96 ETH, you can manage three validators. All of these validators are controlled through the same node, but each operates independently on the Ethereum network.
A committee is a group of validators responsible for making decisions together. Each slot (a 12-second period in Ethereum’s blockchain) has committees with at least 128 validators to ensure security. This large number makes it very difficult for an attacker to control more than two-thirds of the committee — the chance of this happening is less than one in a trillion.
The Beacon Chain enforces consensus through a random process called RANDAO. This process selects which validators will propose blocks and which will form committees for each slot. The selection is pseudorandom, meaning the randomness isn’t truly random but is generated in a way that everyone can verify and predict once they know the starting point, ensuring fairness in the selection process.
At the beginning of each epoch (which lasts about 6.4 minutes), RANDAO chooses the proposers (validators who propose blocks) for each slot and assigns validators to different committees. Each validator has a balance (how much ETH they have staked), and their chance of being selected as a proposer or committee member is weighted by this balance.
Although a validator could be both a proposer and a committee member for the same slot, it doesn’t happen often, with a probability of about 1 in 32. So, you’d see this occur once every epoch.
Validators can only belong to one committee per epoch, but with over 8,192 validators, multiple committees are formed for each slot. This ensures that each committee has at least 128 validators for security. If there are fewer than 4,096 validators, the number of validators in each committee could drop below 128, making the network less secure.
To make sure committees are properly sized, a shuffling algorithm is used to distribute validators evenly across slots and adjust the number of committees based on the total number of validators. This process ensures that committees are always large enough (at least 128 validators per committee) to keep the network secure. The sketch depicts a scenario with less than 8,192 validators, otherwise there would be at least two committees per slot.
Why does Ethereum require at least 128 validators per slot, and how is this number decided?
Ethereum requires at least 128 validators per slot to ensure the network's security, decentralization, and resilience. This number was chosen to make it difficult for an attacker to control the committee and manipulate the consensus process. With 128 validators, even if some validators are offline, the committee can still function properly. The number balances security and efficiency, ensuring the network remains decentralized without compromising on speed or performance. Lowering the number of validators would increase the risk of manipulation, while a larger number could slow down the process.
Imagine the Ethereum network is divided into time slots, and in each slot, a block can be proposed and attested by validators.
Ultimately, the LMD GHOST rule ensures that validators agree on the chain with the most support, resolving the temporary fork and converging on a single Beacon Chain head.
Checkpoints play a crucial role in this structure:
Example Scenario:
Validators in Ethereum use two types of votes to help secure the network and maintain the consensus process. The first is the LMD GHOST vote, where a validator votes for the most valid block they know of on the blockchain. This helps to determine which block should be considered the "head" or the most recent valid block in the chain.
In addition to voting for blocks, validators also participate in Casper FFG voting. This vote involves selecting the checkpoint for each epoch, which is a block that marks the end of an epoch. Validators vote for the checkpoint in the current epoch (referred to as the target) and the checkpoint from the previous epoch (referred to as the source). This ensures that each epoch is properly linked to the previous one, keeping the blockchain consistent.
While only validators assigned to a specific slot cast an LMD GHOST vote for that slot, all validators cast FFG votes for the checkpoints in every epoch to maintain overall network agreement.
A supermajority refers to a vote made by at least two-thirds (⅔) of the total balance of all active validators in the network. For example, suppose there are three active validators. Two of them each have 8 ETH, and one validator has 32 ETH. In order to have a supermajority, the vote must include the vote of the validator with 32 ETH. Even if the two 8 ETH validators vote differently, they cannot form a supermajority because their combined balance (16 ETH) is not enough to reach the two-thirds threshold. Therefore, the vote of the 32 ETH validator is crucial for the supermajority to be reached.
This ensures that the weight of votes in Ethereum’s consensus process is proportional to the amount of ETH staked, giving more influence to validators who have more at stake in the network.
Finality refers to the point in Ethereum's consensus mechanism where a checkpoint (a block marking the end of an epoch) is permanently secured on the blockchain, meaning it cannot be altered without significant cost or effort. This ensures that transactions within the finalized block and its ancestors are irreversible and immutable.
Let’s consider a scenario with epoch 0, epoch 1, and epoch 2, where each epoch has 32 slots, and the chain head is at epoch 2.
Even if some slots in an epoch are empty (meaning no blocks are created during those slots), it doesn’t impact the finality of the blockchain. This is because finality is based on validators voting with a ⅔ majority for the checkpoint block, not on whether every slot has a block. For example, even if some slots in epoch 0 are empty, the checkpoint at the start of epoch 0 can still be justified as long as enough validators vote for it. This ensures that the blockchain keeps moving forward smoothly, even if some blocks are delayed or missing.
Transaction finality usually takes 2.5 epochs. When a transaction is added to a block, it’s typically somewhere in the middle of an epoch. From there, it takes about half an epoch to propose the next checkpoint, and then another two epochs for the checkpoint to be finalized. This means it takes about 16 minutes for a transaction to be fully finalized.
In ideal cases, most validator votes are included by the 22nd slot of an epoch, which can reduce finality time to around 14 minutes. Once finalized, the transaction and the blocks leading up to it are permanently secured and cannot be changed.
Justified vs Finalized
At the end of Epoch 3 (Slot 96), a block is created that includes votes (attestations) from validators supporting the checkpoint at Slot 64, which is the Epoch 2 checkpoint. These votes have been collected from validators throughout Epoch 3. By the time Slot 96 is reached, the votes for the Slot 64 checkpoint meet the required ⅔ supermajority, which means the Slot 64 checkpoint is now justified.
When the Epoch 2 checkpoint (Slot 64) is justified, the previous checkpoint from Epoch 1 (Slot 32) is finalized. Finalization makes Slot 32 and all the blocks before it permanent and unchangeable on the blockchain. This process ensures that the blockchain history up to Slot 32 is secure and cannot be reorganized.
While finalization is calculated only at the end of an epoch, validators continuously add their votes in each block during the epoch. This steady accumulation of votes ensures that checkpoints can be justified and finalized as soon as the conditions are met, keeping the blockchain stable and reliable.
Why does it take two ⅔ supermajority votes and two epochs for a block to finalize?
The first ⅔ supermajority vote justifies the block, but there could still be temporary forks or conflicting blocks in the next epoch. The second supermajority vote ensures that the block is firmly accepted, preventing any reversals or attacks. It also provides confirmation that the block is not part of a temporary fork. This two-step process, across two epochs, guarantees the block's immutability, security, and validity, making it final and secure in the blockchain.
In Epoch 1 (Slots 0-31), blocks are proposed by validators in each slot. As blocks are proposed, they help gather attestations (votes) from the validators for the Epoch 1 checkpoint, which is the block at Slot 32 (the last block of Epoch 1). Validators start to vote for the Epoch 1 checkpoint as each block gets proposed, and by the time the block at Slot 64 (which begins Epoch 2) is proposed, the attestations for Epoch 1 checkpoint reach 70%. This causes the Epoch 1 checkpoint (Slot 32) to be justified.
Now, as Epoch 2 starts (Slots 32-63), the Epoch 2 checkpoint is the block at Slot 64. However, it doesn’t immediately gather enough attestations to reach the ⅔ supermajority required for justification. But when the block at Slot 96 is proposed, validators include their attestations for the Epoch 2 checkpoint, which results in the ⅔ supermajority, causing Epoch 2 checkpoint (Slot 64) to be justified. Once the Epoch 2 checkpoint is justified, the Epoch 1 checkpoint (Slot 32) is considered finalized. This means that all blocks before Slot 32 are now finalized and cannot be changed, ensuring the chain's security and immutability.
There is another possibility: Epoch 1’s checkpoint (Slot 32) could have already reached the necessary ⅔ supermajority before Epoch 2’s checkpoint (Slot 64) was even proposed. For example, during the proposal of blocks between Slot 32 to Slot 54 in Epoch 2, attestations for the Epoch 1 checkpoint could have already reached ⅔ supermajority, causing Epoch 1’s checkpoint (Slot 32) to be justified even before the start of Epoch 2.
However, even if a checkpoint is justified in its current epoch, it can't be finalized until at least the next epoch has passed. This ensures there’s no potential for forks or conflicting blocks, providing certainty that the checkpoint is truly valid. In rare cases, such as network delays, partitions, or attacks, a checkpoint might take more than two epochs to become finalized.
An attestation is a combination of two votes: one for the block's validity (LMD GHOST) and one for the checkpoint (FFG). Validators are expected to submit one attestation each epoch, and they have 32 opportunities (slots) to get their vote included. They earn more rewards if their vote is included earlier in their assigned slot.
Validators are assigned to committees one epoch in advance to improve the process, while proposers are chosen at the start of each epoch. When validators in the same committee vote the same way, their votes are grouped into a single, efficient signature.
To prevent attacks or bribery, research into secret leader election helps make the process more secure.
Inactivity Leak Penalty: If a validator doesn’t participate for more than four epochs, they face an inactivity penalty. The longer they stay inactive, the bigger the penalty. This penalty ensures that validators who aren’t participating are removed from the system so that others can finalize blocks. Validators who are doing their job properly won’t be penalized.
Double Proposal: A proposer is only allowed to propose one block for their assigned slot. If they propose more than one block, it’s considered a slashing offense.
LMD GHOST Double Vote: A validator can only vote for one head of the Beacon Chain in their assigned slot. If they vote for two different heads (two different chain states), it’s a slashing offense.
FFG Surround Vote: A surround vote happens when a validator casts a vote that "surrounds" or is "surrounded" by a previous vote they made in a different epoch. For example, if a validator votes for Slot 32 to Slot 128 in Epoch 5, and later votes for Slot 64 to Slot 96 in Epoch 6, this would be considered a surrounding vote.
FFG Double Vote: A validator cannot cast two votes for different blocks in the same epoch. If they vote for two different blocks in the same epoch, it’s a slashing offense. This can happen during a fork, where a validator votes for two conflicting blocks in the same epoch.
The reason these offenses are slashing offenses is to ensure that validators do not vote for conflicting or multiple versions of the chain. This helps maintain consensus and prevent the blockchain from splitting.
Whistleblower Rewards: If a validator notices another validator making a slashing offense (like a double vote), they can report it and earn a whistleblower reward. This helps maintain the integrity of the network.
Avoiding Slashable Offenses: Validators are in complete control of their actions and can avoid being slashed by simply ensuring that they do not sign conflicting proposals or attestations. If they act honestly and do not make conflicting votes, they cannot be slashed.
To become an active validator on the Beacon Chain, a user needs to stake 32 ETH. When this amount is staked into the deposit contract on the Ethereum mainnet, it activates a validator. Once activated, a validator must maintain a balance of 32 ETH. If the balance drops to 16 ETH, the Beacon Chain will deactivate the validator, forcing them to exit the network. However, stakers will be able to withdraw any remaining balance once the system allows it (likely around 2023).
A validator can also choose to exit voluntarily after serving for 2,048 epochs (about 9 days). Whether the exit is voluntary or forced, there is a 4-epoch delay before the staker can withdraw the funds. During this delay, a validator can still be slashed for misbehavior. If the validator is honest, their balance can be withdrawn in about 27 hours. However, if the validator is slashed, they will face an 8,192-epoch delay (around 36 days) before they can withdraw their funds.
There are mechanisms in place to limit the number of validators that can be activated or exited within a single epoch to prevent sudden changes in the validator set. These restrictions help protect the network from attacks by making it harder to activate a large number of validators in a short time. Additionally, the Beacon Chain uses "effective balances" to manage validators, which change less frequently than validator balances and help with technical optimizations.