Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Schaeff committed Sep 17, 2024
1 parent 84f3d7f commit cf80bf2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 49 deletions.
26 changes: 13 additions & 13 deletions uni-stark/src/check_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use crate::traits::MultistageAirBuilder;
pub(crate) fn check_constraints<F, A>(
air: &A,
preprocessed: &RowMajorMatrix<F>,
stages: Vec<&RowMajorMatrix<F>>,
public_values: &Vec<&Vec<F>>,
traces_by_stage: Vec<&RowMajorMatrix<F>>,
public_values_by_stage: &Vec<&Vec<F>>,
challenges: Vec<&Vec<F>>,
) where
F: Field,
A: for<'a> Air<DebugConstraintBuilder<'a, F>>,
{
let num_stages = stages.len();
let height = stages[0].height();
let num_stages = traces_by_stage.len();
let height = traces_by_stage[0].height();

(0..height).for_each(|i| {
let i_next = (i + 1) % height;
Expand All @@ -34,7 +34,7 @@ pub(crate) fn check_constraints<F, A>(
RowMajorMatrixView::new_row(&*next_preprocessed),
);

let stages_local_next = stages
let stages_local_next = traces_by_stage
.iter()
.map(|trace| {
let stage_local = trace.row_slice(i);
Expand All @@ -43,7 +43,7 @@ pub(crate) fn check_constraints<F, A>(
})
.collect_vec();

let stages = (0..num_stages)
let traces_by_stage = (0..num_stages)
.map(|stage| {
VerticalPair::new(
RowMajorMatrixView::new_row(&*stages_local_next[stage].0),
Expand All @@ -56,8 +56,8 @@ pub(crate) fn check_constraints<F, A>(
row_index: i,
challenges: challenges.clone(),
preprocessed,
stages,
public_values,
traces_by_stage,
public_values_by_stage,
is_first_row: F::from_bool(i == 0),
is_last_row: F::from_bool(i == height - 1),
is_transition: F::from_bool(i != height - 1),
Expand All @@ -74,8 +74,8 @@ pub struct DebugConstraintBuilder<'a, F: Field> {
row_index: usize,
preprocessed: VerticalPair<RowMajorMatrixView<'a, F>, RowMajorMatrixView<'a, F>>,
challenges: Vec<&'a Vec<F>>,
stages: Vec<VerticalPair<RowMajorMatrixView<'a, F>, RowMajorMatrixView<'a, F>>>,
public_values: &'a [&'a Vec<F>],
traces_by_stage: Vec<VerticalPair<RowMajorMatrixView<'a, F>, RowMajorMatrixView<'a, F>>>,
public_values_by_stage: &'a [&'a Vec<F>],
is_first_row: F,
is_last_row: F,
is_transition: F,
Expand Down Expand Up @@ -107,7 +107,7 @@ where
}

fn main(&self) -> Self::M {
self.stages[0]
self.traces_by_stage[0]
}

fn assert_zero<I: Into<Self::Expr>>(&mut self, x: I) {
Expand Down Expand Up @@ -148,11 +148,11 @@ impl<'a, F: Field> MultistageAirBuilder for DebugConstraintBuilder<'a, F> {
type Challenge = Self::Expr;

fn stage_public_values(&self, stage: usize) -> &[Self::F] {
self.public_values[stage]
self.public_values_by_stage[stage]
}

fn stage_trace(&self, stage: usize) -> Self::M {
self.stages[stage]
self.traces_by_stage[stage]
}

fn stage_challenges(&self, stage: usize) -> &[Self::Expr] {
Expand Down
20 changes: 10 additions & 10 deletions uni-stark/src/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use crate::{PackedChallenge, PackedVal, StarkGenericConfig, Val};
#[derive(Debug)]
pub struct ProverConstraintFolder<'a, SC: StarkGenericConfig> {
pub challenges: Vec<Vec<Val<SC>>>,
pub stages: Vec<RowMajorMatrix<PackedVal<SC>>>,
pub traces_by_stage: Vec<RowMajorMatrix<PackedVal<SC>>>,
pub preprocessed: RowMajorMatrix<PackedVal<SC>>,
pub public_values: &'a Vec<Vec<Val<SC>>>,
pub public_values_by_stage: &'a Vec<Vec<Val<SC>>>,
pub is_first_row: PackedVal<SC>,
pub is_last_row: PackedVal<SC>,
pub is_transition: PackedVal<SC>,
Expand All @@ -26,9 +26,9 @@ type ViewPair<'a, T> = VerticalPair<RowMajorMatrixView<'a, T>, RowMajorMatrixVie
#[derive(Debug)]
pub struct VerifierConstraintFolder<'a, SC: StarkGenericConfig> {
pub challenges: Vec<Vec<Val<SC>>>,
pub stages: Vec<ViewPair<'a, SC::Challenge>>,
pub traces_by_stage: Vec<ViewPair<'a, SC::Challenge>>,
pub preprocessed: ViewPair<'a, SC::Challenge>,
pub public_values: Vec<&'a Vec<Val<SC>>>,
pub public_values_by_stage: Vec<&'a Vec<Val<SC>>>,
pub is_first_row: SC::Challenge,
pub is_last_row: SC::Challenge,
pub is_transition: SC::Challenge,
Expand All @@ -43,7 +43,7 @@ impl<'a, SC: StarkGenericConfig> AirBuilder for ProverConstraintFolder<'a, SC> {
type M = RowMajorMatrix<PackedVal<SC>>;

fn main(&self) -> Self::M {
self.stages[0].clone()
self.traces_by_stage[0].clone()
}

fn is_first_row(&self) -> Self::Expr {
Expand Down Expand Up @@ -81,14 +81,14 @@ impl<'a, SC: StarkGenericConfig> MultistageAirBuilder for ProverConstraintFolder
type Challenge = Val<SC>;

fn stage_trace(&self, stage: usize) -> <Self as AirBuilder>::M {
self.stages[stage].clone()
self.traces_by_stage[stage].clone()
}

fn stage_challenges(&self, stage: usize) -> &[Self::Challenge] {
&self.challenges[stage]
}
fn stage_public_values(&self, stage: usize) -> &[Self::PublicVar] {
&self.public_values[stage]
&self.public_values_by_stage[stage]
}
}

Expand All @@ -105,7 +105,7 @@ impl<'a, SC: StarkGenericConfig> AirBuilder for VerifierConstraintFolder<'a, SC>
type M = ViewPair<'a, SC::Challenge>;

fn main(&self) -> Self::M {
self.stages[0]
self.traces_by_stage[0]
}

fn is_first_row(&self) -> Self::Expr {
Expand Down Expand Up @@ -143,14 +143,14 @@ impl<'a, SC: StarkGenericConfig> MultistageAirBuilder for VerifierConstraintFold
type Challenge = Val<SC>;

fn stage_trace(&self, stage: usize) -> <Self as AirBuilder>::M {
self.stages[stage]
self.traces_by_stage[stage]
}

fn stage_challenges(&self, stage: usize) -> &[Self::Challenge] {
&self.challenges[stage]
}
fn stage_public_values(&self, stage: usize) -> &[Self::PublicVar] {
self.public_values[stage]
self.public_values_by_stage[stage]
}
}

Expand Down
12 changes: 6 additions & 6 deletions uni-stark/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ where
.map(|stage| stage.challenge_values.clone())
.collect();

let public_values = state
let public_values_by_stage = state
.processed_stages
.iter()
.map(|stage| stage.public_values.clone())
.collect();

let quotient_values = quotient_values(
air,
&public_values,
&public_values_by_stage,
trace_domain,
quotient_domain,
preprocessed_on_quotient_domain,
Expand Down Expand Up @@ -304,7 +304,7 @@ where
#[instrument(name = "compute quotient polynomial", skip_all)]
fn quotient_values<'a, SC, A, Mat>(
air: &A,
public_values: &'a Vec<Vec<Val<SC>>>,
public_values_by_stage: &'a Vec<Vec<Val<SC>>>,
trace_domain: Domain<SC>,
quotient_domain: Domain<SC>,
preprocessed_on_quotient_domain: Option<Mat>,
Expand Down Expand Up @@ -360,7 +360,7 @@ where
preprocessed_width,
);

let stages = traces_on_quotient_domain
let traces_by_stage = traces_on_quotient_domain
.iter()
.map(|trace_on_quotient_domain| {
RowMajorMatrix::new(
Expand All @@ -378,9 +378,9 @@ where
let accumulator = PackedChallenge::<SC>::zero();
let mut folder = ProverConstraintFolder {
challenges: challenges.clone(),
stages,
traces_by_stage,
preprocessed,
public_values,
public_values_by_stage,
is_first_row,
is_last_row,
is_transition,
Expand Down
20 changes: 10 additions & 10 deletions uni-stark/src/symbolic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where
A: MultiStageAir<SymbolicAirBuilder<F>>,
{
let widths: Vec<_> = (0..air.stage_count())
.map(|i| air.stage_width(i as u32))
.map(|i| air.stage_trace_width(i as u32))
.collect();
let challenges: Vec<_> = (0..air.stage_count())
.map(|i| air.stage_challenge_count(i as u32))
Expand All @@ -70,8 +70,8 @@ where
pub struct SymbolicAirBuilder<F: Field> {
challenges: Vec<Vec<SymbolicVariable<F>>>,
preprocessed: RowMajorMatrix<SymbolicVariable<F>>,
stages: Vec<RowMajorMatrix<SymbolicVariable<F>>>,
public_values: Vec<Vec<SymbolicVariable<F>>>,
traces_by_stage: Vec<RowMajorMatrix<SymbolicVariable<F>>>,
public_values_by_stage: Vec<Vec<SymbolicVariable<F>>>,
constraints: Vec<SymbolicExpression<F>>,
}

Expand All @@ -89,7 +89,7 @@ impl<F: Field> SymbolicAirBuilder<F> {
.map(move |index| SymbolicVariable::new(Entry::Preprocessed { offset }, index))
})
.collect();
let stages = stage_widths
let traces_by_stage = stage_widths
.iter()
.map(|width| {
let values = [0, 1]
Expand All @@ -116,7 +116,7 @@ impl<F: Field> SymbolicAirBuilder<F> {
})
.collect();
let mut public_value_index = 0;
let public_values = public_value_counts
let public_values_by_stage = public_value_counts
.iter()
.map(|count| {
(0..*count)
Expand All @@ -131,8 +131,8 @@ impl<F: Field> SymbolicAirBuilder<F> {
Self {
challenges,
preprocessed: RowMajorMatrix::new(prep_values, preprocessed_width),
stages,
public_values,
traces_by_stage,
public_values_by_stage,
constraints: vec![],
}
}
Expand All @@ -149,7 +149,7 @@ impl<F: Field> AirBuilder for SymbolicAirBuilder<F> {
type M = RowMajorMatrix<Self::Var>;

fn main(&self) -> Self::M {
self.stages[0].clone()
self.traces_by_stage[0].clone()
}

fn is_first_row(&self) -> Self::Expr {
Expand Down Expand Up @@ -185,11 +185,11 @@ impl<F: Field> MultistageAirBuilder for SymbolicAirBuilder<F> {
type Challenge = Self::Var;

fn stage_public_values(&self, stage: usize) -> &[Self::PublicVar] {
&self.public_values[stage]
&self.public_values_by_stage[stage]
}

fn stage_trace(&self, stage: usize) -> Self::M {
self.stages[stage].clone()
self.traces_by_stage[stage].clone()
}

fn stage_challenges(&self, stage: usize) -> &[Self::Challenge] {
Expand Down
5 changes: 3 additions & 2 deletions uni-stark/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub trait MultistageAirBuilder: AirBuilderWithPublicValues {
/// Challenges from each stage, drawn from the base field
fn stage_challenges(&self, stage: usize) -> &[Self::Challenge];

/// Public values for each stage
fn stage_public_values(&self, stage: usize) -> &[Self::PublicVar] {
match stage {
0 => self.public_values(),
Expand All @@ -22,8 +23,8 @@ pub trait MultiStageAir<AB: AirBuilder>: Air<AB> {
1
}

/// The number of columns in a given higher-stage trace.
fn stage_width(&self, stage: u32) -> usize {
/// The number of trace columns in this stage
fn stage_trace_width(&self, stage: u32) -> usize {
match stage {
0 => self.width(),
_ => unimplemented!(),
Expand Down
17 changes: 9 additions & 8 deletions uni-stark/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn verify_with_key<SC, A>(
air: &A,
challenger: &mut SC::Challenger,
proof: &Proof<SC>,
public_values: Vec<&Vec<Val<SC>>>,
public_values_by_stage: Vec<&Vec<Val<SC>>>,
) -> Result<(), VerificationError<PcsError<SC>>>
where
SC: StarkGenericConfig,
Expand All @@ -57,7 +57,7 @@ where
let degree = 1 << degree_bits;
let log_quotient_degree = get_log_quotient_degree::<Val<SC>, A>(
air,
&public_values
&public_values_by_stage
.iter()
.map(|values| values.len())
.collect::<Vec<_>>(),
Expand All @@ -76,7 +76,7 @@ where

let air_widths = (0..stage_count)
.map(|stage| {
<A as MultiStageAir<SymbolicAirBuilder<Val<SC>>>>::stage_width(air, stage as u32)
<A as MultiStageAir<SymbolicAirBuilder<Val<SC>>>>::stage_trace_width(air, stage as u32)
})
.collect::<Vec<usize>>();
let air_fixed_width = <A as BaseAir<Val<SC>>>::preprocessed_width(air);
Expand All @@ -97,8 +97,9 @@ where
.quotient_chunks
.iter()
.all(|qc| qc.len() == <SC::Challenge as AbstractExtensionField<Val<SC>>>::D)
&& public_values.len() == stage_count
&& public_values_by_stage.len() == stage_count
&& challenge_counts.len() == stage_count;

if !valid_shape {
return Err(VerificationError::InvalidProofShape);
}
Expand All @@ -120,7 +121,7 @@ where
commitments
.traces_by_stage
.iter()
.zip(&public_values)
.zip(&public_values_by_stage)
.zip(challenge_counts)
.for_each(|((commitment, public_values), challenge_count)| {
challenger.observe(commitment.clone());
Expand Down Expand Up @@ -220,7 +221,7 @@ where
RowMajorMatrixView::new_row(&opened_values.preprocessed_next),
);

let stages = opened_values
let traces_by_stage = opened_values
.traces_by_stage_local
.iter()
.zip(opened_values.traces_by_stage_next.iter())
Expand All @@ -235,8 +236,8 @@ where
let mut folder = VerifierConstraintFolder {
challenges,
preprocessed,
stages,
public_values,
traces_by_stage,
public_values_by_stage,
is_first_row: sels.is_first_row,
is_last_row: sels.is_last_row,
is_transition: sels.is_transition,
Expand Down

0 comments on commit cf80bf2

Please sign in to comment.