Skip to content

Commit

Permalink
chore: Move random related packages to dev dependency and constant po…
Browse files Browse the repository at this point in the history
…seidon2 RCs (#182)
  • Loading branch information
kevjue authored Feb 10, 2024
1 parent 2c4e34f commit a670b4e
Show file tree
Hide file tree
Showing 23 changed files with 589 additions and 80 deletions.
30 changes: 1 addition & 29 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ p3-blake3 = { workspace = true }
p3-symmetric = { workspace = true }
p3-uni-stark = { workspace = true }
p3-maybe-rayon = { workspace = true }
rand = "0.8.5"
p3-util = { workspace = true }
itertools = "0.12.0"
rrs-lib = { git = "https://github.com/GregAC/rrs.git" }
log = "0.4.20"
env_logger = "0.10.1"
num = { version = "0.4.1", features = ["rand"] }
num = { version = "0.4.1" }
nohash-hasher = "0.2.0"
lazy_static = "1.4"

succinct-k12 = { path = "../k12" }

Expand All @@ -57,6 +56,9 @@ serial_test = "3.0.0"

[dev-dependencies]
criterion = "0.5.1"
num = { version = "0.4.1", features = ["rand"] }
rand = "0.8.5"


[features]
perf = ["parallel"]
Expand Down
2 changes: 1 addition & 1 deletion core/src/alu/add/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut shard = ExecutionRecord::default();
Expand Down
3 changes: 1 addition & 2 deletions core/src/alu/bitwise/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ mod tests {

use crate::chip::Chip;
use crate::utils::{uni_stark_prove as prove, uni_stark_verify as verify};
use rand::thread_rng;

use super::BitwiseChip;
use crate::alu::AluEvent;
Expand All @@ -180,7 +179,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut shard = ExecutionRecord::default();
Expand Down
3 changes: 1 addition & 2 deletions core/src/alu/divrem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,6 @@ mod tests {
};
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use rand::thread_rng;

use crate::{
alu::AluEvent,
Expand All @@ -785,7 +784,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut divrem_events: Vec<AluEvent> = Vec::new();
Expand Down
3 changes: 1 addition & 2 deletions core/src/alu/lt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ mod tests {
};
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use rand::thread_rng;

use crate::{
alu::AluEvent,
Expand All @@ -327,7 +326,7 @@ mod tests {
}

fn prove_babybear_template(shard: &mut ExecutionRecord) {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let chip = LtChip::default();
Expand Down
3 changes: 1 addition & 2 deletions core/src/alu/mul/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ mod tests {
};
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use rand::thread_rng;

use crate::{
alu::AluEvent,
Expand All @@ -429,7 +428,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut shard = ExecutionRecord::default();
Expand Down
3 changes: 1 addition & 2 deletions core/src/alu/sll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ mod tests {
};
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use rand::thread_rng;

use crate::{
alu::AluEvent,
Expand All @@ -372,7 +371,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut shift_events: Vec<AluEvent> = Vec::new();
Expand Down
3 changes: 1 addition & 2 deletions core/src/alu/sr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,6 @@ mod tests {
};
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use rand::thread_rng;

use crate::{
alu::AluEvent,
Expand All @@ -499,7 +498,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let shifts = vec![
Expand Down
2 changes: 1 addition & 1 deletion core/src/alu/sub/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut shard = ExecutionRecord::default();
Expand Down
3 changes: 1 addition & 2 deletions core/src/cpu/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ impl CpuChip {
mod tests {
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use rand::thread_rng;

use super::*;
use crate::utils::{uni_stark_prove as prove, uni_stark_verify as verify};
Expand Down Expand Up @@ -520,7 +519,7 @@ mod tests {

#[test]
fn prove_trace() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let program = simple_program();
Expand Down
3 changes: 1 addition & 2 deletions core/src/memory/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ mod tests {
use crate::utils::{uni_stark_prove as prove, uni_stark_verify as verify};
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use rand::thread_rng;

use super::*;
use crate::runtime::tests::simple_program;
Expand Down Expand Up @@ -175,7 +174,7 @@ mod tests {

#[test]
fn test_memory_prove_babybear() {
let config = BabyBearPoseidon2::new(&mut thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let program = simple_program();
Expand Down
2 changes: 1 addition & 1 deletion core/src/operations/field/fp_den.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut rand::thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut shard = ExecutionRecord::default();
Expand Down
2 changes: 1 addition & 1 deletion core/src/operations/field/fp_inner_product.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut rand::thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let mut shard = ExecutionRecord::default();
Expand Down
2 changes: 1 addition & 1 deletion core/src/operations/field/fp_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut rand::thread_rng());
let config = BabyBearPoseidon2::new();

for op in [
FpOperation::Add,
Expand Down
2 changes: 1 addition & 1 deletion core/src/operations/field/fp_sqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ mod tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut rand::thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let chip: EdSqrtChip<Ed25519BaseField> = EdSqrtChip::new();
Expand Down
2 changes: 1 addition & 1 deletion core/src/syscall/precompiles/keccak256/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub mod permute_tests {
#[test]
fn prove_babybear() {
utils::setup_logger();
let config = BabyBearPoseidon2::new(&mut rand::thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let program = keccak_permute_program();
Expand Down
2 changes: 1 addition & 1 deletion core/src/syscall/precompiles/sha256/compress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub mod compress_tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut rand::thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let program = sha_compress_program();
Expand Down
2 changes: 1 addition & 1 deletion core/src/syscall/precompiles/sha256/extend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub mod extend_tests {

#[test]
fn prove_babybear() {
let config = BabyBearPoseidon2::new(&mut rand::thread_rng());
let config = BabyBearPoseidon2::new();
let mut challenger = config.challenger();

let program = sha_extend_program();
Expand Down
6 changes: 0 additions & 6 deletions core/src/utils/ec/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ use super::utils::biguint_from_limbs;
use crate::operations::field::params::Limbs;
use crate::operations::field::params::NB_BITS_PER_LIMB;
use crate::operations::field::params::NUM_LIMBS;
use num::bigint::RandBigInt;
use num::BigUint;
use p3_field::Field;
use rand::rngs::OsRng;
use serde::{de::DeserializeOwned, Serialize};
use std::fmt::Debug;

Expand All @@ -28,10 +26,6 @@ pub trait FieldParameters:
Self::NB_BITS_PER_LIMB * Self::NB_LIMBS
}

fn rand() -> BigUint {
OsRng.gen_biguint_below(&Self::modulus())
}

fn modulus_field_iter<F: Field>() -> impl Iterator<Item = F> {
Self::MODULUS
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions core/src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod ec;
pub mod env;
mod logger;
mod poseidon2_instance;
mod programs;
mod prove;
mod tracer;
Expand Down
Loading

0 comments on commit a670b4e

Please sign in to comment.