Словник

Fork Choice Rule

Moderate

The fork choice rule is a mechanism in Ethereum that allows nodes to agree on a canonical chain when the network splits into competing forks.

What Is the Fork Choice Rule?

The fork choice rule is a mechanism in Ethereum that allows nodes to agree on a canonical chain when the network splits into competing forks. To fully grasp the nuances of this process, we first need to understand some basic concepts like what exactly constitutes a fork in Ethereum.

For our newcomers, let’s briefly discuss what a fork is!

What Is a Fork in Ethereum?

A fork refers to a divergence in the blockchain, whereby the network splits into two chains. This occurs when some nodes upgrade to new software while others continue running the old software. The upgraded nodes split onto a new chain, while the remaining nodes stay on the original chain. In this way, two parallel versions of the blockchain can coexist. This splitting of paths creates considerable complexity that must be managed through careful protocols and mechanisms. 

What Caused the DAO Fork in Ethereum?

The most well-known Ethereum fork resulted from the infamous DAO hack in 2016. The DAO was conceived as a decentralized venture capital fund, allowing investors to democratically fund Ethereum projects. However, an exploit was discovered that allowed a hacker to drain $50 million worth of Ether from The DAO. To recover the stolen funds and restore confidence, Ethereum was hard-forked. This was controversial, as not all agreed this intervention adhered to Ethereum’s guiding principles. Thus, the original unforked chain continued as Ethereum Classic, while the new fork became the dominant Ethereum chain we know today. 

What Is the Fork Choice Rule in Ethereum? 

The fork choice rule provides the logic for nodes to assess competing chain candidates and reach a consensus on the legitimate chain. It acts as the referee to decide between valid forks. Without a clear fork choice rule, Ethereum risks descending into an ambiguous state where forks proliferate and consensus breaks down. The rule enables synchronized progression in the face of dissenting perspectives. As such, it is foundational to Ethereum’s order and security. By formalizing chain selection, fork choice reduces uncertainty and keeps decision-making decentralized.

How Does the Fork Choice Rule Help Nodes Decide on the Canonical Chain? 

The simplest fork choice rule is the Longest Chain Rule, whereby nodes follow the fork with the most blocks mined. This leverages the principle that greater hashing power reflects agreement between miners. However, since mining power alone does not guarantee validity, the Longest Chain policy is vulnerable to attacks. Rules relying solely on chained blocks cannot capture more nuanced metrics of accuracy. Hence, advanced protocols like GHOST were introduced to incorporate richer criteria such as uncle blocks when weighing forks. By sampling more data points, nodes can make more informed determinations to align on the canonical chain.

What Is the Longest Chain Rule in Ethereum?

The Longest Chain Rule dictates that nodes should follow the fork with the highest number of chained blocks. Under this rule, the fork that demonstrates greater mining activity and participation wins consensus. The rationale is that the longest chain presumably attracts the most mining power and reflects the dominant validator perspective. However, attackers can potentially manipulate this metric by aggressively mining invalid blocks faster than honest miners. Since length alone does not guarantee validity, relying solely on this rule exposes the network to risk. Thus, more sophisticated fork choice rules have been developed to supersede the Longest Chain Rule in Ethereum.

What Are the Limitations of Using the Longest Chain Rule?

The Longest Chain Rule has several weaknesses that necessitate improved fork choice protocols. Most critically, it is vulnerable to attacks by malicious miners who simply need to operate a sufficient hash rate to rapidly mine an invalid fork ahead of the current chain. This allows them to fool nodes into accepting their illegitimate fork as the honest canonical chain. Further, the Longest Chain Rule fails to account for other factors like validity and community adoption that better indicate a chain's legitimacy. It also provides no mechanisms to guard against double-spend attacks across forks. For these reasons, Ethereum has migrated to more robust fork choice rules like GHOST that sample more points of data to establish fork validity.

How Does the GHOST Protocol Improve on the Longest Chain Rule? 

GHOST (Greedy Heaviest Observed SubTree) strengthens security by incorporating more fork data than just length when weighing chains. In addition to the main chain, GHOST considers “uncle” blocks - orphaned blocks that were mined but not included in the main chain. By factoring in uncle blocks, GHOST compiles a fuller representation of miner activity to make its assessments. Chains accrue more “weight” by referencing a greater share of uncles, making them harder to override. It means that chains that reference a greater share of uncles are considered to have more weight because they represent more work and effort by miners. As a result, these chains are harder to override because doing so would require more computational power and effort to create a longer chain. This provides fuller context to identify the dominant fork, preventing secret mining attacks possible under the Longest Chain Rule. In essence, GHOST improves accuracy by assessing a more holistic snapshot of network activity.

What Is Uncle Blocks in Ethereum, and How Does GHOST Use It?

In Ethereum, uncle blocks refer to valid blocks that were mined but not included in the main chain. Usually, this occurs because two miners produce blocks at similar times, and the first one wins. These orphaned “uncle” blocks can still provide useful signals about node activity, despite being omitted from the blockchain. GHOST leverages this by assigning greater weight to forks that reference more uncles. This means miners cannot strengthen a fork simply by mining new blocks in isolation. They must capture a broader share of uncles attesting to support. This way, GHOST uses uncles to paint a more information-rich picture for reliable fork choice.

How Did EIP-155 Change the Fork Choice Rule To Prevent Replay Attacks? 

Despite improvements from GHOST, Ethereum remained vulnerable to replay attacks whereby transactions could be illegitimately re-broadcast across forked chains. To address this, the EIP-155 proposal altered the signature scheme in Ethereum to tie transactions to a specific fork. This modifies the fork choice rule by requiring transactions to be signed with the fork-specific chain ID. Now transactions that are marked as invalid cannot be replayed across divergent forks. By binding transactions to a particular chain, EIP-155 prevents cross-fork replay attacks that could otherwise compromise legitimacy.

How Has the Fork Choice Rule Evolved After the Ethereum 2.0 Implementation?

The Ethereum Merge, which was executed on September 15, 2022, marks a significant change in Ethereum's architecture. The Merge involved the original Ethereum mainnet merging with the Beacon Chain, a separate proof-of-stake blockchain. As a result, proof-of-work was permanently replaced by proof-of-stake, which reduces the reliance on mining power and significantly reduces energy consumption. The Merge also introduced new approaches for fork choice to maintain security, as the planned beacon chain facilitates cross-shard consensus. The fork choice rule must now sample validation signals across the beacon chain, shard chains and execution layer to maintain security. As Ethereum advances, the fork choice rule must continue to evolve to support this new technical terrain. The Merge is the beginning of a new phase of Ethereum's development, and the Ethereum community will continue to innovate and develop solutions to enhance the security and resilience of the network.