-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BabyBear with only Plonky3 changes #1693
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
11d971f
plonky3 changes
topanisto e310a7e
associated types for FieldElementMap
topanisto 07e2dca
traits implemented
topanisto 106ca22
merge
topanisto 7fee9d3
baby bear and goldilocks impl done
topanisto d210602
baby bear and goldilocks impl done
topanisto 6b61778
Merge branch 'main' of https://github.com/powdr-labs/powdr into babyb…
topanisto 615bcf6
wip
topanisto 819c090
revert to challenger state
topanisto 6798619
compiles
topanisto 9734704
working tests
topanisto 64aa40a
Merge branch 'main' of https://github.com/powdr-labs/powdr into babyb…
topanisto 2b8a401
builds for backend
topanisto 928317f
backend edits
topanisto 50c5636
Babybear assoc type bounds (#1719)
Schaeff 8a01c8f
Allowing construction of Plonky3 backend for BabyBear and Goldilocks.…
lvella ba32320
Merge remote-tracking branch 'origin/main' into babybear-params-2
leonardoalt b942b9e
use p3 bb in some tests
leonardoalt 19dbac8
self fix self review
Schaeff 7d1ae5e
fix convert
leonardoalt 4fec39f
into inner
leonardoalt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
//! The concrete parameters used in the prover | ||
//! Inspired from [this example](https://github.com/Plonky3/Plonky3/blob/6a1b0710fdf85136d0fdd645b92933615867740a/keccak-air/examples/prove_goldilocks_keccak.rs#L57) | ||
|
||
use lazy_static::lazy_static; | ||
|
||
use crate::params::FieldElementMap; | ||
use p3_baby_bear::{BabyBear, DiffusionMatrixBabyBear, MdsMatrixBabyBear}; | ||
use p3_challenger::DuplexChallenger; | ||
use p3_commit::ExtensionMmcs; | ||
use p3_dft::Radix2DitParallel; | ||
use p3_field::{extension::BinomialExtensionField, Field}; | ||
use p3_fri::{FriConfig, TwoAdicFriPcs}; | ||
use p3_merkle_tree::FieldMerkleTreeMmcs; | ||
use p3_poseidon2::{Poseidon2, Poseidon2ExternalMatrixGeneral}; | ||
use p3_symmetric::{PaddingFreeSponge, TruncatedPermutation}; | ||
use p3_uni_stark::StarkConfig; | ||
|
||
use rand::{distributions::Standard, Rng, SeedableRng}; | ||
|
||
use powdr_number::{BabyBearField, FieldElement}; | ||
|
||
const DEGREE: usize = 2; | ||
type Challenge<T: FieldElementMap> = BinomialExtensionField<T::P3Field, DEGREE>; | ||
|
||
const WIDTH: usize = 16; | ||
const D: u64 = 7; | ||
type Perm = Poseidon2<BabyBear, Poseidon2ExternalMatrixGeneral, DiffusionMatrixBabyBear, WIDTH, D>; | ||
|
||
// const ROUNDS_F: usize = poseidon2_round_numbers_128::<dyn BabyBear>(WIDTH, D).0; | ||
// const ROUNDS_P: usize = poseidon2_round_numbers_128::<dyn BabyBear>(WIDTH, D).1; | ||
|
||
// params directly taken from plonky3's poseidon2_round_numbers_128 function | ||
// to guarentee 128-bit security. | ||
|
||
const ROUNDS_F: usize = 8; | ||
const ROUNDS_P: usize = 13; | ||
|
||
const RATE: usize = 8; | ||
const OUT: usize = 8; | ||
type Hash<T: FieldElementMap> = PaddingFreeSponge<Perm, WIDTH, RATE, OUT>; | ||
|
||
const N: usize = 2; | ||
const CHUNK: usize = 8; | ||
type Compress<T: FieldElementMap> = TruncatedPermutation<Perm, N, CHUNK, WIDTH>; | ||
|
||
const DIGEST_ELEMS: usize = 8; | ||
type ValMmcs<T: FieldElementMap> = FieldMerkleTreeMmcs< | ||
<T::P3Field as Field>::Packing, | ||
<T::P3Field as Field>::Packing, | ||
Hash<T>, | ||
Compress<T>, | ||
DIGEST_ELEMS, | ||
>; | ||
|
||
pub type Val = BabyBear; | ||
|
||
pub type Challenger<T: FieldElementMap> = DuplexChallenger<T::P3Field, Perm, WIDTH, RATE>; | ||
type ChallengeMmcs<T: FieldElementMap> = ExtensionMmcs<T::P3Field, Challenge<T>, ValMmcs<T>>; | ||
type Dft = Radix2DitParallel; | ||
type MyPcs<T: FieldElementMap> = TwoAdicFriPcs<T::P3Field, Dft, ValMmcs<T>, ChallengeMmcs<T>>; | ||
pub type Config<T: FieldElementMap> = StarkConfig<MyPcs<T>, Challenge<T>, Challenger<T>>; | ||
|
||
const FRI_LOG_BLOWUP: usize = 1; | ||
const FRI_NUM_QUERIES: usize = 100; | ||
const FRI_PROOF_OF_WORK_BITS: usize = 16; | ||
|
||
const RNG_SEED: u64 = 42; | ||
|
||
lazy_static! { | ||
static ref PERM_BB: Perm = Perm::new( | ||
ROUNDS_F, | ||
rand_chacha::ChaCha8Rng::seed_from_u64(RNG_SEED) | ||
.sample_iter(Standard) | ||
.take(ROUNDS_F) | ||
.collect::<Vec<[BabyBear; WIDTH]>>(), | ||
Poseidon2ExternalMatrixGeneral, | ||
ROUNDS_P, | ||
rand_chacha::ChaCha8Rng::seed_from_u64(RNG_SEED) | ||
.sample_iter(Standard) | ||
.take(ROUNDS_P) | ||
.collect(), | ||
DiffusionMatrixBabyBear::default() | ||
); | ||
} | ||
|
||
impl FieldElementMap for BabyBearField { | ||
type P3Field = BabyBear; | ||
type MdsMatrix = MdsMatrixBabyBear; | ||
|
||
fn to_p3_field(&self) -> Self::P3Field { | ||
BabyBear::from_canonical_u32(self.to_integer().try_into_u32().unwrap()) | ||
} | ||
} | ||
|
||
pub(crate) fn get_challenger_baby_bear<T: FieldElementMap>() -> Challenger<T> { | ||
Challenger::new(PERM_BB.clone()) | ||
} | ||
|
||
pub(crate) fn get_config_baby_bear<T: FieldElementMap>( | ||
) -> StarkConfig<MyPcs<T>, Challenge<T>, Challenger<T>> { | ||
let hash = Hash::<T>::new(PERM_BB.clone()); | ||
|
||
let compress = Compress::<T>::new(PERM_BB.clone()); | ||
|
||
let val_mmcs = ValMmcs::<T>::new(hash, compress); | ||
|
||
let challenge_mmcs = ChallengeMmcs::<T>::new(val_mmcs.clone()); | ||
|
||
let dft = Dft {}; | ||
|
||
let fri_config = FriConfig { | ||
log_blowup: FRI_LOG_BLOWUP, | ||
num_queries: FRI_NUM_QUERIES, | ||
proof_of_work_bits: FRI_PROOF_OF_WORK_BITS, | ||
mmcs: challenge_mmcs, | ||
}; | ||
|
||
let pcs = MyPcs::<T>::new(dft, val_mmcs, fri_config); | ||
|
||
Config::new(pcs) | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to go through integers, as our BabyBearField type wraps a p3 babybear element. Opened #1761
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in the latest commit