https://github.com/mynameisvinn/merkle
merkle merkle merkle
https://github.com/mynameisvinn/merkle
algorithm hash merkle merkle-dag merkle-tree
Last synced: 19 days ago
JSON representation
merkle merkle merkle
- Host: GitHub
- URL: https://github.com/mynameisvinn/merkle
- Owner: mynameisvinn
- Created: 2017-08-20T12:52:03.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-12-02T19:18:06.000Z (over 8 years ago)
- Last Synced: 2025-07-08T12:46:15.156Z (about 1 year ago)
- Topics: algorithm, hash, merkle, merkle-dag, merkle-tree
- Language: Python
- Homepage:
- Size: 2.93 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# merkle
combining hash functions with graphs was ralph merkle’s big idea. merkle dags are everywhere you want data integrity *through self verification*: git, ipfs, blockchain.
#### whats a merkle tree?
we have a hashing function $h(x)$ and four records a, b, c, d. a merkle tree would be y:
```
h_ab = h[h(a) + h(b)]
h_cd = h[h(c) + h(d)]
root_hash = h(h_ab + h_cd)
```
#### whats a merkle dag?
a merkle dag is an *acylic* collection of merkle trees. by referencing its predecessor's root hash, a merkle dag tracks history.
```
h_ab = h[h(a) + h(b)]
h_cd = h[h(c) + h(d)]
root_hash_1 = h(h_ab + h_cd)
h_ef = h[h(e) + h(f)]
h_gh = h[h(g) + h(h)]
root_hash_2 = h(h_ef + h_gh + root_hash_1) # 2nd root hash knows its parent
```
## usage
```python
import merkle
from merkle import generate_merkle_root
transactions = ['tx1', 'tx2', 'tx3', 'tx4', 'tx5']
generate_merkle_root(transactions) # returns e5fb69843938b939e7f1823414b2e3aaa52c1eaa
```
assuming you have the hash `e5fb69843938b939e7f1823414b2e3aaa52c1eaa` from a trusted authority, you can download chunks of data from various sources, compare its merkle root hash with the trusted one, and be confident that it's the same set of data.