# What Happens After Finality in ETH2? A fundamental property of blockchains is the notion of "finality", which roughly means that after a certain period of time, transactions that have been included in the canonical chain are extremely difficult, or almost impossible, to revert. Eth2 has an "explicit" mechanism of chain finality enshrined within the protocol, which is different than the "probabilistic" finality found in proof of work chains such as Ethereum or Bitcoin today. In proof of work, consensus is fundamentally a global race that a lucky miner wins by being the first to produce a valid block: a result of finding a mathematical solution to a computationally difficult problem. As such, block times are probabilistic. The more blocks are added to the chain, the harder it is to revert, as each represents a cumulative sum of electrical and computational power required to create it. Given there are real, physical guarantees that would prevent an attacker from being able to revert the Bitcoin and Ethereum blockchains today, we can consider transactions past a certain amount of time included on chain as "finalized". Ethereum proof of stake, however, does not function on the concept of probabilistic finality. Instead, it enshrines finality into the protocol by saying "If > 2/3s of validators have voted correctly on the chain head for a long period of time, we can consider everything before a specific checkpoint as finalized". Finality is explicit, and nodes that follow the protocol will not be able to revert the finalized checkpoint as it is fundamentally impossible regardless of consensus weight. ## How Finality Works in ETH2 ETH2 is a synchronous protocol that operates on a "checkpoint" mechanism for bookkeeping. Essentially, a set of validators is assigned to either produce blocks or vote on blocks in a window of 32 potential **slots**. Each slot is a period of 12 seconds. Those 32 slots constitute an **epoch**. In an epoch, there are 32 assigned block proposers and everyone else is known as an **attester**, assigned to vote on proposed blocks once per epoch. > There is only one block proposer assigned per slot, but many "attesters" can be assigned per slot For example, Alice is selected as a block proposer for slot 4 in the epoch and Bob, James, Charlie, and Susan are assigned as attesters at slot 4, meaning they should be voting on Alice's produced block as canonical. ETH2 uses Casper Proof of Stake, specifically, something called a "finality gadget". The ETH2 finality process is defined as follows: 1. If > 2/3rds of validators vote correctly on the chain head during an epoch, we call the last epoch **justified** 2. If two epochs in a row are justified, the `current_epoch - 2` is considered **finalized** In normal operation, the chain is meant to always be finalizing. If more than 4 epochs have passed since a finalized epoch, all active will start being penalized to incentivize quick recovery of finality. ### What happens at the end of an epoch At the end of an epoch in eth2, the state transition function performs important bookkeeping to figure out exactly what happened at the consensus layer during the time period and prepare for the next epoch. Validators are shuffled every epoch into new assignments, and we are able to know assignments for 2 epochs in advance, unless there is a chain reorg. During an epoch transition, we tally up all the votes for the head of chain. Validators vote using the **effective balance**, which is measured in **gwei**. When chatting about eth2, we typically mention **validator participation**, which is defined as the amount of total gwei at stake that was used to correctly vote on chain heads during the epoch versus the total gwei of all active validators. ### Consequences of determining a new, finalized checkpoint Determing a finalized checkpoint is very important in eth2 because it serves as the lower bound for many things that are defined explicitly in the protocol. Namely, all messages received via p2p gossipsub that are from *before* the finalized checkpoint are ignored and thrown away. Moreover Here are the things that happen upon a new finalized checkpoint in eth2: - All incoming gossipsub messages from before the new finalized checkpoint are ignored - The **fork choice rule** is updated to only consider votes starting from the finalized checkpoint. Meaning, it is impossible for a node following the protocol to revert the finalized checkpoint - Stored data earlier than the finalized checkpoint is **safe to prune** ## Incentives and reorgs There is a strong incentive to maintain what we call "chain liveness" from protocol rewards. Since mainnet of eth2 launched this past December 1st, 2020, the chain has had perfect liveness, essentially finalizing as expected, every single epoch. The chain participation, meaning the percent of staked ETH that is correctly voting on the chain head vs. the total available, has remained in the high 90s the entire time. ![beaconcha.in](https://i.imgur.com/jR3rv6y.png) From https://beaconcha.in Unless major validators go offline, or if there is a serious bug in a popular client implementation, the incentive to always finalize the `current_epoch - 2`. Given epochs in eth2 are 6.4 minutes long, the epoch 12.8 minutes ago should always be finalized in ideal conditions. For MEV purposes, we have not seen a reorg > 12.8 minutes in the blockchain, of course. So then, is it possible we can get a probabilistic estimate of *transaction* finality via data from the beacon chain itself? ### MEV Every block in eth2 contains metadata about consensus. Namely, a block contains information about: - New validators joining the chain (eth1 validator deposits) - Attestations, which is the name for votes from other validators on previous blocks in the chain - Proof of validators wanting to exit their responsibilities - Proof of validators being slashed and forcefully ejected from their responsibilities For our purposes, the most important are **attestations**. Since blocks are meant to happen every **slot**, which is a period of exactly 12 seconds, upon every block we receive, we can calculate what percentage of staked ETH has correctly voted on the chain head so far compared to the total active validator count's staked ETH. For example, if we have already reached > 2/3rds before an epoch is over, and we did > 2/3rds last epoch, it is fairly safe to assume that chain finality will follow very soon. That is, we can get confidence in finality happening before 6.4 minutes pass. Although this "confidence" can be useful, it is still possible there could be a chain reorg within an epoch, even a 1 block or 2 block reorg, if enough voting power is on a fork of the canonical chain. As far as we have seen, minor forks with significant voting power on eth2 are rare, and have never happened in current chain conditions. Question about MEV: how soon could we know about finality for it to be useful to MEV-geth? ## Philosophical discussion on finality ### Can nodes go against the protocol? Finality, at the end of the day, is an abstract concept enforced by a social consensus on the rules of a protocol. There is an honesty assumption that nodes are indeed following the protocol. This means that even a few rogue nodes trying to modify their client software to ignore the rules around finality will not affect the network as whole, because all other nodes are following the protocol. Given fork choice, which decides _reorgs_, begins at the last finalized epoch, it is impossible for a reorg to occur unless a large majority of nodes go against the protocol. ## References - [eth2 specs](https://github.com/ethereum/eth2.0-specs) - [beaconcha.in](https://beaconcha.in)