Hard fork and soft fork explained

Most of the people have no clear idea about fork. Even I’ve been here since 2011, I still dare not to say I’m aware of all the complexities in it. It is a very complicated phenomenon, here is the translation of a post that I posted on Chinese forums 6 months ago, hoping it can help miners and technical interested to get a better understanding of the topic

What is fork?

I will take the analogy of blockchain as a large accounting book

In mining, every miner tries to solve a puzzle, who solve it first get the right to extend a new page (block) on the accounting book. About every 10 minutes a miner wins the puzzle and win the right to add this new page. In this new page, he write one transaction to send himself 12.5 bitcoins, and then collect all the transactions of others in the network during previous 10 minutes and write them into this page, extending the accounting book

Every page must follow certain defined rules, for example miners can not claim more than 12.5 bitcoin, the total number of transactions can not be larger than 2000, etc… The pages that do not qualify these rules will be discarded and will not enter the accounting book (blockchain). If everyone use the same rules (running the same client version), then the accounting book will be roughly identical for all of them

Why “roughly”? Since it takes time to transfer data on the network, so there might be different “truth” in different parts of the network, this is where “fork” comes from

A fork under same rules — orphan

After miner A solved the puzzle and made a page A and sent it to network, somewhere far away a miner B also solved the puzzle and made a page B and sent it to the network (There is more than one correct answer), because it takes time to transfer data, the nodes who are close to miner A will first receive page A and accept page A and nodes who are close to miner B will accept page B

At this moment, the bitcoin network is forked, since for two different part of the network, they are having different accounting books, both are valid based on the same rule set

But this is only temporary, since there is another rule that says the network only accept the longest chain, e.g. the account book that have most pages, as soon as the next page is out, there will be a winner

After a while, miner A made another page C, while miner B is not that lucky and not able to make another page at the same time, thus the nodes near miner A will have page AC, while nodes near miner B will also see page C, C is not valid when attached to B, thus nodes near miner B will accept page AC and discard previously accepted page B, B is orphaned

This kind of fork happens occasionally but eventually one side wins and everyone would still have the same accounting book

However, when there is an upgrade of the network, and the nodes start to run different clients with different rules, there will be different type of forks, that’s hard fork and soft fork

Based on general accepted definition, hard fork means the rules loosened, and soft fork means the rules tightened, but in reality the situation is much more complex than this single definition, but anyway start by very simple examples

Hard fork: The rules loosened

So take that page AC for example. There is a rule in network says each page could write maximum 2000 transactions, but now miner A and some nodes upgraded to a new rule set, allowing maximum 4000 transactions per page. Now miner A write a page D with 3000 transactions inside, and send it to rest of the nodes. upgraded nodes will accept it, and their book becomes ACD

However, miner B is still running the old version, accepting only pages with less than 2000 transactions, he made a page E with 1800 transactions, and those who are running old clients would accept E and reject D, since D contains 3000 transactions, violated their rules, so their accounting book becomes ACE, D is discarded

What happens next is most important

If miner A have larger hash power and can solve the puzzle quickly, he will soon get a page F which contains maybe 1000 transactions, and extend his book, it becomes ACDF, but this book still violates the rules of old clients since page D is invalid, so even page F is valid from old clients point of view, the miner B and old clients will still reject it since page D is invalid, so the network permanent splits and will not be able to converge to one

However, if miner B have larger hash power and get a page G containing 1000 transactions, the miner A and upgraded version will all accept this page, and since now miner B side have page ACEG and miner A side have only ACD, miner A and upgraded nodes will disgard ACD and accept ACEG due to the longest chain rule, thus D becomes orphaned

So, for a change that loosens restrictions (hard fork), if the upgraded side have major hash power support, then the result is two different chains extending. But if the upgraded side have minor hash power, then all the new format blocks becomes orphaned

Soft fork means the rules tightened, so exactly the opposite happens, I’m not going to draw the details again but the conclusion is also exactly opposite:

For a change that tightens rules (soft fork), if the upgraded side have minor hash power, then the network will split into two different chains. If the upgraded side have major hash power, then the old style blocks will all be orphaned and network will not split

Given this definition, depends on hash power, both hard fork and soft fork can cause the network to split into two different chains. But even with minority hash power support, a soft fork can split the network into two chains permanently, and that is exactly what happened during July 2015 soft fork incident, where majority of the hash power are on the old rules but believed to be on the new rules

Anyway, this is only technically speak, in reality, all the previous bitcoin hard forks have major hash rate support but did not evolve into two different chains, simply because it is always the consensus of the community decide which chain is real bitcoin and worth extending, not hash power or code