In my previous post, I explained how the P2P network makes blockchain to be the most efficient technology.
In 1979 Ralph Merkle created and patented one of the most relevant and optimized data-structure modifications combining a hash-list and a binary tree.
Merkle trees are the basic fundamental of blockchain structure, It is used to make verification of individual record without having to verify and compare records of the entire database.This structure makes verification of blockchain data more secure and efficient manner, This structure is useful for blockchain network where multiple computers keep copies of the same data, so most of the peer to peer networks( i.e bitcoin,ethereum) are using Merkle tree structure for transaction verification.
How Merkle Tree Works?
The main two properties of the hash or Merkle tree is :
1. Every leaf node is labeled with the hash of a data block,
2. Every non-leaf node is labeled with the hash of the labels of its child nodes(Previous nodes)
Les’s see the example how bitcoin blockchain verifies the transaction data using Merkle tree structure.
A B, C, and D are the four transactions in bitcoin blockchain and all the transaction are hashed and stored in an individual node, Now constructive pair of nodes like H(A) and H(B) are hashed together and stored as H(AB), H(C) and H(D) stored as H(CD). The H(AB) and H(CD) are hashed again to produce H(ABCD). This single hash node called root hash(Merkle Root). In Bitcoin, blockchain hashing is conducted using the SHA-2 cryptographic hash function.
The Merkle Root summarizes all the transaction data stored in the block header. If we want to validate whether all the transaction data are similar on the blockchain ledger, We have to see the process of data being similar on A and B, then A needs to do receive the top-level hash(Root Hash) of A transaction and validate it against the top-level(Root Hash )hash on B. If there is a mismatch – say A hasn’t synced up to the level of B as yet, all A has to do is traverse to the child nodes and check if the child nodes match. If a match is found then the new data is valid, if isn’t then it continues traversing down the tree.
This is how bitcoin uses the Merkle tree to validate the transaction data efficiently.