Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
kevjue committed Apr 8, 2024
2 parents 4480b4f + 13c36fb commit dc9f1f9
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 125 deletions.
50 changes: 29 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ debug = true
debug-assertions = true

[workspace.dependencies]
p3-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-field = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-util = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-dft = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-fri = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-keccak = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-keccak-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-blake3 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-mds = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
p3-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-field = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-commit = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-matrix = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-baby-bear = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-util = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-challenger = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-dft = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-fri = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-goldilocks = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-keccak = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-keccak-air = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-blake3 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-mds = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-merkle-tree = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-poseidon2 = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-symmetric = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-uni-stark = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-maybe-rayon = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }
p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "random-var" }

# For local development.
#

# p3-air = { path = "../Plonky3/air" }
# p3-field = { path = "../Plonky3/field" }
# p3-commit = { path = "../Plonky3/commit" }
Expand All @@ -70,4 +70,4 @@ p3-bn254-fr = { git = "https://github.com/Plonky3/Plonky3.git", branch = "sp1" }
# p3-symmetric = { path = "../Plonky3/symmetric" }
# p3-uni-stark = { path = "../Plonky3/uni-stark" }
# p3-maybe-rayon = { path = "../Plonky3/maybe-rayon" }
# p3-bn254-fr = { path = "../Plonky3/bn254-fr" }
# p3-bn254-fr = { path = "../Plonky3/bn254-fr" }
2 changes: 2 additions & 0 deletions core/src/stark/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ where
{
type MP = TwoRowMatrixView<'a, EF>;

type RandomVar = EF;

fn permutation(&self) -> Self::MP {
self.perm
}
Expand Down
13 changes: 8 additions & 5 deletions core/src/stark/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct ProverConstraintFolder<'a, SC: StarkGenericConfig> {
pub preprocessed: TwoRowMatrixView<'a, PackedVal<SC>>,
pub main: TwoRowMatrixView<'a, PackedVal<SC>>,
pub perm: TwoRowMatrixView<'a, PackedChallenge<SC>>,
pub perm_challenges: &'a [SC::Challenge],
pub perm_challenges: &'a [PackedChallenge<SC>],
pub cumulative_sum: SC::Challenge,
pub is_first_row: PackedVal<SC>,
pub is_last_row: PackedVal<SC>,
Expand Down Expand Up @@ -79,11 +79,13 @@ impl<'a, SC: StarkGenericConfig> ExtensionBuilder for ProverConstraintFolder<'a,
impl<'a, SC: StarkGenericConfig> PermutationAirBuilder for ProverConstraintFolder<'a, SC> {
type MP = TwoRowMatrixView<'a, PackedChallenge<SC>>;

type RandomVar = PackedChallenge<SC>;

fn permutation(&self) -> Self::MP {
self.perm
}

fn permutation_randomness(&self) -> &[Self::EF] {
fn permutation_randomness(&self) -> &[Self::RandomVar] {
self.perm_challenges
}
}
Expand Down Expand Up @@ -120,15 +122,15 @@ pub struct GenericVerifierConstraintFolder<'a, F, EF, Var, Expr> {
pub preprocessed: TwoRowMatrixView<'a, Var>,
pub main: TwoRowMatrixView<'a, Var>,
pub perm: TwoRowMatrixView<'a, Var>,
pub perm_challenges: &'a [EF],
pub perm_challenges: &'a [Var],
pub cumulative_sum: Var,
pub is_first_row: Var,
pub is_last_row: Var,
pub is_transition: Var,
pub alpha: Var,
pub accumulator: Expr,
pub public_values: &'a [F],
pub _marker: PhantomData<F>,
pub _marker: PhantomData<(F, EF)>,
}

impl<'a, F, EF, Var, Expr> AirBuilder for GenericVerifierConstraintFolder<'a, F, EF, Var, Expr>
Expand Down Expand Up @@ -253,12 +255,13 @@ where
+ Mul<Expr, Output = Expr>,
{
type MP = TwoRowMatrixView<'a, Var>;
type RandomVar = Var;

fn permutation(&self) -> Self::MP {
self.perm
}

fn permutation_randomness(&self) -> &[Self::EF] {
fn permutation_randomness(&self) -> &[Self::Var] {
self.perm_challenges
}
}
Expand Down
15 changes: 8 additions & 7 deletions core/src/stark/permutation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use p3_air::{ExtensionBuilder, PairBuilder};
use p3_field::{AbstractExtensionField, AbstractField, ExtensionField, Field, Powers, PrimeField};
use p3_field::{AbstractField, ExtensionField, Field, Powers, PrimeField};
use p3_matrix::{dense::RowMajorMatrix, Matrix, MatrixRowSlices};
use p3_maybe_rayon::prelude::*;

Expand All @@ -9,11 +9,11 @@ use crate::{air::MultiTableAirBuilder, lookup::Interaction};
/// Generates powers of a random element based on how many interactions there are in the chip.
///
/// These elements are used to uniquely fingerprint each interaction.
pub fn generate_interaction_rlc_elements<F: Field, EF: AbstractExtensionField<F>>(
pub fn generate_interaction_rlc_elements<F: Field, AF: AbstractField>(
sends: &[Interaction<F>],
receives: &[Interaction<F>],
random_element: EF,
) -> Vec<EF> {
random_element: AF,
) -> Vec<AF> {
let n = sends
.iter()
.chain(receives.iter())
Expand Down Expand Up @@ -183,7 +183,8 @@ pub fn eval_permutation_constraints<F, AB>(
AB: MultiTableAirBuilder<F = F> + PairBuilder,
{
let random_elements = builder.permutation_randomness();
let (alpha, beta) = (random_elements[0], random_elements[1]);
let (alpha, beta): (AB::ExprEF, AB::ExprEF) =
(random_elements[0].into(), random_elements[1].into());

let main = builder.main();
let main_local: &[AB::Var] = main.row_slice(0);
Expand Down Expand Up @@ -214,9 +215,9 @@ pub fn eval_permutation_constraints<F, AB>(
let mut rlc = AB::ExprEF::zero();
for (field, beta) in interaction.values.iter().zip(betas.clone()) {
let elem = field.apply::<AB::Expr, AB::Var>(preprocessed_local, main_local);
rlc += AB::ExprEF::from_f(beta) * elem;
rlc += beta * elem;
}
rlc += AB::ExprEF::from_f(alphas[interaction.argument_index()]);
rlc += alphas[interaction.argument_index()].clone();
builder.assert_one_ext(rlc * perm_local[m].into());

let mult_local = interaction
Expand Down
Loading

0 comments on commit dc9f1f9

Please sign in to comment.