Ethereum 2.0: Casper & Beacon Chain
Editor's Note: This article comes fromUnitimes(ID:Uni-times), Author: Colin Schwarz, Compiler: Jhonny, published with permission.

secondary title
Background InformationIn the first article in this series, "What will Serenity bring?", we outline the history of the Ethereum network so far and explain the main problems that the highly anticipated Eth 2.0 will solve. In the second article "secondary title
consensus algorithm
consensus algorithm
In traditional value and information exchange networks, there is usually an intermediary that secures and verifies the network. For example, banks provide security for customers’ assets and centralize control over customers’ online transactions and information. In the blockchain field, since the blockchain network is decentralized, there is no need for such intermediaries.
Since there are no intermediaries, blockchain networks must use some form of system to maintain security and ensure the validity of new information added to the distributed ledger. [1]
That is, a majority of nodes in a blockchain network must "reach consensus" on a single version of the network state in order to keep the network secure.To achieve this, blockchains use various "consensus algorithms," which are a set of predefined rules written into the protocol code that allow the network to reach consensus and achieve finality. Finality means that "once a specific operation is completed, the operation will be permanently engraved in the historical records, and the operation will not be reversed." [2] [Remarks, for the finality of the blockchain, readers can refer to Unitimes previous published article "Ethereum 2.0:》]。
How to achieve finality?
Proof of Work (PoW) is the earliest blockchain consensus algorithm used by Bitcoin, which ensures the security and decentralization of the Bitcoin network. Recently, many other blockchain platforms have introduced other consensus algorithms such as PoS (Proof of Stake), DPoS (Proxy Proof of Stake) and PoA (Proof of Authority) for many reasons.
secondary title
Why PoS is needed?
Proof-of-work (PoW) systems such as Bitcoin involve many miners connected to the blockchain network through computer hardware. The PoW consensus algorithm will set a target value for each new block, and miners will compete to be the first to find the target value and add the new block, so that they can get mining rewards.
To do this, they run the proposed block's header data through a hash function that returns/outputs a fixed-length string (the hash value). Miners will keep changing their input "nonce value", that is, re-hash the block header, until the input "nonce value" generates a hash value that matches the target value. At this time, the new block will be broadcast to all nodes in the network, and these nodes will verify the block and add it to the ledger, and the miners who successfully dig out the block will receive mining rewards.
The key aspect of a PoW system is that finding the correct hash input requires a lot of computing power (i.e. there is mining difficulty), but once the miner has found the correct input (i.e. the "nonce value"), it is easy to verify the output ( That is, the hash value returned by the hash function). The difficulty of the mining process guarantees the security of the network, and it is relatively simple for nodes to verify each block, which allows thousands of network nodes to maintain the latest records of the blockchain.
But unfortunately, the difficulty of finding each target value by hashing requires a lot of computing power and electricity, which reduces the efficiency of the network and the profit of the miners. All miners have to spend a lot of electricity and calculations trying to confirm blocks and win rewards, but only one of them will successfully mine a new block. Because of this, the mining of each block wastes a lot of power and computation. This means that although the PoW algorithm can guarantee the security of the network, the efficiency of the algorithm is very low.
In addition to the inefficiency of PoW blockchains, the mining space is also vulnerable to market monopoly because this method of mining gives unfair advantages to those participants with more resources. Wealthy and powerful individuals and organizations can afford large quantities of faster and more powerful mining hardware, giving them a better chance of successfully mining new coins. Currently, about 65% of Bitcoin mining is done by 5 large mining groups, and they could theoretically combine to control more than 50% of the computing power market (although it is unlikely that they will do so). This creates a situation where Bitcoin and other PoW blockchain networks are not as decentralized as they were originally envisioned, which jeopardizes their independence and utility.
In a PoS network, "miners" are replaced by "validators" who own the network's native token. Validators participate in block verification in the network by staking a certain amount of tokens (including proposing blocks and proving blocks). If the proposed/proven block is added to the network, then Validators who propose/prove the block will be rewarded proportional to their stake. In a PoS network, the lack of mining like PoW makes it thousands of times more cost-effective and energy-efficient than a PoW system.
secondary title
The "Nothing at Stake" Problem
One of the biggest problems in implementing the PoS consensus proof algorithm is the "Nothing at Stake" problem. People have been experimenting with PoS consensus since 2013, and early adopters such as Peercoin quickly ran into this problem [4].
Early adoption of the PoS protocol allowed anyone who owned the network’s native tokens to act as a network validator. These PoS projects assumed that those who owned the tokens had a vested interest in the success of the network (i.e. would spontaneously participate as validators for their own benefit, and honestly verify).
Those with more tokens are given more validating power on the assumption that those with more tokens have little incentive to attack.
However, early PoS projects quickly realized that this logic was flawed. Typically, miners/validators are only given one block to validate. However, due to latency, often multiple blocks are proposed and miners/validators are presented with two blocks to choose from.
In the traditional PoW system, miners can only mine in one forked chain at a time [5]. To successfully replace an illegal forked chain with the previous "authoritative chain" (that is, the longest chain), it needs to have more than 50% of the network's computing power, which is extremely high for a large PoW blockchain network such as Bitcoin. very difficult.
In the PoS network, it is possible for the verifier to verify the blocks on two different forked chains at the same time, and there is no need to bear additional costs. In fact, in the early stages of PoS adoption, it was theoretically in a validator's economic interest to stake on any available fork, since by doing so, validators would Obtain transaction fee rewards, this is the "Nothing at Stake (no cost to do evil, unlimited benefits)" problem.
The worst consequences of this kind of problem can be illustrated by the following security assumptions:
Validators will try to maximize their own profit, even if it hurts the entire network;
No validator will validate altruistically (blocks are only validated on one chain);
Validators will modify their software, or download modified software, allowing them to validate multiple forked chains (standard software with internal logic to choose the correct forked chain when a fork occurs).
Due to the above-mentioned security assumptions, multiple forked chains may appear, which will delay and complicate the network consensus. If not resolved, it may also lead to major security vulnerabilities in the network. If every verifier can actually verify the blocks of every forked chain in the network, then a malicious verifier will be able to carry out a double-spend attack (that is, the same token spent multiple times). They can send tokens through one of the forks to an exchange, withdraw tokens from that exchange, and then only validate blocks on the other fork.
Since it is assumed that all validators are validating against two different forked chains, the second chain will gain more and more proofs and eventually become the only valid chain. This means that token transactions previously spent on the first forked chain and withdrawn from exchanges will no longer be valid. In this way, a successful double-spending expenditure occurs and the exchange is defrauded of funds, no matter how large the amount involved.
In short, the lack of requiring each validator to stake actual value in early attempts at PoS made the network likely to be delayed, complex, and insecure.
secondary title

The Solution to the “Nothing at Stake” Problem: Casper
Fortunately, the Ethereum team has learned from the shortcomings of early PoS projects and designed the Casper protocol to eliminate the "Nothing at Stake" problem. In 2014, Vitalik first proposed the idea of eliminating the "Nothing at Stake" problem in an article called "Slasher" [5]. The paper proposes a simple solution: "Make the main chain aware of other forked chains. Later, if a miner is caught mining on both chains at the same time, the miner will be punished.
"Although the concept has evolved considerably since it was proposed, it became the basis of the Casper consensus algorithm.
Casper is an algorithm for penalizing validators who validate multiple forked chains or cause damage to the network.
The first implementation of Casper will use Ethereum's current PoW proposal mechanism to introduce new blocks on the Eth2.0 chain. If two blocks are proposed at the same time, the validator will only be rewarded for staking on one chain, so it makes sense to stake through the current Eth1.0 chain, because this old chain is the most likely chain of success.
More importantly, the Casper protocol introduces a mechanism whereby if any validator tries to support an invalid forked chain by validating multiple blocks at the same time, the token assets pledged by the validator will be destroyed. This is achieved through a special protection mechanism that enforces two "Casper commandments" [6]:
The first "Casper Commandment" is that a validator cannot issue two different votes at the same block height (i.e. cannot sign two different blocks at the same block height);
The second "Casper commandment" is that validators cannot vote again in other voting timeframes if they have already voted.Any validator who violates one of these precepts is considered a malicious validator and their entire deposit (not just their stake) will be forfeited. In order to improve the availability of the network and reduce the censorship of transactions, validators whose nodes are offline are also moderately punished. For details, please refer to the article previously published by Unitimes "Eth 2.0 AMA Phase 2 | Vitalik:Ethereum 2.0 has no unsolved research challenges
". Casper researcher Vlad Zamfir likened this new PoS security mechanism to the mining hardware used by anyone who launches a 51% attack in a PoW system will instantly catch fire and burn [2].
If the Casper mechanism is implemented correctly, it will eliminate the "Nothing at Stake" problem and allow the Ethereum network to safely transition to a PoS mechanism.
secondary title
beacon chain

beacon chain
The Casper proof-of-stake mechanism will be implemented through the beacon chain, which will be an independent chain running in parallel with the current Ethereum PoW chain. The beacon chain will be the "system chain" of the Eth2.0 chain, and its main responsibilities will be to store and maintain the validator registry, handle the crosslink between the shard chain and the beacon chain, and open the chain during each epoch. Randomize and assign verifiers to each shard chain (there will be 1024 shard chains in the Eth2.0 system) and so on.
Users can participate in the proof-of-stake protocol of the beacon chain by sending 32 ETH (deposit) in a smart contract that will be deployed on the current old Ethereum chain. This deposit will generate a receipt which will contain an ID showing which shard chain this validator is sharded to (read this article [12] to learn more about sharding).
After the user pledges, he will become a pending validator in the beacon chain. After waiting for a period of time, the user will be "activated" to become an active validator, and then can participate in the PoS protocol verification [9]. Only after the beacon chain has processed the pledge receipt from the Eth1.0 chain can the user be "activated" as a valid validator. The activated validators will take turns proposing new blocks and voting on the validity of the blocks.
Early versions of Casper will use the existing PoW proposal mechanism, and later versions will use a more efficient proposal mechanism. Vitalik envisions "transforming block proposals into a PoS circular block signature mechanism." [6] In order to prevent validators from colluding to launch attacks, the beacon chain randomly assigns validators to different shards by implementing randomness block proposal/voting verification in the chain [8]. If validators don't know when they will be assigned to which shard chain, it prevents them from colluding in advance to launch an attack.In the event of a fork, validators will use their client's beacon chain fork selection rules to automatically select the correct chain. The fork selection rule uses "Last Message DriVEN Greediest Heaviest Observed SubTree (LMD GHOST, GHOST driven by the latest news)" to determine which chain is the "canonical chain". If a potential attacker wants to verify the wrong forked chain, he must manually modify or eliminate the LMD GHOST fork selection rule. [Remarks: For more information about LMD GHOST, readers can refer to the article "Ethereum 2.0:》]
How to achieve finality?
secondary title
route map
route map
The beacon chain (that is, phase 0 of Eth2.0) is expected to be launched in early 2020, but only when the number of ETH pledged in the system reaches the minimum number requirements, and there are at least three production-ready clients, the beacon chain can be launched. Started successfully. Phases 1 and 2 are expected to follow in 2021 and 2020, respectively.
Phase 1 will introduce the basic shard chain structure, which is essentially a trial operation stage of the shard structure, used to test how the shard system will operate. Therefore, Phase 1 will not immediately realize the full scalability potential of sharding. This phase will address the consensus and finality of the shard chains and will allow the beacon chain to monitor the execution of the shard chains.
Phase 2 will witness a fully integrated Eth2.0 system with shards becoming fully functioning chains. Phase 2 will also introduce the brand new Ethereum Virtual Machine eWASM.
It is important to note that although these phases are conceptually separate, the work in each phase is being carried out simultaneously due to the interrelatedness of the phases.
In addition, efforts are currently underway to improve the Eth1.0 chain, also known as Eth 1.x, which aims to increase the throughput of the network through client-side optimization and implement "state fees" to ensure full operation. Sustainability of nodes, as well as stable transaction fees and the development of finality gadgets that can be used to connect Eth1.x chains to Eth2.0 chains.


