Reprint: Block chain: About soft fork and hard fork and what is consensus

Source: Internet
Author: User
Tags abstract definition
No. 0 Chapter Introduction

Bitcoin is a set of software, the software code to modify the upgrade will often involve two concepts, one is called a hard fork, a soft fork. What the hell does that mean? The most common definition in the community is the revision of consensus. But "consensus" specifically refers to what is difficult to understand. Let's actually modify the code level to see how they are defined.

Chapter 1th transaction format and transaction history of Bitcoin

Before we understand what a hard fork or a soft fork is, we need to know what the two things are going to change.

Bitcoin trading has a double meaning in Chinese, which is a key to a hard fork and a soft fork that is often misunderstood.

One of the implications of a Bitcoin transaction is that we send the data structure for the uniform use of bitcoin, which is a set of rules that all of us send Bitcoin, no matter what wallet software you use, you have to follow this set of rules. It is defined as a data structure in which each field represents what it means. All wallet software can understand this meaning.

Another implication of the Bitcoin transaction is the event that the person using the bitcoin sends the bitcoin to each other. Like I sent you 0.12345BTC, this is a deal. All of these events, which send Bitcoin, constitute a bit-currency transaction history, which is the main content of the data of more than 80 g, which is currently the full node of the bitcoin. All of these records can be found in a block-chain browser, you can find all your transactions by typing your bitcoin address on the block chain browser.

Make an analogy to illustrate. The format of the transaction is similar to the one we went to the bank to fill in the remittance money, the money order clearly defined the name of the sender, ID card, mobile phone number, account, amount, payee name, account number ... and other information. The transaction format of the Bitcoin also stipulates the information of the sender and the payee, but this information is not related to the person's identity information, and the specific information required by the Bitcoin transaction should be read in the next chapter.

2nd. Transaction format and block format of Bitcoin

Bitcoin's transaction history this concept is easy for everyone to understand, do not start to say, there is nothing to talk about. But the transaction format of Bitcoin, that is, the data structure of the transaction needs to be explained, otherwise it is impossible to understand what is called a hard fork and a soft fork.

A bit-currency transaction is a data structure that contains input values and output values that are embedded in code information that transfers a sum of money from the initial point (input value) to the destination address (the output value). This data structure contains fields, and we'll look at these fields in detail, excerpt from the 5th chapter in "Mastering Bitcoin."

All Bitcoin wallets have to send Bitcoin in the form specified in this table, otherwise they will not be recognized on the Bitcoin network, which is an invalid transaction. It's like you go to a bank remittance, you do not fill in the money order, the bank will not accept the same.

The Bitcoin network collects transactions from each node within an average of 10 minutes and then makes a packet, called a block, covers a timestamp, and then adds it to the block chain. What is the block?

A block is a container data structure that aggregates transaction information (that is, an average of 10 minutes of bitcoin transactions issued by each node on the network). It consists of a block header that contains metadata and a long list of transactions immediately following the constituent block body. The block's data structure is defined as the following.

All of the mining node wallet must be in accordance with the form specified in the way to pack blocks, otherwise in the Bitcoin network will not be other complete node identification (SPV node does not count), that is, will be considered invalid transactions.

3rd Chapter "official" Definition of hard fork and soft bifurcation

Hard forks and soft forks are defined on the bitcoin.org, but the definitions are vague, and in order to prevent my nonsense (questioning the definition of bitcoin.org, I am really scared.) ), I extract the original text:

The hard bifurcation is defined as this:

A permanent divergence in the "block chain", commonly occurs when non-upgraded nodes can ' t validate blocks created by up Graded nodes that follow newer consensus rules.

Https://bitcoin.org/en/glossary/hard-fork

The block chain is permanently divided, and after the new consensus rule is released, some nodes that have not been upgraded cannot verify the blocks that have been produced by the upgraded node, usually hard forks will occur.

The definition of a soft fork is this:

A temporary fork in the blocks chain which commonly occurs when miners using non-upgraded nodes violate a new consensus Rul e their nodes don ' t know about.

