Teacher Xiao Zhen from Peking University's "Blockchain Technology and Application" series of course study notes [17] Ethereum-GHOST protocol

Table of contents

1. The block generation time of Ethereum and possible problems

        1. The block time of Ethereum

        2. Comparison of the average block time between Ethereum and Bitcoin systems

        3. Problems brought about

2. GHOST protocol

        1. The core idea of ​​GHOST protocol

        2. Defects of the GHOST protocol

        3. Improved GHOST protocol

        4. Problems that cannot be solved by the improved GHOST protocol

3. Rewards in Ethereum

4. Thinking

5. The real situation in Ethereum

1. The block generation time of Ethereum and possible problems

1. The block time of Ethereum

        Ethereum has reduced the block generation time to more than ten seconds , which improves the throughput of the system and reduces the reaction time. Compared with the 10-minute block generation time of the Bitcoin system, the block generation speed of Ethereum is equivalent to 40 times higher. This greatly reduces the block generation time and brings some new problems . Both Bitcoin and Ethereum are consensus protocols running on the application layer. The bottom layer is a P2P Overlay Network. The transmission time of the Overlay Network itself is relatively long (the topology protocol does not consider the actual topology when flooding). It brings a problem: when a block is released, it may take more than ten seconds for the block to be uploaded to other nodes on the network, so there is a high possibility that two nodes (or even more) will obtain the bookkeeping right at the same time, thus cause a temporary fork .

2. Comparison of the average block time between Ethereum and Bitcoin systems

        For the Bitcoin system , the average block generation time is 600 seconds, which is enough for the newly released block to spread to other nodes on the network. However, since mining is a probabilistic process, there are still two miners who obtain the bookkeeping right at the same time. The possibility of publishing blocks will bring temporary forks. In Ethereum, this kind of temporary fork will become the norm, and the number of forks will become more (the block generation time of more than ten seconds is very likely that other nodes have not had time to receive the published block , and dig down along the original blockchain, he may have already dug the block by the time he receives the released block), which is a challenge for the consensus protocol.

Picture 1-1

3. Problems brought about

        In the Bitcoin system, only those blocks on the longest legal chain contain block rewards that are really useful, and block rewards on other forked chains are actually invalid, as shown in Figure 1- 1. For example, the block chain in the picture is divided into three forks, and the bookkeeping rights are obtained almost at the same time, and the last one will win to become the longest legal chain. Assuming that the middle block wins, then the upper and lower blocks are called Orphan Block or Stale Block , the miners who dig this type of block have a minting transaction in it, and can get a certain amount of bitcoins, but this is actually useless, because it is not on the longest legal chain, so the obtained output The block reward is finally invalidated . For Bitcoin, there are not many such temporary forks, so this regulation is acceptable.

        For Ethereum, if the block reward for the forked block is also invalidated, it means that the block dug by the miner has a high probability of being dug for nothing, especially for individual miners . According to common sense, the income of miners should be proportional to the computing power, and the income of the mining pool should also be proportional to the total computing power of the mining pool. However, there will be Mining Centralization (mining centralization) in large mining pools, that is, the fork where the large mining pool is located is more likely to become the longest legal chain, which prompts other miners to continue digging along the longest legal chain (because if other chain to dig, it is very likely to dig in vain). This will lead to a vicious cycle for large mining pools. The larger the mining pool, the greater the income, and the more serious Mining Centralization, sometimes called Centralization Bias, that is, the disproportionate advantages brought by centralization. If Ethereum follows the consensus mechanism of Bitcoin, there will be certain problems .

2. GHOST protocol

        In order to solve the problems caused by the consensus mechanism of Bitcoin in Ethereum, a consensus mechanism based on the GHOST protocol is adopted. This protocol was not invented by Ethereum, and Ethereum only made some modifications to the protocol.

1. The core idea of ​​GHOST protocol

        The miners who have dug the mine publish a block. Even if the block is finally invalidated, they will be given some rewards . At this time, they can also get some block rewards . Stale Block) is called Uncle Block . Compared with the current block of the longest legal chain, it is his uncle block, and the next block of the longest legal chain can include the uncle block when it is released, as shown in Figure 2-1.

Figure 2-1

         The core idea of ​​the agreement is: to give comfort to those miners who have dug mines but have not become the longest legal chain . Although the mined block does not become the block on the longest legal chain, it can still get most of the block rewards. This is conducive to encouraging timely merging after a fork occurs in the system, which is equivalent to recruiting the other two forked chains from the block on the longest legal chain. This is the original version of the GHOST protocol.

