diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b39f3a..c1e09a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Skip unchanged leaves in the concurrent implementation of `Smt::compute_mutations` (#385). - Add range checks to `ntru_gen` for Falcon DSA (#391). - Optimized duplicate key detection in `Smt::with_entries_concurrent` (#395). +- [BREAKING] Moved `rand` to version `0.9` removing the `try_fill_bytes` method (#398). ## 0.13.3 (2025-02-18) diff --git a/Cargo.lock b/Cargo.lock index ce00182..11a55d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -97,21 +97,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "bit-set" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" - [[package]] name = "bitflags" version = "2.8.0" @@ -362,28 +347,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" -[[package]] -name = "errno" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "fastrand" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "foldhash" version = "0.1.4" @@ -407,10 +370,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi 0.11.0+wasi-snapshot-preview1", - "wasm-bindgen", ] [[package]] @@ -532,12 +493,6 @@ dependencies = [ "cpufeatures", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" version = "0.2.169" @@ -550,12 +505,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" -[[package]] -name = "linux-raw-sys" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" - [[package]] name = "log" version = "0.4.25" @@ -577,16 +526,16 @@ dependencies = [ "cc", "clap", "criterion", - "getrandom 0.2.15", + "getrandom 0.3.1", "glob", "hashbrown", "hex", "num", "num-complex", "proptest", - "rand", - "rand_chacha", - "rand_core", + "rand 0.9.0", + "rand_chacha 0.9.0", + "rand_core 0.9.3", "rayon", "seq-macro", "serde", @@ -718,7 +667,7 @@ version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" dependencies = [ - "zerocopy", + "zerocopy 0.7.35", ] [[package]] @@ -736,26 +685,14 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14cae93065090804185d3b75f0bf93b8eeda30c7a9b4a33d3bdb3988d6229e50" dependencies = [ - "bit-set", - "bit-vec", "bitflags", - "lazy_static", "num-traits", - "rand", - "rand_chacha", + "rand 0.8.5", + "rand_chacha 0.3.1", "rand_xorshift", - "regex-syntax", - "rusty-fork", - "tempfile", "unarray", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.38" @@ -772,8 +709,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", + "zerocopy 0.8.23", ] [[package]] @@ -783,7 +731,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", ] [[package]] @@ -795,13 +753,22 @@ dependencies = [ "getrandom 0.2.15", ] +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.1", +] + [[package]] name = "rand_xorshift" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -853,37 +820,12 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" -[[package]] -name = "rustix" -version = "0.38.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "rustversion" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" -[[package]] -name = "rusty-fork" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" -dependencies = [ - "fnv", - "quick-error", - "tempfile", - "wait-timeout", -] - [[package]] name = "ryu" version = "1.0.19" @@ -970,20 +912,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e5a0acb1f3f55f65cc4a866c361b2fb2a0ff6366785ae6fbb5f85df07ba230" -dependencies = [ - "cfg-if", - "fastrand", - "getrandom 0.3.1", - "once_cell", - "rustix", - "windows-sys", -] - [[package]] name = "thiserror" version = "2.0.11" @@ -1044,15 +972,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "wait-timeout" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11" -dependencies = [ - "libc", -] - [[package]] name = "walkdir" version = "2.5.0" @@ -1256,7 +1175,7 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc6321741f063344258c80f0c0255a559ded99bc17fe99fab9577f2460065ddf" dependencies = [ - "rand", + "rand 0.8.5", "winter-utils", ] @@ -1282,7 +1201,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "byteorder", - "zerocopy-derive", + "zerocopy-derive 0.7.35", +] + +[[package]] +name = "zerocopy" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd97444d05a4328b90e75e503a34bad781f14e28a823ad3557f0750df1ebcbc6" +dependencies = [ + "zerocopy-derive 0.8.23", ] [[package]] @@ -1295,3 +1223,14 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zerocopy-derive" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6352c01d0edd5db859a63e2605f4ea3183ddbd15e2c4a9e7d32184df75e4f154" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 7e1125f..c09185c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,7 @@ std = [ "blake3/std", "dep:cc", "rand/std", - "rand/std_rng", + "rand/thread_rng", "winter-crypto/std", "winter-math/std", "winter-utils/std", @@ -67,8 +67,8 @@ clap = { version = "4.5", optional = true, features = ["derive"] } hashbrown = { version = "0.15", optional = true, features = ["serde"] } num = { version = "0.4", default-features = false, features = ["alloc", "libm"] } num-complex = { version = "0.4", default-features = false } -rand = { version = "0.8", default-features = false } -rand_core = { version = "0.6", default-features = false } +rand = { version = "0.9", default-features = false } +rand_core = { version = "0.9", default-features = false } rand-utils = { version = "0.12", package = "winter-rand-utils", optional = true } rayon = { version = "1.10", optional = true } serde = { version = "1.0", default-features = false, optional = true, features = ["derive"] } @@ -81,10 +81,10 @@ winter-utils = { version = "0.12", default-features = false } [dev-dependencies] assert_matches = { version = "1.5", default-features = false } criterion = { version = "0.5", features = ["html_reports"] } -getrandom = { version = "0.2", features = ["js"] } +getrandom = { version = "0.3", default-features = false } hex = { version = "0.4", default-features = false, features = ["alloc"] } -proptest = "1.6" -rand_chacha = { version = "0.3", default-features = false } +proptest = { version = "1.6", default-features = false, features = ["alloc"]} +rand_chacha = { version = "0.9", default-features = false } rand-utils = { version = "0.12", package = "winter-rand-utils" } seq-macro = { version = "0.3" } diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..2e07606 --- /dev/null +++ b/config.toml @@ -0,0 +1,2 @@ +[target.wasm32-unknown-unknown] +rustflags = ['--cfg', 'getrandom_backend="wasm_js"'] diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 9029557..77f1d3d 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -10,7 +10,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.4" miden-crypto = { path = "..", features = ["concurrent"] } -rand = { version = "0.8", default-features = false } +rand = { version = "0.9", default-features = false } [[bin]] name = "smt" diff --git a/src/dsa/rpo_falcon512/keys/secret_key.rs b/src/dsa/rpo_falcon512/keys/secret_key.rs index 5204a3a..3cdf095 100644 --- a/src/dsa/rpo_falcon512/keys/secret_key.rs +++ b/src/dsa/rpo_falcon512/keys/secret_key.rs @@ -68,7 +68,7 @@ impl SecretKey { pub fn new() -> Self { use rand::{rngs::StdRng, SeedableRng}; - let mut rng = StdRng::from_entropy(); + let mut rng = StdRng::from_os_rng(); Self::with_rng(&mut rng) } @@ -117,7 +117,7 @@ impl SecretKey { pub fn sign(&self, message: Word) -> Signature { use rand::{rngs::StdRng, SeedableRng}; - let mut rng = StdRng::from_entropy(); + let mut rng = StdRng::from_os_rng(); self.sign_with_rng(message, &mut rng) } diff --git a/src/dsa/rpo_falcon512/math/samplerz.rs b/src/dsa/rpo_falcon512/math/samplerz.rs index c16c071..c047eb6 100644 --- a/src/dsa/rpo_falcon512/math/samplerz.rs +++ b/src/dsa/rpo_falcon512/math/samplerz.rs @@ -100,14 +100,14 @@ pub(crate) fn sampler_z(mu: f64, sigma: f64, sigma_min: f64, rng: &mut R let r = mu - s; let ccs = sigma_min * isigma; loop { - let z0 = base_sampler(rng.gen()); - let random_byte: u8 = rng.gen(); + let z0 = base_sampler(rng.random()); + let random_byte: u8 = rng.random(); let b = (random_byte & 1) as i16; let z = b + ((b << 1) - 1) * z0; let zf_min_r = (z as f64) - r; // x = ((z-r)^2)/(2*sigma^2) - ((z-b)^2)/(2*sigma0^2) let x = zf_min_r * zf_min_r * dss - (z0 * z0) as f64 * INV_2SIGMA_MAX_SQ; - if ber_exp(x, ccs, rng.gen()) { + if ber_exp(x, ccs, rng.random()) { return z + (s as i16); } } @@ -174,13 +174,6 @@ mod test { *d = self.next(); } } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> { - for d in dest.iter_mut() { - *d = self.next(); - } - Ok(()) - } } #[test] diff --git a/src/main.rs b/src/main.rs index 83daef6..85045cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use miden_crypto::{ merkle::{MerkleError, Smt}, Felt, Word, EMPTY_WORD, ONE, }; -use rand::{prelude::IteratorRandom, thread_rng, Rng}; +use rand::{prelude::IteratorRandom, rng, Rng}; use rand_utils::rand_value; #[derive(Parser, Debug)] @@ -141,7 +141,7 @@ pub fn batched_update( println!("Running a batched update benchmark:"); let size = tree.num_leaves(); - let mut rng = thread_rng(); + let mut rng = rng(); let new_pairs = entries @@ -149,10 +149,10 @@ pub fn batched_update( .choose_multiple(&mut rng, updates) .into_iter() .map(|(key, _)| { - let value = if rng.gen_bool(REMOVAL_PROBABILITY) { + let value = if rng.random_bool(REMOVAL_PROBABILITY) { EMPTY_WORD } else { - [ONE, ONE, ONE, Felt::new(rng.gen())] + [ONE, ONE, ONE, Felt::new(rng.random())] }; (key, value) diff --git a/src/merkle/smt/full/concurrent/tests.rs b/src/merkle/smt/full/concurrent/tests.rs index 5a05c44..97dd68b 100644 --- a/src/merkle/smt/full/concurrent/tests.rs +++ b/src/merkle/smt/full/concurrent/tests.rs @@ -5,7 +5,7 @@ use alloc::{ use assert_matches::assert_matches; use proptest::prelude::*; -use rand::{prelude::IteratorRandom, thread_rng, Rng}; +use rand::{prelude::IteratorRandom, rng, Rng}; use super::{ build_subtree, InnerNode, NodeIndex, NodeMutations, PairComputations, RpoDigest, Smt, SmtLeaf, @@ -114,7 +114,7 @@ fn generate_entries(pair_count: u64) -> Vec<(RpoDigest, Word)> { fn generate_updates(entries: Vec<(RpoDigest, Word)>, updates: usize) -> Vec<(RpoDigest, Word)> { const REMOVAL_PROBABILITY: f64 = 0.2; - let mut rng = thread_rng(); + let mut rng = rng(); // Assertion to ensure input keys are unique assert!( entries.iter().map(|(key, _)| key).collect::>().len() == entries.len(), @@ -125,10 +125,10 @@ fn generate_updates(entries: Vec<(RpoDigest, Word)>, updates: usize) -> Vec<(Rpo .choose_multiple(&mut rng, updates) .into_iter() .map(|(key, _)| { - let value = if rng.gen_bool(REMOVAL_PROBABILITY) { + let value = if rng.random_bool(REMOVAL_PROBABILITY) { EMPTY_WORD } else { - [ONE, ONE, ONE, Felt::new(rng.gen())] + [ONE, ONE, ONE, Felt::new(rng.random())] }; (key, value) }) @@ -381,11 +381,11 @@ fn test_multithreaded_subtrees() { fn test_with_entries_concurrent() { const PAIR_COUNT: u64 = COLS_PER_SUBTREE * 64; let mut entries = generate_entries(PAIR_COUNT); - let mut rng = rand::thread_rng(); + let mut rng = rand::rng(); // Set 10% of the entries to have empty words as their values. for _ in 0..PAIR_COUNT / 10 { - let random_index = rng.gen_range(0..PAIR_COUNT); + let random_index = rng.random_range(0..PAIR_COUNT); entries[random_index as usize].1 = EMPTY_WORD; } diff --git a/src/rand/rpo.rs b/src/rand/rpo.rs index 2669592..8658cbb 100644 --- a/src/rand/rpo.rs +++ b/src/rand/rpo.rs @@ -208,11 +208,6 @@ impl RngCore for RpoRandomCoin { fn fill_bytes(&mut self, dest: &mut [u8]) { impls::fill_bytes_via_next(self, dest) } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> { - self.fill_bytes(dest); - Ok(()) - } } // SERIALIZATION diff --git a/src/rand/rpx.rs b/src/rand/rpx.rs index 2f91b0c..2661fa9 100644 --- a/src/rand/rpx.rs +++ b/src/rand/rpx.rs @@ -206,11 +206,6 @@ impl RngCore for RpxRandomCoin { fn fill_bytes(&mut self, dest: &mut [u8]) { impls::fill_bytes_via_next(self, dest) } - - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> { - self.fill_bytes(dest); - Ok(()) - } } // SERIALIZATION