-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from succinctlabs/tamir/air-api-change
feat: Plonky3 updates
- Loading branch information
Showing
50 changed files
with
1,374 additions
and
1,866 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
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
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
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
Oops, something went wrong.