https://github.com/nhussein11/merkle-tree
Rust implementation and explanation of the Merkle Tree structure
https://github.com/nhussein11/merkle-tree
blockchain cryptography rust web3
Last synced: 8 months ago
JSON representation
Rust implementation and explanation of the Merkle Tree structure
- Host: GitHub
- URL: https://github.com/nhussein11/merkle-tree
- Owner: nhussein11
- Created: 2023-02-14T18:29:48.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-04-01T14:49:56.000Z (about 3 years ago)
- Last Synced: 2025-01-14T13:41:43.297Z (over 1 year ago)
- Topics: blockchain, cryptography, rust, web3
- Language: Rust
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Merkle Tree
A merkle tree is a data structure that allows you to verify the integrity of a large set of data. It is a binary tree where each leaf node is the hash of a block of data. Each non-leaf node is the hash of the two child nodes. The root node is the hash of the entire tree.

The idea of this project is just to implement a simple version of a merkle tree in Rust. Anyway, if you want to learn more about merkle trees, I highly recommend you to read this [Wikipedia article](https://en.wikipedia.org/wiki/Merkle_tree) and also [Simplilearn Article](https://www.simplilearn.com/tutorials/blockchain-tutorial/merkle-tree-in-blockchain#:~:text=Merkle%20trees%2C%20also%20known%20as,data%20more%20efficiently%20and%20securely.).
:rocket: Or even better, if you want to contribute to this humble implementation, feel free to open a pull request. :rocket:
## Why it is important?
Merkle trees are used in many applications, including blockchains, to verify the integrity of large sets of data. For example, in a blockchain, the merkle tree is used to verify that a transaction is included in a block. The merkle tree is also used to verify that a block is included in a blockchain.
## How it works?
Each item in the set is hashed and stored in a leaf node. The leaf nodes are then paired and hashed together. The resulting hash is stored in a non-leaf node. This process is repeated until there is only one node left, the root node.
A Merkle tree totals all transactions in a block and generates a digital fingerprint of the entire set of operations, allowing the user to verify whether it includes a transaction in the block.
## How to run the tests?
I wrote a suite of unit tests to test the merkle tree.
To run the tests, run the following command:
1 - Clone the project:
```bash
git clone https://github.com/nhussein11/merkle-tree.git
```
2 - Run the tests:
```bash
cargo test
```