From 35867737137db6fab7d8d1bb18fc50060df22a8b Mon Sep 17 00:00:00 2001 From: curiecrypt Date: Wed, 22 Feb 2023 16:15:35 +0300 Subject: [PATCH 1/5] first trial --- Cargo.lock | 176 +++++++++++++++++++++++++++++---- mithril-stm/Cargo.toml | 1 + mithril-stm/src/merkle_tree.rs | 17 ++++ 3 files changed, 176 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 916ce3b3438..f7544586380 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,7 +134,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" dependencies = [ "async-lock", - "autocfg", + "autocfg 1.1.0", "concurrent-queue", "futures-lite", "libc", @@ -174,7 +174,7 @@ checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" dependencies = [ "async-io", "async-lock", - "autocfg", + "autocfg 1.1.0", "blocking", "cfg-if", "event-listener", @@ -245,6 +245,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "autocfg" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" +dependencies = [ + "autocfg 1.1.0", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -598,6 +607,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -735,7 +753,7 @@ version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" dependencies = [ - "autocfg", + "autocfg 1.1.0", "cfg-if", "crossbeam-utils", "memoffset", @@ -1212,6 +1230,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + [[package]] name = "futures" version = "0.3.26" @@ -1636,7 +1660,7 @@ version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ - "autocfg", + "autocfg 1.1.0", "hashbrown", "serde", ] @@ -1920,7 +1944,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ - "autocfg", + "autocfg 1.1.0", "scopeguard", ] @@ -1952,7 +1976,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ - "autocfg", + "autocfg 1.1.0", ] [[package]] @@ -2163,6 +2187,7 @@ dependencies = [ "num-rational", "num-traits", "proptest", + "rand 0.6.5", "rand_chacha 0.3.1", "rand_core 0.6.4", "rayon", @@ -2293,7 +2318,7 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-integer", "num-traits", ] @@ -2304,7 +2329,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-integer", "num-traits", ] @@ -2330,7 +2355,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-traits", ] @@ -2340,7 +2365,7 @@ version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-integer", "num-traits", ] @@ -2351,7 +2376,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ - "autocfg", + "autocfg 1.1.0", "num-bigint 0.4.3", "num-integer", "num-traits", @@ -2363,7 +2388,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg", + "autocfg 1.1.0", "libm", ] @@ -2442,7 +2467,7 @@ version = "0.9.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" dependencies = [ - "autocfg", + "autocfg 1.1.0", "cc", "libc", "pkg-config", @@ -2658,7 +2683,7 @@ version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22122d5ec4f9fe1b3916419b76be1e80bcb93f618d071d2edf841b137b2a2bd6" dependencies = [ - "autocfg", + "autocfg 1.1.0", "cfg-if", "libc", "log", @@ -2755,7 +2780,7 @@ dependencies = [ "quick-error 2.0.1", "rand 0.8.5", "rand_chacha 0.3.1", - "rand_xorshift", + "rand_xorshift 0.3.0", "regex-syntax", "rusty-fork", "tempfile", @@ -2783,6 +2808,25 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.8", + "libc", + "rand_chacha 0.1.1", + "rand_core 0.4.2", + "rand_hc 0.1.0", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift 0.1.1", + "winapi", +] + [[package]] name = "rand" version = "0.7.3" @@ -2793,7 +2837,7 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc", + "rand_hc 0.2.0", ] [[package]] @@ -2807,6 +2851,16 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.3.1", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -2827,6 +2881,21 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + [[package]] name = "rand_core" version = "0.5.1" @@ -2845,6 +2914,15 @@ dependencies = [ "getrandom 0.2.8", ] +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rand_hc" version = "0.2.0" @@ -2854,6 +2932,59 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.8", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "rand_xorshift" version = "0.3.0" @@ -2885,6 +3016,15 @@ dependencies = [ "num_cpus", ] +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -3339,7 +3479,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ - "autocfg", + "autocfg 1.1.0", ] [[package]] @@ -3719,7 +3859,7 @@ version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ - "autocfg", + "autocfg 1.1.0", "bytes", "libc", "memchr", diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index dbc2e48508f..a52f0b6cb49 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -31,6 +31,7 @@ rayon = "1.5.1" rug = { version = "1.14", optional = true } serde = { version = "1", features = ["rc", "derive"] } thiserror = "1.0" +rand = "0.6.1" [dev-dependencies] bincode = "1.3.3" diff --git a/mithril-stm/src/merkle_tree.rs b/mithril-stm/src/merkle_tree.rs index 14e05502e68..4f096e88cc0 100644 --- a/mithril-stm/src/merkle_tree.rs +++ b/mithril-stm/src/merkle_tree.rs @@ -627,6 +627,7 @@ mod tests { use blake2::{digest::consts::U32, Blake2b}; use proptest::collection::vec; use proptest::prelude::*; + use rand::{seq::IteratorRandom, thread_rng}; prop_compose! { fn arb_tree(max_size: u32) @@ -778,4 +779,20 @@ mod tests { assert!(t.to_commitment_batch_compat().check(&batch_values, &path).is_err()); } } + + // prop_compose! { + // fn arb_tree_arb_index_list(max_size: u32) + // (v in vec(any::(), 2..max_size as usize)) -> (MerkleTree>, Vec, Vec<&'static usize>) { + // let mut rng = thread_rng(); + // let size = v.len(); + // let pks = vec![VerificationKey::default(); size]; + // let leaves = pks.into_iter().zip(v.into_iter()).map(|(key, stake)| MTLeaf(key, stake)).collect::>(); + // let mut indices :Vec = Vec::with_capacity(size); + // for (i, _v) in leaves.iter().enumerate() { + // indices.push(i); + // } + // let mt_index_list: Vec<&usize> = indices.iter().choose_multiple(&mut rng, (size/10)*7); + // (MerkleTree::>::create(&leaves), leaves, mt_index_list) + // } + // } } From 4a817208c51b63fdf182922421908615fffdd9f1 Mon Sep 17 00:00:00 2001 From: curiecrypt Date: Thu, 23 Feb 2023 01:29:26 +0300 Subject: [PATCH 2/5] prop compose for batch test --- mithril-stm/src/merkle_tree.rs | 97 +++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/mithril-stm/src/merkle_tree.rs b/mithril-stm/src/merkle_tree.rs index 4f096e88cc0..db4d35087f8 100644 --- a/mithril-stm/src/merkle_tree.rs +++ b/mithril-stm/src/merkle_tree.rs @@ -684,16 +684,16 @@ mod tests { assert_eq!(tree.nodes, decoded.nodes); } - #[test] - fn test_create_batch_proof((t, values) in arb_tree(30)) { - let mut mt_index_list :Vec = Vec::new(); - for (i, _v) in values.iter().enumerate() { - mt_index_list.push(i); - } - mt_index_list.sort_unstable(); - let batch_proof = t.get_batched_path(mt_index_list); - assert!(t.to_commitment_batch_compat().check(&values, &batch_proof).is_ok()); - } + // #[test] + // fn test_create_batch_proof((t, values) in arb_tree(30)) { + // let mut mt_index_list :Vec = Vec::new(); + // for (i, _v) in values.iter().enumerate() { + // mt_index_list.push(i); + // } + // mt_index_list.sort_unstable(); + // let batch_proof = t.get_batched_path(mt_index_list); + // assert!(t.to_commitment_batch_compat().check(&values, &batch_proof).is_ok()); + // } #[test] fn test_bytes_batch_path((t, values) in arb_tree(30)) { @@ -780,19 +780,66 @@ mod tests { } } - // prop_compose! { - // fn arb_tree_arb_index_list(max_size: u32) - // (v in vec(any::(), 2..max_size as usize)) -> (MerkleTree>, Vec, Vec<&'static usize>) { - // let mut rng = thread_rng(); - // let size = v.len(); - // let pks = vec![VerificationKey::default(); size]; - // let leaves = pks.into_iter().zip(v.into_iter()).map(|(key, stake)| MTLeaf(key, stake)).collect::>(); - // let mut indices :Vec = Vec::with_capacity(size); - // for (i, _v) in leaves.iter().enumerate() { - // indices.push(i); - // } - // let mt_index_list: Vec<&usize> = indices.iter().choose_multiple(&mut rng, (size/10)*7); - // (MerkleTree::>::create(&leaves), leaves, mt_index_list) - // } - // } + prop_compose! { + fn arb_tree_arb_index_list(max_size: u32) + (v in vec(any::(), 2..max_size as usize)) -> (MerkleTree>, Vec, Vec) { + let mut rng = thread_rng(); + let size = v.len(); + let pks = vec![VerificationKey::default(); size]; + let leaves = pks.into_iter().zip(v.into_iter()).map(|(key, stake)| MTLeaf(key, stake)).collect::>(); + let mut indices :Vec = Vec::with_capacity(size); + for (i, _v) in leaves.iter().enumerate() { + indices.push(i); + } + indices.iter().choose_multiple(&mut rng, size / 10 * 7); + (MerkleTree::>::create(&leaves), leaves, indices) + } + } + + proptest! { + // Test the relation that t.get_path(i) is a valid + // proof for i + #![proptest_config(ProptestConfig::with_cases(100))] + #[test] + fn test_create_batch_proof((t, values, indices) in arb_tree_arb_index_list(60)) { + + indices.clone().sort_unstable(); + print!("Indices: {}\n", indices.len()); + let batch_proof = t.get_batched_path(indices); + print!("Path: {}\n", batch_proof.values.len()); + print!("tree: {}\n", t.nodes.len()); + + assert!(t.to_commitment_batch_compat().check(&values, &batch_proof).is_ok()); + } + + // #[test] + // fn test_bytes_batch_path((t, values) in arb_tree(30)) { + // let mut mt_index_list :Vec = Vec::new(); + // for (i, _v) in values.iter().enumerate() { + // mt_index_list.push(i); + // } + // mt_index_list.sort_unstable(); + // + // let bp = t.get_batched_path(mt_index_list); + // + // let bytes = &bp.to_bytes(); + // let deserialized = BatchPath::from_bytes(bytes).unwrap(); + // assert!(t.to_commitment_batch_compat().check(&values, &deserialized).is_ok()); + // + // let encoded = bincode::serialize(&bp).unwrap(); + // let decoded: BatchPath> = bincode::deserialize(&encoded).unwrap(); + // assert!(t.to_commitment_batch_compat().check(&values, &decoded).is_ok()); + // } + // + // #[test] + // fn test_bytes_tree_commitment_batch_compat((t, values) in arb_tree(5)) { + // let encoded = bincode::serialize(&t.to_commitment_batch_compat()).unwrap(); + // let decoded: MerkleTreeCommitmentBatchCompat::> = bincode::deserialize(&encoded).unwrap(); + // let tree_commitment = MerkleTree::>::create(&values).to_commitment_batch_compat(); + // assert_eq!(tree_commitment.root, decoded.root); + // assert_eq!(tree_commitment.nr_leaves, decoded.nr_leaves); + // + // } + + } } From ae276effae39b7c05e680d7d57cba29c9257efac Mon Sep 17 00:00:00 2001 From: curiecrypt Date: Fri, 24 Feb 2023 01:06:16 +0300 Subject: [PATCH 3/5] batch proof tests corrected --- mithril-stm/src/merkle_tree.rs | 102 +++++++++------------------------ 1 file changed, 26 insertions(+), 76 deletions(-) diff --git a/mithril-stm/src/merkle_tree.rs b/mithril-stm/src/merkle_tree.rs index db4d35087f8..626dca9e933 100644 --- a/mithril-stm/src/merkle_tree.rs +++ b/mithril-stm/src/merkle_tree.rs @@ -684,36 +684,6 @@ mod tests { assert_eq!(tree.nodes, decoded.nodes); } - // #[test] - // fn test_create_batch_proof((t, values) in arb_tree(30)) { - // let mut mt_index_list :Vec = Vec::new(); - // for (i, _v) in values.iter().enumerate() { - // mt_index_list.push(i); - // } - // mt_index_list.sort_unstable(); - // let batch_proof = t.get_batched_path(mt_index_list); - // assert!(t.to_commitment_batch_compat().check(&values, &batch_proof).is_ok()); - // } - - #[test] - fn test_bytes_batch_path((t, values) in arb_tree(30)) { - let mut mt_index_list :Vec = Vec::new(); - for (i, _v) in values.iter().enumerate() { - mt_index_list.push(i); - } - mt_index_list.sort_unstable(); - - let bp = t.get_batched_path(mt_index_list); - - let bytes = &bp.to_bytes(); - let deserialized = BatchPath::from_bytes(bytes).unwrap(); - assert!(t.to_commitment_batch_compat().check(&values, &deserialized).is_ok()); - - let encoded = bincode::serialize(&bp).unwrap(); - let decoded: BatchPath> = bincode::deserialize(&encoded).unwrap(); - assert!(t.to_commitment_batch_compat().check(&values, &decoded).is_ok()); - } - #[test] fn test_bytes_tree_commitment_batch_compat((t, values) in arb_tree(5)) { let encoded = bincode::serialize(&t.to_commitment_batch_compat()).unwrap(); @@ -781,65 +751,45 @@ mod tests { } prop_compose! { - fn arb_tree_arb_index_list(max_size: u32) + fn arb_tree_arb_batch(max_size: u32) (v in vec(any::(), 2..max_size as usize)) -> (MerkleTree>, Vec, Vec) { let mut rng = thread_rng(); let size = v.len(); let pks = vec![VerificationKey::default(); size]; let leaves = pks.into_iter().zip(v.into_iter()).map(|(key, stake)| MTLeaf(key, stake)).collect::>(); - let mut indices :Vec = Vec::with_capacity(size); - for (i, _v) in leaves.iter().enumerate() { - indices.push(i); + + let indices: Vec = (0..size).collect(); + let mut mt_list: Vec = indices.into_iter().choose_multiple(&mut rng, size * 2 / 10 + 1); + mt_list.sort_unstable(); + + let mut batch_values: Vec = Vec::with_capacity(mt_list.len()); + for i in mt_list.iter() { + batch_values.push(leaves[*i]); } - indices.iter().choose_multiple(&mut rng, size / 10 * 7); - (MerkleTree::>::create(&leaves), leaves, indices) + + (MerkleTree::>::create(&leaves), batch_values, mt_list) } } proptest! { - // Test the relation that t.get_path(i) is a valid - // proof for i #![proptest_config(ProptestConfig::with_cases(100))] #[test] - fn test_create_batch_proof((t, values, indices) in arb_tree_arb_index_list(60)) { - - indices.clone().sort_unstable(); - print!("Indices: {}\n", indices.len()); + fn test_create_batch_proof((t, batch_values, indices) in arb_tree_arb_batch(30)) { let batch_proof = t.get_batched_path(indices); - print!("Path: {}\n", batch_proof.values.len()); - print!("tree: {}\n", t.nodes.len()); - - assert!(t.to_commitment_batch_compat().check(&values, &batch_proof).is_ok()); - } - - // #[test] - // fn test_bytes_batch_path((t, values) in arb_tree(30)) { - // let mut mt_index_list :Vec = Vec::new(); - // for (i, _v) in values.iter().enumerate() { - // mt_index_list.push(i); - // } - // mt_index_list.sort_unstable(); - // - // let bp = t.get_batched_path(mt_index_list); - // - // let bytes = &bp.to_bytes(); - // let deserialized = BatchPath::from_bytes(bytes).unwrap(); - // assert!(t.to_commitment_batch_compat().check(&values, &deserialized).is_ok()); - // - // let encoded = bincode::serialize(&bp).unwrap(); - // let decoded: BatchPath> = bincode::deserialize(&encoded).unwrap(); - // assert!(t.to_commitment_batch_compat().check(&values, &decoded).is_ok()); - // } - // - // #[test] - // fn test_bytes_tree_commitment_batch_compat((t, values) in arb_tree(5)) { - // let encoded = bincode::serialize(&t.to_commitment_batch_compat()).unwrap(); - // let decoded: MerkleTreeCommitmentBatchCompat::> = bincode::deserialize(&encoded).unwrap(); - // let tree_commitment = MerkleTree::>::create(&values).to_commitment_batch_compat(); - // assert_eq!(tree_commitment.root, decoded.root); - // assert_eq!(tree_commitment.nr_leaves, decoded.nr_leaves); - // - // } + assert!(t.to_commitment_batch_compat().check(&batch_values, &batch_proof).is_ok()); + } + + #[test] + fn test_bytes_batch_path((t, batch_values, indices) in arb_tree_arb_batch(30)) { + let bp = t.get_batched_path(indices); + let bytes = &bp.to_bytes(); + let deserialized = BatchPath::from_bytes(bytes).unwrap(); + assert!(t.to_commitment_batch_compat().check(&batch_values, &deserialized).is_ok()); + + let encoded = bincode::serialize(&bp).unwrap(); + let decoded: BatchPath> = bincode::deserialize(&encoded).unwrap(); + assert!(t.to_commitment_batch_compat().check(&batch_values, &decoded).is_ok()); + } } } From 9fe31ea670b245c138eb45c3ea1e1e6588d9f863 Mon Sep 17 00:00:00 2001 From: iquerejeta Date: Mon, 27 Feb 2023 11:41:47 +0100 Subject: [PATCH 4/5] cargo sort for stm dependencies --- mithril-stm/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index a52f0b6cb49..e070f640493 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -26,12 +26,12 @@ digest = { version = "0.10.5", features = ["alloc"] } num-bigint = { version = "0.4.0", optional = true } num-rational = { version = "0.4.0", optional = true } num-traits = { version = "0.2.14", optional = true } +rand = "0.6.1" rand_core = "0.6.3" rayon = "1.5.1" rug = { version = "1.14", optional = true } serde = { version = "1", features = ["rc", "derive"] } thiserror = "1.0" -rand = "0.6.1" [dev-dependencies] bincode = "1.3.3" From 77299d0be1c587ebc01123aa8c3467dead89d608 Mon Sep 17 00:00:00 2001 From: iquerejeta Date: Mon, 27 Feb 2023 12:14:06 +0100 Subject: [PATCH 5/5] Use latest version of rand --- Cargo.lock | 177 +++++------------------------------------ mithril-stm/Cargo.toml | 2 +- 2 files changed, 20 insertions(+), 159 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7544586380..1c39d45a578 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,7 +134,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" dependencies = [ "async-lock", - "autocfg 1.1.0", + "autocfg", "concurrent-queue", "futures-lite", "libc", @@ -174,7 +174,7 @@ checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" dependencies = [ "async-io", "async-lock", - "autocfg 1.1.0", + "autocfg", "blocking", "cfg-if", "event-listener", @@ -245,15 +245,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "autocfg" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dde43e75fd43e8a1bf86103336bc699aa8d17ad1be60c76c0bdfd4828e19b78" -dependencies = [ - "autocfg 1.1.0", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -607,15 +598,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "codespan-reporting" version = "0.11.1" @@ -753,7 +735,7 @@ version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cfg-if", "crossbeam-utils", "memoffset", @@ -1230,12 +1212,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "futures" version = "0.3.26" @@ -1660,7 +1636,7 @@ version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ - "autocfg 1.1.0", + "autocfg", "hashbrown", "serde", ] @@ -1944,7 +1920,7 @@ version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ - "autocfg 1.1.0", + "autocfg", "scopeguard", ] @@ -1976,7 +1952,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -2187,7 +2163,7 @@ dependencies = [ "num-rational", "num-traits", "proptest", - "rand 0.6.5", + "rand 0.8.5", "rand_chacha 0.3.1", "rand_core 0.6.4", "rayon", @@ -2318,7 +2294,7 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] @@ -2329,7 +2305,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] @@ -2355,7 +2331,7 @@ version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-traits", ] @@ -2365,7 +2341,7 @@ version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-integer", "num-traits", ] @@ -2376,7 +2352,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ - "autocfg 1.1.0", + "autocfg", "num-bigint 0.4.3", "num-integer", "num-traits", @@ -2388,7 +2364,7 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ - "autocfg 1.1.0", + "autocfg", "libm", ] @@ -2467,7 +2443,7 @@ version = "0.9.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cc", "libc", "pkg-config", @@ -2683,7 +2659,7 @@ version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22122d5ec4f9fe1b3916419b76be1e80bcb93f618d071d2edf841b137b2a2bd6" dependencies = [ - "autocfg 1.1.0", + "autocfg", "cfg-if", "libc", "log", @@ -2780,7 +2756,7 @@ dependencies = [ "quick-error 2.0.1", "rand 0.8.5", "rand_chacha 0.3.1", - "rand_xorshift 0.3.0", + "rand_xorshift", "regex-syntax", "rusty-fork", "tempfile", @@ -2808,25 +2784,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.8", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_os", - "rand_pcg", - "rand_xorshift 0.1.1", - "winapi", -] - [[package]] name = "rand" version = "0.7.3" @@ -2837,7 +2794,7 @@ dependencies = [ "libc", "rand_chacha 0.2.2", "rand_core 0.5.1", - "rand_hc 0.2.0", + "rand_hc", ] [[package]] @@ -2851,16 +2808,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.3.1", -] - [[package]] name = "rand_chacha" version = "0.2.2" @@ -2881,21 +2828,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -2914,15 +2846,6 @@ dependencies = [ "getrandom 0.2.8", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" @@ -2932,59 +2855,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi", -] - -[[package]] -name = "rand_os" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.4.2", - "rdrand", - "winapi", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.8", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_xorshift" version = "0.3.0" @@ -3016,15 +2886,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "redox_syscall" version = "0.2.16" @@ -3479,7 +3340,7 @@ version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ - "autocfg 1.1.0", + "autocfg", ] [[package]] @@ -3859,7 +3720,7 @@ version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ - "autocfg 1.1.0", + "autocfg", "bytes", "libc", "memchr", diff --git a/mithril-stm/Cargo.toml b/mithril-stm/Cargo.toml index e070f640493..3d05d214969 100644 --- a/mithril-stm/Cargo.toml +++ b/mithril-stm/Cargo.toml @@ -26,7 +26,6 @@ digest = { version = "0.10.5", features = ["alloc"] } num-bigint = { version = "0.4.0", optional = true } num-rational = { version = "0.4.0", optional = true } num-traits = { version = "0.2.14", optional = true } -rand = "0.6.1" rand_core = "0.6.3" rayon = "1.5.1" rug = { version = "1.14", optional = true } @@ -40,6 +39,7 @@ hex = "0.4.3" num-bigint = "0.4.0" num-rational = "0.4.0" proptest = "1.0.0" +rand = "0.8" rand_chacha = "0.3.1" [[bench]]