Skip to content

Commit 46708e6

Browse files
committed
y
1 parent 67f470e commit 46708e6

5 files changed

Lines changed: 963 additions & 7 deletions

File tree

Cargo.toml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ members = [
66
"bin/stress-test",
77
"crates/block-producer",
88
"crates/grpc-error-macro",
9+
"crates/large-smt",
910
"crates/ntx-builder",
1011
"crates/proto",
1112
"crates/remote-prover-client",
@@ -49,15 +50,16 @@ miden-node-validator = { path = "crates/validator", version = "0.13" }
4950
miden-remote-prover-client = { path = "crates/remote-prover-client", version = "0.13" }
5051

5152
# miden-base aka protocol dependencies. These should be updated in sync.
52-
miden-block-prover = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
53-
miden-protocol = { branch = "next", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
54-
miden-standards = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
55-
miden-testing = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
56-
miden-tx = { branch = "next", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
57-
miden-tx-batch-prover = { branch = "next", git = "https://github.com/0xMiden/miden-base.git" }
53+
miden-block-prover = { branch = "bernhard-migrate-rocksdb-from-crypto", git = "https://github.com/0xMiden/miden-base.git" }
54+
miden-protocol = { branch = "bernhard-migrate-rocksdb-from-crypto", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
55+
miden-standards = { branch = "bernhard-migrate-rocksdb-from-crypto", git = "https://github.com/0xMiden/miden-base.git" }
56+
miden-testing = { branch = "bernhard-migrate-rocksdb-from-crypto", git = "https://github.com/0xMiden/miden-base.git" }
57+
miden-tx = { branch = "bernhard-migrate-rocksdb-from-crypto", default-features = false, git = "https://github.com/0xMiden/miden-base.git" }
58+
miden-tx-batch-prover = { branch = "bernhard-migrate-rocksdb-from-crypto", git = "https://github.com/0xMiden/miden-base.git" }
5859

5960
# Other miden dependencies. These should align with those expected by miden-base.
60-
miden-air = { features = ["std", "testing"], version = "0.20" }
61+
miden-air = { features = ["std", "testing"], version = "0.20" }
62+
miden-crypto = { branch = "bernhard-migrate-rocksdb-from-crypto", git = "https://github.com/0xMiden/crypto.git" }
6163

6264
# External dependencies
6365
anyhow = { version = "1.0" }
@@ -112,3 +114,6 @@ must_use_candidate = "allow" # This marks many fn's which isn't helpfu
112114
needless_for_each = "allow" # Context dependent if that's useful.
113115
should_panic_without_expect = "allow" # We don't care about the specific panic message.
114116
# End of pedantic lints.
117+
118+
[patch.crates-io]
119+
miden-crypto = { branch = "bernhard-migrate-rocksdb-from-crypto", git = "https://github.com/0xMiden/crypto.git" }

crates/large-smt/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
authors.workspace = true
3+
description = "Large-scale Sparse Merkle Tree backed by pluggable storage (RocksDB, memory)"
4+
edition.workspace = true
5+
homepage.workspace = true
6+
keywords = ["miden", "node", "smt", "merkle"]
7+
license.workspace = true
8+
name = "miden-large-smt"
9+
readme = "README.md"
10+
repository.workspace = true
11+
rust-version.workspace = true
12+
version.workspace = true
13+
14+
[lints]
15+
workspace = true
16+
17+
[features]
18+
default = ["concurrent"]
19+
concurrent = []
20+
rocksdb = ["dep:rocksdb", "dep:rayon", "dep:winter-utils"]
21+
22+
[dependencies]
23+
miden-protocol = { features = ["std"], workspace = true }
24+
rayon = { version = "1.10", optional = true }
25+
rocksdb = { default-features = false, features = ["bindgen-runtime", "lz4"], optional = true, version = "0.24" }
26+
winter-utils = { version = "0.13", optional = true }

crates/large-smt/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# miden-large-smt
2+
3+
Large-scale Sparse Merkle Tree backed by pluggable storage (RocksDB, memory).
4+
5+
This crate provides `LargeSmt`, a hybrid SMT implementation that stores the top of the tree
6+
(depths 0–23) in memory and persists the lower depths (24–64) in storage as fixed-size subtrees.
7+
This hybrid layout scales beyond RAM while keeping common operations fast.
8+
9+
## Migration Status
10+
11+
This crate is the future home for `LargeSmt` and its storage backends. Currently it re-exports
12+
types from `miden-protocol` (which re-exports from `miden-crypto`).
13+
14+
The migration will be completed in phases:
15+
1. ✅ Create this crate as a re-export layer (current state)
16+
2. Copy the full implementation from miden-crypto to this crate
17+
3. Update miden-crypto to remove the rocksdb feature
18+
4. Update dependents to use this crate directly
19+
20+
## Features
21+
22+
- **concurrent**: Enables parallel processing with rayon (enabled by default)
23+
- **rocksdb**: (Future) Enables RocksDB storage backend
24+
25+
## Usage
26+
27+
```rust
28+
use miden_large_smt::{LargeSmt, MemoryStorage};
29+
30+
// Create an empty tree with in-memory storage
31+
let storage = MemoryStorage::new();
32+
let smt = LargeSmt::new(storage).unwrap();
33+
```
34+
35+
## Re-exported Types
36+
37+
This crate re-exports the following types from `miden-protocol`:
38+
39+
- `LargeSmt` - The large-scale SMT implementation
40+
- `LargeSmtError` - Error type for LargeSmt operations
41+
- `MemoryStorage` - In-memory storage backend
42+
- `SmtStorage` - Storage backend trait
43+
- `Subtree` - Serializable subtree representation
44+
- `StorageUpdates` / `StorageUpdateParts` - Batch update types
45+
- Various SMT types: `Smt`, `SmtLeaf`, `SmtProof`, `LeafIndex`, etc.

crates/large-smt/src/lib.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//! Large-scale Sparse Merkle Tree backed by pluggable storage.
2+
//!
3+
//! `LargeSmt` stores the top of the tree (depths 0–23) in memory and persists the lower
4+
//! depths (24–64) in storage as fixed-size subtrees. This hybrid layout scales beyond RAM
5+
//! while keeping common operations fast.
6+
//!
7+
//! # Usage
8+
//!
9+
//! ```ignore
10+
//! use miden_large_smt::{LargeSmt, MemoryStorage};
11+
//!
12+
//! // Create an empty tree with in-memory storage
13+
//! let storage = MemoryStorage::new();
14+
//! let smt = LargeSmt::new(storage).unwrap();
15+
//! ```
16+
//!
17+
//! With RocksDB (requires `rocksdb` feature):
18+
//!
19+
//! ```ignore
20+
//! use miden_large_smt::{LargeSmt, RocksDbConfig, RocksDbStorage};
21+
//!
22+
//! let storage = RocksDbStorage::open(RocksDbConfig::new("/path/to/db")).unwrap();
23+
//! let smt = LargeSmt::new(storage).unwrap();
24+
//! ```
25+
26+
#![cfg_attr(not(feature = "concurrent"), allow(unused_imports))]
27+
28+
extern crate alloc;
29+
30+
#[cfg(feature = "rocksdb")]
31+
mod rocksdb;
32+
#[cfg(feature = "rocksdb")]
33+
pub use rocksdb::{RocksDbConfig, RocksDbStorage};
34+
35+
// Re-export from miden-protocol.
36+
pub use miden_protocol::crypto::merkle::smt::{
37+
InnerNode,
38+
LargeSmt,
39+
LargeSmtError,
40+
LeafIndex,
41+
MemoryStorage,
42+
SMT_DEPTH,
43+
Smt,
44+
SmtLeaf,
45+
SmtLeafError,
46+
SmtProof,
47+
SmtStorage,
48+
StorageError,
49+
StorageUpdateParts,
50+
StorageUpdates,
51+
SubtreeUpdate,
52+
Subtree,
53+
SubtreeError,
54+
};
55+
56+
// Also re-export commonly used types for convenience
57+
pub use miden_protocol::{
58+
EMPTY_WORD,
59+
Felt,
60+
Word,
61+
crypto::{
62+
hash::rpo::Rpo256,
63+
merkle::{EmptySubtreeRoots, InnerNodeInfo, MerkleError, NodeIndex, SparseMerklePath},
64+
},
65+
};

0 commit comments

Comments
 (0)