How Merkle Tree Works

5ireChain
4 min readMay 27, 2022

A Merkle tree is a cryptographic data structure upon which data is stored in a blockchain. A block in a blockchain comprises a set of transactions. This block has a unique hash function with which the transactions in the block can be verified. All the transactions in a block are grouped in pairs and computed with a hash function. The hash function results are paired again and calculated with a hash function. This process is repeated until the entire transaction in a block is represented with a hash.

Applications of Merkle Tree

Merkle is used in various cryptocurrencies to validate transactions. Bitcoin is the first cryptocurrency to deploy the Merkle tree in its cryptography.

A less notable use of the Merkle tree is in IPFS, an interplanetary file system. IPFS is a decentralized cloud data storage. It differs from traditional cloud storage in that there is no central server for data storage. Instead, data in IPFS is broken down into chunks and stored over decentralized servers across the world.

The stored data is marked with a content addressing system for easy retrieval across the servers. The chunks of data are merged to their original form and delivered to the owner upon request.

How Merkle Tree works

Merkle trees work by combining pairs of transactions with a hash function and repeating the same process on the computation results until a single result is reached. Consider a block of 4 transactions, A,B,C,D. Transactions A and B are combined with a hash function to give hash AB. The same process is done on transactions C and D to produce a hash CD. Furthermore, hashes AB and CD are computed again with the same function to give hash ABCD. The final hash result ABCD is regarded as the Merkle root.

Benefits of Merkle Tree

Merkle Tree requires less memory space than other data structures. A node in the network is not necessary to have the entire record of transactions to verify subsequent ones. Without the Merkle tree, nodes will have to cross-check the existing record of transactions each time they verify transactions to make sure its entry is the same as other nodes. This cumbersome verification process requires a considerable processing capacity that all nodes may not afford. If affordable, the processor will be overpowered as the chain grows with transaction records, leading to an upgrade to a more powerful processor. The resulting rate of acquisition and discard will lead to electronic waste, making blockchains hardly sustainable.

Tamper-proof

When a transaction record is tampered with, it alters the transaction’s hash, hence the Merkle tree. Since the hash of each block is derived from the Merkle tree, the hash of that block will also be altered. Blockchain is a string of blocks of transactions, and each block’s hash is contained in the header of the succeeding block, which contributes to the block’s hash. In other words, any alteration in a transaction will spiral down to the blockchain, making the transactions recorded from the point of that alteration invalid.

Merkle tree makes a blockchain tamper-proof and immutable.

Merkle Proofs

Merkle proofs help bypass the extensive data stored in a blockchain when trying to verify a single transaction. To increase efficiency and flexibility, blockchain networks like 5ireChain utilize lightweight nodes and full nodes in their ecosystem.

Lightweight nodes do not contain the entire transaction data on the blockchain. Instead, they are an offshoot of the main chain.

Lightweight nodes can verify transactions in a block by requesting the Merkle root of the block and the hashes of other transactions in the block from the full node. Since the Merkle root is derived by a progressive concatenation of transaction hashes in the block, the process can be repeated to verify a transaction.

To throw more light on the process, consider a user trying to verify transaction D, TxD with transaction hash, SHA-D, in a block of transactions, Tx A, B, C, D. The user already provides the transaction hash of TxD, SHA-D to the lightweight node.

On the other hand, the lightweight node requests the hashes of Tx A, B, C and their derivatives from the full node. The hashes are recomputed with SHA-D provided by the user. If the resulting Merkle root derived from the process corresponds to the block’s Merkle root as contained in the main chain, the transaction is considered valid.

More information about 5ireChain can be found by clicking on the following links:

Website: https://5ire.org

White paper: https://bit.ly/3Qcsmor

LinkedIn: https://www.linkedin.com/company/5ireChain

Twitter: https://twitter.com/5irechain

Discord: http://discord.gg/5ire

Telegram: https://t.me/OfficialFireChain

--

--

5ireChain

5ireChain — www.5ire.org | Layer-1 EVM Compatible Smart Contract Platform | In Consensus Sustainability