This commit is contained in:
wborgeaud 2022-09-23 16:28:20 +02:00
parent 502305146f
commit 0053a02119
5 changed files with 6 additions and 215 deletions

View File

@ -172,7 +172,6 @@ mod tests {
use anyhow::Result;
use ethereum_types::U256;
use itertools::Itertools;
use log::debug;
use plonky2::field::polynomial::PolynomialValues;
use plonky2::field::types::{Field, PrimeField64};
use plonky2::iop::witness::PartialWitness;

View File

@ -450,55 +450,6 @@ pub struct CtlCheckVarsTarget<'a, F: Field, const D: usize> {
}
impl<'a, F: Field, const D: usize> CtlCheckVarsTarget<'a, F, D> {
pub(crate) fn from_proofs(
proofs: &[StarkProofTarget<D>; NUM_TABLES],
cross_table_lookups: &'a [CrossTableLookup<F>],
ctl_challenges: &'a GrandProductChallengeSet<Target>,
num_permutation_zs: &[usize; NUM_TABLES],
) -> [Vec<Self>; NUM_TABLES] {
let mut ctl_zs = proofs
.iter()
.zip(num_permutation_zs)
.map(|(p, &num_perms)| {
let openings = &p.openings;
let ctl_zs = openings.permutation_ctl_zs.iter().skip(num_perms);
let ctl_zs_next = openings.permutation_ctl_zs_next.iter().skip(num_perms);
ctl_zs.zip(ctl_zs_next)
})
.collect::<Vec<_>>();
let mut ctl_vars_per_table = [0; NUM_TABLES].map(|_| vec![]);
for CrossTableLookup {
looking_tables,
looked_table,
..
} in cross_table_lookups
{
for &challenges in &ctl_challenges.challenges {
for table in looking_tables {
let (looking_z, looking_z_next) = ctl_zs[table.table as usize].next().unwrap();
ctl_vars_per_table[table.table as usize].push(Self {
local_z: *looking_z,
next_z: *looking_z_next,
challenges,
columns: &table.columns,
filter_column: &table.filter_column,
});
}
let (looked_z, looked_z_next) = ctl_zs[looked_table.table as usize].next().unwrap();
ctl_vars_per_table[looked_table.table as usize].push(Self {
local_z: *looked_z,
next_z: *looked_z_next,
challenges,
columns: &looked_table.columns,
filter_column: &looked_table.filter_column,
});
}
}
ctl_vars_per_table
}
pub(crate) fn from_proof(
table: Table,
proof: &StarkProofTarget<D>,

View File

@ -8,8 +8,8 @@ use plonky2::plonk::config::{AlgebraicHasher, GenericConfig};
use crate::all_stark::{AllStark, NUM_TABLES};
use crate::config::StarkConfig;
use crate::permutation::{
get_grand_product_challenge_set, get_grand_product_challenge_set_target,
get_n_grand_product_challenge_sets, get_n_grand_product_challenge_sets_target,
get_grand_product_challenge_set, get_n_grand_product_challenge_sets,
get_n_grand_product_challenge_sets_target,
};
use crate::proof::*;
@ -86,43 +86,6 @@ impl<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize> A
}
}
impl<const D: usize> AllProofTarget<D> {
pub(crate) fn get_challenges<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>>(
&self,
builder: &mut CircuitBuilder<F, D>,
all_stark: &AllStark<F, D>,
config: &StarkConfig,
) -> AllProofChallengesTarget<D>
where
C::Hasher: AlgebraicHasher<F>,
{
let mut challenger = RecursiveChallenger::<F, C::Hasher, D>::new(builder);
for proof in &self.stark_proofs {
challenger.observe_cap(&proof.trace_cap);
}
let ctl_challenges =
get_grand_product_challenge_set_target(builder, &mut challenger, config.num_challenges);
let num_permutation_zs = all_stark.nums_permutation_zs(config);
let num_permutation_batch_sizes = all_stark.permutation_batch_sizes();
AllProofChallengesTarget {
stark_challenges: std::array::from_fn(|i| {
self.stark_proofs[i].get_challenges::<F, C>(
builder,
&mut challenger,
num_permutation_zs[i] > 0,
num_permutation_batch_sizes[i],
config,
)
}),
ctl_challenges,
}
}
}
impl<F, C, const D: usize> StarkProof<F, C, D>
where
F: RichField + Extendable<D>,

View File

