Skip to content

Commit

Permalink
perf(prover): powers of alpha (#2000)
Browse files Browse the repository at this point in the history
Co-authored-by: nhtyy <[email protected]>
Co-authored-by: Yuwen Zhang <[email protected]>
Co-authored-by: jtguibas <[email protected]>
Co-authored-by: Ratan Kaliani <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: rkm0959 <[email protected]>
Co-authored-by: Aurélien <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: srdtrk <[email protected]>
Co-authored-by: Matt Stam <[email protected]>
Co-authored-by: Ivan Mikushin <[email protected]>
Co-authored-by: Abishek Bashyal <[email protected]>
Co-authored-by: DevOrbitlabs <[email protected]>
Co-authored-by: Gengar <[email protected]>
Co-authored-by: crStiv <[email protected]>
Co-authored-by: Chris T. <[email protected]>
  • Loading branch information
17 people authored Jan 29, 2025
1 parent a78d2b6 commit 1721066
Show file tree
Hide file tree
Showing 13 changed files with 824 additions and 625 deletions.
264 changes: 159 additions & 105 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion audits/sp1-v4.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ builder

The global interaction system works as follows. Each chip that needs to send a global interaction, first sends an interaction with `InteractionKind::Global` locally. Then, the `GlobalChip` receives these local interactions with `InteractionKind::Global`, then converts these messages into digests and accumulates them, making the results global.

However, while these informations are sent locally with `InteractionKind::Global`, there are actually two different "actual" `InteractionKind`s - `Memory` and `Syscall`.
However, while these information are sent locally with `InteractionKind::Global`, there are actually two different "actual" `InteractionKind`s - `Memory` and `Syscall`.

The vulnerability was in that the actual underlying `InteractionKind` was not sent as a part of the local interaction between the chips and `GlobalChip`. Therefore, a "memory" interaction could be regarded as "syscall" interaction, and vice versa.

Expand Down
7 changes: 5 additions & 2 deletions crates/core/machine/src/utils/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use p3_air::Air;
use p3_baby_bear::BabyBear;
use p3_matrix::dense::RowMajorMatrix;
use p3_uni_stark::SymbolicAirBuilder;
use serde::{de::DeserializeOwned, Serialize};
use sp1_core_executor::{ExecutionRecord, Executor, Program, SP1Context};
use sp1_primitives::io::SP1PublicValues;
Expand Down Expand Up @@ -128,7 +129,8 @@ where
A: MachineAir<SC::Val>
+ Air<InteractionBuilder<Val<SC>>>
+ for<'a> Air<VerifierConstraintFolder<'a, SC>>
+ for<'a> Air<DebugConstraintBuilder<'a, Val<SC>, SC::Challenge>>,
+ for<'a> Air<DebugConstraintBuilder<'a, Val<SC>, SC::Challenge>>
+ Air<SymbolicAirBuilder<SC::Val>>,
A::Record: MachineRecord<Config = SP1CoreOpts>,
SC: StarkGenericConfig,
SC::Val: p3_field::PrimeField32,
Expand Down Expand Up @@ -169,7 +171,8 @@ where
+ for<'a> Air<ProverConstraintFolder<'a, SC>>
+ Air<InteractionBuilder<Val<SC>>>
+ for<'a> Air<VerifierConstraintFolder<'a, SC>>
+ for<'a> Air<DebugConstraintBuilder<'a, Val<SC>, SC::Challenge>>,
+ for<'a> Air<DebugConstraintBuilder<'a, Val<SC>, SC::Challenge>>
+ Air<SymbolicAirBuilder<SC::Val>>,
A::Record: MachineRecord<Config = SP1CoreOpts>,
SC: StarkGenericConfig,
SC::Val: p3_field::PrimeField32,
Expand Down
1 change: 1 addition & 0 deletions crates/recursion/circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ p3-challenger = { workspace = true }
p3-dft = { workspace = true }
p3-bn254-fr = { workspace = true }
p3-baby-bear = { workspace = true }
p3-uni-stark = { workspace = true }

sp1-core-machine = { workspace = true }
sp1-core-executor = { workspace = true }
Expand Down
16 changes: 10 additions & 6 deletions crates/stark/src/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ pub struct ProverConstraintFolder<'a, SC: StarkGenericConfig> {
pub is_last_row: PackedVal<SC>,
/// The selector for the transition.
pub is_transition: PackedVal<SC>,
/// The constraint folding challenge.
pub alpha: SC::Challenge,
/// The powers of the constraint folding challenge.
pub powers_of_alpha: &'a Vec<SC::Challenge>,
/// The accumulator for the constraint folding.
pub accumulator: PackedChallenge<SC>,
/// The public values.
pub public_values: &'a [Val<SC>],
/// The constraint index.
pub constraint_index: usize,
}

impl<'a, SC: StarkGenericConfig> AirBuilder for ProverConstraintFolder<'a, SC> {
Expand Down Expand Up @@ -77,8 +79,9 @@ impl<'a, SC: StarkGenericConfig> AirBuilder for ProverConstraintFolder<'a, SC> {

fn assert_zero<I: Into<Self::Expr>>(&mut self, x: I) {
let x: PackedVal<SC> = x.into();
self.accumulator *= PackedChallenge::<SC>::from_f(self.alpha);
self.accumulator += x;
self.accumulator +=
PackedChallenge::<SC>::from_f(self.powers_of_alpha[self.constraint_index]) * x;
self.constraint_index += 1;
}
}

Expand All @@ -94,8 +97,9 @@ impl<SC: StarkGenericConfig> ExtensionBuilder for ProverConstraintFolder<'_, SC>
I: Into<Self::ExprEF>,
{
let x: PackedChallenge<SC> = x.into();
self.accumulator *= PackedChallenge::<SC>::from_f(self.alpha);
self.accumulator += x;
self.accumulator +=
PackedChallenge::<SC>::from_f(self.powers_of_alpha[self.constraint_index]) * x;
self.constraint_index += 1;
}
}

Expand Down
3 changes: 1 addition & 2 deletions crates/stark/src/lookup/debug.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::BTreeMap;

use p3_baby_bear::BabyBear;
use p3_field::{AbstractField, Field, PrimeField32, PrimeField64};
use p3_matrix::Matrix;
use std::collections::BTreeMap;

use super::InteractionKind;
use crate::{
Expand Down
Loading

0 comments on commit 1721066

Please sign in to comment.