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

Prove Starks without constraints #1552

Merged
merged 21 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
4 changes: 1 addition & 3 deletions field/src/polynomial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ impl<F: Field> PolynomialValues<F> {
}

pub fn degree(&self) -> usize {
self.degree_plus_one()
.checked_sub(1)
.expect("deg(0) is undefined")
self.degree_plus_one().saturating_sub(1)
}

pub fn degree_plus_one(&self) -> usize {
Expand Down
10 changes: 8 additions & 2 deletions plonky2/src/recursion/recursive_verifier.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use alloc::vec;

use crate::field::extension::Extendable;
use crate::hash::hash_types::{HashOutTarget, RichField};
use crate::plonk::circuit_builder::CircuitBuilder;
Expand Down Expand Up @@ -149,13 +152,16 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
let cap_height = fri_params.config.cap_height;

let salt = salt_size(common_data.fri_params.hiding);
let num_leaves_per_oracle = &[
let num_leaves_per_oracle = &mut vec![
common_data.num_preprocessed_polys(),
config.num_wires + salt,
common_data.num_zs_partial_products_polys() + common_data.num_all_lookup_polys() + salt,
common_data.num_quotient_polys() + salt,
];

if common_data.num_quotient_polys() > 0 {
num_leaves_per_oracle.push(common_data.num_quotient_polys() + salt);
}

ProofTarget {
wires_cap: self.add_virtual_cap(cap_height),
plonk_zs_partial_products_cap: self.add_virtual_cap(cap_height),
Expand Down
17 changes: 11 additions & 6 deletions starky/src/get_challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn get_challenges<F, C, const D: usize>(
challenges: Option<&GrandProductChallengeSet<F>>,
trace_cap: Option<&MerkleCap<F, C::Hasher>>,
auxiliary_polys_cap: Option<&MerkleCap<F, C::Hasher>>,
quotient_polys_cap: &MerkleCap<F, C::Hasher>,
quotient_polys_cap: Option<&MerkleCap<F, C::Hasher>>,
openings: &StarkOpeningSet<F, D>,
commit_phase_merkle_caps: &[MerkleCap<F, C::Hasher>],
final_poly: &PolynomialCoeffs<F::Extension>,
Expand Down Expand Up @@ -60,7 +60,9 @@ where

let stark_alphas = challenger.get_n_challenges(num_challenges);

challenger.observe_cap(quotient_polys_cap);
if let Some(quotient_polys_cap) = quotient_polys_cap {
challenger.observe_cap(quotient_polys_cap);
}
let stark_zeta = challenger.get_extension_challenge::<D>();

challenger.observe_openings(&openings.to_fri_openings());
Expand Down Expand Up @@ -125,7 +127,7 @@ where
challenges,
trace_cap,
auxiliary_polys_cap.as_ref(),
quotient_polys_cap,
quotient_polys_cap.as_ref(),
openings,
commit_phase_merkle_caps,
final_poly,
Expand Down Expand Up @@ -168,7 +170,7 @@ fn get_challenges_target<F, C, const D: usize>(
challenges: Option<&GrandProductChallengeSet<Target>>,
trace_cap: Option<&MerkleCapTarget>,
auxiliary_polys_cap: Option<&MerkleCapTarget>,
quotient_polys_cap: &MerkleCapTarget,
quotient_polys_cap: Option<&MerkleCapTarget>,
openings: &StarkOpeningSetTarget<D>,
commit_phase_merkle_caps: &[MerkleCapTarget],
final_poly: &PolynomialCoeffsExtTarget<D>,
Expand Down Expand Up @@ -200,7 +202,10 @@ where

let stark_alphas = challenger.get_n_challenges(builder, num_challenges);

challenger.observe_cap(quotient_polys_cap);
if let Some(cap) = quotient_polys_cap {
challenger.observe_cap(cap);
}

let stark_zeta = challenger.get_extension_challenge(builder);

challenger.observe_openings(&openings.to_fri_openings(builder.zero()));
Expand Down Expand Up @@ -266,7 +271,7 @@ impl<const D: usize> StarkProofTarget<D> {
challenges,
trace_cap,
auxiliary_polys_cap.as_ref(),
quotient_polys_cap,
quotient_polys_cap.as_ref(),
openings,
commit_phase_merkle_caps,
final_poly,
Expand Down
2 changes: 2 additions & 0 deletions starky/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,5 @@ pub mod verifier;

#[cfg(test)]
pub mod fibonacci_stark;
#[cfg(test)]
pub mod permutation_stark;
48 changes: 27 additions & 21 deletions starky/src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ impl<F: Field> Lookup<F> {
pub fn num_helper_columns(&self, constraint_degree: usize) -> usize {
// One helper column for each column batch of size `constraint_degree-1`,
// then one column for the inverse of `table + challenge` and one for the `Z` polynomial.
ceil_div_usize(self.columns.len(), constraint_degree - 1) + 1
ceil_div_usize(
self.columns.len(),
constraint_degree.checked_sub(1).unwrap_or(1),
) + 1
}
}

Expand Down Expand Up @@ -577,7 +580,7 @@ pub(crate) fn lookup_helper_columns<F: Field>(
constraint_degree: usize,
) -> Vec<PolynomialValues<F>> {
assert!(
constraint_degree == 2 || constraint_degree == 3,
constraint_degree <= 3,
"TODO: Allow other constraint degrees."
Nashtare marked this conversation as resolved.
Show resolved Hide resolved
);

Expand Down Expand Up @@ -666,12 +669,12 @@ pub(crate) fn eval_helper_columns<F, FE, P, const D: usize, const D2: usize>(
P: PackedField<Scalar = FE>,
{
if !helper_columns.is_empty() {
for (j, chunk) in columns.chunks(constraint_degree - 1).enumerate() {
let fs =
&filter[(constraint_degree - 1) * j..(constraint_degree - 1) * j + chunk.len()];
let h = helper_columns[j];

match chunk.len() {
let chunk_size = constraint_degree.checked_sub(1).unwrap_or(1);
for (chunk, (fs, &h)) in columns
.chunks(chunk_size)
.zip(filter.chunks(chunk_size).zip(helper_columns))
{
match chunk_size {
2 => {
let combin0 = challenges.combine(&chunk[0]);
let combin1 = challenges.combine(chunk[1].iter());
Expand Down Expand Up @@ -719,9 +722,12 @@ pub(crate) fn eval_helper_columns_circuit<F: RichField + Extendable<D>, const D:
consumer: &mut RecursiveConstraintConsumer<F, D>,
) {
if !helper_columns.is_empty() {
for (j, chunk) in columns.chunks(constraint_degree - 1).enumerate() {
let fs =
&filter[(constraint_degree - 1) * j..(constraint_degree - 1) * j + chunk.len()];
for (j, chunk) in columns
.chunks(constraint_degree.checked_sub(1).unwrap_or(1))
.enumerate()
{
let fs = &filter[(constraint_degree.saturating_sub(1)) * j
..(constraint_degree.saturating_sub(1)) * j + chunk.len()];
4l0n50 marked this conversation as resolved.
Show resolved Hide resolved
let h = helper_columns[j];

let one = builder.one_extension();
Expand Down Expand Up @@ -774,11 +780,17 @@ pub(crate) fn get_helper_cols<F: Field>(
challenge: GrandProductChallenge<F>,
constraint_degree: usize,
) -> Vec<PolynomialValues<F>> {
let num_helper_columns = ceil_div_usize(columns_filters.len(), constraint_degree - 1);
let num_helper_columns = ceil_div_usize(
columns_filters.len(),
constraint_degree.checked_sub(1).unwrap_or(1),
);

let mut helper_columns = Vec::with_capacity(num_helper_columns);

for mut cols_filts in &columns_filters.iter().chunks(constraint_degree - 1) {
for mut cols_filts in &columns_filters
.iter()
.chunks(constraint_degree.checked_sub(1).unwrap_or(1))
{
let (first_col, first_filter) = cols_filts.next().unwrap();

let mut filter_col = Vec::with_capacity(degree);
Expand Down Expand Up @@ -885,10 +897,7 @@ pub(crate) fn eval_packed_lookups_generic<F, FE, P, S, const D: usize, const D2:
let local_values = vars.get_local_values();
let next_values = vars.get_next_values();
let degree = stark.constraint_degree();
assert!(
degree == 2 || degree == 3,
"TODO: Allow other constraint degrees."
);
assert!(degree <= 3, "TODO: Allow other constraint degrees.");
4l0n50 marked this conversation as resolved.
Show resolved Hide resolved
let mut start = 0;
for lookup in lookups {
let num_helper_columns = lookup.num_helper_columns(degree);
Expand Down Expand Up @@ -958,10 +967,7 @@ pub(crate) fn eval_ext_lookups_circuit<

let local_values = vars.get_local_values();
let next_values = vars.get_next_values();
assert!(
degree == 2 || degree == 3,
"TODO: Allow other constraint degrees."
);
assert!(degree <= 3, "TODO: Allow other constraint degrees.");
4l0n50 marked this conversation as resolved.
Show resolved Hide resolved
let mut start = 0;
for lookup in lookups {
let num_helper_columns = lookup.num_helper_columns(degree);
Expand Down
Loading