Https://bitcoin.org/en/glossary/soft-fork

When the new consensus rule is released, nodes that are not upgraded will produce an illegal block because they do not know the new consensus rule, and will create a temporary fork.

In the community's contention that block expansion is a hard fork or a soft fork, I guess the two vague definitions on bitcoin.org should bear the primary responsibility. The biggest responsibility is that the original "consensus rules" definition is not clear, if we go to bitcoin.org to look for "consensus rules (consensus rule)" What the meaning, the original is this:

The block validation rules this full nodes follow to stay in consensus with other nodes.

Https://bitcoin.org/en/glossary/consensus-rules

Block validation rules that a full node follows in order to maintain consensus with other nodes.

This definition of consensus logically commits the fallacy of cyclic authentication, which means that "consensus is the rule to maintain consensus". This is the same as what Xu Sando said: "It is meaningful to live well." "Then what is good to live for." "To live well is to do meaningful things." "In fact, he did not answer what is good to live, and what is meaningful."

In addition, the two definitions of the hard fork as "permanent divergence (permanent fork)", and the soft fork defined as "temporary fork (Temporary Fork)", which is almost a word game definition, so that many people in the community afraid of the hard bifurcation. It's a terrible thing to think of a hard fork.

To tell you the truth, this article has been written in my mind for a long time, but I have been afraid to write, because I doubt the definition of the Holy Land bitcoin.org. I struggled to read the bitcoin.org definition of the Bitcoin protocol upgrade, and I couldn't find a description that I could understand. I have asked many Big V in the country and haven't got a complete answer. The days of the community's soft fork lovers have sent a lot of articles to promote soft forks, calling for resistance to hard forks, after I read, I reasoned, in my knowledge system, I was convinced that they were wrong. The source of their mistakes comes from the understanding of "consensus" is an illusory description, do not know what specifically refers to, as long as the reference to "consensus" is sacrosanct, all logic and reasoning to the "consensus" stopped.

Since there is no abstract definition of a soft fork or a hard fork, let's start by analyzing what they do.

4th chapter on the implementation of soft fork upgrade in Bitcoin block chain

The Bitcoin block chain recently performed a soft fork upgrade a few months ago, making it the bip68/112/113 official in the Bitcoin protocol, known as the CSV Soft fork in the community. The upgrade was completed around June 2016. Where does this soft fork change the bit-currency code? To answer this question, we need to look for answers from the Bitcoin trading data structure.

What happens to the bits trading data structure before and after the CSV Soft fork.

The Red Word bold field in the figure is the main modification of the CSV Soft fork. Before the CSV soft fork, this field is the "serial number (currently unused transaction substitution function)" as shown below:

It is because this field is not used in the data structure of the bitcoin transaction, or it is a fuzzy definition at that time, so it can be redefined using. This undefined field is not carefully validated on the old version of the bit-currency complete node, and the new version of the node will be able to be validated by the old version of the node as it is produced by the defined rules. This is the concrete process of the soft fork.

But this is obviously not a long-term plan, because this kind of field is such a, you use once, after that no more.

Bitcoin also had an important upgrade in 2012 called P2SH, which the community called multiple signature soft forking. This is a change to the token transaction signature script, making it easy to send transactions through multiple signatures. What was changed that time.

The red word bold in the picture is the field where multiple signature soft forks are mainly modified. In the beginning, this field is defined as P2pkh (Pay-to-public-key-hash, paid to the public key), which can now have 5 scripts.

Because after multiple signature soft forks, the nodes that have not been upgraded can also be validated by verifying the blocks generated by the upgraded node, so this is also a soft fork.

The above two soft forks are for the bit currency transaction data structure modification. Soft forks can also modify the transaction history of Bitcoin in disguise.

On August 15, 2010, a hacker used a loophole in the Bitcoin code to brush a deal in the No. 74638 height block containing 184.4 billion bitcoin. It was later discovered by the developer in half a day and a patch was released, which invalidated the output of the transaction. But this is not simply to define the deal itself as null and void, and a class called "negative output" of the transaction is defined as invalid, just that the transaction is the use of Bitcoin before the negative output value of this vulnerability, but defined as long as the output total amount can not be higher than the total amount of input. In the patch (should be the issue of the Cong) fixed this loophole, the specific modification of what it is.

