First, see Commitment Hash. Merkel trees can be seen as a special form of a commitment hash, where similar to any form of hashing of data, the root of the tree is a commitment to the entire data.
In a Merkel Tree, the data is organized in the leafs of the tree, and all intermediate nodes (and the root) are merely the hashes of their children.
Merkel trees have two interesting properties for blockchains and their needs.
- If we update node
J, only nodesJ,F,CandAhave to be updated to have a fresh new root and Commitment Hash to the entire data. The complexity of number of hashes is . This is an overhead compared to hashing[H, I, J, K]just once, but the justification of it can be seen in the next point. - If we want to prove to Alice, who only knows
A(the State Root), what the value ofJis, we could send her:J,GandB, and that’s all that she needs to know.- Knowing
J, she can computeF = Hash(J). Then, having receivedG, she can computeC = Hash(F|G). WithCandB, she can recomputeA, and if it matches her copy ofA, she can be sure that data she received was correct. - We hadn’t used a merkle tree, we would have to send the entire
[H, I, J, K]to Alice to prove to her thatJis part of the set. This would have a complexity. With a tree of depth 3 like above, the difference of and is not very bold, but rest assured in a database of billions of items, it is a big deal.
- Knowing
This mechanism is used in Block Header to store:
- State root: Merkel tree of the entire blockchain state.
- Transaction root: merkel tree of all of the transactions in the block. Moreover, it is a key piece of how Light Node request State Proofs and operate.