Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bytemuck = { version = "1.14.3", default-features = false }
tracing = { version = "0.1.40", default-features = false }
tracing-subscriber = { version = "0.3.18", default-features = false }
rayon = { version = "1.10.0", optional = false }
rand = { version = "0.8.5", default-features = false, features = ["small_rng"] }
rand = { version = "0.9.2", default-features = false, features = ["small_rng"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
hashbrown = ">=0.15.2"
std-shims = { path = "crates/std-shims", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions crates/constraint-framework/src/expr/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ mod tests {

let mut rng = SmallRng::seed_from_u64(0);
let columns: HashMap<(usize, usize, isize), BaseField> =
HashMap::from([((1, 0, 0), rng.gen()), ((1, 1, 0), rng.gen())]);
let vars: HashMap<String, BaseField> = HashMap::from([("a".to_string(), rng.gen())]);
let ext_vars: HashMap<String, SecureField> = HashMap::from([("b".to_string(), rng.gen())]);
HashMap::from([((1, 0, 0), rng.random()), ((1, 1, 0), rng.random())]);
let vars: HashMap<String, BaseField> = HashMap::from([("a".to_string(), rng.random())]);
let ext_vars: HashMap<String, SecureField> = HashMap::from([("b".to_string(), rng.random())]);

let base_expr = (((zero.clone() + c0.clone()) + (a.clone() + zero.clone()))
* ((-c1.clone()) + (-c0.clone()))
Expand Down
22 changes: 11 additions & 11 deletions crates/examples/src/xor/gkr_lookups/mle_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,9 @@ mod tests {
let mut rng = SmallRng::seed_from_u64(0);
let log_size = N_VARIABLES as u32;
let size = 1 << log_size;
let mle_coeffs = (0..size).map(|_| rng.gen::<SecureField>()).collect();
let mle_coeffs = (0..size).map(|_| rng.random::<SecureField>()).collect();
let mle = Mle::<SimdBackend, SecureField>::new(mle_coeffs);
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.gen());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.random());
let claim = mle_eval_at_point(&mle, &eval_point);
// Setup protocol.
let twiddles = SimdBackend::precompute_twiddles(
Expand Down Expand Up @@ -858,9 +858,9 @@ mod tests {
let mut rng = SmallRng::seed_from_u64(0);
let log_size = N_VARIABLES as u32;
let size = 1 << log_size;
let mle_coeffs = (0..size).map(|_| rng.gen::<SecureField>()).collect();
let mle_coeffs = (0..size).map(|_| rng.random::<SecureField>()).collect();
let mle = Mle::<SimdBackend, SecureField>::new(mle_coeffs);
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.gen());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.random());
let claim = mle_eval_at_point(&mle, &eval_point);
// Setup protocol.
let twiddles = SimdBackend::precompute_twiddles(
Expand Down Expand Up @@ -947,9 +947,9 @@ mod tests {
let mut rng = SmallRng::seed_from_u64(0);
let log_size = N_VARIABLES as u32;
let size = 1 << log_size;
let mle_coeffs = (0..size).map(|_| rng.gen::<SecureField>()).collect();
let mle_coeffs = (0..size).map(|_| rng.random::<SecureField>()).collect();
let mle = Mle::<SimdBackend, SecureField>::new(mle_coeffs);
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.gen());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.random());
let claim = mle_eval_at_point(&mle, &eval_point);
let mle_eval_point = MleEvalPoint::new(&eval_point);
let mle_eval_trace = build_trace(&mle, &eval_point, claim);
Expand Down Expand Up @@ -994,7 +994,7 @@ mod tests {
const AUX_TRACE: usize = 1;
let mut rng = SmallRng::seed_from_u64(0);
let mle = Mle::new(repeat_n(SecureField::one(), 1 << N_VARIABLES).collect());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.gen());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.random());
let mle_eval_point = MleEvalPoint::new(&eval_point);
let trace = build_trace(&mle, &eval_point, mle_eval_at_point(&mle, &eval_point));
let carry_quotients_col = gen_carry_quotient_col(&eval_point).into_coordinate_evals();
Expand Down Expand Up @@ -1031,7 +1031,7 @@ mod tests {
const AUX_TRACE: usize = 1;
let mut rng = SmallRng::seed_from_u64(0);
let mle = Mle::new(repeat_n(SecureField::one(), 1 << N_VARIABLES).collect());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.gen());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.random());
let mle_eval_point = MleEvalPoint::new(&eval_point);
let trace = build_trace(&mle, &eval_point, mle_eval_at_point(&mle, &eval_point));
let carry_quotients_col = gen_carry_quotient_col(&eval_point).into_coordinate_evals();
Expand Down Expand Up @@ -1068,7 +1068,7 @@ mod tests {
const AUX_TRACE: usize = 1;
let mut rng = SmallRng::seed_from_u64(0);
let mle = Mle::new(repeat_n(SecureField::one(), 1 << N_VARIABLES).collect());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.gen());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.random());
let mle_eval_point = MleEvalPoint::new(&eval_point);
let trace = build_trace(&mle, &eval_point, mle_eval_at_point(&mle, &eval_point));
let carry_quotients_col = gen_carry_quotient_col(&eval_point).into_coordinate_evals();
Expand Down Expand Up @@ -1102,7 +1102,7 @@ mod tests {
fn inclusive_prefix_sum_constraints_with_log_size_5() {
const LOG_SIZE: u32 = 5;
let mut rng = SmallRng::seed_from_u64(0);
let vals = (0..1 << LOG_SIZE).map(|_| rng.gen()).collect_vec();
let vals = (0..1 << LOG_SIZE).map(|_| rng.random()).collect_vec();
let cumulative_sum = vals.iter().sum::<SecureField>();
let cumulative_sum_shift = cumulative_sum / BaseField::from(vals.len());
let trace = TreeVec::new(vec![gen_prefix_sum_trace(vals)]);
Expand Down Expand Up @@ -1139,7 +1139,7 @@ mod tests {
fn eval_carry_quotient_col_works() {
const N_VARIABLES: usize = 5;
let mut rng = SmallRng::seed_from_u64(0);
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.gen());
let eval_point: [SecureField; N_VARIABLES] = array::from_fn(|_| rng.random());
let mle_eval_point = MleEvalPoint::new(&eval_point);
let col_eval = gen_carry_quotient_col(&eval_point);
let twiddles = SimdBackend::precompute_twiddles(col_eval.domain.half_coset);
Expand Down
4 changes: 2 additions & 2 deletions crates/stwo/benches/eval_at_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const LOG_SIZE: u32 = 20;
fn bench_eval_at_secure_point<B: PolyOps>(c: &mut Criterion, id: &str) {
let poly = CirclePoly::new((0..1 << LOG_SIZE).map(BaseField::from).collect());
let mut rng = SmallRng::seed_from_u64(0);
let x = rng.gen();
let y = rng.gen();
let x = rng.random();
let y = rng.random();
let point = CirclePoint { x, y };
c.bench_function(
&format!("{id} eval_at_secure_field_point 2^{LOG_SIZE}"),
Expand Down
16 changes: 8 additions & 8 deletions crates/stwo/benches/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub const N_STATE_ELEMENTS: usize = 8;

pub fn m31_operations_bench(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(0);
let elements: Vec<M31> = (0..N_ELEMENTS).map(|_| rng.gen()).collect();
let mut state: [M31; N_STATE_ELEMENTS] = rng.gen();
let elements: Vec<M31> = (0..N_ELEMENTS).map(|_| rng.random()).collect();
let mut state: [M31; N_STATE_ELEMENTS] = rng.random();

c.bench_function("M31 mul", |b| {
b.iter(|| {
Expand Down Expand Up @@ -42,8 +42,8 @@ pub fn m31_operations_bench(c: &mut Criterion) {

pub fn cm31_operations_bench(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(0);
let elements: Vec<CM31> = (0..N_ELEMENTS).map(|_| rng.gen()).collect();
let mut state: [CM31; N_STATE_ELEMENTS] = rng.gen();
let elements: Vec<CM31> = (0..N_ELEMENTS).map(|_| rng.random()).collect();
let mut state: [CM31; N_STATE_ELEMENTS] = rng.random();

c.bench_function("CM31 mul", |b| {
b.iter(|| {
Expand Down Expand Up @@ -72,8 +72,8 @@ pub fn cm31_operations_bench(c: &mut Criterion) {

pub fn qm31_operations_bench(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(0);
let elements: Vec<SecureField> = (0..N_ELEMENTS).map(|_| rng.gen()).collect();
let mut state: [SecureField; N_STATE_ELEMENTS] = rng.gen();
let elements: Vec<SecureField> = (0..N_ELEMENTS).map(|_| rng.random()).collect();
let mut state: [SecureField; N_STATE_ELEMENTS] = rng.random();

c.bench_function("SecureField mul", |b| {
b.iter(|| {
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn qm31_operations_bench(c: &mut Criterion) {

pub fn simd_m31_operations_bench(c: &mut Criterion) {
let mut rng = SmallRng::seed_from_u64(0);
let elements: Vec<PackedBaseField> = (0..N_ELEMENTS / N_LANES).map(|_| rng.gen()).collect();
let elements: Vec<PackedBaseField> = (0..N_ELEMENTS / N_LANES).map(|_| rng.random()).collect();
let mut states = vec![PackedBaseField::broadcast(BaseField::one()); N_STATE_ELEMENTS];

c.bench_function("mul_simd", |b| {
Expand Down Expand Up @@ -145,6 +145,6 @@ pub fn simd_m31_operations_bench(c: &mut Criterion) {
criterion_group!(
name = benches;
config = Criterion::default().sample_size(10);
targets = m31_operations_bench, cm31_operations_bench, qm31_operations_bench,
targets = m31_operations_bench, cm31_operations_bench, qm31_operations_bench,
simd_m31_operations_bench);
criterion_main!(benches);
6 changes: 3 additions & 3 deletions crates/stwo/benches/lookups.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use rand::distributions::{Distribution, Standard};
use rand::distr::{Distribution, StandardUniform};
use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};
use stwo::core::channel::Blake2sChannel;
Expand Down Expand Up @@ -83,9 +83,9 @@ fn bench_gkr_logup_singles<B: GkrOps>(c: &mut Criterion, id: &str) {
/// Generates a random multilinear polynomial.
fn gen_random_mle<B: MleOps<F>, F: Field>(rng: &mut impl Rng, n_variables: u32) -> Mle<B, F>
where
Standard: Distribution<F>,
StandardUniform: Distribution<F>,
{
Mle::new((0..1 << n_variables).map(|_| rng.gen()).collect())
Mle::new((0..1 << n_variables).map(|_| rng.random()).collect())
}

fn gkr_lookup_benches(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion crates/stwo/benches/pcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn bench_pcs<B: BackendForChannel<Blake2sMerkleChannel>>(c: &mut Criterion, id:
let evals: Vec<CircleEvaluation<B, BaseField, BitReversedOrder>> = iter::repeat_with(|| {
CircleEvaluation::new(
small_domain.circle_domain(),
(0..1 << LOG_COSET_SIZE).map(|_| rng.gen()).collect(),
(0..1 << LOG_COSET_SIZE).map(|_| rng.random()).collect(),
)
})
.take(N_POLYS)
Expand Down
4 changes: 2 additions & 2 deletions crates/stwo/src/core/air/accumulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ mod tests {
const MAX_LOG_SIZE: u32 = 10;
const MASK: u32 = P;
let log_sizes = (0..100)
.map(|_| rng.gen_range(4..MAX_LOG_SIZE))
.map(|_| rng.random_range(4..MAX_LOG_SIZE))
.collect::<Vec<_>>();

// Generate random evaluations.
let evaluations = log_sizes
.iter()
.map(|_| M31::from_u32_unchecked(rng.gen::<u32>() & MASK))
.map(|_| M31::from_u32_unchecked(rng.random::<u32>() & MASK))
.collect::<Vec<_>>();
let alpha = qm31!(2, 3, 4, 5);

Expand Down
10 changes: 5 additions & 5 deletions crates/stwo/src/core/fields/m31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::ops::{
};

use bytemuck::{Pod, Zeroable};
use rand::distributions::{Distribution, Standard};
use rand::distr::{Distribution, StandardUniform};
use serde::{Deserialize, Serialize};

use super::{ComplexConjugate, FieldExpOps};
Expand Down Expand Up @@ -166,10 +166,10 @@ impl From<i32> for M31 {
}
}

impl Distribution<M31> for Standard {
impl Distribution<M31> for StandardUniform {
// Not intended for cryptographic use. Should only be used in tests and benchmarks.
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> M31 {
M31(rng.gen_range(0..P))
M31(rng.random_range(0..P))
}
}

Expand Down Expand Up @@ -239,8 +239,8 @@ mod tests {
fn test_basic_ops() {
let mut rng = SmallRng::seed_from_u64(0);
for _ in 0..10000 {
let x: u32 = rng.gen::<u32>() % P;
let y: u32 = rng.gen::<u32>() % P;
let x: u32 = rng.random::<u32>() % P;
let y: u32 = rng.random::<u32>() % P;
assert_eq!(m31!(add_p(x, y)), m31!(x) + m31!(y));
assert_eq!(m31!(mul_p(x, y)), m31!(x) * m31!(y));
assert_eq!(m31!(neg_p(x)), -m31!(x));
Expand Down
12 changes: 6 additions & 6 deletions crates/stwo/src/core/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ macro_rules! impl_field {
#[macro_export]
macro_rules! impl_extension_field {
($field_name: ident, $extended_field_name: ty) => {
use rand::distributions::{Distribution, Standard};
use rand::distr::{Distribution, StandardUniform};
use $crate::core::fields::ExtensionOf;

impl ExtensionOf<M31> for $field_name {
Expand Down Expand Up @@ -462,10 +462,10 @@ macro_rules! impl_extension_field {
}
}

impl Distribution<$field_name> for Standard {
impl Distribution<$field_name> for StandardUniform {
// Not intended for cryptographic use. Should only be used in tests and benchmarks.
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> $field_name {
$field_name(rng.gen(), rng.gen())
$field_name(rng.random(), rng.random())
}
}
};
Expand All @@ -486,7 +486,7 @@ mod tests {
#[test]
fn test_batch_inverse() {
let mut rng = SmallRng::seed_from_u64(0);
let elements: [M31; 16] = rng.gen();
let elements: [M31; 16] = rng.random();
let expected = elements.iter().map(|e| e.inverse()).collect::<Vec<_>>();

let actual = batch_inverse(&elements);
Expand All @@ -498,7 +498,7 @@ mod tests {
#[should_panic]
fn test_slice_batch_inverse_wrong_dst_size() {
let mut rng = SmallRng::seed_from_u64(0);
let elements: [M31; 16] = rng.gen();
let elements: [M31; 16] = rng.random();
let mut dst = [M31::zero(); 15];

batch_inverse_in_place(&elements, &mut dst);
Expand All @@ -507,7 +507,7 @@ mod tests {
#[test]
fn test_batch_inverse_chunked() {
let mut rng = SmallRng::seed_from_u64(0);
let elements: [M31; 16] = rng.gen();
let elements: [M31; 16] = rng.random();
let chunk_size = 4;
let expected = batch_inverse(&elements);

Expand Down
2 changes: 1 addition & 1 deletion crates/stwo/src/core/vcs/poseidon252_merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod tests {
#[test]
fn test_construct_word() {
let mut rng = SmallRng::seed_from_u64(1638);
let random_values = (0..8 * 1000 + 5).map(|_| rng.gen::<M31>()).collect_vec();
let random_values = (0..8 * 1000 + 5).map(|_| rng.random::<M31>()).collect_vec();

let expected = random_values
.chunks(ELEMENTS_IN_BLOCK)
Expand Down
6 changes: 3 additions & 3 deletions crates/stwo/src/core/vcs/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ where

let mut rng = SmallRng::seed_from_u64(0);
let log_sizes = (0..N_COLS)
.map(|_| rng.gen_range(log_size_range.clone()))
.map(|_| rng.random_range(log_size_range.clone()))
.collect_vec();
let cols = log_sizes
.iter()
.map(|&log_size| {
(0..(1 << log_size))
.map(|_| BaseField::from(rng.gen_range(0..(1 << 30))))
.map(|_| BaseField::from(rng.random_range(0..(1 << 30))))
.collect_vec()
})
.collect_vec();
Expand All @@ -43,7 +43,7 @@ where
let mut queries = BTreeMap::<u32, Vec<usize>>::new();
for log_size in log_size_range.rev() {
let layer_queries = (0..N_QUERIES)
.map(|_| rng.gen_range(0..(1 << log_size)))
.map(|_| rng.random_range(0..(1 << log_size)))
.sorted()
.dedup()
.collect_vec();
Expand Down
Loading