How are Merkle trees used in blockchain technology and why?
In the Bitcoin network, all the transactions inside a block are summarised in a Merkle tree by producing a digital fingerprint of the entire set of transactions. This way a user is able to verify whether a transaction is included in a block or not.
All nodes in the tree-like structure of the Merkle tree are partial representations of the hashed data underneath them.
Now you may ask yourself why a hash tree is needed to prove this? Wouldn’t it be possible to hash all messages (the original data), put the hashed values into one single string and get the value of the root hash this way? Why do Merkle trees make life easier?
The issue of trust
Imagine life without Merkle trees. Instead of the Merkle root, we would store a hash of all the transactions from the blockchain in the block header. This means: in order to verify just one transaction, you would have to download the data from all of them.
Merkle trees reduce the amount of data needed for verification. Let us say Sue wants to prove to John that the transaction “m6” has not been tampered with. John could obtain the root hash from a trusted source and verify that this is the case.
If Sue and John proceeded without Merkle trees, Sue would need to provide John with all the hashed transactions to prove that “m6” has not been tampered with. A Merkle tree provides a much better way to verify this. Again, John gets the root from a source he trusts. This time, if Sue wants to prove that “m6” has not been tampered with, she only needs to send the message and four hashed values (shown in purple) to John as outlined in the graphic below: