merkletree
merkletree copied to clipboard
Is this a self-balancing Merkle Tree?
Sorry I'm kind of mixed up what is the current standard Bitcoin Merkle Tree implementation, and what are like "research efforts" or evolving projects? . From here https://codetrips.com/2020/08/02/modern-c-implementing-a-merkle-tree/ It's stated
Rather obviously, this results in a highly unbalanced tree: however, as the purpose of a MerkleTree is to hold data and ensure its validity against tampering or computation errors (and not, for example, search efficiency) this is a very convenient trade-off: re-balancing the tree after each (or even several) addition would require recomputing almost all of the nodes’ hashes (apart from the leaf nodes, which remain unchanged); given that this would likely require many cryptographic operations (which are notoriously CPU intensive) it would be a rather poor trade-off.
-and this project from 2018 is entitled "self-balancing"? https://github.com/sputnik1458/merkle-tree
-How do you implement "add leaf" in here?
2-second Q: All these implementations r for full nodes right?Did things got mixed in my mind, or there r no deletes in a full node Merkle Tree? In other words, do u have a "delete leaf" in ur implementation?If so how it works?
I'm really in no need for likes here, these are questions that need to be answered/clarified not liked?!
If you want to know about the current Bitcoin Merkle Tree standard, you may check directly at their GitHub repo: https://github.com/bitcoin/bitcoin/blob/master/src/consensus/merkle.cpp.
The Merkle Tree implemented in this repo is similar to Bitcoin's but different from binary search trees. Please check the sample image in the readme for more detail: https://github.com/cbergoon/merkletree/blob/master/merkle_tree.png. Merkle trees are always balanced since the depths of the leaves are always the same.
I have looked through the C++ Merkle Tree implementation you sent, and it seems that it doesn't contain any "self-balancing" process.
Merkle Trees are commonly used as proof of the existence of the data, and it is immutable. If you want to delete a node from the leaf, you have to compute the whole tree and get a new Merkle root again. So normally there is no deletion method for a Merkle Tree.
Also please feel free to check my own Go Merkle Tree implementation: https://github.com/txaty/go-merkletree. It is much faster in terms of proof-gen and verification, and it supports parallel execution.