The Red Word bold field in the figure is the main modification of this patch. The rule before the modification is that "total" cannot be higher than "transaction", and the rule after modification is to add "total" to not be negative. This modified node can verify the blocks generated by the upgraded node, so it is also a soft fork.

Now we abstract these three cases and give a definition of a soft fork: The soft fork refers to the data structure of the Bitcoin transaction (this is the widely circulated "consensus"), the upgraded node can verify the blocks produced by the upgraded node, A node that has already been upgraded can also verify that a block is produced by a node that is not upgraded.

Soft bifurcation changes to the "consensus" must also include changes to the format of the block, but the three cases here are changes to the format of the transaction.

Here we look at the hard fork case.

5th chapter on the implementation of a hard fork in the chain of Bitcoin block case

On March 12, 2013, the bitcoin QT 0.8.0 version of the software was released, and version 0.8 adopted a new database level db. Some miner nodes upgraded the Bitcoin QT 0.8 version, and some miners continued to use Bitcoin qt0.7 version of the software. Each side produces blocks, but the blocks produced by the new database used by Bitcoin QT 0.8 are rejected by the qt0.7 version node. The specific reason is that the old database is sometimes not acceptable for blocks exceeding 800Kb. Therefore, in the block height of 225430 bitcoin block chain divided into two chains, resulting in a Bitcoin block chain to produce two chains, one is more than 800kb block chain, the other is to refuse to recognize these larger blocks of the chain, which took place a hard bifurcation.

The miners who used the bitcoin QT version 0.8 abandoned the chain they had dug and returned to Bitcoin QT 0.7 to continue digging.

The hard fork was an accident, a bug in the bitcoin QT 0.8 version of the software, which led to the use of the old software node to refuse to verify the blocks produced by the new software node. But the reason for the hard fork is that the old software version of the node refused to verify the new software version of the node production blocks, and then each side of the mining.

On the July 4, 2015 Bitcoin block chain occurs a hard fork in the block height 363731. It was the bitcoin core developer who added Bip 66 to the new version of the Bitcoin core 0.10.0. It would have been a soft forked modification, in the Bitcoin network, the main mine pool all use 0.10 version of the software, but there is a mining pool BTC Nuggets did not upgrade, leading to BTC Nuggets dug out of the two blocks other miners refused to drop, and then each side of the respective mining to continue their own thought is the right block chain , resulting in a hard bifurcation, divided into two strands.

Subsequently, Bitcoin.org issued an announcement calling on miners to upgrade to Bitcoin Core version 0.10.2 to eliminate forking.

This is also an accident, the reason for the hard fork is that the new software version of the node refused to verify the use of the old software version of the node production blocks, and then each side of the mining.

So far these two hard forks are accidents, but the reason for the hard fork is because the new block format on the different node differences, the latter is because of the transaction format in different nodes of differences. However, because it was an accident, the community did not discuss enough information, I also do not understand the specific block or the transaction of which field was modified to cause the fork.

Here, we can abstract these two cases, give a definition of a hard fork: A hard fork is a bit-currency block format or a transaction format (this is the widely circulated "consensus") when a change occurs, the upgraded node refuses to verify the blocks produced by the upgraded node, However, the upgraded node can verify the blocks produced by the not upgraded node, and then each of them continues to be the right chain, so it is divided into two chains.

Here's a look at what the community is planning, but not yet activated for soft forks and hard forks.

the 6th chapter is planning the block expansion of the hard fork

At present the Bitcoin community is planning a hard fork, the reason is that the current block is crammed into the transaction, in order to be able to accommodate more transactions in a 10-minute block, you need to modify the data structure of the block. Let's look at the data structure of the block first.

