Validate EVM proof shape

This commit is contained in:
Daniel Lubarov 2022-09-19 20:54:45 -07:00
parent e20b76f104
commit 616a6b3919
2 changed files with 48 additions and 0 deletions

View File

@ -76,6 +76,10 @@ pub trait Stark<F: RichField + Extendable<D>, const D: usize>: Sync {
1.max(self.constraint_degree() - 1) 1.max(self.constraint_degree() - 1)
} }
fn num_quotient_polys(&self, config: &StarkConfig) -> usize {
self.quotient_degree_factor() * config.num_challenges
}
/// Computes the FRI instance used to prove this Stark. /// Computes the FRI instance used to prove this Stark.
fn fri_instance( fn fri_instance(
&self, &self,

View File

@ -119,6 +119,7 @@ where
[(); S::COLUMNS]:, [(); S::COLUMNS]:,
[(); C::Hasher::HASH_SIZE]:, [(); C::Hasher::HASH_SIZE]:,
{ {
validate_proof_shape(&stark, proof, config, ctl_vars.len())?;
let StarkOpeningSet { let StarkOpeningSet {
local_values, local_values,
next_values, next_values,
@ -204,6 +205,49 @@ where
Ok(()) Ok(())
} }
fn validate_proof_shape<F, C, S, const D: usize>(
stark: &S,
proof: &StarkProof<F, C, D>,
config: &StarkConfig,
num_ctls: usize,
) -> anyhow::Result<()>
where
F: RichField + Extendable<D>,
C: GenericConfig<D, F = F>,
S: Stark<F, D>,
[(); S::COLUMNS]:,
[(); C::Hasher::HASH_SIZE]:,
{
let StarkProof {
trace_cap,
permutation_ctl_zs_cap,
quotient_polys_cap,
openings,
// The shape of the opening proof will be checked in the FRI verifier (see
// validate_fri_proof_shape), so we ignore it here.
opening_proof: _,
} = proof;
let degree_bits = proof.recover_degree_bits(config);
let fri_params = config.fri_params(degree_bits);
let cap_height = fri_params.config.cap_height;
ensure!(trace_cap.height() == cap_height);
ensure!(permutation_ctl_zs_cap.height() == cap_height);
ensure!(quotient_polys_cap.height() == cap_height);
ensure!(openings.local_values.len() == S::COLUMNS);
ensure!(openings.next_values.len() == S::COLUMNS);
let num_ctl_zs = num_ctls * config.num_challenges;
let num_zs = num_ctl_zs + stark.num_permutation_batches(config);
ensure!(openings.permutation_ctl_zs.len() == num_zs);
ensure!(openings.permutation_ctl_zs_next.len() == num_zs);
ensure!(openings.ctl_zs_last.len() == num_ctl_zs);
let num_quotient_polys = stark.num_quotient_polys(config);
ensure!(openings.quotient_polys.len() == num_quotient_polys);
Ok(())
}
/// Evaluate the Lagrange polynomials `L_0` and `L_(n-1)` at a point `x`. /// Evaluate the Lagrange polynomials `L_0` and `L_(n-1)` at a point `x`.
/// `L_0(x) = (x^n - 1)/(n * (x - 1))` /// `L_0(x) = (x^n - 1)/(n * (x - 1))`
/// `L_(n-1)(x) = (x^n - 1)/(n * (g * x - 1))`, with `g` the first element of the subgroup. /// `L_(n-1)(x) = (x^n - 1)/(n * (g * x - 1))`, with `g` the first element of the subgroup.