@ -99,11 +99,6 @@ pub struct BlockMetadataTarget {
pub block_base_fee: Target,
}
pub(crate) struct AllProofChallengesTarget<const D: usize> {
pub stark_challenges: [StarkProofChallengesTarget<D>; NUM_TABLES],
pub ctl_challenges: GrandProductChallengeSet<Target>,
}
#[derive(Debug, Clone)]
pub struct StarkProof<F: RichField + Extendable<D>, C: GenericConfig<D, F = F>, const D: usize> {
/// Merkle cap of LDEs of trace values.

View File

@ -5,17 +5,14 @@ use itertools::Itertools;
use plonky2::field::extension::Extendable;
use plonky2::field::types::Field;
use plonky2::fri::witness_util::set_fri_proof_target;
use plonky2::hash::hash_types::{HashOut, RichField};
use plonky2::hash::hash_types::RichField;
use plonky2::hash::hashing::SPONGE_WIDTH;
use plonky2::hash::merkle_tree::MerkleCap;
use plonky2::hash::poseidon::PoseidonHash;
use plonky2::iop::challenger::{Challenger, RecursiveChallenger};
use plonky2::iop::ext_target::ExtensionTarget;
use plonky2::iop::target::Target;
use plonky2::iop::witness::{PartialWitness, Witness};
use plonky2::plonk::circuit_builder::CircuitBuilder;
use plonky2::plonk::circuit_data::{CircuitConfig, VerifierCircuitData, VerifierCircuitTarget};
use plonky2::plonk::config::GenericHashOut;
use plonky2::plonk::config::Hasher;
use plonky2::plonk::config::{AlgebraicHasher, GenericConfig};
use plonky2::plonk::proof::ProofWithPublicInputs;
@ -39,9 +36,9 @@ use crate::permutation::{
GrandProductChallengeSet, PermutationCheckDataTarget,
};
use crate::proof::{
AllChallengerState, AllProof, AllProofChallengesTarget, AllProofTarget, BlockMetadata,
BlockMetadataTarget, PublicValues, PublicValuesTarget, StarkOpeningSetTarget, StarkProof,
StarkProofChallengesTarget, StarkProofTarget, TrieRoots, TrieRootsTarget,
AllChallengerState, AllProof, AllProofTarget, BlockMetadata, BlockMetadataTarget, PublicValues,
PublicValuesTarget, StarkOpeningSetTarget, StarkProof, StarkProofChallengesTarget,
StarkProofTarget, TrieRoots, TrieRootsTarget,
};
use crate::stark::Stark;
use crate::util::{h160_limbs, u256_limbs};
@ -425,120 +422,6 @@ where
})
}
// pub fn verify_proof_circuit<
// F: RichField + Extendable<D>,
// C: GenericConfig<D, F = F>,
// const D: usize,
// >(
// builder: &mut CircuitBuilder<F, D>,
// all_stark: AllStark<F, D>,
// all_proof: AllProofTarget<D>,
// inner_config: &StarkConfig,
// ) where
// [(); CpuStark::<F, D>::COLUMNS]:,
// [(); KeccakStark::<F, D>::COLUMNS]:,
// [(); KeccakMemoryStark::<F, D>::COLUMNS]:,
// [(); LogicStark::<F, D>::COLUMNS]:,
// [(); MemoryStark::<F, D>::COLUMNS]:,
// C::Hasher: AlgebraicHasher<F>,
// {
// let AllProofChallengesTarget {
// stark_challenges,
// ctl_challenges,
// } = all_proof.get_challenges::<F, C>(builder, &all_stark, inner_config);
//
// let nums_permutation_zs = all_stark.nums_permutation_zs(inner_config);
//
// let AllStark {
// cpu_stark,
// keccak_stark,
// keccak_memory_stark,
// logic_stark,
// memory_stark,
// cross_table_lookups,
// } = all_stark;
//
// let ctl_vars_per_table = CtlCheckVarsTarget::from_proofs(
// &all_proof.stark_proofs,
// &cross_table_lookups,
// &ctl_challenges,
// &nums_permutation_zs,
// );
//
// with_context!(
// builder,
// "verify CPU proof",
// verify_stark_proof_with_challenges_circuit::<F, C, _, D>(
// builder,
// &cpu_stark,
// &all_proof.stark_proofs[Table::Cpu as usize],
// &stark_challenges[Table::Cpu as usize],
// &ctl_vars_per_table[Table::Cpu as usize],
// inner_config,
// )
// );
// with_context!(
// builder,
// "verify Keccak proof",
// verify_stark_proof_with_challenges_circuit::<F, C, _, D>(
// builder,
// &keccak_stark,
// &all_proof.stark_proofs[Table::Keccak as usize],
// &stark_challenges[Table::Keccak as usize],
// &ctl_vars_per_table[Table::Keccak as usize],
// inner_config,
// )
// );
// with_context!(
// builder,
// "verify Keccak memory proof",
// verify_stark_proof_with_challenges_circuit::<F, C, _, D>(
// builder,
// &keccak_memory_stark,
// &all_proof.stark_proofs[Table::KeccakMemory as usize],
// &stark_challenges[Table::KeccakMemory as usize],
// &ctl_vars_per_table[Table::KeccakMemory as usize],
// inner_config,
// )
// );
// with_context!(
// builder,
// "verify logic proof",
// verify_stark_proof_with_challenges_circuit::<F, C, _, D>(
// builder,
// &logic_stark,
// &all_proof.stark_proofs[Table::Logic as usize],
// &stark_challenges[Table::Logic as usize],
// &ctl_vars_per_table[Table::Logic as usize],
// inner_config,
// )
// );
// with_context!(
// builder,
// "verify memory proof",
// verify_stark_proof_with_challenges_circuit::<F, C, _, D>(
// builder,
// &memory_stark,
// &all_proof.stark_proofs[Table::Memory as usize],
// &stark_challenges[Table::Memory as usize],
// &ctl_vars_per_table[Table::Memory as usize],
// inner_config,
// )
// );
//
// with_context!(
// builder,
// "verify cross-table lookups",
// verify_cross_table_lookups_circuit::<F, C, D>(
// builder,
// cross_table_lookups,
// &all_proof.stark_proofs,
// ctl_challenges,
// inner_config,
// )
// );
// }
/// Recursively verifies an inner proof.
fn verify_stark_proof_with_challenges_circuit<
F: RichField + Extendable<D>,