In this post we are going to try to explain what the Merkle tree in Bitcoin (Merkle Tree) and the Verkle tree in Ethereum. The Merkle tree is a data structure divided into several layers that allows to verify, in a fast and efficient way, the information of a set of related data, with a final single root. That is, it relates the transactions that enter a block through peer-to-peer grouping. In Bitcoin, the blocks are connected by hash values. Each block header contains information related to Merkle Root Hash, Version, TimeStamp, Nonce, Difficulty Target, and the previous block’s hash.
What is the Merkle tree
The basis of the operation of the Merkle tree is hashing, which in the case of Bitcoin uses the famous secure hash algorithm SHA-256 (256 bits). Hashing is done repeatedly until only one hash remains. This hash will be the one that is entered in the block and is known as Merkle Root.
All about bitcoin crypto and how it has changed
On the other hand, we can differentiate different types of nodes within the tree. Leaf Node refers to the nodes that contain transaction hashes and are considered as the child nodes. The Non-Leaf Nodes are known as the parent nodes and are the ones that contain the hashes of the child nodes.
How does the Merkle tree work?
Let’s imagine we have four transactions in the block (L1, L2, L3, L4). A hashing is applied to these transactions, thus having a hash for each transaction and originating a Leaf node or child node. Next, the Leaf Nodes are combined and hashed, thus generating a Non-Leaf Node or Parent Node, which is the single hash originated from the combination of two hashes. That is, if the 0-0 hash and the 0-1 hash are combined and a new hashing is applied, the result is the “zero” hash. Finally, the Non-Leaf Nodes are re-combined and hashed to create the Merkle Root or Merkle Root. This hash is the one that is entered in the block of the Blockchain. This example is a simple case, but for cases like Bitcoin, where the data set is large, this method is also very useful. Transactions can be verified if previous transactions are verifiable.
Discovering DeFi: how to apply for a loan by skipping the banks
Merkle tree benefits
A Merkle tree enables us to effectively validate data integrity. Also, it takes up little disk space compared to other data structures. Merkle trees provide an efficient data structure and it does not take a long time to verify data integrity. Another notable benefit is Simple Payment Verification, or SVP, which involves requesting proof from Merkle to verify that a transaction is in a particular block. This is usually done when a node is running on a device with limited resources and you do not want to download and has all transactions in a block.
There is also an alternative to Merkle trees, known as the Verkle trees. In fact, this solution is becoming a very important part of Ethereum updates. The main idea of the Verkle tree is that you can build a Merkle tree, but replacing the cryptographic hash functions with vector commitments.
Therefore, a Verkle tree has the same function as a Merkle tree. However, the main difference is that Verkle trees are much more efficient in terms of size in bytes. Running a test on a binary Merkle tree requires about 1 kilobyte, but on the Verkle tree the test would require at least 150 bytes.