homecryptocurrency NewsExplained: Merkle trees and how they work

Explained: Merkle trees and how they work

A Merkle Tree is a data structure often used for data verification in computer applications. It allows for quick and secure data verification and synchronisation across massive datasets. Merkle trees are also widely used to encrypt blockchain data efficiently and securely.

Profile image

By CNBCTV18.com Dec 14, 2022 1:38:55 PM IST (Published)

Listen to the Article(6 Minutes)
4 Min Read
Explained: Merkle trees and how they work
Following the FTX collapse, major crypto exchanges such as Binance, Kraken, Bybit, and others started presenting Proof-of-Reserves (PoR) as a means of assuring users and investors that their funds are safe and backed 1:1. Many of these exchanges use a data structure called 'Merkle Trees' to create their PoR audit reports. This allows for quick and secure verification of a company's reserves. But what exactly is a Merkle Tree, and how does it work? Tag along to find out.

What is a Merkle Tree?
A Merkle Tree is a data structure often used for data verification in computer applications. It allows for quick and secure data verification and synchronisation across massive datasets. Merkle trees are also widely used to encrypt blockchain data efficiently and securely. Several blockchains, including Bitcoin, employ this data structuring model to streamline the storage and verification of transaction records.
How does a Merkle Tree work?
Merkle Trees are created from the hashes of multiple data blocks, which help summarise all transactions into a single block, known as the Merkle Root.
A hash function helps crunch an input into a smaller output. This output is known as a hash and works like a fingerprint of all the input data. It allows large amounts of data to be easily identified through their hash.
Let's better understand how Merkle Trees work through an example. Say you have details of four blockchain transactions: A, B, C, and D. The details of all these transactions are then encrypted into four hashes: Hash A, Hash, B, Hash C, and Hash D. Now, Hash A and Hash B are further encrypted into Hash AB. Similarly, C and D are encrypted into Hash CD. Finally, Hash AB and Hash CD are encrypted into a singular Merkle Root, Hash ABCD.
Each hash is a fingerprint of its input data, and the Merkle Root can be seen as a fingerprint of the entire data. Also, this binary structure is how Merkle Trees get their name. We begin with all the details of Transaction A. This could include the amount sent, the recipient, the gas fees, etc. It's basically all the information you would see about a transaction on a block explorer.
These individual transactions are encrypted into hashes, known as leaf nodes. Leaf nodes are then paired together and hashed into what's known as a non-leaf node. Non-leaf nodes are again paired together and hashed into another non-leaf node.
Therefore, a layer of leaf nodes is hashed into a layer of half as many non-leaf nodes. These non-leaf nodes are then hashed into another layer of half as many non-leaf nodes. This process continues until we have just one hash, the Merkle Root.
Why are Merkle Trees used in blockchains?
Blockchains are transaction ledgers. They contain all the information of every transaction that has ever occurred on the network. That's a lot of data, and it keeps increasing as the network grows and users increase. When it comes to validating all this data, two significant problems come forward: computing power and storage space.
Nodes would have to download a massive database of transactional records. They would then have to sift through each transaction to corroborate its details. However, a Merkle Tree encrypts all these transactions into hashes. By doing this, it separates the data from its supporting evidence.
Using a Merkle Tree, nodes can quickly ascertain a dataset's validity without downloading the entire set. This results in less computing power and storage space needed to validate the transactions, a vital benefit for blockchain networks.
Merkle Trees also allow nodes to detect any alterations made to the dataset. This is because the output hash will change if transaction details are altered. This will result in the creation of a Merkle Root that is different from the Merkle Root stored with the rest of the nodes. Therefore, any alterations in a Merkle Tree dataset are easily identifiable.
Conclusion
Merkle trees have become an integral part of blockchain operations. This is because blockchains generally deal with mammoth chunks of data. Merkle trees can compress these massive chunks, eliminate unnecessary data and turn the remaining into hashes, making it easy to process.

Most Read

Share Market Live

View All
Top GainersTop Losers
CurrencyCommodities
CurrencyPriceChange%Change