2. Defects of the GHOST protocol

(1) The number of Uncle Blocks cannot exceed two

        Uncle Block can only contain two. If there is a third Uncle Block, as shown in Figure 2-2 below, the purpose of designing GHOST is to give Uncle Block a little benefit and merge them, but only two can be recruited . If there is a third Uncle Block There is no way for three Uncle Blocks. In fact, it makes sense to only include two Uncle Blocks, because the Uncle Block gets seven-eighths of the block reward is very high, if there is no limit, then the Ethereum is too worthless.

Figure 2-2

(2) There is a delay in block propagation

        The prerequisite for block D to use block A as the uncle block is: when the block D is mined, the existence of the uncle block of block A is already known. If the block D has been released, then the uncle block is known. block, it is too late at this time, and the uncle block becomes nothing good.

(3) subject to the subjective influence of miners

        If the miner is selfish, for commercial purposes, he may deliberately not include the uncle block, that is, he knows the uncle block when digging, but he does not include it. In this case, for the uncle block, 7/8 The block reward is unobtainable. For himself, 1/32 of the block reward is unobtainable, which seems to be detrimental to others, but from the perspective of commercial competition, the loss to the miner is huge. If it is relatively small, the loss to the miners who dug out the uncle block is relatively large.

3. Improved GHOST protocol

        The improved GHOST protocol is shown in Figure 2-3. This rule solves the problem that the mining pool deliberately does not include an uncle block due to competition . For example, block D deliberately does not contain block A, but block E can still contain block A. There may even be a situation where the miner who dug up block A finds that he is not on the longest legal chain, so he digs out block E along block D, and then he can include his own block A in it.

Figure 2-3

        In this case, the problem of the third uncle block is also solved . The essence of the improved GHOST protocol is to improve some problems in the original version of the GHOST protocol, so the definition of uncle is expanded, not necessarily the current uncle, but may be the uncle of several generations. Ethereum stipulates that uncle blocks can get 7/8 block rewards. If one generation is pushed forward, the uncle block gets 6/8 block rewards. By analogy, only these six blocks are uncle blocks, and any further blocks are not uncle blocks, as shown in Figure 2-4. The definition of an uncle block is that it must have a common ancestor with the current block within 7 generations, and it will not be recognized if it exceeds 7 generations. In other words, there are only 6 generations of legal uncles.

Figure 2-4

Why set the legal uncle must be within seven generations of the current block and have a common ancestor ?

(1) If you do not limit the seniority of uncles, then to implement it, the full node needs to maintain a lot of state (maybe remember which uncle blocks there are 100 generations ago), and the newly released block contains the uncle area blocks, other nodes also need to verify;

(2) The design is separated by a maximum of 7 generations, and within these 7 generations, the block rewards are gradually decreasing, which is conducive to encouraging early mergers after a fork occurs, and the block rewards that can be obtained when a fork occurs and merge immediately It is the most, if after a few generations, the block rewards will become less and less, and if there are too many generations, you will not get any block rewards.

        The reward of the uncle block is called Uncle Reward. If the current block contains an uncle block, it will get 1/32 of the block reward, no matter which generation of uncle it contains.

4. Problems that cannot be solved by the improved GHOST protocol

        This protocol is designed mainly to solve the temporary forks that appear in the system, including Bitcoin and Ethereum. The purpose of specifying the principle of the longest legal chain is to prevent tampering, but it is also to solve temporary forks. The longest legal chain provides a mechanism for merging after a temporary fork ( State Fork ). If the fork is caused by other reasons, such as different opinions on the running blockchain protocol, then this method cannot solve it, that is to say, the improved GHOST protocol still cannot solve the hard fork .

        For example, when learning Bitcoin script, I learned CHECKMULTISIG (used to check the validity of multi-signatures). There is a bug in this process. When checking, one more element will be popped from the stack. If it doesn’t work, you have to press a useless extra element into it first, just to offset this bug. The reason why this BUG is not changed here is because the version is different after the change. The Bitcoin system is different from the centralized system (it is easy for the centralized system to release a new version), and if the decentralized system is modified, there will be a hard fork . If the two chains in Figure 2-4 are not because of differences of opinion on the current state, but each other thinks that the other is illegal and that the other’s block contains illegal transactions, then this method cannot be merged. If a miner includes such a block, other miners will think that this chain is illegal, and they will not continue to dig along this chain if it is included, or dig along other forked chains, because: even if the main The chain is the longest, but contains illegal transactions.

