Simplification

This commit is contained in:
wborgeaud 2022-02-22 17:00:08 +01:00
parent 4ea418a486
commit 150d764440
5 changed files with 33 additions and 49 deletions

View File

@ -13,7 +13,7 @@ use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars};
/// Toy STARK system used for testing.
/// Computes a Fibonacci sequence with state `[x0, x1, i, j]` using the state transition
/// `x0' <- x1, x1' <- x0 + x1, i' <- i+1, j' <- j+1`.
/// Note: The `i, j` columns are used to test the permutation argument.
/// Note: The `i, j` columns are only used to test the permutation argument.
#[derive(Copy, Clone)]
struct FibonacciStark<F: RichField + Extendable<D>, const D: usize> {
num_rows: usize,
@ -48,7 +48,7 @@ impl<F: RichField + Extendable<D>, const D: usize> FibonacciStark<F, D> {
Some(tmp)
})
.collect::<Vec<_>>();
trace[self.num_rows - 1][3] = F::ZERO;
trace[self.num_rows - 1][3] = F::ZERO; // So that column 2 and 3 are permutation of one another.
trace
}
}
@ -234,7 +234,7 @@ mod tests {
let pt = add_virtual_stark_proof_with_pis(&mut builder, stark, inner_config, degree_bits);
set_stark_proof_with_pis_target(&mut pw, &pt, &inner_proof);
recursively_verify_stark_proof::<F, InnerC, S, D>(&mut builder, stark, pt, inner_config)?;
recursively_verify_stark_proof::<F, InnerC, S, D>(&mut builder, stark, pt, inner_config);
if print_gate_counts {
builder.print_gate_counts(0);

View File

@ -1,4 +1,3 @@
use anyhow::Result;
use plonky2::field::extension_field::Extendable;
use plonky2::field::polynomial::PolynomialCoeffs;
use plonky2::fri::proof::{FriProof, FriProofTarget};
@ -28,7 +27,7 @@ fn get_challenges<F, C, S, const D: usize>(
pow_witness: F,
config: &StarkConfig,
degree_bits: usize,
) -> Result<StarkProofChallenges<F, D>>
) -> StarkProofChallenges<F, D>
where
F: RichField + Extendable<D>,
C: GenericConfig<D, F = F>,
@ -40,20 +39,15 @@ where
challenger.observe_cap(trace_cap);
let permutation_challenge_sets = if stark.uses_permutation_args() {
get_n_permutation_challenge_sets(
let permutation_challenge_sets = permutation_zs_cap.map(|permutation_zs_cap| {
let tmp = get_n_permutation_challenge_sets(
&mut challenger,
num_challenges,
stark.permutation_batch_size(),
)
} else {
vec![]
};
if stark.uses_permutation_args() {
let cap =
permutation_zs_cap.ok_or_else(|| anyhow::Error::msg("expected permutation_zs_cap"));
challenger.observe_cap(cap?);
}
);
challenger.observe_cap(permutation_zs_cap);
tmp
});
let stark_alphas = challenger.get_n_challenges(num_challenges);
@ -62,7 +56,7 @@ where
challenger.observe_openings(&openings.to_fri_openings());
Ok(StarkProofChallenges {
StarkProofChallenges {
permutation_challenge_sets,
stark_alphas,
stark_zeta,
@ -73,7 +67,7 @@ where
degree_bits,
&config.fri_config,
),
})
}
}
impl<F, C, const D: usize> StarkProofWithPublicInputs<F, C, D>
@ -86,11 +80,10 @@ where
stark: &S,
config: &StarkConfig,
degree_bits: usize,
) -> anyhow::Result<Vec<usize>> {
Ok(self
.get_challenges(stark, config, degree_bits)?
) -> Vec<usize> {
self.get_challenges(stark, config, degree_bits)
.fri_challenges
.fri_query_indices)
.fri_query_indices
}
/// Computes all Fiat-Shamir challenges used in the STARK proof.
@ -99,7 +92,7 @@ where
stark: &S,
config: &StarkConfig,
degree_bits: usize,
) -> Result<StarkProofChallenges<F, D>> {
) -> StarkProofChallenges<F, D> {
let StarkProof {
trace_cap,
permutation_zs_cap,
@ -146,7 +139,7 @@ pub(crate) fn get_challenges_target<
final_poly: &PolynomialCoeffsExtTarget<D>,
pow_witness: Target,
config: &StarkConfig,
) -> Result<StarkProofChallengesTarget<D>>
) -> StarkProofChallengesTarget<D>
where
C::Hasher: AlgebraicHasher<F>,
{
@ -156,21 +149,16 @@ where
challenger.observe_cap(trace_cap);
let permutation_challenge_sets = if stark.uses_permutation_args() {
get_n_permutation_challenge_sets_target(
let permutation_challenge_sets = permutation_zs_cap.map(|permutation_zs_cap| {
let tmp = get_n_permutation_challenge_sets_target(
builder,
&mut challenger,
num_challenges,
stark.permutation_batch_size(),
)
} else {
vec![]
};
if stark.uses_permutation_args() {
let cap =
permutation_zs_cap.ok_or_else(|| anyhow::Error::msg("expected permutation_zs_cap"));
challenger.observe_cap(cap?);
}
);
challenger.observe_cap(permutation_zs_cap);
tmp
});
let stark_alphas = challenger.get_n_challenges(builder, num_challenges);
@ -179,7 +167,7 @@ where
challenger.observe_openings(&openings.to_fri_openings());
Ok(StarkProofChallengesTarget {
StarkProofChallengesTarget {
permutation_challenge_sets,
stark_alphas,
stark_zeta,
@ -190,7 +178,7 @@ where
pow_witness,
&config.fri_config,
),
})
}
}
impl<const D: usize> StarkProofWithPublicInputsTarget<D> {
@ -203,7 +191,7 @@ impl<const D: usize> StarkProofWithPublicInputsTarget<D> {
builder: &mut CircuitBuilder<F, D>,
stark: &S,
config: &StarkConfig,
) -> Result<StarkProofChallengesTarget<D>>
) -> StarkProofChallengesTarget<D>
where
C::Hasher: AlgebraicHasher<F>,
{

View File

@ -101,7 +101,7 @@ pub struct CompressedStarkProofWithPublicInputs<
pub(crate) struct StarkProofChallenges<F: RichField + Extendable<D>, const D: usize> {
/// Randomness used in any permutation arguments.
pub permutation_challenge_sets: Vec<PermutationChallengeSet<F>>,
pub permutation_challenge_sets: Option<Vec<PermutationChallengeSet<F>>>,
/// Random values used to combine STARK constraints.
pub stark_alphas: Vec<F>,
@ -113,7 +113,7 @@ pub(crate) struct StarkProofChallenges<F: RichField + Extendable<D>, const D: us
}
pub(crate) struct StarkProofChallengesTarget<const D: usize> {
pub permutation_challenge_sets: Vec<PermutationChallengeSet<Target>>,
pub permutation_challenge_sets: Option<Vec<PermutationChallengeSet<Target>>>,
pub stark_alphas: Vec<Target>,
pub stark_zeta: ExtensionTarget<D>,
pub fri_challenges: FriChallengesTarget<D>,

View File

@ -1,6 +1,5 @@
use std::iter::once;
use anyhow::Result;
use itertools::Itertools;
use plonky2::field::extension_field::Extendable;
use plonky2::field::field_types::Field;
@ -33,15 +32,14 @@ pub fn recursively_verify_stark_proof<
stark: S,
proof_with_pis: StarkProofWithPublicInputsTarget<D>,
inner_config: &StarkConfig,
) -> Result<()>
where
) where
C::Hasher: AlgebraicHasher<F>,
[(); S::COLUMNS]:,
[(); S::PUBLIC_INPUTS]:,
{
assert_eq!(proof_with_pis.public_inputs.len(), S::PUBLIC_INPUTS);
let degree_bits = proof_with_pis.proof.recover_degree_bits(inner_config);
let challenges = proof_with_pis.get_challenges::<F, C, S>(builder, &stark, inner_config)?;
let challenges = proof_with_pis.get_challenges::<F, C, S>(builder, &stark, inner_config);
recursively_verify_stark_proof_with_challenges::<F, C, S, D>(
builder,
@ -51,8 +49,6 @@ where
inner_config,
degree_bits,
);
Ok(())
}
/// Recursively verifies an inner proof.
@ -115,7 +111,7 @@ fn recursively_verify_stark_proof_with_challenges<
.then(|| PermutationCheckDataTarget {
local_zs: permutation_zs.as_ref().unwrap().clone(),
next_zs: permutation_zs_right.as_ref().unwrap().clone(),
permutation_challenge_sets: challenges.permutation_challenge_sets,
permutation_challenge_sets: challenges.permutation_challenge_sets.unwrap(),
});
eval_vanishing_poly_recursively::<F, C, S, D>(
builder,

View File

@ -34,7 +34,7 @@ where
{
ensure!(proof_with_pis.public_inputs.len() == S::PUBLIC_INPUTS);
let degree_bits = proof_with_pis.proof.recover_degree_bits(config);
let challenges = proof_with_pis.get_challenges(&stark, config, degree_bits)?;
let challenges = proof_with_pis.get_challenges(&stark, config, degree_bits);
verify_stark_proof_with_challenges(stark, proof_with_pis, challenges, degree_bits, config)
}
@ -93,7 +93,7 @@ where
let permutation_data = stark.uses_permutation_args().then(|| PermutationCheckData {
local_zs: permutation_zs.as_ref().unwrap().clone(),
next_zs: permutation_zs_right.as_ref().unwrap().clone(),
permutation_challenge_sets: challenges.permutation_challenge_sets,
permutation_challenge_sets: challenges.permutation_challenge_sets.unwrap(),
});
eval_vanishing_poly::<F, F::Extension, C, S, D, D>(
&stark,