Skip to content

Commit 4f3a9b4

Browse files
authored
Docs + fix benchmarks (#16)
1 parent c723f3f commit 4f3a9b4

File tree

1 file changed

+58
-14
lines changed

1 file changed

+58
-14
lines changed

README.md

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
![GitHub License](https://img.shields.io/github/license/bilinearlabs/rs-merkle-tree?style=flat-square)
66
[![Join our Discord](https://img.shields.io/badge/Discord-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/Et8BTnVBZS)
77

8-
Merkle tree implementation in Rust with configurable storage backends and hash functions. This Merkle tree implementation features:
8+
Merkle tree implementation in Rust with the following features:
99
* Fixed depth: All proofs have a constant size equal to the `Depth`.
1010
* Append-only: Leaves are added sequentially starting at index `0`. Once added, a leaf cannot be modified.
1111
* Optimized for Merkle proof retrieval: Intermediate leaves are stored so that Merkle proofs can be fetched from memory without needing to be calculated lazily, resulting in very fast retrieval times.
12+
* Configurable storage backends to store the bottom and intermediate leaves up the root.
13+
* Configurable hash functions to hash nodes.
14+
* Simple and easy to use interface: `add_leaves`, `root`, `num_leaves`, `proof`.
1215

1316

1417
Add `rs-merkle-tree` as a dependency to your Rust `Cargo.toml`.
1518

1619
```toml
1720
[dependencies]
18-
rs-merkle-tree = { git = "https://github.com/bilinearlabs/rs-merkle-tree.git" }
21+
rs-merkle-tree = "0.1.0"
1922
```
2023

2124
You can create a Merkle tree, add leaves, get the number of leaves and get the Merkle proof of a given index as follows. This creates a simple merkle tree using keccak256 hashing algorithm, a memory storage and a depth 32.
@@ -37,19 +40,60 @@ fn main() {
3740
}
3841
```
3942

40-
You can customize your tree by choosing a different store, hash function, and depth as follows. This tree also uses keccak256 but persists the leaves in a key-value sled store and has a depth of 32.
43+
You can customize your tree by choosing a different store, hash function, and depth as follows. Note that you have to modify the `feature` for the stores. This avoids importing the stuff you don't need. See the following examples.
44+
45+
**Depth: 32 | Hashing: Keccak | Store: sled**
46+
47+
```toml
48+
[dependencies]
49+
rs-merkle-tree = { version = "0.1.0", features = ["sled_store"] }
50+
```
4151

4252
```rust
43-
use rs_merkle_tree::store::SledStore;
44-
use rs_merkle_tree::tree::MerkleTree;
4553
use rs_merkle_tree::hasher::Keccak256Hasher;
54+
use rs_merkle_tree::stores::SledStore;
55+
use rs_merkle_tree::tree::MerkleTree;
4656

4757
fn main() {
4858
let mut tree: MerkleTree<Keccak256Hasher, SledStore, 32> =
4959
MerkleTree::new(Keccak256Hasher, SledStore::new("sled.db", true));
5060
}
5161
```
5262

63+
**Depth: 32 | Hashing: Poseidon | Store: rocksdb**
64+
```toml
65+
rs-merkle-tree = { version = "0.1.0", features = ["rocksdb_store"] }
66+
```
67+
68+
```rust
69+
use rs_merkle_tree::hasher::PoseidonHasher;
70+
use rs_merkle_tree::stores::RocksDbStore;
71+
use rs_merkle_tree::tree::MerkleTree;
72+
73+
fn main() {
74+
let mut tree: MerkleTree<PoseidonHasher, RocksDbStore, 32> =
75+
MerkleTree::new(PoseidonHasher, RocksDbStore::new("rocksdb.db"));
76+
}
77+
78+
```
79+
80+
**Depth: 32 | Hashing: Poseidon | Store: sqlite**
81+
82+
```toml
83+
rs-merkle-tree = { version = "0.1.0", features = ["sqlite_store"] }
84+
```
85+
86+
```rust
87+
use rs_merkle_tree::hasher::PoseidonHasher;
88+
use rs_merkle_tree::stores::SqliteStore;
89+
use rs_merkle_tree::tree::MerkleTree;
90+
91+
fn main() {
92+
let mut tree: MerkleTree<PoseidonHasher, SqliteStore, 32> =
93+
MerkleTree::new(PoseidonHasher, SqliteStore::new("tree.db"));
94+
}
95+
```
96+
5397
## Stores
5498

5599
The following stores are supported:
@@ -65,7 +109,7 @@ The following hash functions are supported:
65109

66110
## Benchmarks
67111

68-
The following benchmarks measure in a MacBook Pro the following:
112+
The following benchmarks measure in a AMD Ryzen 7 7700 8-Core Processor with 64GB of RAM the following:
69113
* Consumed disk size
70114
* Leaf insertion throughput in thousands per second.
71115
* Merkle proof generation times.
@@ -92,19 +136,19 @@ python benchmarks.py
92136

93137
| Depth | Hash | Store | Throughput (Kelem/s) |
94138
|---|---|---|---|
95-
| 32 | keccak256 | sqlite | 9.203 |
96-
| 32 | keccak256 | rocksdb | 11.315 |
97-
| 32 | keccak256 | sled | 38.518 |
98-
| 32 | keccak256 | memory | 88.117 |
139+
| 32 | keccak256 | rocksdb | 18.280 |
140+
| 32 | keccak256 | sqlite | 22.348 |
141+
| 32 | keccak256 | sled | 43.280 |
142+
| 32 | keccak256 | memory | 86.084 |
99143

100144
### `proof` time
101145

102146
| Depth | Hash | Store | Time |
103147
|---|---|---|---|
104-
| 32 | keccak256 | memory | 880.810 ns |
105-
| 32 | keccak256 | sled | 8.613 µs |
106-
| 32 | keccak256 | rocksdb | 64.176 µs |
107-
| 32 | keccak256 | sqlite | 92.422 µs |
148+
| 32 | keccak256 | memory | 560.990 ns |
149+
| 32 | keccak256 | sled | 7.878 µs |
150+
| 32 | keccak256 | sqlite | 14.562 µs |
151+
| 32 | keccak256 | rocksdb | 34.391 µs |
108152

109153
## License
110154

0 commit comments

Comments
 (0)