3. Rewards in Ethereum

        The rewards that blockchain and Ethereum can get for publishing a block are shown in Figure 3-1 below. In fact, there are two parts of rewards. The uncle block gets 7/8 of the rewards and is limited to Block Reward, that is, 7/8 ×3ETH. Uncle blocks do not get gas fees, but the proportion of gas fees is very small, and most of them are block rewards, which is similar to the situation of Bitcoin.

Figure 3-1

        There is no rule in Ethereum to halve block rewards on a regular basis. Bitcoin’s regulation is to artificially create scarcity. In Ethereum, five ethers are reduced to three ethers. It is related to the adjustment of mining difficulty. In 2017, the mining difficulty bomb was adjusted back by 3 million blocks, resulting in a significant drop in mining difficulty. In order to maintain fairness and prevent drastic changes in the supply of Ethereum, it dropped to Three ethers, this is a one-off, and it does not say that it will be adjusted continuously in the future.

        Bitcoin is generally regarded as digital gold, which is used to store value; Ethereum is compared to oil, which is used to spend, consume, and then execute smart contracts. This analogy is not completely appropriate, because the oil will be gone after the oil is spent, and the gas consumed by executing the smart contract in Ethereum is just transferred from one account to another account. The miners of this smart contract can get this gas fee, so this analogy is not entirely appropriate.

4. Thinking

1. When the uncle block is included, should the transactions in the uncle block be executed? Ethereum is a transaction-driven state machine, and Bitcoin is the same, so every time a new block is released on the longest legal chain, the current state will be transferred to the next state. Now that the uncle block is introduced, do you want to execute it? What about transactions in uncle blocks?

        Should not be executed, the transactions contained in the parent block and its uncle blocks on the longest legal chain may conflict, and if they contain different transactions, different transactions may not be executed. For the Bitcoin system, for conflicting transactions, Bitcoin has to do Double Spending Attack to detect whether it is a double spending attack. In Ethereum, the double-spend attack costs two minus two, but it is possible that after one transaction is spent, the other transaction cannot be spent. Therefore, some transactions in the uncle block may become illegal transactions. The uncle block itself is not necessarily illegal, but after executing the transactions in the parent block, it may become illegal to execute the transactions in the uncle block. .

        In Ethereum, only the transactions on the longest legal chain are executed. These transactions of the uncle blocks are not executed in the current block. And it does not check the legality of the uncle block transaction at all, only checks whether the uncle block is a legally released block , that is, whether the block meets the difficulty of mining, that is, whether it has obtained the right to bookkeeping.

2. Can the uncle block be generalized?

        The uncle block is the first block after the fork. If the fork is followed by a string, as shown in Figure 4-1, these cannot be considered uncle blocks. Assuming that these blocks are considered uncle blocks, there will be a consequence: the cost of forking attacks is too low. A fork attack in the normal sense needs to make the length of the forked chain greater than the length of the original longest legal chain to be considered successful, otherwise the blocks used for the fork attack will be invalidated, and the original block rewards will also be lost. If the block on the forked chain is considered to be the uncle block, the fork attack fails and it can be used as the uncle block to get some rewards. Therefore, it is stipulated in Ethereum that only the first block after the fork can get Uncle Reward, and the rest cannot.

Pic 4-1

5. The real situation in Ethereum

        Etherscan.io can view the current status of Ethereum in real time. The curve on the right shows the transaction history of the past two weeks, and the latest mined block and the latest transaction are also included below, as shown in Figure 5-1 below.

Figure 5-1

        Figure 5-2 below shows several situations of uncle blocks. Each row here corresponds to an uncle block. The Block Height in the first column is the serial number of the block, that is, Block Number, which is different from uncles of different generations in the table. Corresponds to the number of Uncle Rewards obtained.

Figure 5-2

        Figure 5-3 below is a specific example of two blocks. The block on the left contains an uncle block. The uncle reward in the penultimate line is 2.25, which should be the uncle with a distance of 2. The reward for this block, in the penultimate row, consists of three parts, namely, 3ETH block reward, gas fee, and 1/32nd of the block reward that includes the uncle block.

Guess you like

Origin blog.csdn.net/YSL_Lsy_/article/details/126443249