forked from Plonky3/Plonky3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial fri refactor * progress * more work * hmm debugging * fix bug * well it works it's just slow * delete p3-ldt * rm p3-ldt * do math smarter * wee faster * enable parallel * most optimization done, time to start cleaning up * linting * verifier works * cleanup * lints and ci * fmt * no_std * rm commented code * fix error handling * iterate theh right way * hm, it works even with a normal Vec * initial config rework * make config more concise * fix tests * clippy * remove commented code * move two_adic_fri_pcs to toplevel reexport * fmt
- Loading branch information
Showing
25 changed files
with
985 additions
and
1,516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ members = [ | |
"keccak", | ||
"keccak-air", | ||
"lde", | ||
"ldt", | ||
"matrix", | ||
"merkle-tree", | ||
"maybe-rayon", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
use p3_field::PrimeField64; | ||
use p3_field::{Field, PrimeField64}; | ||
use p3_maybe_rayon::prelude::*; | ||
use p3_symmetric::CryptographicPermutation; | ||
use tracing::instrument; | ||
|
||
use crate::{DuplexChallenger, FieldChallenger}; | ||
use crate::{CanObserve, CanSampleBits, DuplexChallenger}; | ||
|
||
pub trait GrindingChallenger<F: PrimeField64>: FieldChallenger<F> + Clone { | ||
// Can be overridden for more efficient methods not involving cloning, depending on the | ||
// internals of the challenger. | ||
#[instrument(name = "grind for proof-of-work witness", skip_all)] | ||
fn grind(&mut self, bits: usize) -> F { | ||
let witness = (0..F::ORDER_U64) | ||
.into_par_iter() | ||
.map(|i| F::from_canonical_u64(i)) | ||
.find_any(|witness| self.clone().check_witness(bits, *witness)) | ||
.expect("failed to find witness"); | ||
assert!(self.check_witness(bits, witness)); | ||
witness | ||
} | ||
pub trait GrindingChallenger: | ||
CanObserve<Self::Witness> + CanSampleBits<usize> + Sync + Clone | ||
{ | ||
type Witness: Field; | ||
|
||
fn grind(&mut self, bits: usize) -> Self::Witness; | ||
|
||
#[must_use] | ||
fn check_witness(&mut self, bits: usize, witness: F) -> bool { | ||
fn check_witness(&mut self, bits: usize, witness: Self::Witness) -> bool { | ||
self.observe(witness); | ||
self.sample_bits(bits) == 0 | ||
} | ||
} | ||
|
||
impl<F, P, const WIDTH: usize> GrindingChallenger<F> for DuplexChallenger<F, P, WIDTH> | ||
impl<F, P, const WIDTH: usize> GrindingChallenger for DuplexChallenger<F, P, WIDTH> | ||
where | ||
F: PrimeField64, | ||
P: CryptographicPermutation<[F; WIDTH]>, | ||
{ | ||
type Witness = F; | ||
|
||
#[instrument(name = "grind for proof-of-work witness", skip_all)] | ||
fn grind(&mut self, bits: usize) -> Self::Witness { | ||
let witness = (0..F::ORDER_U64) | ||
.into_par_iter() | ||
.map(|i| F::from_canonical_u64(i)) | ||
.find_any(|witness| self.clone().check_witness(bits, *witness)) | ||
.expect("failed to find witness"); | ||
assert!(self.check_witness(bits, witness)); | ||
witness | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,12 @@ | ||
use core::marker::PhantomData; | ||
|
||
use p3_challenger::{CanObserve, GrindingChallenger}; | ||
use p3_commit::{DirectMmcs, Mmcs}; | ||
use p3_field::{ExtensionField, PrimeField64, TwoAdicField}; | ||
|
||
pub trait FriConfig { | ||
type Val: PrimeField64; | ||
type Challenge: ExtensionField<Self::Val> + TwoAdicField; | ||
|
||
type InputMmcs: Mmcs<Self::Val>; | ||
type CommitPhaseMmcs: DirectMmcs<Self::Challenge>; | ||
|
||
type Challenger: GrindingChallenger<Self::Val> | ||
+ CanObserve<<Self::CommitPhaseMmcs as Mmcs<Self::Challenge>>::Commitment>; | ||
|
||
fn commit_phase_mmcs(&self) -> &Self::CommitPhaseMmcs; | ||
|
||
fn num_queries(&self) -> usize; | ||
|
||
fn log_blowup(&self) -> usize; | ||
|
||
fn blowup(&self) -> usize { | ||
1 << self.log_blowup() | ||
} | ||
|
||
fn proof_of_work_bits(&self) -> usize; | ||
} | ||
|
||
pub struct FriConfigImpl<Val, Challenge, InputMmcs, CommitPhaseMmcs, Challenger> { | ||
log_blowup: usize, | ||
num_queries: usize, | ||
proof_of_work_bits: usize, | ||
commit_phase_mmcs: CommitPhaseMmcs, | ||
_phantom: PhantomData<(Val, Challenge, InputMmcs, Challenger)>, | ||
} | ||
|
||
impl<Val, Challenge, InputMmcs, CommitPhaseMmcs, Challenger> | ||
FriConfigImpl<Val, Challenge, InputMmcs, CommitPhaseMmcs, Challenger> | ||
{ | ||
pub fn new( | ||
log_blowup: usize, | ||
num_queries: usize, | ||
proof_of_work_bits: usize, | ||
commit_phase_mmcs: CommitPhaseMmcs, | ||
) -> Self { | ||
Self { | ||
log_blowup, | ||
num_queries, | ||
commit_phase_mmcs, | ||
proof_of_work_bits, | ||
_phantom: PhantomData, | ||
} | ||
} | ||
pub struct FriConfig<M> { | ||
pub log_blowup: usize, | ||
pub num_queries: usize, | ||
pub proof_of_work_bits: usize, | ||
pub mmcs: M, | ||
} | ||
|
||
impl<Val, Challenge, InputMmcs, CommitPhaseMmcs, Challenger> FriConfig | ||
for FriConfigImpl<Val, Challenge, InputMmcs, CommitPhaseMmcs, Challenger> | ||
where | ||
Val: PrimeField64, | ||
Challenge: ExtensionField<Val> + TwoAdicField, | ||
InputMmcs: Mmcs<Val>, | ||
CommitPhaseMmcs: DirectMmcs<Challenge>, | ||
Challenger: | ||
GrindingChallenger<Val> + CanObserve<<CommitPhaseMmcs as Mmcs<Challenge>>::Commitment>, | ||
{ | ||
type Val = Val; | ||
type Challenge = Challenge; | ||
type InputMmcs = InputMmcs; | ||
type CommitPhaseMmcs = CommitPhaseMmcs; | ||
type Challenger = Challenger; | ||
|
||
fn commit_phase_mmcs(&self) -> &CommitPhaseMmcs { | ||
&self.commit_phase_mmcs | ||
} | ||
|
||
fn num_queries(&self) -> usize { | ||
self.num_queries | ||
} | ||
|
||
fn log_blowup(&self) -> usize { | ||
self.log_blowup | ||
} | ||
|
||
fn proof_of_work_bits(&self) -> usize { | ||
self.proof_of_work_bits | ||
impl<M> FriConfig<M> { | ||
pub fn blowup(&self) -> usize { | ||
1 << self.log_blowup | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.