From aae01b6630d2992ae2ad0751c4662f49e9dfec6d Mon Sep 17 00:00:00 2001 From: sergerad Date: Thu, 9 Apr 2026 09:23:13 +1200 Subject: [PATCH 01/19] Patch crypto with Clones --- Cargo.lock | 12 ++++-------- Cargo.toml | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60f048bd64..bbeaf03378 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,8 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0a034a460e27723dcfdf25effffab84331c3b46b13e7a1bd674197cc71bfe" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" dependencies = [ "blake3", "cc", @@ -1702,8 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8bf6ebde028e79bcc61a3632d2f375a5cc64caa17d014459f75015238cb1e08" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" dependencies = [ "quote", "syn 2.0.117", @@ -1730,8 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38011348f4fb4c9e5ce1f471203d024721c00e3b60a91aa91aaefe6738d8b5ea" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1921,8 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff78082e9b4ca89863e68da01b35f8a4029ee6fd912e39fa41fde4273a7debab" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" dependencies = [ "p3-field", "p3-goldilocks", diff --git a/Cargo.toml b/Cargo.toml index 5fc25f6118..14dfcdbdc7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,3 +70,7 @@ rstest = { version = "0.26" } serde = { default-features = false, version = "1.0" } thiserror = { default-features = false, version = "2.0" } tokio = { default-features = false, features = ["sync"], version = "1" } + +[patch.crates-io] +miden-crypto = { git = "https://github.com/0xmiden/crypto", branch = "sergerad-clone" } +miden-serde-utils = { git = "https://github.com/0xmiden/crypto", branch = "sergerad-clone" } From 1cc7a4557ede42d4d5aaf4c9f49a0a485d7896ce Mon Sep 17 00:00:00 2001 From: sergerad Date: Fri, 10 Apr 2026 15:13:47 +1200 Subject: [PATCH 02/19] Split reader writer impls --- Cargo.lock | 8 +- .../src/block/account_tree/backend.rs | 120 ++++++++++-------- .../src/block/account_tree/mod.rs | 33 +++-- 3 files changed, 90 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbeaf03378..06e1285eda 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#71e667f6383751586c078f8723d79e59489a2e66" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" dependencies = [ "p3-field", "p3-goldilocks", diff --git a/crates/miden-protocol/src/block/account_tree/backend.rs b/crates/miden-protocol/src/block/account_tree/backend.rs index 58963f0e44..2947d077ca 100644 --- a/crates/miden-protocol/src/block/account_tree/backend.rs +++ b/crates/miden-protocol/src/block/account_tree/backend.rs @@ -5,7 +5,7 @@ use super::{AccountId, AccountIdKey, AccountIdPrefix, AccountTree, AccountTreeEr use crate::Word; use crate::crypto::merkle::MerkleError; #[cfg(feature = "std")] -use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage}; +use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorageWriter}; use crate::crypto::merkle::smt::{LeafIndex, MutationSet, SMT_DEPTH, Smt, SmtLeaf, SmtProof}; // ACCOUNT TREE BACKEND @@ -14,6 +14,9 @@ use crate::crypto::merkle::smt::{LeafIndex, MutationSet, SMT_DEPTH, Smt, SmtLeaf /// This trait abstracts over different SMT backends (e.g., `Smt` and `LargeSmt`) to allow /// the `AccountTree` to work with either implementation transparently. /// +/// This trait contains only read-only methods. For write methods, see +/// [`AccountTreeBackendWriter`]. +/// /// Implementors must provide `Default` for creating empty instances. Users should /// instantiate the backend directly (potentially with entries) and then pass it to /// [`AccountTree::new`]. @@ -29,6 +32,24 @@ pub trait AccountTreeBackend: Sized { /// Opens the leaf at the given key, returning a Merkle proof. fn open(&self, key: &Word) -> SmtProof; + /// Computes the mutation set required to apply the given updates to the SMT. + fn compute_mutations( + &self, + updates: Vec<(Word, Word)>, + ) -> Result, Self::Error>; + + /// Returns the value associated with the given key. + fn get_value(&self, key: &Word) -> Word; + + /// Returns the leaf at the given key. + fn get_leaf(&self, key: &Word) -> SmtLeaf; + + /// Returns the root of the SMT. + fn root(&self) -> Word; +} + +/// Extension trait for [`AccountTreeBackend`] that provides write methods. +pub trait AccountTreeBackendWriter: AccountTreeBackend { /// Applies the given mutation set to the SMT. fn apply_mutations( &mut self, @@ -43,23 +64,8 @@ pub trait AccountTreeBackend: Sized { set: MutationSet, ) -> Result, Self::Error>; - /// Computes the mutation set required to apply the given updates to the SMT. - fn compute_mutations( - &self, - updates: Vec<(Word, Word)>, - ) -> Result, Self::Error>; - /// Inserts a key-value pair into the SMT, returning the previous value at that key. fn insert(&mut self, key: Word, value: Word) -> Result; - - /// Returns the value associated with the given key. - fn get_value(&self, key: &Word) -> Word; - - /// Returns the leaf at the given key. - fn get_leaf(&self, key: &Word) -> SmtLeaf; - - /// Returns the root of the SMT. - fn root(&self) -> Word; } // BACKEND IMPLEMENTATION FOR SMT @@ -80,20 +86,6 @@ impl AccountTreeBackend for Smt { Smt::open(self, key) } - fn apply_mutations( - &mut self, - set: MutationSet, - ) -> Result<(), Self::Error> { - Smt::apply_mutations(self, set) - } - - fn apply_mutations_with_reversion( - &mut self, - set: MutationSet, - ) -> Result, Self::Error> { - Smt::apply_mutations_with_reversion(self, set) - } - fn compute_mutations( &self, updates: Vec<(Word, Word)>, @@ -101,10 +93,6 @@ impl AccountTreeBackend for Smt { Smt::compute_mutations(self, updates) } - fn insert(&mut self, key: Word, value: Word) -> Result { - Smt::insert(self, key, value) - } - fn get_value(&self, key: &Word) -> Word { Smt::get_value(self, key) } @@ -118,13 +106,33 @@ impl AccountTreeBackend for Smt { } } +impl AccountTreeBackendWriter for Smt { + fn apply_mutations( + &mut self, + set: MutationSet, + ) -> Result<(), Self::Error> { + Smt::apply_mutations(self, set) + } + + fn apply_mutations_with_reversion( + &mut self, + set: MutationSet, + ) -> Result, Self::Error> { + Smt::apply_mutations_with_reversion(self, set) + } + + fn insert(&mut self, key: Word, value: Word) -> Result { + Smt::insert(self, key, value) + } +} + // BACKEND IMPLEMENTATION FOR LARGE SMT // ================================================================================================ #[cfg(feature = "std")] impl AccountTreeBackend for LargeSmt where - Backend: SmtStorage, + Backend: SmtStorageWriter, { type Error = MerkleError; @@ -140,20 +148,6 @@ where LargeSmt::open(self, key) } - fn apply_mutations( - &mut self, - set: MutationSet, - ) -> Result<(), Self::Error> { - LargeSmt::apply_mutations(self, set).map_err(large_smt_error_to_merkle_error) - } - - fn apply_mutations_with_reversion( - &mut self, - set: MutationSet, - ) -> Result, Self::Error> { - LargeSmt::apply_mutations_with_reversion(self, set).map_err(large_smt_error_to_merkle_error) - } - fn compute_mutations( &self, updates: Vec<(Word, Word)>, @@ -161,10 +155,6 @@ where LargeSmt::compute_mutations(self, updates).map_err(large_smt_error_to_merkle_error) } - fn insert(&mut self, key: Word, value: Word) -> Result { - LargeSmt::insert(self, key, value) - } - fn get_value(&self, key: &Word) -> Word { LargeSmt::get_value(self, key) } @@ -178,6 +168,30 @@ where } } +#[cfg(feature = "std")] +impl AccountTreeBackendWriter for LargeSmt +where + Backend: SmtStorageWriter, +{ + fn apply_mutations( + &mut self, + set: MutationSet, + ) -> Result<(), Self::Error> { + LargeSmt::apply_mutations(self, set).map_err(large_smt_error_to_merkle_error) + } + + fn apply_mutations_with_reversion( + &mut self, + set: MutationSet, + ) -> Result, Self::Error> { + LargeSmt::apply_mutations_with_reversion(self, set).map_err(large_smt_error_to_merkle_error) + } + + fn insert(&mut self, key: Word, value: Word) -> Result { + LargeSmt::insert(self, key, value) + } +} + // CONVENIENCE METHODS // ================================================================================================ diff --git a/crates/miden-protocol/src/block/account_tree/mod.rs b/crates/miden-protocol/src/block/account_tree/mod.rs index e594684be1..bf1e8e84c2 100644 --- a/crates/miden-protocol/src/block/account_tree/mod.rs +++ b/crates/miden-protocol/src/block/account_tree/mod.rs @@ -21,7 +21,7 @@ mod witness; pub use witness::AccountWitness; mod backend; -pub use backend::AccountTreeBackend; +pub use backend::{AccountTreeBackend, AccountTreeBackendWriter}; mod account_id_key; pub use account_id_key::AccountIdKey; @@ -245,6 +245,24 @@ where Ok(AccountMutationSet::new(mutation_set)) } + // HELPERS + // -------------------------------------------------------------------------------------------- + + /// Returns the SMT key of the given account ID prefix. + fn id_prefix_to_smt_key(account_id: AccountIdPrefix) -> Word { + // We construct this in such a way that we're forced to use the constants, so that when + // they're updated, the other usages of the constants are also updated. + let mut key = Word::empty(); + key[Self::KEY_PREFIX_IDX] = account_id.as_felt(); + + key + } +} + +impl AccountTree +where + S: AccountTreeBackendWriter, +{ // PUBLIC MUTATORS // -------------------------------------------------------------------------------------------- @@ -314,19 +332,6 @@ where .map_err(AccountTreeError::ApplyMutations)?; Ok(AccountMutationSet::new(reversion)) } - - // HELPERS - // -------------------------------------------------------------------------------------------- - - /// Returns the SMT key of the given account ID prefix. - fn id_prefix_to_smt_key(account_id: AccountIdPrefix) -> Word { - // We construct this in such a way that we're forced to use the constants, so that when - // they're updated, the other usages of the constants are also updated. - let mut key = Word::empty(); - key[Self::KEY_PREFIX_IDX] = account_id.as_felt(); - - key - } } // SERIALIZATION From a16534c873596cc6da0b59cca61a69348be88834 Mon Sep 17 00:00:00 2001 From: sergerad Date: Fri, 10 Apr 2026 15:26:02 +1200 Subject: [PATCH 03/19] Fix impl read write matching --- .../src/block/account_tree/backend.rs | 44 +++++++++---------- .../src/block/account_tree/mod.rs | 42 +++++++++--------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/crates/miden-protocol/src/block/account_tree/backend.rs b/crates/miden-protocol/src/block/account_tree/backend.rs index 2947d077ca..2910cdd099 100644 --- a/crates/miden-protocol/src/block/account_tree/backend.rs +++ b/crates/miden-protocol/src/block/account_tree/backend.rs @@ -5,7 +5,7 @@ use super::{AccountId, AccountIdKey, AccountIdPrefix, AccountTree, AccountTreeEr use crate::Word; use crate::crypto::merkle::MerkleError; #[cfg(feature = "std")] -use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorageWriter}; +use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorageReader, SmtStorageWriter}; use crate::crypto::merkle::smt::{LeafIndex, MutationSet, SMT_DEPTH, Smt, SmtLeaf, SmtProof}; // ACCOUNT TREE BACKEND @@ -32,12 +32,6 @@ pub trait AccountTreeBackend: Sized { /// Opens the leaf at the given key, returning a Merkle proof. fn open(&self, key: &Word) -> SmtProof; - /// Computes the mutation set required to apply the given updates to the SMT. - fn compute_mutations( - &self, - updates: Vec<(Word, Word)>, - ) -> Result, Self::Error>; - /// Returns the value associated with the given key. fn get_value(&self, key: &Word) -> Word; @@ -50,6 +44,12 @@ pub trait AccountTreeBackend: Sized { /// Extension trait for [`AccountTreeBackend`] that provides write methods. pub trait AccountTreeBackendWriter: AccountTreeBackend { + /// Computes the mutation set required to apply the given updates to the SMT. + fn compute_mutations( + &self, + updates: Vec<(Word, Word)>, + ) -> Result, Self::Error>; + /// Applies the given mutation set to the SMT. fn apply_mutations( &mut self, @@ -86,13 +86,6 @@ impl AccountTreeBackend for Smt { Smt::open(self, key) } - fn compute_mutations( - &self, - updates: Vec<(Word, Word)>, - ) -> Result, Self::Error> { - Smt::compute_mutations(self, updates) - } - fn get_value(&self, key: &Word) -> Word { Smt::get_value(self, key) } @@ -107,6 +100,13 @@ impl AccountTreeBackend for Smt { } impl AccountTreeBackendWriter for Smt { + fn compute_mutations( + &self, + updates: Vec<(Word, Word)>, + ) -> Result, Self::Error> { + Smt::compute_mutations(self, updates) + } + fn apply_mutations( &mut self, set: MutationSet, @@ -132,7 +132,7 @@ impl AccountTreeBackendWriter for Smt { #[cfg(feature = "std")] impl AccountTreeBackend for LargeSmt where - Backend: SmtStorageWriter, + Backend: SmtStorageReader, { type Error = MerkleError; @@ -148,13 +148,6 @@ where LargeSmt::open(self, key) } - fn compute_mutations( - &self, - updates: Vec<(Word, Word)>, - ) -> Result, Self::Error> { - LargeSmt::compute_mutations(self, updates).map_err(large_smt_error_to_merkle_error) - } - fn get_value(&self, key: &Word) -> Word { LargeSmt::get_value(self, key) } @@ -173,6 +166,13 @@ impl AccountTreeBackendWriter for LargeSmt where Backend: SmtStorageWriter, { + fn compute_mutations( + &self, + updates: Vec<(Word, Word)>, + ) -> Result, Self::Error> { + LargeSmt::compute_mutations(self, updates).map_err(large_smt_error_to_merkle_error) + } + fn apply_mutations( &mut self, set: MutationSet, diff --git a/crates/miden-protocol/src/block/account_tree/mod.rs b/crates/miden-protocol/src/block/account_tree/mod.rs index bf1e8e84c2..a4fc457ab5 100644 --- a/crates/miden-protocol/src/block/account_tree/mod.rs +++ b/crates/miden-protocol/src/block/account_tree/mod.rs @@ -188,6 +188,27 @@ where }) } + // HELPERS + // -------------------------------------------------------------------------------------------- + + /// Returns the SMT key of the given account ID prefix. + fn id_prefix_to_smt_key(account_id: AccountIdPrefix) -> Word { + // We construct this in such a way that we're forced to use the constants, so that when + // they're updated, the other usages of the constants are also updated. + let mut key = Word::empty(); + key[Self::KEY_PREFIX_IDX] = account_id.as_felt(); + + key + } +} + +impl AccountTree +where + S: AccountTreeBackendWriter, +{ + // PUBLIC MUTATORS + // -------------------------------------------------------------------------------------------- + /// Computes the necessary changes to insert the specified (account ID, state commitment) pairs /// into this tree, allowing for validation before applying those changes. /// @@ -245,27 +266,6 @@ where Ok(AccountMutationSet::new(mutation_set)) } - // HELPERS - // -------------------------------------------------------------------------------------------- - - /// Returns the SMT key of the given account ID prefix. - fn id_prefix_to_smt_key(account_id: AccountIdPrefix) -> Word { - // We construct this in such a way that we're forced to use the constants, so that when - // they're updated, the other usages of the constants are also updated. - let mut key = Word::empty(); - key[Self::KEY_PREFIX_IDX] = account_id.as_felt(); - - key - } -} - -impl AccountTree -where - S: AccountTreeBackendWriter, -{ - // PUBLIC MUTATORS - // -------------------------------------------------------------------------------------------- - /// Inserts the state commitment for the given account ID, returning the previous state /// commitment associated with that ID. /// From a56b359904e5f9918eb1bcc8c4fdf429cb3ea78e Mon Sep 17 00:00:00 2001 From: sergerad Date: Fri, 10 Apr 2026 15:56:25 +1200 Subject: [PATCH 04/19] Split NullifierTreeBackend reader writer --- .../src/block/nullifier_tree/backend.rs | 97 +++++++++++-------- .../src/block/nullifier_tree/mod.rs | 13 ++- 2 files changed, 63 insertions(+), 47 deletions(-) diff --git a/crates/miden-protocol/src/block/nullifier_tree/backend.rs b/crates/miden-protocol/src/block/nullifier_tree/backend.rs index 90f0955046..68e3325637 100644 --- a/crates/miden-protocol/src/block/nullifier_tree/backend.rs +++ b/crates/miden-protocol/src/block/nullifier_tree/backend.rs @@ -4,7 +4,7 @@ use super::{BlockNumber, Nullifier, NullifierBlock, NullifierTree, NullifierTree use crate::Word; use crate::crypto::merkle::MerkleError; #[cfg(feature = "std")] -use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage}; +use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorageReader, SmtStorageWriter}; use crate::crypto::merkle::smt::{MutationSet, SMT_DEPTH, Smt, SmtProof}; // NULLIFIER TREE BACKEND @@ -33,26 +33,29 @@ pub trait NullifierTreeBackend: Sized { /// Opens the leaf at the given key, returning a Merkle proof. fn open(&self, key: &Word) -> SmtProof; - /// Applies the given mutation set to the SMT. - fn apply_mutations( - &mut self, - set: MutationSet, - ) -> Result<(), Self::Error>; + /// Returns the value associated with the given key. + fn get_value(&self, key: &Word) -> NullifierBlock; + + /// Returns the root of the SMT. + fn root(&self) -> Word; +} +/// Extension trait for [`NullifierTreeBackend`] that provides write methods. +pub trait NullifierTreeBackendWriter: NullifierTreeBackend { /// Computes the mutation set required to apply the given updates to the SMT. fn compute_mutations( &self, updates: impl IntoIterator, ) -> Result, Self::Error>; + /// Applies the given mutation set to the SMT. + fn apply_mutations( + &mut self, + set: MutationSet, + ) -> Result<(), Self::Error>; + /// Inserts a key-value pair into the SMT, returning the previous value at that key. fn insert(&mut self, key: Word, value: NullifierBlock) -> Result; - - /// Returns the value associated with the given key. - fn get_value(&self, key: &Word) -> NullifierBlock; - - /// Returns the root of the SMT. - fn root(&self) -> Word; } // BACKEND IMPLEMENTATION FOR SMT @@ -73,13 +76,17 @@ impl NullifierTreeBackend for Smt { Smt::open(self, key) } - fn apply_mutations( - &mut self, - set: MutationSet, - ) -> Result<(), Self::Error> { - Smt::apply_mutations(self, set) + fn get_value(&self, key: &Word) -> NullifierBlock { + NullifierBlock::new(Smt::get_value(self, key)) + .expect("SMT should only store valid NullifierBlocks") } + fn root(&self) -> Word { + Smt::root(self) + } +} + +impl NullifierTreeBackendWriter for Smt { fn compute_mutations( &self, updates: impl IntoIterator, @@ -87,20 +94,18 @@ impl NullifierTreeBackend for Smt { Smt::compute_mutations(self, updates) } + fn apply_mutations( + &mut self, + set: MutationSet, + ) -> Result<(), Self::Error> { + Smt::apply_mutations(self, set) + } + fn insert(&mut self, key: Word, value: NullifierBlock) -> Result { Smt::insert(self, key, value.into()).map(|word| { NullifierBlock::try_from(word).expect("SMT should only store valid NullifierBlocks") }) } - - fn get_value(&self, key: &Word) -> NullifierBlock { - NullifierBlock::new(Smt::get_value(self, key)) - .expect("SMT should only store valid NullifierBlocks") - } - - fn root(&self) -> Word { - Smt::root(self) - } } // NULLIFIER TREE BACKEND FOR LARGE SMT @@ -109,7 +114,7 @@ impl NullifierTreeBackend for Smt { #[cfg(feature = "std")] impl NullifierTreeBackend for LargeSmt where - Backend: SmtStorage, + Backend: SmtStorageReader, { type Error = MerkleError; @@ -127,13 +132,22 @@ where LargeSmt::open(self, key) } - fn apply_mutations( - &mut self, - set: MutationSet, - ) -> Result<(), Self::Error> { - LargeSmt::apply_mutations(self, set).map_err(large_smt_error_to_merkle_error) + fn get_value(&self, key: &Word) -> NullifierBlock { + LargeSmt::get_value(self, key) + .try_into() + .expect("unable to create NullifierBlock") } + fn root(&self) -> Word { + LargeSmt::root(self) + } +} + +#[cfg(feature = "std")] +impl NullifierTreeBackendWriter for LargeSmt +where + Backend: SmtStorageWriter, +{ fn compute_mutations( &self, updates: impl IntoIterator, @@ -141,21 +155,18 @@ where LargeSmt::compute_mutations(self, updates).map_err(large_smt_error_to_merkle_error) } + fn apply_mutations( + &mut self, + set: MutationSet, + ) -> Result<(), Self::Error> { + LargeSmt::apply_mutations(self, set).map_err(large_smt_error_to_merkle_error) + } + fn insert(&mut self, key: Word, value: NullifierBlock) -> Result { LargeSmt::insert(self, key, value.into()).map(|word| { NullifierBlock::try_from(word).expect("SMT should only store valid NullifierBlocks") }) } - - fn get_value(&self, key: &Word) -> NullifierBlock { - LargeSmt::get_value(self, key) - .try_into() - .expect("unable to create NullifierBlock") - } - - fn root(&self) -> Word { - LargeSmt::root(self) - } } // CONVENIENCE METHODS @@ -188,7 +199,7 @@ impl NullifierTree { #[cfg(feature = "std")] impl NullifierTree> where - Backend: SmtStorage, + Backend: SmtStorageWriter, { /// Creates a new nullifier tree from the provided entries using the given storage backend /// diff --git a/crates/miden-protocol/src/block/nullifier_tree/mod.rs b/crates/miden-protocol/src/block/nullifier_tree/mod.rs index b85a4aebd7..073ca09ebd 100644 --- a/crates/miden-protocol/src/block/nullifier_tree/mod.rs +++ b/crates/miden-protocol/src/block/nullifier_tree/mod.rs @@ -16,7 +16,7 @@ use crate::utils::serde::{ use crate::{Felt, Word}; mod backend; -pub use backend::NullifierTreeBackend; +pub use backend::{NullifierTreeBackend, NullifierTreeBackendWriter}; mod witness; pub use witness::NullifierWitness; @@ -116,6 +116,14 @@ where Some(nullifier_block.into()) } +} + +impl NullifierTree +where + Backend: NullifierTreeBackendWriter, +{ + // PUBLIC MUTATORS + // -------------------------------------------------------------------------------------------- /// Computes a mutation set resulting from inserting the provided nullifiers into this nullifier /// tree. @@ -153,9 +161,6 @@ where Ok(NullifierMutationSet::new(mutation_set)) } - // PUBLIC MUTATORS - // -------------------------------------------------------------------------------------------- - /// Marks the given nullifier as spent at the given block number. /// /// # Errors From 271c6f85edd987112c2c91d85785949cd7efd1b4 Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 13 Apr 2026 11:12:39 +1200 Subject: [PATCH 05/19] Replace write with reader traits --- Cargo.lock | 22 ++++++++-- .../src/block/account_tree/backend.rs | 37 ++++++++++------- .../src/block/account_tree/mod.rs | 6 +-- .../src/block/nullifier_tree/backend.rs | 40 ++++++++++++------- .../src/block/nullifier_tree/mod.rs | 6 +-- 5 files changed, 73 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 06e1285eda..e534d56078 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,8 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed0a034a460e27723dcfdf25effffab84331c3b46b13e7a1bd674197cc71bfe" dependencies = [ "blake3", "cc", @@ -1701,7 +1702,8 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8bf6ebde028e79bcc61a3632d2f375a5cc64caa17d014459f75015238cb1e08" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1730,8 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38011348f4fb4c9e5ce1f471203d024721c00e3b60a91aa91aaefe6738d8b5ea" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1921,8 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#17e071c17b6343b5ca8c4a6c803f23c429fbab8e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff78082e9b4ca89863e68da01b35f8a4029ee6fd912e39fa41fde4273a7debab" dependencies = [ "p3-field", "p3-goldilocks", @@ -4219,3 +4223,13 @@ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" + +[[patch.unused]] +name = "miden-crypto" +version = "0.24.0" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#5de66e4ffc5f36bead4508245c2050b2e76a1843" + +[[patch.unused]] +name = "miden-serde-utils" +version = "0.24.0" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#5de66e4ffc5f36bead4508245c2050b2e76a1843" diff --git a/crates/miden-protocol/src/block/account_tree/backend.rs b/crates/miden-protocol/src/block/account_tree/backend.rs index 2910cdd099..c48895a2b7 100644 --- a/crates/miden-protocol/src/block/account_tree/backend.rs +++ b/crates/miden-protocol/src/block/account_tree/backend.rs @@ -5,22 +5,22 @@ use super::{AccountId, AccountIdKey, AccountIdPrefix, AccountTree, AccountTreeEr use crate::Word; use crate::crypto::merkle::MerkleError; #[cfg(feature = "std")] -use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorageReader, SmtStorageWriter}; +use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage}; use crate::crypto::merkle::smt::{LeafIndex, MutationSet, SMT_DEPTH, Smt, SmtLeaf, SmtProof}; -// ACCOUNT TREE BACKEND +// ACCOUNT TREE BACKEND READER // ================================================================================================ /// This trait abstracts over different SMT backends (e.g., `Smt` and `LargeSmt`) to allow /// the `AccountTree` to work with either implementation transparently. /// /// This trait contains only read-only methods. For write methods, see -/// [`AccountTreeBackendWriter`]. +/// [`AccountTreeBackend`]. /// /// Implementors must provide `Default` for creating empty instances. Users should /// instantiate the backend directly (potentially with entries) and then pass it to /// [`AccountTree::new`]. -pub trait AccountTreeBackend: Sized { +pub trait AccountTreeBackendReader: Sized { type Error: core::error::Error + Send + 'static; /// Returns the number of leaves in the SMT. @@ -42,8 +42,11 @@ pub trait AccountTreeBackend: Sized { fn root(&self) -> Word; } -/// Extension trait for [`AccountTreeBackend`] that provides write methods. -pub trait AccountTreeBackendWriter: AccountTreeBackend { +// ACCOUNT TREE BACKEND +// ================================================================================================ + +/// Extension trait for [`AccountTreeBackendReader`] that provides write methods. +pub trait AccountTreeBackend: AccountTreeBackendReader { /// Computes the mutation set required to apply the given updates to the SMT. fn compute_mutations( &self, @@ -68,10 +71,10 @@ pub trait AccountTreeBackendWriter: AccountTreeBackend { fn insert(&mut self, key: Word, value: Word) -> Result; } -// BACKEND IMPLEMENTATION FOR SMT +// BACKEND READER IMPLEMENTATION FOR SMT // ================================================================================================ -impl AccountTreeBackend for Smt { +impl AccountTreeBackendReader for Smt { type Error = MerkleError; fn num_leaves(&self) -> usize { @@ -99,7 +102,10 @@ impl AccountTreeBackend for Smt { } } -impl AccountTreeBackendWriter for Smt { +// BACKEND IMPLEMENTATION FOR SMT +// ================================================================================================ + +impl AccountTreeBackend for Smt { fn compute_mutations( &self, updates: Vec<(Word, Word)>, @@ -126,13 +132,13 @@ impl AccountTreeBackendWriter for Smt { } } -// BACKEND IMPLEMENTATION FOR LARGE SMT +// BACKEND READER IMPLEMENTATION FOR LARGE SMT // ================================================================================================ #[cfg(feature = "std")] -impl AccountTreeBackend for LargeSmt +impl AccountTreeBackendReader for LargeSmt where - Backend: SmtStorageReader, + Backend: SmtStorage, { type Error = MerkleError; @@ -161,10 +167,13 @@ where } } +// BACKEND IMPLEMENTATION FOR LARGE SMT +// ================================================================================================ + #[cfg(feature = "std")] -impl AccountTreeBackendWriter for LargeSmt +impl AccountTreeBackend for LargeSmt where - Backend: SmtStorageWriter, + Backend: SmtStorage, { fn compute_mutations( &self, diff --git a/crates/miden-protocol/src/block/account_tree/mod.rs b/crates/miden-protocol/src/block/account_tree/mod.rs index a4fc457ab5..d9130bfd02 100644 --- a/crates/miden-protocol/src/block/account_tree/mod.rs +++ b/crates/miden-protocol/src/block/account_tree/mod.rs @@ -21,7 +21,7 @@ mod witness; pub use witness::AccountWitness; mod backend; -pub use backend::{AccountTreeBackend, AccountTreeBackendWriter}; +pub use backend::{AccountTreeBackend, AccountTreeBackendReader}; mod account_id_key; pub use account_id_key::AccountIdKey; @@ -53,7 +53,7 @@ where impl AccountTree where - S: AccountTreeBackend, + S: AccountTreeBackendReader, { // CONSTANTS // -------------------------------------------------------------------------------------------- @@ -204,7 +204,7 @@ where impl AccountTree where - S: AccountTreeBackendWriter, + S: AccountTreeBackend, { // PUBLIC MUTATORS // -------------------------------------------------------------------------------------------- diff --git a/crates/miden-protocol/src/block/nullifier_tree/backend.rs b/crates/miden-protocol/src/block/nullifier_tree/backend.rs index 68e3325637..953c081c98 100644 --- a/crates/miden-protocol/src/block/nullifier_tree/backend.rs +++ b/crates/miden-protocol/src/block/nullifier_tree/backend.rs @@ -4,15 +4,18 @@ use super::{BlockNumber, Nullifier, NullifierBlock, NullifierTree, NullifierTree use crate::Word; use crate::crypto::merkle::MerkleError; #[cfg(feature = "std")] -use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorageReader, SmtStorageWriter}; +use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage}; use crate::crypto::merkle::smt::{MutationSet, SMT_DEPTH, Smt, SmtProof}; -// NULLIFIER TREE BACKEND +// NULLIFIER TREE BACKEND READER // ================================================================================================ /// This trait abstracts over different SMT backends (e.g., `Smt` and `LargeSmt`) to allow /// the `NullifierTree` to work with either implementation transparently. /// +/// This trait contains only read-only methods. For write methods, see +/// [`NullifierTreeBackend`]. +/// /// Users should instantiate the backend directly (potentially with entries) and then /// pass it to [`NullifierTree::new_unchecked`]. /// @@ -21,7 +24,7 @@ use crate::crypto::merkle::smt::{MutationSet, SMT_DEPTH, Smt, SmtProof}; /// Assumes the provided SMT upholds the guarantees of the [`NullifierTree`]. Specifically: /// - Nullifiers are only spent once and their block numbers do not change. /// - Nullifier leaf values must be valid according to [`NullifierBlock`]. -pub trait NullifierTreeBackend: Sized { +pub trait NullifierTreeBackendReader: Sized { type Error: core::error::Error + Send + 'static; /// Returns the number of entries in the SMT. @@ -40,8 +43,11 @@ pub trait NullifierTreeBackend: Sized { fn root(&self) -> Word; } -/// Extension trait for [`NullifierTreeBackend`] that provides write methods. -pub trait NullifierTreeBackendWriter: NullifierTreeBackend { +// NULLIFIER TREE BACKEND +// ================================================================================================ + +/// Extension trait for [`NullifierTreeBackendReader`] that provides write methods. +pub trait NullifierTreeBackend: NullifierTreeBackendReader { /// Computes the mutation set required to apply the given updates to the SMT. fn compute_mutations( &self, @@ -58,10 +64,10 @@ pub trait NullifierTreeBackendWriter: NullifierTreeBackend { fn insert(&mut self, key: Word, value: NullifierBlock) -> Result; } -// BACKEND IMPLEMENTATION FOR SMT +// BACKEND READER IMPLEMENTATION FOR SMT // ================================================================================================ -impl NullifierTreeBackend for Smt { +impl NullifierTreeBackendReader for Smt { type Error = MerkleError; fn num_entries(&self) -> usize { @@ -86,7 +92,10 @@ impl NullifierTreeBackend for Smt { } } -impl NullifierTreeBackendWriter for Smt { +// BACKEND IMPLEMENTATION FOR SMT +// ================================================================================================ + +impl NullifierTreeBackend for Smt { fn compute_mutations( &self, updates: impl IntoIterator, @@ -108,13 +117,13 @@ impl NullifierTreeBackendWriter for Smt { } } -// NULLIFIER TREE BACKEND FOR LARGE SMT +// BACKEND READER IMPLEMENTATION FOR LARGE SMT // ================================================================================================ #[cfg(feature = "std")] -impl NullifierTreeBackend for LargeSmt +impl NullifierTreeBackendReader for LargeSmt where - Backend: SmtStorageReader, + Backend: SmtStorage, { type Error = MerkleError; @@ -143,10 +152,13 @@ where } } +// BACKEND IMPLEMENTATION FOR LARGE SMT +// ================================================================================================ + #[cfg(feature = "std")] -impl NullifierTreeBackendWriter for LargeSmt +impl NullifierTreeBackend for LargeSmt where - Backend: SmtStorageWriter, + Backend: SmtStorage, { fn compute_mutations( &self, @@ -199,7 +211,7 @@ impl NullifierTree { #[cfg(feature = "std")] impl NullifierTree> where - Backend: SmtStorageWriter, + Backend: SmtStorage, { /// Creates a new nullifier tree from the provided entries using the given storage backend /// diff --git a/crates/miden-protocol/src/block/nullifier_tree/mod.rs b/crates/miden-protocol/src/block/nullifier_tree/mod.rs index 073ca09ebd..c7a960998a 100644 --- a/crates/miden-protocol/src/block/nullifier_tree/mod.rs +++ b/crates/miden-protocol/src/block/nullifier_tree/mod.rs @@ -16,7 +16,7 @@ use crate::utils::serde::{ use crate::{Felt, Word}; mod backend; -pub use backend::{NullifierTreeBackend, NullifierTreeBackendWriter}; +pub use backend::{NullifierTreeBackend, NullifierTreeBackendReader}; mod witness; pub use witness::NullifierWitness; @@ -51,7 +51,7 @@ where impl NullifierTree where - Backend: NullifierTreeBackend, + Backend: NullifierTreeBackendReader, { // CONSTANTS // -------------------------------------------------------------------------------------------- @@ -120,7 +120,7 @@ where impl NullifierTree where - Backend: NullifierTreeBackendWriter, + Backend: NullifierTreeBackend, { // PUBLIC MUTATORS // -------------------------------------------------------------------------------------------- From 1bcb54704f15c01e87603e9e92ef4a4902f03d17 Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 13 Apr 2026 11:32:33 +1200 Subject: [PATCH 06/19] Lint --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e534d56078..e9800d4213 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4227,9 +4227,9 @@ checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" [[patch.unused]] name = "miden-crypto" version = "0.24.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#5de66e4ffc5f36bead4508245c2050b2e76a1843" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#7da2e0352154e5969d79ca55cf9b015dd70cc2d6" [[patch.unused]] name = "miden-serde-utils" version = "0.24.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#5de66e4ffc5f36bead4508245c2050b2e76a1843" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#7da2e0352154e5969d79ca55cf9b015dd70cc2d6" diff --git a/Cargo.toml b/Cargo.toml index 14dfcdbdc7..2495decfb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,5 +72,5 @@ thiserror = { default-features = false, version = "2.0" } tokio = { default-features = false, features = ["sync"], version = "1" } [patch.crates-io] -miden-crypto = { git = "https://github.com/0xmiden/crypto", branch = "sergerad-clone" } -miden-serde-utils = { git = "https://github.com/0xmiden/crypto", branch = "sergerad-clone" } +miden-crypto = { branch = "sergerad-clone", git = "https://github.com/0xmiden/crypto" } +miden-serde-utils = { branch = "sergerad-clone", git = "https://github.com/0xmiden/crypto" } From 3ec145d9c0308bc56de01c85e9bdb65be9525176 Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 13 Apr 2026 12:06:43 +1200 Subject: [PATCH 07/19] update crypto after revert --- Cargo.lock | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77c0697a01..fb36fc41ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,8 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0a034a460e27723dcfdf25effffab84331c3b46b13e7a1bd674197cc71bfe" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" dependencies = [ "blake3", "cc", @@ -1702,8 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8bf6ebde028e79bcc61a3632d2f375a5cc64caa17d014459f75015238cb1e08" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" dependencies = [ "quote", "syn 2.0.117", @@ -1730,8 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38011348f4fb4c9e5ce1f471203d024721c00e3b60a91aa91aaefe6738d8b5ea" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1921,8 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff78082e9b4ca89863e68da01b35f8a4029ee6fd912e39fa41fde4273a7debab" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" dependencies = [ "p3-field", "p3-goldilocks", @@ -4223,13 +4219,3 @@ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" - -[[patch.unused]] -name = "miden-crypto" -version = "0.24.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#7da2e0352154e5969d79ca55cf9b015dd70cc2d6" - -[[patch.unused]] -name = "miden-serde-utils" -version = "0.24.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#7da2e0352154e5969d79ca55cf9b015dd70cc2d6" From c651d1f692e038a65afdb3efff30174acd512565 Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 13 Apr 2026 12:28:30 +1200 Subject: [PATCH 08/19] Back to v0.14 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 03caff78e8..74f7a6cf0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ homepage = "https://miden.xyz" license = "MIT" repository = "https://github.com/0xMiden/protocol" rust-version = "1.90" -version = "0.15.0" +version = "0.14.0" [profile.release] codegen-units = 1 From 18a86fce54d7173b8fd617475728fa4f93721511 Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 13 Apr 2026 12:41:37 +1200 Subject: [PATCH 09/19] Back to v0.15 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 74f7a6cf0b..03caff78e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ homepage = "https://miden.xyz" license = "MIT" repository = "https://github.com/0xMiden/protocol" rust-version = "1.90" -version = "0.14.0" +version = "0.15.0" [profile.release] codegen-units = 1 From b6dcab32565289d5772b45230f0df1118d16a9db Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 13 Apr 2026 12:46:38 +1200 Subject: [PATCH 10/19] Fix trait bound readers --- crates/miden-protocol/src/block/account_tree/backend.rs | 4 ++-- crates/miden-protocol/src/block/nullifier_tree/backend.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/miden-protocol/src/block/account_tree/backend.rs b/crates/miden-protocol/src/block/account_tree/backend.rs index c48895a2b7..a92982bf08 100644 --- a/crates/miden-protocol/src/block/account_tree/backend.rs +++ b/crates/miden-protocol/src/block/account_tree/backend.rs @@ -5,7 +5,7 @@ use super::{AccountId, AccountIdKey, AccountIdPrefix, AccountTree, AccountTreeEr use crate::Word; use crate::crypto::merkle::MerkleError; #[cfg(feature = "std")] -use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage}; +use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage, SmtStorageReader}; use crate::crypto::merkle::smt::{LeafIndex, MutationSet, SMT_DEPTH, Smt, SmtLeaf, SmtProof}; // ACCOUNT TREE BACKEND READER @@ -138,7 +138,7 @@ impl AccountTreeBackend for Smt { #[cfg(feature = "std")] impl AccountTreeBackendReader for LargeSmt where - Backend: SmtStorage, + Backend: SmtStorageReader, { type Error = MerkleError; diff --git a/crates/miden-protocol/src/block/nullifier_tree/backend.rs b/crates/miden-protocol/src/block/nullifier_tree/backend.rs index 953c081c98..2f956f5b75 100644 --- a/crates/miden-protocol/src/block/nullifier_tree/backend.rs +++ b/crates/miden-protocol/src/block/nullifier_tree/backend.rs @@ -4,7 +4,7 @@ use super::{BlockNumber, Nullifier, NullifierBlock, NullifierTree, NullifierTree use crate::Word; use crate::crypto::merkle::MerkleError; #[cfg(feature = "std")] -use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage}; +use crate::crypto::merkle::smt::{LargeSmt, LargeSmtError, SmtStorage, SmtStorageReader}; use crate::crypto::merkle::smt::{MutationSet, SMT_DEPTH, Smt, SmtProof}; // NULLIFIER TREE BACKEND READER @@ -123,7 +123,7 @@ impl NullifierTreeBackend for Smt { #[cfg(feature = "std")] impl NullifierTreeBackendReader for LargeSmt where - Backend: SmtStorage, + Backend: SmtStorageReader, { type Error = MerkleError; From dba0ccf1a34b0cd0dd1ef1c4f8478bfa122b40a9 Mon Sep 17 00:00:00 2001 From: sergerad Date: Tue, 14 Apr 2026 09:00:46 +1200 Subject: [PATCH 11/19] Update crypto dep --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb36fc41ca..eef1dab769 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#ded92df7616b724d1c4f36fed968ee341d602fda" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" dependencies = [ "p3-field", "p3-goldilocks", From 172df00d27c13f82274b6db16540e82060b0eb08 Mon Sep 17 00:00:00 2001 From: sergerad Date: Tue, 14 Apr 2026 09:03:16 +1200 Subject: [PATCH 12/19] Changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98f6e294b7..252d1a478e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,6 @@ ### Changes - Added validation of leaf type on CLAIM note processing to prevent message leaves from being processed as asset claims ([#2730](https://github.com/0xMiden/protocol/pull/2730)). - - Added `AssetAmount` wrapper type for validated fungible asset amounts ([#2721](https://github.com/0xMiden/protocol/pull/2721)). - [BREAKING] Renamed `ProvenBatch::new` to `new_unchecked` ([#2687](https://github.com/0xMiden/miden-base/issues/2687)). - Added `ShortCapitalString` type and related `TokenSymbol` and `RoleSymbol` types ([#2690](https://github.com/0xMiden/protocol/pull/2690)). @@ -12,6 +11,7 @@ - Added shared `ProcedurePolicy` for AuthMultisig ([#2670](https://github.com/0xMiden/protocol/pull/2670)). - [BREAKING] Changed `NoteType` encoding from 2 bits to 1 and makes `NoteType::Private` the default ([#2691](https://github.com/0xMiden/miden-base/issues/2691)). - Added `BlockNumber::saturating_sub()` ([#2660](https://github.com/0xMiden/protocol/issues/2660)). +- Added `NullifierTreeBackendReader` and `AccountTreeBackendReader` traits ([#2755](https://github.com/0xMiden/protocol/pull/2755)). ## 0.14.3 (2026-04-07) From b65c96cb41b05a62918b06d7d45c0667dfcab595 Mon Sep 17 00:00:00 2001 From: sergerad Date: Wed, 15 Apr 2026 11:51:57 +1200 Subject: [PATCH 13/19] Update crypto branch --- Cargo.lock | 8 ++++---- Cargo.toml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eef1dab769..de67bcc5d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-clone#bcb1daae09b0d821739e89c06d31f50cdc092ae7" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" dependencies = [ "p3-field", "p3-goldilocks", diff --git a/Cargo.toml b/Cargo.toml index 03caff78e8..27d75e57b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,5 +72,5 @@ thiserror = { default-features = false, version = "2.0" } tokio = { default-features = false, features = ["sync"], version = "1" } [patch.crates-io] -miden-crypto = { branch = "sergerad-clone", git = "https://github.com/0xmiden/crypto" } -miden-serde-utils = { branch = "sergerad-clone", git = "https://github.com/0xmiden/crypto" } +miden-crypto = { branch = "sergerad-largesmt-reader-trait", git = "https://github.com/0xmiden/crypto" } +miden-serde-utils = { branch = "sergerad-largesmt-reader-trait", git = "https://github.com/0xmiden/crypto" } From 99feef0004f9489508216b8cadc67050bffe9c2a Mon Sep 17 00:00:00 2001 From: sergerad Date: Thu, 16 Apr 2026 09:07:42 +1200 Subject: [PATCH 14/19] Update deps --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index de67bcc5d1..3d3cac17ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#22c1b78f47be84f42a189651c589fe02c8cec8ab" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" dependencies = [ "p3-field", "p3-goldilocks", From 25b84a04b1c92c1ebbff9f57bf23769dbcd6d52c Mon Sep 17 00:00:00 2001 From: sergerad Date: Thu, 16 Apr 2026 09:18:09 +1200 Subject: [PATCH 15/19] Update deps --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d3cac17ea..deab012571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#83ce9f383747927b53ca9a132a7a3492e9aa85f5" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" dependencies = [ "p3-field", "p3-goldilocks", From fa7e960bf00a4c1e389f2a1066920476e6f1ea2c Mon Sep 17 00:00:00 2001 From: sergerad Date: Thu, 16 Apr 2026 19:11:49 +1200 Subject: [PATCH 16/19] Update deps --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index deab012571..c505979a97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4661f8507e756653b89ff09cbf15e772185e06d6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" dependencies = [ "p3-field", "p3-goldilocks", From 854c8b4f0c195c8f9b894fc2618b7a218ade1ed6 Mon Sep 17 00:00:00 2001 From: sergerad Date: Thu, 16 Apr 2026 19:43:39 +1200 Subject: [PATCH 17/19] Update deps --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c505979a97..c61ca5e387 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#157f0ed010582edf2188b5b0883f03827dd980f6" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" dependencies = [ "p3-field", "p3-goldilocks", From b82601603cc329f42d9da782e980e5afeaba9a48 Mon Sep 17 00:00:00 2001 From: sergerad Date: Thu, 16 Apr 2026 20:20:58 +1200 Subject: [PATCH 18/19] Add reader() --- .../miden-protocol/src/block/account_tree/backend.rs | 11 +++++++++++ .../src/block/nullifier_tree/backend.rs | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/crates/miden-protocol/src/block/account_tree/backend.rs b/crates/miden-protocol/src/block/account_tree/backend.rs index a92982bf08..bdcc8e4329 100644 --- a/crates/miden-protocol/src/block/account_tree/backend.rs +++ b/crates/miden-protocol/src/block/account_tree/backend.rs @@ -246,6 +246,17 @@ impl AccountTree { } } +#[cfg(feature = "std")] +impl AccountTree> +where + Backend: SmtStorage, +{ + /// Returns a read-only account tree backed by a reader view of this tree's storage. + pub fn reader(&self) -> AccountTree> { + AccountTree::new_unchecked(self.smt.reader()) + } +} + // HELPER FUNCTIONS // ================================================================================================ diff --git a/crates/miden-protocol/src/block/nullifier_tree/backend.rs b/crates/miden-protocol/src/block/nullifier_tree/backend.rs index 2f956f5b75..77e01fba55 100644 --- a/crates/miden-protocol/src/block/nullifier_tree/backend.rs +++ b/crates/miden-protocol/src/block/nullifier_tree/backend.rs @@ -237,6 +237,15 @@ where Ok(Self::new_unchecked(smt)) } + + /// Returns a read-only nullifier tree backed by a reader view of this tree's storage. + /// + /// The returned tree shares the same root and entries as `self`, but its storage is a + /// read-only snapshot produced by [`SmtStorage::reader`]. The returned tree cannot be + /// mutated. + pub fn reader(&self) -> NullifierTree> { + NullifierTree::new_unchecked(self.smt.reader()) + } } // HELPER FUNCTIONS From e14a3b0ba2409d175e2c570e143c95d5ff32c338 Mon Sep 17 00:00:00 2001 From: sergerad Date: Mon, 20 Apr 2026 14:04:33 +1200 Subject: [PATCH 19/19] Update deps --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c61ca5e387..bcb8634dac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,7 +1659,7 @@ dependencies = [ [[package]] name = "miden-crypto" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#652f6c0b7d459ed6a4de84eb7a872a994a81e3af" dependencies = [ "blake3", "cc", @@ -1701,7 +1701,7 @@ dependencies = [ [[package]] name = "miden-crypto-derive" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#652f6c0b7d459ed6a4de84eb7a872a994a81e3af" dependencies = [ "quote", "syn 2.0.117", @@ -1728,7 +1728,7 @@ dependencies = [ [[package]] name = "miden-field" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#652f6c0b7d459ed6a4de84eb7a872a994a81e3af" dependencies = [ "miden-serde-utils", "num-bigint", @@ -1918,7 +1918,7 @@ dependencies = [ [[package]] name = "miden-serde-utils" version = "0.23.0" -source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#4441d9c2ab43ae3e9c8dcf1544d3ad4bb2001407" +source = "git+https://github.com/0xmiden/crypto?branch=sergerad-largesmt-reader-trait#652f6c0b7d459ed6a4de84eb7a872a994a81e3af" dependencies = [ "p3-field", "p3-goldilocks",