Skip to content

Commit e1694dc

Browse files
committed
chore: update snarkVM rev and rand
Many tests needed to be updated to confirm to the new `rand` API.
1 parent ccc9270 commit e1694dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+887
-626
lines changed

Cargo.lock

Lines changed: 448 additions & 346 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ default-features = false
4747

4848
[workspace.dependencies.snarkvm]
4949
#path = "../snarkVM"
50-
#git = "https://github.com/ProvableHQ/snarkVM.git"
51-
#rev = "2a5e6e2"
52-
version = "=4.6.0"
50+
git = "https://github.com/ProvableHQ/snarkVM.git"
51+
branch = "fix/prop-tests"
52+
#rev = "f7abfceee0"
53+
#version = "=4.6.0"
5354
default-features = false
5455

5556
[workspace.dependencies.anyhow]
@@ -107,7 +108,7 @@ version = "1"
107108
version = "1"
108109

109110
[workspace.dependencies.proptest]
110-
version = "=1.6.0" # Remove this once we upgrade to rand 0.9
111+
version = "1.11"
111112

112113
[workspace.dependencies.rayon]
113114
version = "1"
@@ -145,15 +146,15 @@ version = "1"
145146
version = "0.12"
146147

147148
[workspace.dependencies.rand]
148-
version = "0.8"
149+
version = "0.10"
149150
default-features = false
150151

151152
[workspace.dependencies.rand_chacha]
152-
version = "0.3"
153+
version = "0.10"
153154
default-features = false
154155

155156
[workspace.dependencies.rand_distr]
156-
version = "0.4"
157+
version = "0.6"
157158

158159
[workspace.dependencies.smol_str]
159160
version = "=0.3.2" # Update after Rust >1.88

