Skip to content
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

Refactor CTL Handling #1629

Merged
merged 8 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the name is slightly misleading now, as we're not passing the multi_proof as arg anymore. What about get_ctl_vars_from_aux_polys?

multi_proof: &MultiProof<F, C, D, N>,
auxiliary_polys: &[&Option<Vec<F::Extension>>; N],
auxiliary_polys_next: &[&Option<Vec<F::Extension>>; N],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these could share the same lifetimes as below

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
3 changes: 2 additions & 1 deletion starky/src/fibonacci_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const FIBONACCI_COLUMNS: usize = 2;
const FIBONACCI_PUBLIC_INPUTS: usize = 3;

impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for FibonacciStark<F, D> {
type EvaluationFrame<FE, P, const D2: usize> = StarkFrame<P, P::Scalar, FIBONACCI_COLUMNS, FIBONACCI_PUBLIC_INPUTS>
type EvaluationFrame<FE, P, const D2: usize>
= StarkFrame<P, P::Scalar, FIBONACCI_COLUMNS, FIBONACCI_PUBLIC_INPUTS>
where
FE: FieldExtension<D2, BaseField = F>,
P: PackedField<Scalar = FE>;
Expand Down
3 changes: 2 additions & 1 deletion starky/src/permutation_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const PERM_COLUMNS: usize = 3;
const PERM_PUBLIC_INPUTS: usize = 1;

impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for PermutationStark<F, D> {
type EvaluationFrame<FE, P, const D2: usize> = StarkFrame<P, P::Scalar, PERM_COLUMNS, PERM_PUBLIC_INPUTS>
type EvaluationFrame<FE, P, const D2: usize>
= StarkFrame<P, P::Scalar, PERM_COLUMNS, PERM_PUBLIC_INPUTS>
where
FE: FieldExtension<D2, BaseField = F>,
P: PackedField<Scalar = FE>;
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))
}
}

Nashtare marked this conversation as resolved.
Show resolved Hide resolved
/// Randomness used for a STARK proof.
#[derive(Debug)]
pub struct StarkProofChallenges<F: RichField + Extendable<D>, const D: usize> {
Expand Down
3 changes: 2 additions & 1 deletion starky/src/unconstrained_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const COLUMNS: usize = 2;
const PUBLIC_INPUTS: usize = 0;

impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for UnconstrainedStark<F, D> {
type EvaluationFrame<FE, P, const D2: usize> = StarkFrame<P, P::Scalar, COLUMNS, PUBLIC_INPUTS>
type EvaluationFrame<FE, P, const D2: usize>
= StarkFrame<P, P::Scalar, COLUMNS, PUBLIC_INPUTS>
where
FE: FieldExtension<D2, BaseField = F>,
P: PackedField<Scalar = FE>;
Expand Down