Disclaimer: This article is intended to convey more market information and does not constitute any investment advice. The article only represents the author's views and does not represent the official position of MarsBit.
Editor: Remember to follow
Source: Slow mist technology
Blockchain forks are divided into soft forks and hard forks. This article mainly discusses hard fork, a software upgrade method that does not support backward compatibility. Hard fork is a split or change of consensus. Consensus is an algorithm for each node in the blockchain system to reach data consistency. Under normal circumstances, each node needs to run an algorithm with the same rules. For example, Bitcoin runs based on PoW (Proof of Work) consensus. Ethereum used to be a PoW consensus, and recently switched to the PoS consensus algorithm through "The Merge". There are many reasons for
fork. It is a very common phenomenon in blockchain, usually short-distance fork, which is related to consensus algorithms. Competing blocks sometimes appear at the same height, but in the end some blocks will be abandoned and only one block is retained. But hard forks are different. This is a planned and purposeful fork. Some node clients deploy program versions different from the original network. The blocks produced can only be verified on the fork chain and cannot be accepted by the original network, nor do they accept blocks of the original network. For example, the recent popular EthereumPoW (ETHW) fork.
is not easy to fork a blockchain successfully. It is not easy to directly copy the code of the original network. Basic modifications are required to ensure that it runs safely. To this end, we have summarized several common security issues and protection methods.
Network layer
Since the forked chain is a blockchain independent of the original network, it first needs to be isolated at the network layer (P2P):
1, seed node
seed node, also known as bootnode or seednode, is the node that the network will first try to connect when the blockchain is started. When the fork chain is started, it first connects the nodes in the seed node list, so as to further discover other peer nodes in the network, and then further synchronizes the blocks and reach a consensus. Therefore, it is necessary to modify the seed node list to prevent nodes connected to the original network.
2. Alien attack
Even if the seed node list changes, it does not mean that the forked network will not connect to the original network, because the P2P protocol of both parties is the same. If one node accidentally adds a node connection to another network, the two nodes will successfully shake hands and add the other party to the node address pool. Not only that, both nodes will also share the addresses in their nodes with each other, which will cause the pool of bilateral network nodes to pollute each other. Regarding this issue, Shouwu has previously disclosed the "Conflict Public Chain" separately! Alien Attack Vulnerability from P2P Protocol》.
In order to solve the problem of mutual contamination of address pools, network identification is required on the communication protocol. Early Ethereum did not support network separation, but subsequent versions added NetworkID as a symbol of network distinction in the protocol. NetworkID is usually the ChainID of each chain. For example, the NetworkID and ChainID of the Ethereum main network are 1, while the NetworkID was not forked in the initial version of ETHW, which may have a shape attack vulnerability.
In the Bitcoin network, Magic value is used to identify different networks, which are usually defined in chainparams. For example, the main network value of Bitcoin is F9BEB4D9 and the test network value is FABFB5DA.
consensus layer
1, transaction isolation
Usually when interacting with the blockchain, we need to sign a transaction with our private key , and then the transaction is broadcast to the network and packaged into the block by miners or block nodes. However, if the blockchain forks, the transaction may be packaged into different blocks by the two networks. Assuming this is a transfer on the original chain, there will be the same transfer on the forked chain. Obviously, this is an unexpected behavior and will cause asset losses.
needs to replay the transactions at this time, and there was no such protection in the early Ethereum version. Later, EIP155 added ChainID to the transaction structure to ensure that the transactions signed by the user are only used for the current network.If Ethereum is forked, then ChainID needs to be redefined. Of course, this is not as simple as modifying the ChainID in the configuration, because the forked chain needs to be compatible with the old blocks, so the new ChainID needs to be used after the forked height to ensure that the forked chain runs normally. ChainID does not exist in the transaction structure of
Bitcoin, so how does it replay protection? Bitcoin uses a model called UTXO. Simply put, it costs one transaction (UTXO) rather than an account. Usually, the newly launched network will not have the same two transactions, so there will be no replay scenario.
However, in the case of hard fork, there will still be problems with transaction replay, such as the BCH fork in 2017 and the later BSV fork. BCH adds SIGHASH_FORKID(0x40) to the transaction data signature, so that transactions on BCH and transactions on BTC are no longer compatible with each other, thereby achieving the purpose of playback protection.
2. Computing Power Adjustment
Before forking, the original chain occupies all the computing power of the entire network. Therefore, according to the PoW consensus algorithm, its block calculation is also relatively difficult. After the fork, the computing power is dispersed on different blockchains. Therefore, due to insufficient consensus, the fork chain usually cannot obtain enough computing power to produce new blocks, and the growth of blocks will stagnate. At this time, it is necessary to reduce the initial calculation difficulty after the fork, and give the fork chain a time window to quickly adjust the computing power.
3, Prevention 51% Attack
The network and transactions are isolated, the blockchain is forked, the new block is successfully produced, and everything seems normal. However, security issues remain prominent, and it still has a more common and difficult attack: 51% attack.
mining is profit-seeking. When a fork coin appears, miners who have high mining income will switch their computing power to that network. But the reality is that fork coin is often low in price, resulting in a very low overall computing power. Taking the ETHW fork as an example, we can see from 2miners that the peak computing power of the original ETH network exceeds 900TH/s, while the computing power of ETHW is only about 30TH/s when writing. It is not a good thing that a large amount of computing power disappears. It can launch a 51% attack on ETHW at any time.
has almost no good way to prevent such 51% attacks, and can only be prevented by increasing the number of confirmations.
application layer
We classify applications built on transactions, such as smart contracts based on virtual machines, into the application layer. When blockchain is forked, it will also have a huge impact on applications running on blockchain.
1, signature playback
signature playback is the same as the transaction playback mentioned above. There are some contracts, such as Gnosis Safe, which will verify the user's signature in the contract. If the ChainID is not included in the signature, then this signature is very likely to be reproduced on both chains, resulting in asset losses.
2, oracle failure,
, most smart contracts in the blockchain forked can still run normally, such as Token contracts and AMM contracts. These self-running systems can run stably without relying on off-chain data, but lending systems like MakerDAO are highly dependent on oracle price data. After losing off-chain price feed support, it will not be able to continue running.
3. Price changes drastically
blockchain has forked, and an application runs on two chains at the same time. Which chain should users use? Which one is considered "orthodox"? This question returns to consensus. Usually, which blockchain has an orthodox consensus, then the assets on it will retain the original value consensus, while the assets on another blockchain will lose value in an instant. The drastic price changes in
will cause the DeFi application to completely collapse, and the lending application will never close the position. Some knowledgeable people will seize the time window of the fork and exchange the "zero" assets through applications such as AMM tokens, thereby retaining some value. In the ETHW fork event, we observed a large number of arbitrage behaviors on the fork chain.
Summary
So far, we have analyzed the security of blockchain forks from the network layer, consensus layer and application layer. We can see the technical risks in it. We need to treat forks very cautiously. Moreover, behind many forks is not only the need for technological changes, but some may have direct commercial interests. For example, the initiator directly obtains a large number of fork coins in the fork, which requires users to accurately understand and avoid unnecessary losses.
blockchain is a decentralized system. Its upgrade does not depend on a single person or organization. Therefore, forking is inevitable in blockchain. Although it brings chaos to community users, it also promotes the system to develop forward to better serve the society.