MERKLE TREE AND FORKS

John Nyingi
3 min readMay 27, 2018

--

In this chapter I would like us to look into two case scenario’s. Consider this, how can we tell that transactions hosted in a ledger/block remain unchanged; or they retain their integrity even 50yrs from today? The second scenario is what are forks? How and why do they appear?

Merkle Trees

Typical structure of a Merkle tree

Merkle trees are simply hash trees that can be used to verify the integrity of data. In this case scenario let’s look at transactions being our data. At the bottom of the tree we have F(a), F(b), F(c) and F(d) these are Hash functions that generate hashes for our transactions that is a, b, c and d. So, in this case our tree base will have hashes for each and every transaction which will also be unique. At the 2nd layer we have Hash functions that combine the bottom hashes in pairs, then concatenates them to produce a new hash. This binds the F(a), F(b) and F(c), F(d) respectively.

At the top / root of the tree we have F(z) this hash function combines the second layer hashes and produces a new Hash. So now the top / root hash has the Hash from F(a) to F(d). This is important because it prevents modification of transaction. If a user modifies a transaction the root hash changes and so does the Block hash; hence causing a “chain reaction” where the data becomes untrustworthy.

Forks

Going back to our question what is a fork? Forks are branches or diversions generated within the block chain that divert from the main chain, that is smaller block chains. However, they are not necessarily bad news. There are two main types of Forks

a) Soft Forks; These are the most common types of forks in a block chain network. They occur when a there’s a new version, where new blocks reject old versions of blocks but old version blocks accept the new versions of blocks.

Image from coinpickings; How the Soft Forks appear

This results to us having the longest branch being the new blocks instead of the old version; as miners update their versions. In the previous topic I did mention that in some instances two valid blocks can be generated at the same time. This would result to a soft work where the network would choose which of the two will be used/ which has the longest chain.

b) Hard Forks; These are the disruptive kind of forks where the block-chain completely splits into two distinct and correct chains.

Image from coinpickings; Hard Forks create completely new chains off the old ones

In this case the hard forks render older versions of blocks as invalid as they transition to a newer version of blocks. These parallel blocks could grow indefinitely with no limits. A good example would be bitcoin which experienced a hard fork due to the differences within the community; one side wanted larger block sizes while the other wanted the traditional smaller block sizes to be in use.

--

--

John Nyingi

1st. I am a Lifetime Learner… Then a Software Developer