diff --git a/starky/src/fibonacci_stark.rs b/starky/src/fibonacci_stark.rs index 10b54d69..7961ad50 100644 --- a/starky/src/fibonacci_stark.rs +++ b/starky/src/fibonacci_stark.rs @@ -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, const D: usize> { num_rows: usize, @@ -48,7 +48,7 @@ impl, const D: usize> FibonacciStark { Some(tmp) }) .collect::>(); - 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::(&mut builder, stark, pt, inner_config)?; + recursively_verify_stark_proof::(&mut builder, stark, pt, inner_config); if print_gate_counts { builder.print_gate_counts(0); diff --git a/starky/src/get_challenges.rs b/starky/src/get_challenges.rs index 8ee71667..0f4aacee 100644 --- a/starky/src/get_challenges.rs +++ b/starky/src/get_challenges.rs @@ -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( pow_witness: F, config: &StarkConfig, degree_bits: usize, -) -> Result> +) -> StarkProofChallenges where F: RichField + Extendable, C: GenericConfig, @@ -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 StarkProofWithPublicInputs @@ -86,11 +80,10 @@ where stark: &S, config: &StarkConfig, degree_bits: usize, - ) -> anyhow::Result> { - Ok(self - .get_challenges(stark, config, degree_bits)? + ) -> Vec { + 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 { let StarkProof { trace_cap, permutation_zs_cap, @@ -146,7 +139,7 @@ pub(crate) fn get_challenges_target< final_poly: &PolynomialCoeffsExtTarget, pow_witness: Target, config: &StarkConfig, -) -> Result> +) -> StarkProofChallengesTarget where C::Hasher: AlgebraicHasher, { @@ -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 StarkProofWithPublicInputsTarget { @@ -203,7 +191,7 @@ impl StarkProofWithPublicInputsTarget { builder: &mut CircuitBuilder, stark: &S, config: &StarkConfig, - ) -> Result> + ) -> StarkProofChallengesTarget where C::Hasher: AlgebraicHasher, { diff --git a/starky/src/proof.rs b/starky/src/proof.rs index d1f86d7e..1975b1b9 100644 --- a/starky/src/proof.rs +++ b/starky/src/proof.rs @@ -101,7 +101,7 @@ pub struct CompressedStarkProofWithPublicInputs< pub(crate) struct StarkProofChallenges, const D: usize> { /// Randomness used in any permutation arguments. - pub permutation_challenge_sets: Vec>, + pub permutation_challenge_sets: Option>>, /// Random values used to combine STARK constraints. pub stark_alphas: Vec, @@ -113,7 +113,7 @@ pub(crate) struct StarkProofChallenges, const D: us } pub(crate) struct StarkProofChallengesTarget { - pub permutation_challenge_sets: Vec>, + pub permutation_challenge_sets: Option>>, pub stark_alphas: Vec, pub stark_zeta: ExtensionTarget, pub fri_challenges: FriChallengesTarget, diff --git a/starky/src/recursive_verifier.rs b/starky/src/recursive_verifier.rs index de01d39e..6a7363ae 100644 --- a/starky/src/recursive_verifier.rs +++ b/starky/src/recursive_verifier.rs @@ -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, inner_config: &StarkConfig, -) -> Result<()> -where +) where C::Hasher: AlgebraicHasher, [(); 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::(builder, &stark, inner_config)?; + let challenges = proof_with_pis.get_challenges::(builder, &stark, inner_config); recursively_verify_stark_proof_with_challenges::( 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::( builder, diff --git a/starky/src/verifier.rs b/starky/src/verifier.rs index 44d3f9c7..959cbc8e 100644 --- a/starky/src/verifier.rs +++ b/starky/src/verifier.rs @@ -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::( &stark,