use p3_baby_bear::{BabyBear, DiffusionMatrixBabyBear}; use p3_challenger::DuplexChallenger; use p3_commit::ExtensionMmcs; use p3_dft::Radix2DitParallel; use p3_field::extension::BinomialExtensionField; use p3_field::Field; use p3_fri::{FriConfig, TwoAdicFriPcs}; use p3_keccak_air::{generate_trace_rows, KeccakAir}; use p3_matrix::Matrix; use p3_merkle_tree::FieldMerkleTreeMmcs; use p3_poseidon2::{Poseidon2, Poseidon2ExternalMatrixGeneral}; use p3_symmetric::{PaddingFreeSponge, TruncatedPermutation}; use p3_uni_stark::{prove, verify, StarkConfig, VerificationError}; use p3_util::log2_ceil_usize; use rand::{random, thread_rng}; use tracing_forest::util::LevelFilter; use tracing_forest::ForestLayer; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; use tracing_subscriber::{EnvFilter, Registry}; const NUM_HASHES: usize = 1365; fn main() -> Result<(), VerificationError> { let env_filter = EnvFilter::builder() .with_default_directive(LevelFilter::INFO.into()) .from_env_lossy(); Registry::default() .with(env_filter) .with(ForestLayer::default()) .init(); type Val = BabyBear; type Challenge = BinomialExtensionField; type Perm = Poseidon2; let perm = Perm::new_from_rng_128( Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, &mut thread_rng(), ); type MyHash = PaddingFreeSponge; let hash = MyHash::new(perm.clone()); type MyCompress = TruncatedPermutation; let compress = MyCompress::new(perm.clone()); type ValMmcs = FieldMerkleTreeMmcs< ::Packing, ::Packing, MyHash, MyCompress, 8, >; let val_mmcs = ValMmcs::new(hash, compress); type ChallengeMmcs = ExtensionMmcs; let challenge_mmcs = ChallengeMmcs::new(val_mmcs.clone()); type Dft = Radix2DitParallel; let dft = Dft {}; type Challenger = DuplexChallenger; let inputs = (0..NUM_HASHES).map(|_| random()).collect::>(); let trace = generate_trace_rows::(inputs); let fri_config = FriConfig { log_blowup: 1, num_queries: 100, proof_of_work_bits: 16, mmcs: challenge_mmcs, }; type Pcs = TwoAdicFriPcs; let pcs = Pcs::new(log2_ceil_usize(trace.height()), dft, val_mmcs, fri_config); type MyConfig = StarkConfig; let config = MyConfig::new(pcs); let mut challenger = Challenger::new(perm.clone()); let proof = prove(&config, &KeccakAir {}, &mut challenger, trace, &vec![]); let mut challenger = Challenger::new(perm); verify(&config, &KeccakAir {}, &mut challenger, &proof, &vec![]) }