https://github.com/anudishjain/merkle-tree
Python Script to calculate Merkle 🌲. Transaction Verifications using Cryptography.
https://github.com/anudishjain/merkle-tree
cryptography csv hash merkle-root merkle-root-calculation merkle-tree python-script python3 transaction tree verification
Last synced: about 1 year ago
JSON representation
Python Script to calculate Merkle 🌲. Transaction Verifications using Cryptography.
- Host: GitHub
- URL: https://github.com/anudishjain/merkle-tree
- Owner: anudishjain
- License: mit
- Created: 2018-10-20T14:49:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-27T05:17:07.000Z (almost 4 years ago)
- Last Synced: 2025-03-24T21:22:08.346Z (about 1 year ago)
- Topics: cryptography, csv, hash, merkle-root, merkle-root-calculation, merkle-tree, python-script, python3, transaction, tree, verification
- Language: Python
- Homepage:
- Size: 21.5 KB
- Stars: 9
- Watchers: 1
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Merkle-Tree 🌲
Python Script to calculate Merkle Root of a CSV File Input.
A Merkle Tree is a complete binary tree which is used by Cryptocurrency SPV Wallets.
Simple Payment Verification (SPV) is a technique described in Satoshi Nakamoto's paper. SPV allows a lightweight client to verify that a transaction is included in the Bitcoin blockchain, without downloading the entire blockchain.
By using a merkle tree, one can validate a large data set contained inside the tree by just comparing the merkle root / root node of the tree.
This script assumes the input data is in the form of CSV File, and saves the finally calculated merkle root for the user in another CSV File.
A Merkle Tree can look like this :

The data is stored in the leaf nodes and we bubble up from botton to top by calculating the hash of each leaf node.
At the end we are left with a single merkle root capable of validating the whole data set with just a single hash string of 32 bytes.
# Applications
- Multiple Vendor Systems can use merkle trees to validate the copy of transactions / data that each individual holds and thus instead of traversing the file to compare values, they can simply verify the merkle root that they calculated.
- Merkle Trees reduce the number of computations required for verification of a single component in a large data set as once the tree is created it needs a small amount of information (1 hash per level of the tree) to calculate and reach the valid merkle root. As shown,

# Performance of the Script
For a CSV File with 1000 rows it takes 1.1 sec to get merkle root.
(The script doesn't support validation currently, just merkle root calculation using sha256 hashing)