mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-08 16:53:07 +00:00
Parallel proof-of-work search (#92)
This commit is contained in:
parent
77ce69dc15
commit
573badc96f
@ -18,7 +18,7 @@ itertools = "0.10.0"
|
|||||||
num = "0.3"
|
num = "0.3"
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
rand_chacha = "0.2.2"
|
rand_chacha = "0.2.2"
|
||||||
rayon = "1.5.0"
|
rayon = "1.5.1"
|
||||||
unroll = "0.1.5"
|
unroll = "0.1.5"
|
||||||
anyhow = "1.0.40"
|
anyhow = "1.0.40"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|||||||
@ -26,9 +26,9 @@ fn bench_prove<F: Field + Extendable<D>, const D: usize>() {
|
|||||||
rate_bits: 3,
|
rate_bits: 3,
|
||||||
num_challenges: 3,
|
num_challenges: 3,
|
||||||
fri_config: FriConfig {
|
fri_config: FriConfig {
|
||||||
proof_of_work_bits: 10,
|
proof_of_work_bits: 20,
|
||||||
rate_bits: 3,
|
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,
|
num_query_rounds: 35,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::field::extension_field::{flatten, unflatten, Extendable};
|
use crate::field::extension_field::{flatten, unflatten, Extendable};
|
||||||
use crate::field::field::Field;
|
use crate::field::field::Field;
|
||||||
use crate::fri::FriConfig;
|
use crate::fri::FriConfig;
|
||||||
@ -7,6 +9,7 @@ use crate::plonk_challenger::Challenger;
|
|||||||
use crate::plonk_common::reduce_with_powers;
|
use crate::plonk_common::reduce_with_powers;
|
||||||
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
use crate::polynomial::polynomial::{PolynomialCoeffs, PolynomialValues};
|
||||||
use crate::proof::{FriInitialTreeProof, FriProof, FriQueryRound, FriQueryStep, Hash};
|
use crate::proof::{FriInitialTreeProof, FriProof, FriQueryRound, FriQueryStep, Hash};
|
||||||
|
use crate::timed;
|
||||||
use crate::util::reverse_index_bits_in_place;
|
use crate::util::reverse_index_bits_in_place;
|
||||||
|
|
||||||
/// Builds a FRI proof.
|
/// Builds a FRI proof.
|
||||||
@ -32,7 +35,10 @@ pub fn fri_proof<F: Field + Extendable<D>, const D: usize>(
|
|||||||
|
|
||||||
// PoW phase
|
// PoW phase
|
||||||
let current_hash = challenger.get_hash();
|
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
|
// Query phase
|
||||||
let query_round_proofs =
|
let query_round_proofs =
|
||||||
@ -94,8 +100,9 @@ fn fri_committed_trees<F: Field + Extendable<D>, const D: usize>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn fri_proof_of_work<F: Field>(current_hash: Hash<F>, config: &FriConfig) -> F {
|
fn fri_proof_of_work<F: Field>(current_hash: Hash<F>, config: &FriConfig) -> F {
|
||||||
(0u64..)
|
(0..u64::MAX)
|
||||||
.find(|&i| {
|
.into_par_iter()
|
||||||
|
.find_any(|&i| {
|
||||||
hash_n_to_1(
|
hash_n_to_1(
|
||||||
current_hash
|
current_hash
|
||||||
.elements
|
.elements
|
||||||
@ -110,7 +117,7 @@ fn fri_proof_of_work<F: Field>(current_hash: Hash<F>, config: &FriConfig) -> F {
|
|||||||
>= config.proof_of_work_bits + F::ORDER.leading_zeros()
|
>= config.proof_of_work_bits + F::ORDER.leading_zeros()
|
||||||
})
|
})
|
||||||
.map(F::from_canonical_u64)
|
.map(F::from_canonical_u64)
|
||||||
.expect("Proof of work failed.")
|
.expect("Proof of work failed. This is highly unlikely!")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fri_prover_query_rounds<F: Field + Extendable<D>, const D: usize>(
|
fn fri_prover_query_rounds<F: Field + Extendable<D>, const D: usize>(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user