Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rkdud007/sn-merkle-trie
Minimal SN merkle patricia trie implementation
https://github.com/rkdud007/sn-merkle-trie
Last synced: 8 days ago
JSON representation
Minimal SN merkle patricia trie implementation
- Host: GitHub
- URL: https://github.com/rkdud007/sn-merkle-trie
- Owner: rkdud007
- License: other
- Created: 2024-09-04T02:57:47.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-11T03:58:48.000Z (2 months ago)
- Last Synced: 2024-09-12T06:24:32.137Z (2 months ago)
- Language: Rust
- Homepage:
- Size: 72.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sn-merkle-trie
[![Crates.io](https://img.shields.io/crates/v/sn-merkle-trie?style=flat-square&logo=lootcrate)](https://crates.io/crates/sn-merkle-trie)
[![Documentation](https://img.shields.io/docsrs/sn-merkle-trie)](https://docs.rs/sn-merkle-trie)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)Minimal implelementation of a [StarkNet MPT](https://docs.starknet.io/architecture-and-concepts/network-architecture/starknet-state/#merkle_patricia_trie).
Heavily rely on [pathfinder's merkle tree implementation](https://github.com/eqlabs/pathfinder/tree/9e0ceec2c56a88ed58b6e49ee7ca6bccd703af33/crates/merkle-tree), but target to make it easy port as external dependency + sync primitives with [type-rs](https://github.com/starknet-io/types-rs).
### Usage
- tx trie
```rust
fn main() {
// transaction tree either pedersen or poseidon
let mut tree = TransactionMerkleTree::Pedersen(MerkleTree::default());
let key1 = from_felt_to_bits(&Felt::from_hex_unchecked("0x0")); // 0b01
let value_1 = Felt::from_hex_unchecked("0x2");
// insert key and value
tree.set(key1.clone(), value_1).unwrap();
// commit tree to get root
let (root, root_idx) = tree.commit().unwrap();
// get proof of inclusion/non-inclusion
let proof = tree.get_proof(root_idx, key1.clone()).unwrap().unwrap();
// verify return membership proof
let mem = tree.verify_proof(root, &key1, value_1, &proof);
}
```