From 4828eb4eac866bb3e957b8be2cf324e72718bcf1 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 17 Jan 2024 12:11:31 -0500 Subject: [PATCH 1/4] change branch for miden-crypto --- core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index 238eb98abb..e7f14061c7 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -23,7 +23,7 @@ std = ["miden-crypto/std", "math/std", "winter-utils/std"] [dependencies] math = { package = "winter-math", version = "0.7", default-features = false } # miden-crypto = { package = "miden-crypto", version = "0.8", default-features = false } -miden-crypto = { package = "miden-crypto", git = "https://github.com/0xPolygonMiden/crypto", branch= "next", default-features = false } +miden-crypto = { package = "miden-crypto", git = "https://github.com/0xPolygonMiden/crypto", branch= "plafer-smt-trait", default-features = false } winter-utils = { package = "winter-utils", version = "0.7", default-features = false } [dev-dependencies] From 7419ed8c60c53b50b7c50d0f61cbd16db7c6eca0 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 17 Jan 2024 12:24:25 -0500 Subject: [PATCH 2/4] fix breaking changes --- core/src/lib.rs | 4 ++-- stdlib/tests/collections/mod.rs | 2 +- stdlib/tests/collections/smt64.rs | 20 +++++++++++++------- test-utils/src/crypto.rs | 4 ++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index 3ff77ff612..66d29b193e 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -11,8 +11,8 @@ pub use miden_crypto::{Word, EMPTY_WORD, ONE, WORD_SIZE, ZERO}; pub mod crypto { pub mod merkle { pub use miden_crypto::merkle::{ - DefaultMerkleStore, EmptySubtreeRoots, InnerNodeInfo, MerkleError, MerklePath, - MerkleStore, MerkleTree, Mmr, MmrPeaks, NodeIndex, PartialMerkleTree, + DefaultMerkleStore, EmptySubtreeRoots, InnerNodeInfo, LeafIndex, MerkleError, + MerklePath, MerkleStore, MerkleTree, Mmr, MmrPeaks, NodeIndex, PartialMerkleTree, RecordingMerkleStore, SimpleSmt, StoreNode, TieredSmt, }; } diff --git a/stdlib/tests/collections/mod.rs b/stdlib/tests/collections/mod.rs index 33bc04890c..72483df475 100644 --- a/stdlib/tests/collections/mod.rs +++ b/stdlib/tests/collections/mod.rs @@ -1,5 +1,5 @@ use test_utils::{ - crypto::{MerkleStore, SimpleSmt}, + crypto::{LeafIndex, MerkleStore, SimpleSmt}, Felt, StarkField, TestError, Word, EMPTY_WORD, ONE, ZERO, }; diff --git a/stdlib/tests/collections/smt64.rs b/stdlib/tests/collections/smt64.rs index 3aa2aade6f..f6c800c100 100644 --- a/stdlib/tests/collections/smt64.rs +++ b/stdlib/tests/collections/smt64.rs @@ -1,9 +1,13 @@ -use super::{Felt, MerkleStore, SimpleSmt, StarkField, TestError, Word, EMPTY_WORD, ONE, ZERO}; +use super::{ + Felt, LeafIndex, MerkleStore, SimpleSmt, StarkField, TestError, Word, EMPTY_WORD, ONE, ZERO, +}; use crate::build_test; // TEST DATA // ================================================================================================ +const DEPTH: u8 = 64; + const LEAVES: [(u64, Word); 5] = [ ( 0b00000000_00000000_11111111_11111111_11111111_11111111_11111111_11111111_u64, @@ -36,7 +40,7 @@ const LEAVES: [(u64, Word); 5] = [ #[test] fn get() { - let smt = SimpleSmt::with_leaves(64, LEAVES).unwrap(); + let smt = SimpleSmt::::with_leaves(LEAVES).unwrap(); let source = " use.std::collections::smt64 @@ -58,7 +62,7 @@ fn get() { #[test] fn insert() { - let mut smt = SimpleSmt::new(64).unwrap(); + let mut smt = SimpleSmt::::new().unwrap(); let source = " use.std::collections::smt64 @@ -88,7 +92,7 @@ fn insert() { #[test] fn set() { - let mut smt = SimpleSmt::new(64).unwrap(); + let mut smt = SimpleSmt::::new().unwrap(); let empty_tree_root = smt.root(); let source = " @@ -133,17 +137,19 @@ fn set() { fn prepare_insert_or_set( index: u64, value: Word, - smt: &mut SimpleSmt, + smt: &mut SimpleSmt, ) -> (Vec, Vec, MerkleStore) { + let index = LeafIndex::new_max_depth(index); + // set initial state of the stack to be [VALUE, key, ROOT, ...] let mut initial_stack = Vec::new(); append_word_to_vec(&mut initial_stack, smt.root().into()); - initial_stack.push(index); + initial_stack.push(index.value()); append_word_to_vec(&mut initial_stack, value); // build a Merkle store for the test before the tree is updated, and then update the tree let store: MerkleStore = (&*smt).into(); - let old_value = smt.update_leaf(index, value).unwrap(); + let old_value = smt.insert(index, value); // after insert or set, the stack should be [OLD_VALUE, ROOT, ...] let expected_output = build_expected_stack(old_value, smt.root().into()); diff --git a/test-utils/src/crypto.rs b/test-utils/src/crypto.rs index 6aded79b56..2b062bb609 100644 --- a/test-utils/src/crypto.rs +++ b/test-utils/src/crypto.rs @@ -7,8 +7,8 @@ pub use vm_core::crypto::{ dsa::*, hash::{Rpo256, RpoDigest}, merkle::{ - EmptySubtreeRoots, MerkleError, MerklePath, MerkleStore, MerkleTree, Mmr, MmrPeaks, - NodeIndex, PartialMerkleTree, SimpleSmt, TieredSmt, + EmptySubtreeRoots, LeafIndex, MerkleError, MerklePath, MerkleStore, MerkleTree, Mmr, + MmrPeaks, NodeIndex, PartialMerkleTree, SimpleSmt, TieredSmt, }, }; From 646a7c8be4d3b481c0def369c1a08fdb4b9bcced Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Wed, 17 Jan 2024 12:29:58 -0500 Subject: [PATCH 3/4] fix cli --- miden/src/cli/data.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miden/src/cli/data.rs b/miden/src/cli/data.rs index 444f3dd772..2eef319b32 100644 --- a/miden/src/cli/data.rs +++ b/miden/src/cli/data.rs @@ -16,6 +16,10 @@ use std::{ use stdlib::StdLibrary; pub use tracing::{event, info_span, instrument, trace_span, Level}; +// CONSTANTS +// ================================================================================================ +const SIMPLE_SMT_DEPTH: u8 = u64::BITS as u8; + // HELPERS // ================================================================================================ @@ -206,7 +210,7 @@ impl InputFile { } MerkleData::SparseMerkleTree(data) => { let entries = Self::parse_sparse_merkle_tree(data)?; - let tree = SimpleSmt::with_leaves(u64::BITS as u8, entries) + let tree = SimpleSmt::::with_leaves(entries) .map_err(|e| format!("failed to parse a Sparse Merkle Tree: {e}"))?; merkle_store.extend(tree.inner_nodes()); event!( From 6ae2f1ec311c6c39accc132f039ecf36919f92f2 Mon Sep 17 00:00:00 2001 From: Philippe Laferriere Date: Thu, 18 Jan 2024 16:05:44 -0500 Subject: [PATCH 4/4] fix miden-crypto branch --- core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Cargo.toml b/core/Cargo.toml index e7f14061c7..bfc51b3abf 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -23,7 +23,7 @@ std = ["miden-crypto/std", "math/std", "winter-utils/std"] [dependencies] math = { package = "winter-math", version = "0.7", default-features = false } # miden-crypto = { package = "miden-crypto", version = "0.8", default-features = false } -miden-crypto = { package = "miden-crypto", git = "https://github.com/0xPolygonMiden/crypto", branch= "plafer-smt-trait", default-features = false } +miden-crypto = { package = "miden-crypto", git = "https://github.com/0xPolygonMiden/crypto", branch = "next", default-features = false } winter-utils = { package = "winter-utils", version = "0.7", default-features = false } [dev-dependencies]