Special thanks to Sacha Yves Saint-Leger and Danny Ryan for their reviews.
In this episode, we will discuss the consensus mechanism of eth2. Eth2 has a new approach to determining which block is the leader of the chain. is and no Part of a chain.
By using a hybrid between the two mechanisms, eth2 aims for consensus that is not only fast and secure when the network operates normally, but also remains secure when attacked.
trilemma
FLP not possible A key finding in the field of distributed computation is that in distributed systems it is impossible to: at the same time It is safe, lively, and completely asynchronous, as long as no unreasonable assumptions can be made about the system.
safety The idea is that decisions cannot be undone. vitality It captures the idea that something new can be determined. The protocol is asynchronous When there is no limit to how long it takes for a message to be delivered.
If nodes could communicate reliably and always follow the protocol honestly and never have conflicts, consensus would be easy, but that’s not the case in the world. If these assumptions do not hold, FLP impossibility is evidence that at least one of safety, liveness, or overall asynchrony must be compromised.
Their opinions on GHOST and forks
Eth2 is Greedy Heaviest Observed Subtree(GHOST) With the fork selection rule. GHOST selects the leader of the chain by choosing the fork with the most votes (this is done by taking into account all votes for each fork block and its child blocks).
put another way, whenever there is a fork, GHOST chooses whichever latest message supports more subtrees of that block (i.e., more recent messages support that block or one of its descendants). The algorithm does this until it reaches a block with no children.
Compared to the longest chain rule, GHOST has the advantage of reducing the effectiveness of attacks during periods of high network latency and minimizing the depth of chain reconfiguration. This is because an attacker can efficiently keep building blocks on his own chain to create the longest block, but GHOST will choose another fork because it has a higher total number of votes.
In particular, eth2 uses a variant of GHOST tailored for the PoS context called Latest Message Driven GHOST (LMD-GHOST). The basic idea of LMD-GHOST is that when calculating the head of the chain, it only considers: recent This is not a vote made in the past, but a vote by each validator. This significantly reduces the computation required when running GHOST, since the number of forks that must be considered to execute fork selection cannot be greater than the number of validators. Big O notation).
According to the rules of GHOST, validators/miners can always attempt to add new blocks to the blockchain (active) and can do so at any point in the chain history (asynchronous). Thanks to FLP, it’s live and completely asynchronous, so we know it can’t be foolproof.
The lack of safety comes in the form of reconfigurations where the chain can suddenly switch between forks of arbitrary depth. Obviously, this is undesirable and eth1 handles this by forcing the user to make assumptions about how long it takes for a miner’s block to communicate with the rest of the network. check. In contrast, Eth2 makes no such assumption.
Final Friendly Gadget
A blockchain without any concept of security is useless because no decisions can be made and users cannot agree on the state of the chain. enter Casper the Friendly Finality Gadget(Casper FFG). Casper FFG is a mechanism that favors safety over activity when making decisions. This means that if the network conditions are poor, the decision may be final but may not lead to anything.
FFG is an adaptation of the classic cryptocurrency economy. Practical Byzantine Fault Tolerance (PBFT) There is a step where nodes first indicate that they want to agree on something (justification) then agree that they have seen something they agree on (finish).
Eth2 does not attempt to justify and finalize every slot (the time a block is expected to be produced), but instead only attempts to justify and finalize every 32 slots. A total of 32 slots era. First, validators sign that they agree on all 32 blocks in an epoch. then if That way the block is justified. In subsequent epochs, the verifier gets another chance to vote to indicate that it has seen the previously justified epoch. This will end the era and make it part of the eth2 chain forever.
FFG uses a clever trick. The vote actually consists of two sub-votes. One is for the era being justified and the other is for the previous era being concluded. This saves a lot of extra communication between nodes and helps us achieve our goal of scaling to millions of validators.
Two ghosts wearing trench coats
Consensus within eth2 relies on LMD-GHOST, which adds new blocks and decides what the head of the chain is, and Casper FFG, which makes the final decision on which block. is and no Part of a chain. GHOST’s advantageous active properties allow new blocks to be added to the chain quickly and efficiently, while FFG follows suit to close the era, providing safety.
The two protocols are merged by executing GHOST on the last final block as determined by the FFG. Depending on its configuration, a finalized block is always part of the chain. This means that GHOST does not need to consider previous blocks.
In the general case, a block is created and Once the validators vote on it, this block is added to the front of the chain by GHOST, and shortly afterwards it is justified and finalized by FFG (taking the last few epochs into account).
If there is an attack on the network or multiple validators go offline, GHOST continues to add new blocks. However, since GHOST is enabled but not secure, you may change your mind about the chain head. This is because new blocks are constantly added to the chain. This means that the nodes are constantly learning new information. FFG, on the other hand, favors safety over effectiveness. That is, it stops finalizing blocks until the network is stable enough for validators to consistently vote again.