diff --git a/Cargo.lock b/Cargo.lock index 65920ed88b..e6207c7426 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1204,19 +1204,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -1756,12 +1743,6 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "hyper" version = "0.14.28" @@ -3880,11 +3861,11 @@ dependencies = [ "curve25519-dalek", "elf", "elliptic-curve", - "env_logger", "flate2", "hex", "itertools 0.12.1", "k256", + "lazy_static", "log", "nohash-hasher", "num", @@ -4052,15 +4033,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.56" diff --git a/core/Cargo.toml b/core/Cargo.toml index 2cf5ba6a73..94a0e7e601 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -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" } @@ -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"] diff --git a/core/src/alu/add/mod.rs b/core/src/alu/add/mod.rs index ade5e6f048..a9c4e54fd7 100644 --- a/core/src/alu/add/mod.rs +++ b/core/src/alu/add/mod.rs @@ -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(); diff --git a/core/src/alu/bitwise/mod.rs b/core/src/alu/bitwise/mod.rs index a0724370f3..05a3535727 100644 --- a/core/src/alu/bitwise/mod.rs +++ b/core/src/alu/bitwise/mod.rs @@ -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; @@ -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(); diff --git a/core/src/alu/divrem/mod.rs b/core/src/alu/divrem/mod.rs index 018d99717b..d88c0ce358 100644 --- a/core/src/alu/divrem/mod.rs +++ b/core/src/alu/divrem/mod.rs @@ -760,7 +760,6 @@ mod tests { }; use p3_baby_bear::BabyBear; use p3_matrix::dense::RowMajorMatrix; - use rand::thread_rng; use crate::{ alu::AluEvent, @@ -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 = Vec::new(); diff --git a/core/src/alu/lt/mod.rs b/core/src/alu/lt/mod.rs index 894781b5d0..4de1522317 100644 --- a/core/src/alu/lt/mod.rs +++ b/core/src/alu/lt/mod.rs @@ -307,7 +307,6 @@ mod tests { }; use p3_baby_bear::BabyBear; use p3_matrix::dense::RowMajorMatrix; - use rand::thread_rng; use crate::{ alu::AluEvent, @@ -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(); diff --git a/core/src/alu/mul/mod.rs b/core/src/alu/mul/mod.rs index 8b29976a3d..a57afff924 100644 --- a/core/src/alu/mul/mod.rs +++ b/core/src/alu/mul/mod.rs @@ -402,7 +402,6 @@ mod tests { }; use p3_baby_bear::BabyBear; use p3_matrix::dense::RowMajorMatrix; - use rand::thread_rng; use crate::{ alu::AluEvent, @@ -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(); diff --git a/core/src/alu/sll/mod.rs b/core/src/alu/sll/mod.rs index d8881f7e2d..fe90b0f31c 100644 --- a/core/src/alu/sll/mod.rs +++ b/core/src/alu/sll/mod.rs @@ -351,7 +351,6 @@ mod tests { }; use p3_baby_bear::BabyBear; use p3_matrix::dense::RowMajorMatrix; - use rand::thread_rng; use crate::{ alu::AluEvent, @@ -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 = Vec::new(); diff --git a/core/src/alu/sr/mod.rs b/core/src/alu/sr/mod.rs index 689a3bf074..eb93367348 100644 --- a/core/src/alu/sr/mod.rs +++ b/core/src/alu/sr/mod.rs @@ -478,7 +478,6 @@ mod tests { }; use p3_baby_bear::BabyBear; use p3_matrix::dense::RowMajorMatrix; - use rand::thread_rng; use crate::{ alu::AluEvent, @@ -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![ diff --git a/core/src/alu/sub/mod.rs b/core/src/alu/sub/mod.rs index c7e1b58903..9547125423 100644 --- a/core/src/alu/sub/mod.rs +++ b/core/src/alu/sub/mod.rs @@ -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(); diff --git a/core/src/cpu/trace.rs b/core/src/cpu/trace.rs index cf0cd65828..2b46b39a6c 100644 --- a/core/src/cpu/trace.rs +++ b/core/src/cpu/trace.rs @@ -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}; @@ -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(); diff --git a/core/src/memory/global.rs b/core/src/memory/global.rs index 298722d50c..9e68e49978 100644 --- a/core/src/memory/global.rs +++ b/core/src/memory/global.rs @@ -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; @@ -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(); diff --git a/core/src/operations/field/fp_den.rs b/core/src/operations/field/fp_den.rs index 7b120593aa..8ecc2a683b 100644 --- a/core/src/operations/field/fp_den.rs +++ b/core/src/operations/field/fp_den.rs @@ -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(); diff --git a/core/src/operations/field/fp_inner_product.rs b/core/src/operations/field/fp_inner_product.rs index 9bc0e5a89d..0d328eec99 100644 --- a/core/src/operations/field/fp_inner_product.rs +++ b/core/src/operations/field/fp_inner_product.rs @@ -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(); diff --git a/core/src/operations/field/fp_op.rs b/core/src/operations/field/fp_op.rs index 7103ddb2d5..817a36ec49 100644 --- a/core/src/operations/field/fp_op.rs +++ b/core/src/operations/field/fp_op.rs @@ -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, diff --git a/core/src/operations/field/fp_sqrt.rs b/core/src/operations/field/fp_sqrt.rs index af6aa98185..1f4ae0b171 100644 --- a/core/src/operations/field/fp_sqrt.rs +++ b/core/src/operations/field/fp_sqrt.rs @@ -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 = EdSqrtChip::new(); diff --git a/core/src/syscall/precompiles/keccak256/mod.rs b/core/src/syscall/precompiles/keccak256/mod.rs index 054ed756b9..e63d0c3d7d 100644 --- a/core/src/syscall/precompiles/keccak256/mod.rs +++ b/core/src/syscall/precompiles/keccak256/mod.rs @@ -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(); diff --git a/core/src/syscall/precompiles/sha256/compress/mod.rs b/core/src/syscall/precompiles/sha256/compress/mod.rs index 0994f92225..948a7ef003 100644 --- a/core/src/syscall/precompiles/sha256/compress/mod.rs +++ b/core/src/syscall/precompiles/sha256/compress/mod.rs @@ -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(); diff --git a/core/src/syscall/precompiles/sha256/extend/mod.rs b/core/src/syscall/precompiles/sha256/extend/mod.rs index 28f7036996..88580b8953 100644 --- a/core/src/syscall/precompiles/sha256/extend/mod.rs +++ b/core/src/syscall/precompiles/sha256/extend/mod.rs @@ -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(); diff --git a/core/src/utils/ec/field.rs b/core/src/utils/ec/field.rs index ec8eab8855..2cff8134b9 100644 --- a/core/src/utils/ec/field.rs +++ b/core/src/utils/ec/field.rs @@ -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; @@ -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() -> impl Iterator { Self::MODULUS .into_iter() diff --git a/core/src/utils/mod.rs b/core/src/utils/mod.rs index 4434a961ea..2ebc19f89e 100644 --- a/core/src/utils/mod.rs +++ b/core/src/utils/mod.rs @@ -1,6 +1,7 @@ pub mod ec; pub mod env; mod logger; +mod poseidon2_instance; mod programs; mod prove; mod tracer; diff --git a/core/src/utils/poseidon2_instance.rs b/core/src/utils/poseidon2_instance.rs new file mode 100644 index 0000000000..63e102ea38 --- /dev/null +++ b/core/src/utils/poseidon2_instance.rs @@ -0,0 +1,552 @@ +use lazy_static::lazy_static; +use p3_baby_bear::BabyBear; +use p3_field::AbstractField; + +lazy_static! { + // These constants are created by a RNG. + + // This will be compatible with a poseidon2 permutation config with + // a state width of 16 and total rounds (both full and partial) of 30. + pub static ref RC_16_30: [[BabyBear; 16]; 30] = [ + [ + BabyBear::from_wrapped_u32(2110014213), + BabyBear::from_wrapped_u32(3964964605), + BabyBear::from_wrapped_u32(2190662774), + BabyBear::from_wrapped_u32(2732996483), + BabyBear::from_wrapped_u32(640767983), + BabyBear::from_wrapped_u32(3403899136), + BabyBear::from_wrapped_u32(1716033721), + BabyBear::from_wrapped_u32(1606702601), + BabyBear::from_wrapped_u32(3759873288), + BabyBear::from_wrapped_u32(1466015491), + BabyBear::from_wrapped_u32(1498308946), + BabyBear::from_wrapped_u32(2844375094), + BabyBear::from_wrapped_u32(3042463841), + BabyBear::from_wrapped_u32(1969905919), + BabyBear::from_wrapped_u32(4109944726), + BabyBear::from_wrapped_u32(3925048366), + ], + [ + BabyBear::from_wrapped_u32(3706859504), + BabyBear::from_wrapped_u32(759122502), + BabyBear::from_wrapped_u32(3167665446), + BabyBear::from_wrapped_u32(1131812921), + BabyBear::from_wrapped_u32(1080754908), + BabyBear::from_wrapped_u32(4080114493), + BabyBear::from_wrapped_u32(893583089), + BabyBear::from_wrapped_u32(2019677373), + BabyBear::from_wrapped_u32(3128604556), + BabyBear::from_wrapped_u32(580640471), + BabyBear::from_wrapped_u32(3277620260), + BabyBear::from_wrapped_u32(842931656), + BabyBear::from_wrapped_u32(548879852), + BabyBear::from_wrapped_u32(3608554714), + BabyBear::from_wrapped_u32(3575647916), + BabyBear::from_wrapped_u32(81826002), + ], + [ + BabyBear::from_wrapped_u32(4289086263), + BabyBear::from_wrapped_u32(1563933798), + BabyBear::from_wrapped_u32(1440025885), + BabyBear::from_wrapped_u32(184445025), + BabyBear::from_wrapped_u32(2598651360), + BabyBear::from_wrapped_u32(1396647410), + BabyBear::from_wrapped_u32(1575877922), + BabyBear::from_wrapped_u32(3303853401), + BabyBear::from_wrapped_u32(137125468), + BabyBear::from_wrapped_u32(765010148), + BabyBear::from_wrapped_u32(633675867), + BabyBear::from_wrapped_u32(2037803363), + BabyBear::from_wrapped_u32(2573389828), + BabyBear::from_wrapped_u32(1895729703), + BabyBear::from_wrapped_u32(541515871), + BabyBear::from_wrapped_u32(1783382863), + ], + [ + BabyBear::from_wrapped_u32(2641856484), + BabyBear::from_wrapped_u32(3035743342), + BabyBear::from_wrapped_u32(3672796326), + BabyBear::from_wrapped_u32(245668751), + BabyBear::from_wrapped_u32(2025460432), + BabyBear::from_wrapped_u32(201609705), + BabyBear::from_wrapped_u32(286217151), + BabyBear::from_wrapped_u32(4093475563), + BabyBear::from_wrapped_u32(2519572182), + BabyBear::from_wrapped_u32(3080699870), + BabyBear::from_wrapped_u32(2762001832), + BabyBear::from_wrapped_u32(1244250808), + BabyBear::from_wrapped_u32(606038199), + BabyBear::from_wrapped_u32(3182740831), + BabyBear::from_wrapped_u32(73007766), + BabyBear::from_wrapped_u32(2572204153), + ], + [ + BabyBear::from_wrapped_u32(1196780786), + BabyBear::from_wrapped_u32(3447394443), + BabyBear::from_wrapped_u32(747167305), + BabyBear::from_wrapped_u32(2968073607), + BabyBear::from_wrapped_u32(1053214930), + BabyBear::from_wrapped_u32(1074411832), + BabyBear::from_wrapped_u32(4016794508), + BabyBear::from_wrapped_u32(1570312929), + BabyBear::from_wrapped_u32(113576933), + BabyBear::from_wrapped_u32(4042581186), + BabyBear::from_wrapped_u32(3634515733), + BabyBear::from_wrapped_u32(1032701597), + BabyBear::from_wrapped_u32(2364839308), + BabyBear::from_wrapped_u32(3840286918), + BabyBear::from_wrapped_u32(888378655), + BabyBear::from_wrapped_u32(2520191583), + ], + [ + BabyBear::from_wrapped_u32(36046858), + BabyBear::from_wrapped_u32(2927525953), + BabyBear::from_wrapped_u32(3912129105), + BabyBear::from_wrapped_u32(4004832531), + BabyBear::from_wrapped_u32(193772436), + BabyBear::from_wrapped_u32(1590247392), + BabyBear::from_wrapped_u32(4125818172), + BabyBear::from_wrapped_u32(2516251696), + BabyBear::from_wrapped_u32(4050945750), + BabyBear::from_wrapped_u32(269498914), + BabyBear::from_wrapped_u32(1973292656), + BabyBear::from_wrapped_u32(891403491), + BabyBear::from_wrapped_u32(1845429189), + BabyBear::from_wrapped_u32(2611996363), + BabyBear::from_wrapped_u32(2310542653), + BabyBear::from_wrapped_u32(4071195740), + ], + [ + BabyBear::from_wrapped_u32(3505307391), + BabyBear::from_wrapped_u32(786445290), + BabyBear::from_wrapped_u32(3815313971), + BabyBear::from_wrapped_u32(1111591756), + BabyBear::from_wrapped_u32(4233279834), + BabyBear::from_wrapped_u32(2775453034), + BabyBear::from_wrapped_u32(1991257625), + BabyBear::from_wrapped_u32(2940505809), + BabyBear::from_wrapped_u32(2751316206), + BabyBear::from_wrapped_u32(1028870679), + BabyBear::from_wrapped_u32(1282466273), + BabyBear::from_wrapped_u32(1059053371), + BabyBear::from_wrapped_u32(834521354), + BabyBear::from_wrapped_u32(138721483), + BabyBear::from_wrapped_u32(3100410803), + BabyBear::from_wrapped_u32(3843128331), + ], + [ + BabyBear::from_wrapped_u32(3878220780), + BabyBear::from_wrapped_u32(4058162439), + BabyBear::from_wrapped_u32(1478942487), + BabyBear::from_wrapped_u32(799012923), + BabyBear::from_wrapped_u32(496734827), + BabyBear::from_wrapped_u32(3521261236), + BabyBear::from_wrapped_u32(755421082), + BabyBear::from_wrapped_u32(1361409515), + BabyBear::from_wrapped_u32(392099473), + BabyBear::from_wrapped_u32(3178453393), + BabyBear::from_wrapped_u32(4068463721), + BabyBear::from_wrapped_u32(7935614), + BabyBear::from_wrapped_u32(4140885645), + BabyBear::from_wrapped_u32(2150748066), + BabyBear::from_wrapped_u32(1685210312), + BabyBear::from_wrapped_u32(3852983224), + ], + [ + BabyBear::from_wrapped_u32(2896943075), + BabyBear::from_wrapped_u32(3087590927), + BabyBear::from_wrapped_u32(992175959), + BabyBear::from_wrapped_u32(970216228), + BabyBear::from_wrapped_u32(3473630090), + BabyBear::from_wrapped_u32(3899670400), + BabyBear::from_wrapped_u32(3603388822), + BabyBear::from_wrapped_u32(2633488197), + BabyBear::from_wrapped_u32(2479406964), + BabyBear::from_wrapped_u32(2420952999), + BabyBear::from_wrapped_u32(1852516800), + BabyBear::from_wrapped_u32(4253075697), + BabyBear::from_wrapped_u32(979699862), + BabyBear::from_wrapped_u32(1163403191), + BabyBear::from_wrapped_u32(1608599874), + BabyBear::from_wrapped_u32(3056104448), + ], + [ + BabyBear::from_wrapped_u32(3779109343), + BabyBear::from_wrapped_u32(536205958), + BabyBear::from_wrapped_u32(4183458361), + BabyBear::from_wrapped_u32(1649720295), + BabyBear::from_wrapped_u32(1444912244), + BabyBear::from_wrapped_u32(3122230878), + BabyBear::from_wrapped_u32(384301396), + BabyBear::from_wrapped_u32(4228198516), + BabyBear::from_wrapped_u32(1662916865), + BabyBear::from_wrapped_u32(4082161114), + BabyBear::from_wrapped_u32(2121897314), + BabyBear::from_wrapped_u32(1706239958), + BabyBear::from_wrapped_u32(4166959388), + BabyBear::from_wrapped_u32(1626054781), + BabyBear::from_wrapped_u32(3005858978), + BabyBear::from_wrapped_u32(1431907253), + ], + [ + BabyBear::from_wrapped_u32(1418914503), + BabyBear::from_wrapped_u32(1365856753), + BabyBear::from_wrapped_u32(3942715745), + BabyBear::from_wrapped_u32(1429155552), + BabyBear::from_wrapped_u32(3545642795), + BabyBear::from_wrapped_u32(3772474257), + BabyBear::from_wrapped_u32(1621094396), + BabyBear::from_wrapped_u32(2154399145), + BabyBear::from_wrapped_u32(826697382), + BabyBear::from_wrapped_u32(1700781391), + BabyBear::from_wrapped_u32(3539164324), + BabyBear::from_wrapped_u32(652815039), + BabyBear::from_wrapped_u32(442484755), + BabyBear::from_wrapped_u32(2055299391), + BabyBear::from_wrapped_u32(1064289978), + BabyBear::from_wrapped_u32(1152335780), + ], + [ + BabyBear::from_wrapped_u32(3417648695), + BabyBear::from_wrapped_u32(186040114), + BabyBear::from_wrapped_u32(3475580573), + BabyBear::from_wrapped_u32(2113941250), + BabyBear::from_wrapped_u32(1779573826), + BabyBear::from_wrapped_u32(1573808590), + BabyBear::from_wrapped_u32(3235694804), + BabyBear::from_wrapped_u32(2922195281), + BabyBear::from_wrapped_u32(1119462702), + BabyBear::from_wrapped_u32(3688305521), + BabyBear::from_wrapped_u32(1849567013), + BabyBear::from_wrapped_u32(667446787), + BabyBear::from_wrapped_u32(753897224), + BabyBear::from_wrapped_u32(1896396780), + BabyBear::from_wrapped_u32(3143026334), + BabyBear::from_wrapped_u32(3829603876), + ], + [ + BabyBear::from_wrapped_u32(859661334), + BabyBear::from_wrapped_u32(3898844357), + BabyBear::from_wrapped_u32(180258337), + BabyBear::from_wrapped_u32(2321867017), + BabyBear::from_wrapped_u32(3599002504), + BabyBear::from_wrapped_u32(2886782421), + BabyBear::from_wrapped_u32(3038299378), + BabyBear::from_wrapped_u32(1035366250), + BabyBear::from_wrapped_u32(2038912197), + BabyBear::from_wrapped_u32(2920174523), + BabyBear::from_wrapped_u32(1277696101), + BabyBear::from_wrapped_u32(2785700290), + BabyBear::from_wrapped_u32(3806504335), + BabyBear::from_wrapped_u32(3518858933), + BabyBear::from_wrapped_u32(654843672), + BabyBear::from_wrapped_u32(2127120275), + ], + [ + BabyBear::from_wrapped_u32(1548195514), + BabyBear::from_wrapped_u32(2378056027), + BabyBear::from_wrapped_u32(390914568), + BabyBear::from_wrapped_u32(1472049779), + BabyBear::from_wrapped_u32(1552596765), + BabyBear::from_wrapped_u32(1905886441), + BabyBear::from_wrapped_u32(1611959354), + BabyBear::from_wrapped_u32(3653263304), + BabyBear::from_wrapped_u32(3423946386), + BabyBear::from_wrapped_u32(340857935), + BabyBear::from_wrapped_u32(2208879480), + BabyBear::from_wrapped_u32(139364268), + BabyBear::from_wrapped_u32(3447281773), + BabyBear::from_wrapped_u32(3777813707), + BabyBear::from_wrapped_u32(55640413), + BabyBear::from_wrapped_u32(4101901741), + ], + [ + BabyBear::from_wrapped_u32(104929687), + BabyBear::from_wrapped_u32(1459980974), + BabyBear::from_wrapped_u32(1831234737), + BabyBear::from_wrapped_u32(457139004), + BabyBear::from_wrapped_u32(2581487628), + BabyBear::from_wrapped_u32(2112044563), + BabyBear::from_wrapped_u32(3567013861), + BabyBear::from_wrapped_u32(2792004347), + BabyBear::from_wrapped_u32(576325418), + BabyBear::from_wrapped_u32(41126132), + BabyBear::from_wrapped_u32(2713562324), + BabyBear::from_wrapped_u32(151213722), + BabyBear::from_wrapped_u32(2891185935), + BabyBear::from_wrapped_u32(546846420), + BabyBear::from_wrapped_u32(2939794919), + BabyBear::from_wrapped_u32(2543469905) + ], + [ + BabyBear::from_wrapped_u32(2191909784), + BabyBear::from_wrapped_u32(3315138460), + BabyBear::from_wrapped_u32(530414574), + BabyBear::from_wrapped_u32(1242280418), + BabyBear::from_wrapped_u32(1211740715), + BabyBear::from_wrapped_u32(3993672165), + BabyBear::from_wrapped_u32(2505083323), + BabyBear::from_wrapped_u32(3845798801), + BabyBear::from_wrapped_u32(538768466), + BabyBear::from_wrapped_u32(2063567560), + BabyBear::from_wrapped_u32(3366148274), + BabyBear::from_wrapped_u32(1449831887), + BabyBear::from_wrapped_u32(2408012466), + BabyBear::from_wrapped_u32(294726285), + BabyBear::from_wrapped_u32(3943435493), + BabyBear::from_wrapped_u32(924016661), + ], + [ + BabyBear::from_wrapped_u32(3633138367), + BabyBear::from_wrapped_u32(3222789372), + BabyBear::from_wrapped_u32(809116305), + BabyBear::from_wrapped_u32(30100013), + BabyBear::from_wrapped_u32(2655172876), + BabyBear::from_wrapped_u32(2564247117), + BabyBear::from_wrapped_u32(2478649732), + BabyBear::from_wrapped_u32(4113689151), + BabyBear::from_wrapped_u32(4120146082), + BabyBear::from_wrapped_u32(2512308515), + BabyBear::from_wrapped_u32(650406041), + BabyBear::from_wrapped_u32(4240012393), + BabyBear::from_wrapped_u32(2683508708), + BabyBear::from_wrapped_u32(951073977), + BabyBear::from_wrapped_u32(3460081988), + BabyBear::from_wrapped_u32(339124269), + ], + [ + BabyBear::from_wrapped_u32(130182653), + BabyBear::from_wrapped_u32(2755946749), + BabyBear::from_wrapped_u32(542600513), + BabyBear::from_wrapped_u32(2816103022), + BabyBear::from_wrapped_u32(1931786340), + BabyBear::from_wrapped_u32(2044470840), + BabyBear::from_wrapped_u32(1709908013), + BabyBear::from_wrapped_u32(2938369043), + BabyBear::from_wrapped_u32(3640399693), + BabyBear::from_wrapped_u32(1374470239), + BabyBear::from_wrapped_u32(2191149676), + BabyBear::from_wrapped_u32(2637495682), + BabyBear::from_wrapped_u32(4236394040), + BabyBear::from_wrapped_u32(2289358846), + BabyBear::from_wrapped_u32(3833368530), + BabyBear::from_wrapped_u32(974546524), + ], + [ + BabyBear::from_wrapped_u32(3306659113), + BabyBear::from_wrapped_u32(2234814261), + BabyBear::from_wrapped_u32(1188782305), + BabyBear::from_wrapped_u32(223782844), + BabyBear::from_wrapped_u32(2248980567), + BabyBear::from_wrapped_u32(2309786141), + BabyBear::from_wrapped_u32(2023401627), + BabyBear::from_wrapped_u32(3278877413), + BabyBear::from_wrapped_u32(2022138149), + BabyBear::from_wrapped_u32(575851471), + BabyBear::from_wrapped_u32(1612560780), + BabyBear::from_wrapped_u32(3926656936), + BabyBear::from_wrapped_u32(3318548977), + BabyBear::from_wrapped_u32(2591863678), + BabyBear::from_wrapped_u32(188109355), + BabyBear::from_wrapped_u32(4217723909), + ], + [ + BabyBear::from_wrapped_u32(1564209905), + BabyBear::from_wrapped_u32(2154197895), + BabyBear::from_wrapped_u32(2459687029), + BabyBear::from_wrapped_u32(2870634489), + BabyBear::from_wrapped_u32(1375012945), + BabyBear::from_wrapped_u32(1529454825), + BabyBear::from_wrapped_u32(306140690), + BabyBear::from_wrapped_u32(2855578299), + BabyBear::from_wrapped_u32(1246997295), + BabyBear::from_wrapped_u32(3024298763), + BabyBear::from_wrapped_u32(1915270363), + BabyBear::from_wrapped_u32(1218245412), + BabyBear::from_wrapped_u32(2479314020), + BabyBear::from_wrapped_u32(2989827755), + BabyBear::from_wrapped_u32(814378556), + BabyBear::from_wrapped_u32(4039775921), + ], + [ + BabyBear::from_wrapped_u32(1165280628), + BabyBear::from_wrapped_u32(1203983801), + BabyBear::from_wrapped_u32(3814740033), + BabyBear::from_wrapped_u32(1919627044), + BabyBear::from_wrapped_u32(600240215), + BabyBear::from_wrapped_u32(773269071), + BabyBear::from_wrapped_u32(486685186), + BabyBear::from_wrapped_u32(4254048810), + BabyBear::from_wrapped_u32(1415023565), + BabyBear::from_wrapped_u32(502840102), + BabyBear::from_wrapped_u32(4225648358), + BabyBear::from_wrapped_u32(510217063), + BabyBear::from_wrapped_u32(166444818), + BabyBear::from_wrapped_u32(1430745893), + BabyBear::from_wrapped_u32(1376516190), + BabyBear::from_wrapped_u32(1775891321), + ], + [ + BabyBear::from_wrapped_u32(1170945922), + BabyBear::from_wrapped_u32(1105391877), + BabyBear::from_wrapped_u32(261536467), + BabyBear::from_wrapped_u32(1401687994), + BabyBear::from_wrapped_u32(1022529847), + BabyBear::from_wrapped_u32(2476446456), + BabyBear::from_wrapped_u32(2603844878), + BabyBear::from_wrapped_u32(3706336043), + BabyBear::from_wrapped_u32(3463053714), + BabyBear::from_wrapped_u32(1509644517), + BabyBear::from_wrapped_u32(588552318), + BabyBear::from_wrapped_u32(65252581), + BabyBear::from_wrapped_u32(3696502656), + BabyBear::from_wrapped_u32(2183330763), + BabyBear::from_wrapped_u32(3664021233), + BabyBear::from_wrapped_u32(1643809916), + ], + [ + BabyBear::from_wrapped_u32(2922875898), + BabyBear::from_wrapped_u32(3740690643), + BabyBear::from_wrapped_u32(3932461140), + BabyBear::from_wrapped_u32(161156271), + BabyBear::from_wrapped_u32(2619943483), + BabyBear::from_wrapped_u32(4077039509), + BabyBear::from_wrapped_u32(2921201703), + BabyBear::from_wrapped_u32(2085619718), + BabyBear::from_wrapped_u32(2065264646), + BabyBear::from_wrapped_u32(2615693812), + BabyBear::from_wrapped_u32(3116555433), + BabyBear::from_wrapped_u32(246100007), + BabyBear::from_wrapped_u32(4281387154), + BabyBear::from_wrapped_u32(4046141001), + BabyBear::from_wrapped_u32(4027749321), + BabyBear::from_wrapped_u32(111611860), + ], + [ + BabyBear::from_wrapped_u32(2066954820), + BabyBear::from_wrapped_u32(2502099969), + BabyBear::from_wrapped_u32(2915053115), + BabyBear::from_wrapped_u32(2362518586), + BabyBear::from_wrapped_u32(366091708), + BabyBear::from_wrapped_u32(2083204932), + BabyBear::from_wrapped_u32(4138385632), + BabyBear::from_wrapped_u32(3195157567), + BabyBear::from_wrapped_u32(1318086382), + BabyBear::from_wrapped_u32(521723799), + BabyBear::from_wrapped_u32(702443405), + BabyBear::from_wrapped_u32(2507670985), + BabyBear::from_wrapped_u32(1760347557), + BabyBear::from_wrapped_u32(2631999893), + BabyBear::from_wrapped_u32(1672737554), + BabyBear::from_wrapped_u32(1060867760), + ], + [ + BabyBear::from_wrapped_u32(2359801781), + BabyBear::from_wrapped_u32(2800231467), + BabyBear::from_wrapped_u32(3010357035), + BabyBear::from_wrapped_u32(1035997899), + BabyBear::from_wrapped_u32(1210110952), + BabyBear::from_wrapped_u32(1018506770), + BabyBear::from_wrapped_u32(2799468177), + BabyBear::from_wrapped_u32(1479380761), + BabyBear::from_wrapped_u32(1536021911), + BabyBear::from_wrapped_u32(358993854), + BabyBear::from_wrapped_u32(579904113), + BabyBear::from_wrapped_u32(3432144800), + BabyBear::from_wrapped_u32(3625515809), + BabyBear::from_wrapped_u32(199241497), + BabyBear::from_wrapped_u32(4058304109), + BabyBear::from_wrapped_u32(2590164234), + ], + [ + BabyBear::from_wrapped_u32(1688530738), + BabyBear::from_wrapped_u32(1580733335), + BabyBear::from_wrapped_u32(2443981517), + BabyBear::from_wrapped_u32(2206270565), + BabyBear::from_wrapped_u32(2780074229), + BabyBear::from_wrapped_u32(2628739677), + BabyBear::from_wrapped_u32(2940123659), + BabyBear::from_wrapped_u32(4145206827), + BabyBear::from_wrapped_u32(3572278009), + BabyBear::from_wrapped_u32(2779607509), + BabyBear::from_wrapped_u32(1098718697), + BabyBear::from_wrapped_u32(1424913749), + BabyBear::from_wrapped_u32(2224415875), + BabyBear::from_wrapped_u32(1108922178), + BabyBear::from_wrapped_u32(3646272562), + BabyBear::from_wrapped_u32(3935186184), + ], + [ + BabyBear::from_wrapped_u32(820046587), + BabyBear::from_wrapped_u32(1393386250), + BabyBear::from_wrapped_u32(2665818575), + BabyBear::from_wrapped_u32(2231782019), + BabyBear::from_wrapped_u32(672377010), + BabyBear::from_wrapped_u32(1920315467), + BabyBear::from_wrapped_u32(1913164407), + BabyBear::from_wrapped_u32(2029526876), + BabyBear::from_wrapped_u32(2629271820), + BabyBear::from_wrapped_u32(384320012), + BabyBear::from_wrapped_u32(4112320585), + BabyBear::from_wrapped_u32(3131824773), + BabyBear::from_wrapped_u32(2347818197), + BabyBear::from_wrapped_u32(2220997386), + BabyBear::from_wrapped_u32(1772368609), + BabyBear::from_wrapped_u32(2579960095), + ], + [ + BabyBear::from_wrapped_u32(3544930873), + BabyBear::from_wrapped_u32(225847443), + BabyBear::from_wrapped_u32(3070082278), + BabyBear::from_wrapped_u32(95643305), + BabyBear::from_wrapped_u32(3438572042), + BabyBear::from_wrapped_u32(3312856509), + BabyBear::from_wrapped_u32(615850007), + BabyBear::from_wrapped_u32(1863868773), + BabyBear::from_wrapped_u32(803582265), + BabyBear::from_wrapped_u32(3461976859), + BabyBear::from_wrapped_u32(2903025799), + BabyBear::from_wrapped_u32(1482092434), + BabyBear::from_wrapped_u32(3902972499), + BabyBear::from_wrapped_u32(3872341868), + BabyBear::from_wrapped_u32(1530411808), + BabyBear::from_wrapped_u32(2214923584), + ], + [ + BabyBear::from_wrapped_u32(3118792481), + BabyBear::from_wrapped_u32(2241076515), + BabyBear::from_wrapped_u32(3983669831), + BabyBear::from_wrapped_u32(3180915147), + BabyBear::from_wrapped_u32(3838626501), + BabyBear::from_wrapped_u32(1921630011), + BabyBear::from_wrapped_u32(3415351771), + BabyBear::from_wrapped_u32(2249953859), + BabyBear::from_wrapped_u32(3755081630), + BabyBear::from_wrapped_u32(486327260), + BabyBear::from_wrapped_u32(1227575720), + BabyBear::from_wrapped_u32(3643869379), + BabyBear::from_wrapped_u32(2982026073), + BabyBear::from_wrapped_u32(2466043731), + BabyBear::from_wrapped_u32(1982634375), + BabyBear::from_wrapped_u32(3769609014), + ], + [ + BabyBear::from_wrapped_u32(2195455495), + BabyBear::from_wrapped_u32(2596863283), + BabyBear::from_wrapped_u32(4244994973), + BabyBear::from_wrapped_u32(1983609348), + BabyBear::from_wrapped_u32(4019674395), + BabyBear::from_wrapped_u32(3469982031), + BabyBear::from_wrapped_u32(1458697570), + BabyBear::from_wrapped_u32(1593516217), + BabyBear::from_wrapped_u32(1963896497), + BabyBear::from_wrapped_u32(3115309118), + BabyBear::from_wrapped_u32(1659132465), + BabyBear::from_wrapped_u32(2536770756), + BabyBear::from_wrapped_u32(3059294171), + BabyBear::from_wrapped_u32(2618031334), + BabyBear::from_wrapped_u32(2040903247), + BabyBear::from_wrapped_u32(3799795076), + ] + ]; +} diff --git a/core/src/utils/prove.rs b/core/src/utils/prove.rs index d19946cb8c..f0c2f8543a 100644 --- a/core/src/utils/prove.rs +++ b/core/src/utils/prove.rs @@ -45,7 +45,7 @@ pub fn prove_elf(elf: &[u8]) -> crate::stark::Proof { } pub fn prove_core(runtime: &mut Runtime) -> crate::stark::Proof { - let config = BabyBearBlake3::new(&mut rand::thread_rng()); + let config = BabyBearBlake3::new(); let mut challenger = config.challenger(); let start = Instant::now(); @@ -141,9 +141,8 @@ pub(super) mod baby_bear_poseidon2 { use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon2::{DiffusionMatrixBabybear, Poseidon2}; use p3_symmetric::{PaddingFreeSponge, TruncatedPermutation}; - use rand::Rng; - use crate::stark::StarkConfig; + use crate::{stark::StarkConfig, utils::poseidon2_instance::RC_16_30}; use super::StarkUtils; @@ -173,8 +172,8 @@ pub(super) mod baby_bear_poseidon2 { } impl BabyBearPoseidon2 { - pub fn new(rng: &mut R) -> Self { - let perm = Perm::new_from_rng(8, 22, DiffusionMatrixBabybear, rng); + pub fn new() -> Self { + let perm = Perm::new(8, 22, RC_16_30.to_vec(), DiffusionMatrixBabybear); let hash = MyHash::new(perm.clone()); @@ -249,9 +248,8 @@ pub(super) mod baby_bear_keccak { use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon2::{DiffusionMatrixBabybear, Poseidon2}; use p3_symmetric::{SerializingHasher32, TruncatedPermutation}; - use rand::Rng; - use crate::stark::StarkConfig; + use crate::{stark::StarkConfig, utils::poseidon2_instance::RC_16_30}; use super::StarkUtils; @@ -282,8 +280,8 @@ pub(super) mod baby_bear_keccak { impl BabyBearKeccak { #[allow(dead_code)] - pub fn new(rng: &mut R) -> Self { - let perm = Perm::new_from_rng(8, 22, DiffusionMatrixBabybear, rng); + pub fn new() -> Self { + let perm = Perm::new(8, 22, RC_16_30.to_vec(), DiffusionMatrixBabybear); let hash = MyHash::new(Keccak256Hash {}); @@ -358,10 +356,9 @@ pub(super) mod baby_bear_blake3 { use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon2::{DiffusionMatrixBabybear, Poseidon2}; use p3_symmetric::{SerializingHasher32, TruncatedPermutation}; - use rand::Rng; use serde::Serialize; - use crate::stark::StarkConfig; + use crate::{stark::StarkConfig, utils::poseidon2_instance::RC_16_30}; use super::StarkUtils; @@ -400,8 +397,8 @@ pub(super) mod baby_bear_blake3 { } impl BabyBearBlake3 { - pub fn new(rng: &mut R) -> Self { - let perm = Perm::new_from_rng(8, 22, DiffusionMatrixBabybear, rng); + pub fn new() -> Self { + let perm = Perm::new(8, 22, RC_16_30.to_vec(), DiffusionMatrixBabybear); let hash = MyHash::new(Blake3 {}); @@ -475,10 +472,9 @@ pub(super) mod baby_bear_k12 { use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon2::{DiffusionMatrixBabybear, Poseidon2}; use p3_symmetric::{SerializingHasher32, TruncatedPermutation}; - use rand::Rng; use succinct_k12::KangarooTwelve; - use crate::stark::StarkConfig; + use crate::{stark::StarkConfig, utils::poseidon2_instance::RC_16_30}; use super::StarkUtils; @@ -508,8 +504,8 @@ pub(super) mod baby_bear_k12 { } impl BabyBearK12 { - pub fn new(rng: &mut R) -> Self { - let perm = Perm::new_from_rng(8, 22, DiffusionMatrixBabybear, rng); + pub fn new() -> Self { + let perm = Perm::new(8, 22, RC_16_30.to_vec(), DiffusionMatrixBabybear); let hash = MyHash::new(KangarooTwelve {});