At present, the main complete node software of bitcoin network is bitcoin Core 0.12, which stipulates that the maximum value of "chunk size" in table 6 is 1M. This causes the last field "transaction" to be able to hold the bit currency transaction data is limited, a transaction is at least 250 bytes, 1Mb can only install more than 4,000 transactions, the average can only handle 7 transactions per second. And since the actual transactions tend to be 500 bytes in size, in fact, the average per second often can only accommodate 3 transactions.

So someone put forward to the maximum value of this field, such as Bitcoin classic The software will be the maximum value of this field to 2M, and then plan to take the first 2016 blocks of the size of the median and then multiply by a good number of agreed to determine the size of the next batch of blocks. The Bitcoin XT modifies this value to 20M and doubles every two years until the upper limit reaches 8.3G. and Bitcoin unlimited directly to change this field to the ore pool to decide how big you pack.

The problem is that the blocks produced by the nodes that have modified the software for this field are incompatible with nodes that are not upgraded, and those that are not upgraded will refuse to verify the blocks produced by these new nodes. This causes a hard fork.

Here, we basically know that the so-called hard fork need to modify the "consensus" refers to the modification of block data structure format, or modify the transaction data structure format.

7th Chapter Isolation Witness Soft fork

There is a block in disguise the expansion of the scheme is to witness the isolation, this scheme is to modify the Bitcoin trading data structure, we still look at the map.

The red field in the figure is the main hands-on place for the quarantine witness, which is to move this part of the data out of the transaction-defined data structure, and also to move out of the block-defined data structure. As a result, the transaction is less than a fraction of the data, so the volume of each transaction will be small, and the entire block 1M space can accommodate more transactions.

However, removing this field will also result in blocks that have been produced by the node that did not upgrade to verify those upgraded nodes. But there is a way to keep them from refusing, but the code is very complex to write, anyway this code has been written for more than a year, until now has not been done. The more complex the code, the more potential vulnerabilities are, and the more complex the Bip 66 is caused by a soft fork that leads to a hard bifurcation.

Here, once again verified that the so-called soft fork need to modify the "consensus" means to modify the block data structure format, or modify the format of the transaction data structure.

The 8th Chapter Soft Fork and hard fork to modify the "consensus" are the data structure modification

Now we can sum up what to do with the soft fork and the hard fork, especially the difference between the soft fork and the hard fork, lest it be fainted by the "consensus" that the definition is inaccurate.

The "consensus" of soft bifurcation modification refers to the modification of the bit-currency transaction data structure or the modification of the bit-currency block structure.

The "consensus" of the hard bifurcation modification refers to the modification of the bit-currency transaction data structure or the modification of the bit-currency block structure.

In the specific modification of the object level, soft fork and hard fork is completely indistinguishable, as far as we can see all the already happening, and the planned bifurcation is the case, they all modify or attempt to modify the transaction data structure, or block data structures.

The current, or planned, hard forks and soft forks will never modify the transaction history. Even if the August 15, 2010 of the brush out of the currency of the loophole, the change is also the transaction data structure, but the incidental role is to void the transaction in a block, because the transaction in the new transaction data structure of the definition is illegal.

Therefore, the soft fork and the hard fork in the revision of "consensus" level is essentially no difference.

What's the difference between a soft fork and a hard fork?

the 9th Chapter Soft fork and Hard fork is the main difference between the new and old node compatibility

The difference is the compatibility aspect of the old and new nodes. Soft fork modification data structure, the new node production of transactions and blocks can be validated by the old node and accept, hard fork can not.

Because the data structure is modified by a hard fork, the blocks produced by the new node are rejected by the old node, and if the old node refuses to upgrade the software and insists on digging the old data structure, the bitcoin will produce two strands.

The soft fork does not appear in two chains because it can accept new data produced by new nodes because no upgraded nodes. But the soft fork in order to do the new node and the old node production of the data is completely compatible, it is very difficult, because essentially is not the same data structure everyone to recognize each other, once there is a node refused to verify the different transactions or blocks, it will become a hard fork. This is why the Bip 66 soft fork eventually becomes a hard bifurcation.

From the 4th chapter we see the specific soft Fork modification office

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.