Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"bin/stress-test",
"crates/block-producer",
"crates/grpc-error-macro",
"crates/large-smt",
"crates/ntx-builder",
"crates/proto",
"crates/remote-prover-client",
Expand Down Expand Up @@ -49,15 +50,16 @@ miden-node-validator = { path = "crates/validator", version = "0.13" }
miden-remote-prover-client = { path = "crates/remote-prover-client", version = "0.13" }

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

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

# External dependencies
anyhow = { version = "1.0" }
Expand Down Expand Up @@ -112,3 +114,6 @@ must_use_candidate = "allow" # This marks many fn's which isn't helpfu
needless_for_each = "allow" # Context dependent if that's useful.
should_panic_without_expect = "allow" # We don't care about the specific panic message.
# End of pedantic lints.

[patch.crates-io]
miden-crypto = { branch = "bernhard-migrate-rocksdb-from-crypto", git = "https://github.com/0xMiden/crypto.git" }
26 changes: 26 additions & 0 deletions crates/large-smt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
authors.workspace = true
description = "Large-scale Sparse Merkle Tree backed by pluggable storage (RocksDB, memory)"
edition.workspace = true
homepage.workspace = true
keywords = ["miden", "node", "smt", "merkle"]
license.workspace = true
name = "miden-large-smt"
readme = "README.md"
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[lints]
workspace = true

[features]
default = ["concurrent"]
concurrent = []
rocksdb = ["dep:rocksdb", "dep:rayon", "dep:winter-utils"]

[dependencies]
miden-protocol = { features = ["std"], workspace = true }
rayon = { version = "1.10", optional = true }
rocksdb = { default-features = false, features = ["bindgen-runtime", "lz4"], optional = true, version = "0.24" }
winter-utils = { version = "0.13", optional = true }
45 changes: 45 additions & 0 deletions crates/large-smt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# miden-large-smt

Large-scale Sparse Merkle Tree backed by pluggable storage (RocksDB, memory).

This crate provides `LargeSmt`, a hybrid SMT implementation that stores the top of the tree
(depths 0–23) in memory and persists the lower depths (24–64) in storage as fixed-size subtrees.
This hybrid layout scales beyond RAM while keeping common operations fast.

## Migration Status

This crate is the future home for `LargeSmt` and its storage backends. Currently it re-exports
types from `miden-protocol` (which re-exports from `miden-crypto`).

The migration will be completed in phases:
1. ✅ Create this crate as a re-export layer (current state)
2. Copy the full implementation from miden-crypto to this crate
3. Update miden-crypto to remove the rocksdb feature
4. Update dependents to use this crate directly

## Features

- **concurrent**: Enables parallel processing with rayon (enabled by default)
- **rocksdb**: (Future) Enables RocksDB storage backend

## Usage

```rust
use miden_large_smt::{LargeSmt, MemoryStorage};

// Create an empty tree with in-memory storage
let storage = MemoryStorage::new();
let smt = LargeSmt::new(storage).unwrap();
```

## Re-exported Types

This crate re-exports the following types from `miden-protocol`:

- `LargeSmt` - The large-scale SMT implementation
- `LargeSmtError` - Error type for LargeSmt operations
- `MemoryStorage` - In-memory storage backend
- `SmtStorage` - Storage backend trait
- `Subtree` - Serializable subtree representation
- `StorageUpdates` / `StorageUpdateParts` - Batch update types
- Various SMT types: `Smt`, `SmtLeaf`, `SmtProof`, `LeafIndex`, etc.
65 changes: 65 additions & 0 deletions crates/large-smt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Large-scale Sparse Merkle Tree backed by pluggable storage.
//!
//! `LargeSmt` stores the top of the tree (depths 0–23) in memory and persists the lower
//! depths (24–64) in storage as fixed-size subtrees. This hybrid layout scales beyond RAM
//! while keeping common operations fast.
//!
//! # Usage
//!
//! ```ignore
//! use miden_large_smt::{LargeSmt, MemoryStorage};
//!
//! // Create an empty tree with in-memory storage
//! let storage = MemoryStorage::new();
//! let smt = LargeSmt::new(storage).unwrap();
//! ```
//!
//! With RocksDB (requires `rocksdb` feature):
//!
//! ```ignore
//! use miden_large_smt::{LargeSmt, RocksDbConfig, RocksDbStorage};
//!
//! let storage = RocksDbStorage::open(RocksDbConfig::new("/path/to/db")).unwrap();
//! let smt = LargeSmt::new(storage).unwrap();
//! ```

#![cfg_attr(not(feature = "concurrent"), allow(unused_imports))]

extern crate alloc;

#[cfg(feature = "rocksdb")]
mod rocksdb;
#[cfg(feature = "rocksdb")]
pub use rocksdb::{RocksDbConfig, RocksDbStorage};

// Re-export from miden-protocol.
pub use miden_protocol::crypto::merkle::smt::{
InnerNode,
LargeSmt,
LargeSmtError,
LeafIndex,
MemoryStorage,
SMT_DEPTH,
Smt,
SmtLeaf,
SmtLeafError,
SmtProof,
SmtStorage,
StorageError,
StorageUpdateParts,
StorageUpdates,
SubtreeUpdate,
Subtree,
SubtreeError,
};

// Also re-export commonly used types for convenience
pub use miden_protocol::{
EMPTY_WORD,
Felt,
Word,
crypto::{
hash::rpo::Rpo256,
merkle::{EmptySubtreeRoots, InnerNodeInfo, MerkleError, NodeIndex, SparseMerklePath},
},
};
Loading
Loading