account/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ mod tests {
187187
let account = Account::<CurrentNetwork>::new(&mut rng).unwrap();
188188

189189
// TODO(kaimast): remove once we upgrade the rand crate
190-
let message = (0..10).map(|_| rng.r#gen::<u8>()).collect::<Vec<u8>>();
190+
let message = (0..10).map(|_| rng.random::<u8>()).collect::<Vec<u8>>();
191191
// Sign and verify.
192192
let signature = account.sign_bytes(&message, &mut rng).unwrap();
193193
assert!(account.verify_bytes(&message, &signature));
@@ -199,7 +199,7 @@ mod tests {
199199
let mut rng = TestRng::default();
200200
// Prepare the account and message.
201201
let account = Account::<CurrentNetwork>::new(&mut rng).unwrap();
202-
let message = (0..10).map(|_| rng.r#gen::<bool>()).collect::<Vec<bool>>();
202+
let message = (0..10).map(|_| rng.random::<bool>()).collect::<Vec<bool>>();
203203
// Sign and verify.
204204
let signature = account.sign_bits(&message, &mut rng).unwrap();
205205
assert!(account.verify_bits(&message, &signature));

cli/src/commands/account.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl Account {
156156
/// Generates a new Aleo account with the given vanity string.
157157
fn new_vanity<N: Network>(vanity: &str, discreet: bool) -> Result<String> {
158158
// A closure to generate a new Aleo account.
159-
let sample_account = || snarkos_account::Account::<N>::new(&mut rand::thread_rng());
159+
let sample_account = || snarkos_account::Account::<N>::new(&mut rand::rng());
160160

161161
const ITERATIONS: u128 = u16::MAX as u128;
162162
const ITERATIONS_STR: &str = "65,535";
@@ -235,7 +235,7 @@ impl Account {
235235
Field::new(<N as Environment>::Field::from_str(&seed).map_err(|e| anyhow!("Invalid seed - {e}"))?)
236236
}
237237
// Sample a random field element.
238-
None => Field::rand(&mut ChaChaRng::from_entropy()),
238+
None => Field::rand(&mut ChaChaRng::from_rng(&mut rand::rng())),
239239
};
240240
// Recover the private key from the seed as a field element.
241241
let private_key =

cli/src/commands/account/sign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Sign {
6262
// Sign a message with an Aleo private key
6363
fn sign<N: Network>(self) -> Result<String> {
6464
// Sample a random field element.
65-
let mut rng = ChaChaRng::from_entropy();
65+
let mut rng = ChaChaRng::from_rng(&mut rand::rng());
6666

6767
// Parse the private key
6868
let private_key = parse_private_key(self.private_key.clone(), self.private_key_file.clone(), self.dev_key)?;

cli/src/commands/developer/decrypt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mod tests {
7878
};
7979

8080
use indexmap::IndexMap;
81-
use rand::Rng;
81+
use rand::RngExt;
8282

8383
type CurrentNetwork = MainnetV0;
8484

@@ -91,7 +91,7 @@ mod tests {
9191
) -> Result<Record<N, Ciphertext<N>>> {
9292
// Prepare the record.
9393
let randomizer = Scalar::rand(rng);
94-
let version = match rng.r#gen() {
94+
let version = match rng.random() {
9595
true => U8::<N>::one(),
9696
false => U8::<N>::zero(),
9797
};

cli/src/commands/developer/deploy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl Deploy {
175175
// Generate the deployment transaction.
176176
let transaction = {
177177
// Initialize an RNG.
178-
let rng = &mut rand::thread_rng();
178+
let rng = &mut rand::rng();
179179

180180
// Initialize the storage.
181181
let store = ConsensusStore::<N, ConsensusMemory<N>>::open(StorageMode::Production)

cli/src/commands/developer/execute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl Execute {
148148
// Generate the execution transaction.
149149
let transaction = {
150150
// Initialize an RNG.
151-
let rng = &mut rand::thread_rng();
151+
let rng = &mut rand::rng();
152152

153153
// Initialize the storage.
154154
let store = ConsensusStore::<N, ConsensusMemory<N>>::open(StorageMode::Production)?;

cli/src/commands/developer/transfer_private.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl TransferPrivate {
117117
// Generate the transfer_private transaction.
118118
let transaction = {
119119
// Initialize an RNG.
120-
let rng = &mut rand::thread_rng();
120+
let rng = &mut rand::rng();
121121

122122
// Initialize the storage.
123123
let store = ConsensusStore::<N, ConsensusMemory<N>>::open(StorageMode::Production)?;

cli/src/commands/start.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use clap::Parser;
5252
use colored::Colorize;
5353
use core::str::FromStr;
5454
use indexmap::IndexMap;
55-
use rand::{Rng, SeedableRng};
55+
use rand::{RngExt, SeedableRng};
5656
use rand_chacha::ChaChaRng;
5757
use serde::{Deserialize, Serialize};
5858

@@ -401,7 +401,7 @@ impl Start {
401401
}
402402
// Ensure the private key is provided to the CLI, except for clients or nodes in development mode.
403403
(None, None) => match self.client {
404-
true => Account::new(&mut rand::thread_rng()),
404+
true => Account::new(&mut rand::rng()),
405405
false => bail!("Missing the '--private-key' or '--private-key-file' argument"),
406406
},
407407
// Ensure only one private key flag is provided to the CLI.
@@ -575,7 +575,7 @@ impl Start {
575575
members.entry(*validator_address).and_modify(|(stake, _, _)| *stake += amount).or_insert((
576576
*amount,
577577
true,
578-
rng.gen_range(0..100),
578+
rng.random_range(0..100),
579579
));
580580
}
581581
// Construct the committee.
@@ -591,7 +591,7 @@ impl Start {
591591
// Construct the committee members and distribute stakes evenly among committee members.
592592
let members = development_addresses
593593
.iter()
594-
.map(|address| (*address, (stake_per_member, true, rng.gen_range(0..100))))
594+
.map(|address| (*address, (stake_per_member, true, rng.random_range(0..100))))
595595
.collect::<IndexMap<_, _>>();
596596

597597
// Construct the bonded balances.

0 commit comments

Comments
 (0)