This project is adapted from the pymerkletools of Tierion.
I have refactored and simplified most part of the code so it can be easier for development or for the understanding of MerkleTree.
It includes a MerkleTree class for creating Merkle trees, generating merkle proofs, and verification of merkle proofs.
pip install pymerkletree
The source code is simple by itself and examples can be found in the folder demo.
-
Internally, leaves are stored as
bytearray. When the tree is built, it is generated by hashing together thebytearrayvalues. -
Lonely leaf nodes are promoted to the next level up, as depicted below.
ROOT=Hash(H+E) / \ / \ H=Hash(F+G) E / \ \ / \ \ F=Hash(A+B) G=Hash(C+D) E / \ / \ \ / \ / \ \ A B C D E