diff --git a/Cargo.toml b/Cargo.toml index 062ab1dd..8c4968ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ itertools = "0.10.0" num = "0.3" rand = "0.7.3" rand_chacha = "0.2.2" -rayon = "1.5.0" +rayon = "1.5.1" unroll = "0.1.5" anyhow = "1.0.40" serde = { version = "1.0", features = ["derive"] } diff --git a/src/bin/bench_recursion.rs b/src/bin/bench_recursion.rs index e35f51dd..51f93025 100644 --- a/src/bin/bench_recursion.rs +++ b/src/bin/bench_recursion.rs @@ -26,9 +26,9 @@ fn bench_prove, const D: usize>() { rate_bits: 3, num_challenges: 3, fri_config: FriConfig { - proof_of_work_bits: 10, + proof_of_work_bits: 20, rate_bits: 3, - reduction_arity_bits: vec![2, 2, 2, 2, 2], + reduction_arity_bits: vec![2, 2, 2, 2, 2, 2], num_query_rounds: 35, }, }; diff --git a/src/fri/prover.rs b/src/fri/prover.rs index f937ee55..12968c06 100644 --- a/src/fri/prover.rs +++ b/src/fri/prover.rs @@ -1,3 +1,5 @@ +use rayon::prelude::*; + use crate::field::extension_field::{flatten, unflatten, Extendable}; use crate::field::field::Field; use crate::fri::FriConfig; @@ -7,6 +9,7 @@ use crate::plonk_challenger::Challenger; use crate::plonk_common::reduce_with_powers; use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues}; use crate::proof::{FriInitialTreeProof, FriProof, FriQueryRound, FriQueryStep, Hash}; +use crate::timed; use crate::util::reverse_index_bits_in_place; /// Builds a FRI proof. @@ -32,7 +35,10 @@ pub fn fri_proof, const D: usize>( // PoW phase let current_hash = challenger.get_hash(); - let pow_witness = fri_proof_of_work(current_hash, config); + let pow_witness = timed!( + fri_proof_of_work(current_hash, config), + "to find for proof-of-work witness" + ); // Query phase let query_round_proofs = @@ -94,8 +100,9 @@ fn fri_committed_trees, const D: usize>( } fn fri_proof_of_work(current_hash: Hash, config: &FriConfig) -> F { - (0u64..) - .find(|&i| { + (0..u64::MAX) + .into_par_iter() + .find_any(|&i| { hash_n_to_1( current_hash .elements @@ -110,7 +117,7 @@ fn fri_proof_of_work(current_hash: Hash, config: &FriConfig) -> F { >= config.proof_of_work_bits + F::ORDER.leading_zeros() }) .map(F::from_canonical_u64) - .expect("Proof of work failed.") + .expect("Proof of work failed. This is highly unlikely!") } fn fri_prover_query_rounds, const D: usize>(