What is the merkle tree in blockchain?
What problem does it solve?
Although you can make your data private with hashing, someone can see how many transactions you make. Example: You are UPS and you send a transaction each time you send a package. Then your competitor can know how many packages you sent.
The problem is how to avoid revealing the number of hashes you made
What solution does it provide?
- Create your own merkle trees to combine the hashes of the data and commit a single hash or merkle root in the blockchain.
2. Send the document and data to the person you want to send it
3. Send the merkle proof
4. The receiver uses the merkle proof to prove that the information that you sent them is the same that is in the blockchain and therefore it is valid.
Merkle proof validation
- The receiver hashes the data and compares it with the hash that is supposed to be of the data. If equal then proceed
2. Then, the receiver uses the hash of the data and the hash it is supposed to be combined to generate the next hash in the tree. If equal then proceed.
3. Then, the receiver uses the hash from the previous step and the hash it is supposed to be combined to generate the next hash in the tree. If equal then proceed
4. Then the receiver uses the hash from the previous step and the hash it is supposed to be combined to generate the merkle root. If equal then the merkle proof is valid