Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-deng committed Sep 30, 2024
1 parent dc77c77 commit 0b557bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 46 deletions.
41 changes: 20 additions & 21 deletions starky/src/cross_table_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::lookup::{
eval_helper_columns, eval_helper_columns_circuit, get_grand_product_challenge_set,
get_helper_cols, Column, ColumnFilter, Filter, GrandProductChallenge, GrandProductChallengeSet,
};
use crate::proof::{MultiProof, StarkProofTarget, StarkProofWithMetadata};
use crate::proof::StarkProofTarget;
use crate::stark::Stark;

/// An alias for `usize`, to represent the index of a STARK table in a multi-STARK setting.
Expand Down Expand Up @@ -250,7 +250,8 @@ where

/// Outputs all the CTL data necessary to prove a multi-STARK system.
pub fn get_ctl_vars_from_proofs<'a, F, C, const D: usize, const N: usize>(
multi_proof: &MultiProof<F, C, D, N>,
auxiliary_polys: &[&Option<Vec<F::Extension>>; N],
auxiliary_polys_next: &[&Option<Vec<F::Extension>>; N],
all_cross_table_lookups: &'a [CrossTableLookup<F>],
ctl_challenges: &'a GrandProductChallengeSet<F>,
num_lookup_columns: &'a [usize; N],
Expand All @@ -264,8 +265,9 @@ where
let num_ctl_helper_cols =
num_ctl_helper_columns_by_table(all_cross_table_lookups, max_constraint_degree);

CtlCheckVars::from_proofs(
&multi_proof.stark_proofs,
CtlCheckVars::from_proofs::<C,N>(
auxiliary_polys,
auxiliary_polys_next,
all_cross_table_lookups,
ctl_challenges,
num_lookup_columns,
Expand Down Expand Up @@ -491,7 +493,8 @@ impl<'a, F: RichField + Extendable<D>, const D: usize>
{
/// Extracts the `CtlCheckVars` for each STARK.
pub fn from_proofs<C: GenericConfig<D, F = F>, const N: usize>(
proofs: &[StarkProofWithMetadata<F, C, D>; N],
auxiliary_polys: &[&Option<Vec<F::Extension>>; N],
auxiliary_polys_next: &[&Option<Vec<F::Extension>>; N],
cross_table_lookups: &'a [CrossTableLookup<F>],
ctl_challenges: &'a GrandProductChallengeSet<F>,
num_lookup_columns: &[usize; N],
Expand All @@ -501,10 +504,7 @@ impl<'a, F: RichField + Extendable<D>, const D: usize>
// If there are no auxiliary polys in the proofs `openings`,
// return early. The verifier will reject the proofs when
// calling `validate_proof_shape`.
if proofs
.iter()
.any(|p| p.proof.openings.auxiliary_polys.is_none())
{
if auxiliary_polys.iter().any(|&aux_polys| aux_polys.is_none()) {
return ctl_vars_per_table;
}

Expand All @@ -516,21 +516,20 @@ impl<'a, F: RichField + Extendable<D>, const D: usize>
}

// Get all cross-table lookup polynomial openings for each STARK proof.
let ctl_zs = proofs
let ctl_zs = auxiliary_polys
.iter()
.zip(num_lookup_columns)
.map(|(p, &num_lookup)| {
let openings = &p.proof.openings;

let ctl_zs = &openings
.auxiliary_polys
.zip(auxiliary_polys_next.iter())
.zip(num_lookup_columns.iter())
.map(|((&aux_polys, &aux_polys_next), &num_lookup)| {
// Ensure we have auxiliary polynomials for both current and next steps
let ctl_zs = &aux_polys
.as_ref()
.expect("We cannot have CTls without auxiliary polynomials.")[num_lookup..];
let ctl_zs_next = &openings
.auxiliary_polys_next
.expect("We cannot have CTLs without auxiliary polynomials.")[num_lookup..];
let ctl_zs_next = &aux_polys_next
.as_ref()
.expect("We cannot have CTls without auxiliary polynomials.")[num_lookup..];
ctl_zs.iter().zip(ctl_zs_next).collect::<Vec<_>>()
.expect("We cannot have CTLs without auxiliary polynomials.")[num_lookup..];

ctl_zs.iter().zip(ctl_zs_next.iter()).collect::<Vec<_>>()
})
.collect::<Vec<_>>();

Expand Down
25 changes: 0 additions & 25 deletions starky/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,6 @@ where
pub proof: StarkProof<F, C, D>,
}

/// A combination of STARK proofs for independent statements operating on possibly shared variables,
/// along with Cross-Table Lookup (CTL) challenges to assert consistency of common variables across tables.
#[derive(Debug, Clone)]
pub struct MultiProof<
F: RichField + Extendable<D>,
C: GenericConfig<D, F = F>,
const D: usize,
const N: usize,
> {
/// Proofs for all the different STARK modules.
pub stark_proofs: [StarkProofWithMetadata<F, C, D>; N],
/// Cross-table lookup challenges.
pub ctl_challenges: GrandProductChallengeSet<F>,
}

impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize, const N: usize>
MultiProof<F, C, D, N>
{
/// Returns the degree (i.e. the trace length) of each STARK proof,
/// from their common [`StarkConfig`].
pub fn recover_degree_bits(&self, config: &StarkConfig) -> [usize; N] {
core::array::from_fn(|i| self.stark_proofs[i].proof.recover_degree_bits(config))
}
}

/// Randomness used for a STARK proof.
#[derive(Debug)]
pub struct StarkProofChallenges<F: RichField + Extendable<D>, const D: usize> {
Expand Down

0 comments on commit 0b557bd

Please sign in to comment.