diff --git a/evm/src/byte_packing/byte_packing_stark.rs b/evm/src/byte_packing/byte_packing_stark.rs index f97a2b28..9fba11bc 100644 --- a/evm/src/byte_packing/byte_packing_stark.rs +++ b/evm/src/byte_packing/byte_packing_stark.rs @@ -47,11 +47,11 @@ use plonky2::util::transpose; use super::NUM_BYTES; use crate::byte_packing::columns::{ index_bytes, value_bytes, ADDR_CONTEXT, ADDR_SEGMENT, ADDR_VIRTUAL, BYTE_INDICES_COLS, IS_READ, - NUM_COLUMNS, RANGE_COUNTER, RC_COLS, SEQUENCE_END, SEQUENCE_LEN, TIMESTAMP, + NUM_COLUMNS, RANGE_COUNTER, RC_FREQUENCIES, SEQUENCE_END, SEQUENCE_LEN, TIMESTAMP, }; use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; use crate::cross_table_lookup::Column; -use crate::lookup::{eval_lookups, eval_lookups_circuit, permuted_cols}; +use crate::lookup::Lookup; use crate::stark::Stark; use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; use crate::witness::memory::MemoryAddress; @@ -240,11 +240,18 @@ impl, const D: usize> BytePackingStark { // For each column c in cols, generate the range-check // permutations and put them in the corresponding range-check // columns rc_c and rc_c+1. - for (i, rc_c) in (0..NUM_BYTES).zip(RC_COLS.step_by(2)) { - let c = value_bytes(i); - let (col_perm, table_perm) = permuted_cols(&cols[c], &cols[RANGE_COUNTER]); - cols[rc_c].copy_from_slice(&col_perm); - cols[rc_c + 1].copy_from_slice(&table_perm); + for col in 0..NUM_BYTES { + for i in 0..n_rows { + let c = value_bytes(col); + let x = cols[c][i].to_canonical_u64() as usize; + assert!( + x < BYTE_RANGE_MAX, + "column value {} exceeds the max range value {}", + x, + BYTE_RANGE_MAX + ); + cols[RC_FREQUENCIES][x] += F::ONE; + } } } @@ -291,11 +298,6 @@ impl, const D: usize> Stark for BytePackingSt FE: FieldExtension, P: PackedField, { - // Range check all the columns - for col in RC_COLS.step_by(2) { - eval_lookups(vars, yield_constr, col, col + 1); - } - let one = P::ONES; // We filter active columns by summing all the byte indices. @@ -417,11 +419,6 @@ impl, const D: usize> Stark for BytePackingSt vars: StarkEvaluationTargets, yield_constr: &mut RecursiveConstraintConsumer, ) { - // Range check all the columns - for col in RC_COLS.step_by(2) { - eval_lookups_circuit(builder, vars, yield_constr, col, col + 1); - } - // We filter active columns by summing all the byte indices. // Constraining each of them to be boolean is done later on below. let current_filter = builder.add_many_extension(&vars.local_values[BYTE_INDICES_COLS]); @@ -569,6 +566,14 @@ impl, const D: usize> Stark for BytePackingSt fn constraint_degree(&self) -> usize { 3 } + + fn lookups(&self) -> Vec { + vec![Lookup { + columns: (value_bytes(0)..value_bytes(NUM_BYTES)).collect(), + table_column: RANGE_COUNTER, + frequencies_column: RC_FREQUENCIES, + }] + } } #[cfg(test)] diff --git a/evm/src/byte_packing/columns.rs b/evm/src/byte_packing/columns.rs index f04f450c..1e62b7e8 100644 --- a/evm/src/byte_packing/columns.rs +++ b/evm/src/byte_packing/columns.rs @@ -42,7 +42,6 @@ pub(crate) const fn value_bytes(i: usize) -> usize { // The two permutations associated to the byte in column i will be in // columns RC_COLS[2i] and RC_COLS[2i+1]. pub(crate) const RANGE_COUNTER: usize = BYTES_VALUES_START + NUM_BYTES; -pub(crate) const NUM_RANGE_CHECK_COLS: usize = 1 + 2 * NUM_BYTES; -pub(crate) const RC_COLS: Range = RANGE_COUNTER + 1..RANGE_COUNTER + NUM_RANGE_CHECK_COLS; +pub(crate) const RC_FREQUENCIES: usize = RANGE_COUNTER + 1; -pub(crate) const NUM_COLUMNS: usize = RANGE_COUNTER + NUM_RANGE_CHECK_COLS; +pub(crate) const NUM_COLUMNS: usize = RANGE_COUNTER + 2; diff --git a/evm/src/keccak/keccak_stark.rs b/evm/src/keccak/keccak_stark.rs index e1b4bbb8..329917dc 100644 --- a/evm/src/keccak/keccak_stark.rs +++ b/evm/src/keccak/keccak_stark.rs @@ -777,7 +777,7 @@ mod tests { &trace_poly_values, &trace_commitments, &ctl_data, - GrandProductChallengeSet { + &GrandProductChallengeSet { challenges: vec![ctl_z_data.challenge; config.num_challenges], }, &mut Challenger::new(), diff --git a/evm/src/prover.rs b/evm/src/prover.rs index 77ba4522..10172005 100644 --- a/evm/src/prover.rs +++ b/evm/src/prover.rs @@ -173,7 +173,7 @@ where trace_commitments, ctl_data_per_table, &mut challenger, - ctl_challenges.clone(), + &ctl_challenges, timing )? ); @@ -192,7 +192,7 @@ fn prove_with_commitments( trace_commitments: Vec>, ctl_data_per_table: [CtlData; NUM_TABLES], challenger: &mut Challenger, - ctl_challenges: GrandProductChallengeSet, + ctl_challenges: &GrandProductChallengeSet, timing: &mut TimingTree, ) -> Result<[StarkProofWithMetadata; NUM_TABLES]> where @@ -215,7 +215,7 @@ where &trace_poly_values[Table::Arithmetic as usize], &trace_commitments[Table::Arithmetic as usize], &ctl_data_per_table[Table::Arithmetic as usize], - ctl_challenges.clone(), + ctl_challenges, challenger, timing, )? @@ -229,6 +229,7 @@ where &trace_poly_values[Table::BytePacking as usize], &trace_commitments[Table::BytePacking as usize], &ctl_data_per_table[Table::BytePacking as usize], + ctl_challenges, challenger, timing, )? @@ -242,7 +243,7 @@ where &trace_poly_values[Table::Cpu as usize], &trace_commitments[Table::Cpu as usize], &ctl_data_per_table[Table::Cpu as usize], - ctl_challenges.clone(), + ctl_challenges, challenger, timing, )? @@ -256,7 +257,7 @@ where &trace_poly_values[Table::Keccak as usize], &trace_commitments[Table::Keccak as usize], &ctl_data_per_table[Table::Keccak as usize], - ctl_challenges.clone(), + ctl_challenges, challenger, timing, )? @@ -270,7 +271,7 @@ where &trace_poly_values[Table::KeccakSponge as usize], &trace_commitments[Table::KeccakSponge as usize], &ctl_data_per_table[Table::KeccakSponge as usize], - ctl_challenges.clone(), + ctl_challenges, challenger, timing, )? @@ -284,7 +285,7 @@ where &trace_poly_values[Table::Logic as usize], &trace_commitments[Table::Logic as usize], &ctl_data_per_table[Table::Logic as usize], - ctl_challenges.clone(), + ctl_challenges, challenger, timing, )? @@ -322,7 +323,7 @@ pub(crate) fn prove_single_table( trace_poly_values: &[PolynomialValues], trace_commitment: &PolynomialBatch, ctl_data: &CtlData, - ctl_challenges: GrandProductChallengeSet, + ctl_challenges: &GrandProductChallengeSet, challenger: &mut Challenger, timing: &mut TimingTree, ) -> Result> diff --git a/evm/src/verifier.rs b/evm/src/verifier.rs index 7195486a..e4c277fd 100644 --- a/evm/src/verifier.rs +++ b/evm/src/verifier.rs @@ -17,7 +17,9 @@ use crate::config::StarkConfig; use crate::constraint_consumer::ConstraintConsumer; use crate::cpu::cpu_stark::CpuStark; use crate::cpu::kernel::constants::global_metadata::GlobalMetadata; -use crate::cross_table_lookup::{verify_cross_table_lookups, CtlCheckVars, GrandProductChallenge}; +use crate::cross_table_lookup::{ + verify_cross_table_lookups, CtlCheckVars, GrandProductChallenge, GrandProductChallengeSet, +}; use crate::keccak::keccak_stark::KeccakStark; use crate::keccak_sponge::keccak_sponge_stark::KeccakSpongeStark; use crate::logic::LogicStark; @@ -77,6 +79,7 @@ where &all_proof.stark_proofs[Table::Arithmetic as usize].proof, &stark_challenges[Table::Arithmetic as usize], &ctl_vars_per_table[Table::Arithmetic as usize], + &ctl_challenges, config, )?; verify_stark_proof_with_challenges( @@ -84,6 +87,7 @@ where &all_proof.stark_proofs[Table::BytePacking as usize].proof, &stark_challenges[Table::BytePacking as usize], &ctl_vars_per_table[Table::BytePacking as usize], + &ctl_challenges, config, )?; verify_stark_proof_with_challenges( @@ -91,6 +95,7 @@ where &all_proof.stark_proofs[Table::Cpu as usize].proof, &stark_challenges[Table::Cpu as usize], &ctl_vars_per_table[Table::Cpu as usize], + &ctl_challenges, config, )?; verify_stark_proof_with_challenges( @@ -98,6 +103,7 @@ where &all_proof.stark_proofs[Table::Keccak as usize].proof, &stark_challenges[Table::Keccak as usize], &ctl_vars_per_table[Table::Keccak as usize], + &ctl_challenges, config, )?; verify_stark_proof_with_challenges( @@ -105,6 +111,7 @@ where &all_proof.stark_proofs[Table::KeccakSponge as usize].proof, &stark_challenges[Table::KeccakSponge as usize], &ctl_vars_per_table[Table::KeccakSponge as usize], + &ctl_challenges, config, )?; verify_stark_proof_with_challenges( @@ -112,6 +119,7 @@ where &all_proof.stark_proofs[Table::Logic as usize].proof, &stark_challenges[Table::Logic as usize], &ctl_vars_per_table[Table::Logic as usize], + &ctl_challenges, config, )?; verify_stark_proof_with_challenges( @@ -119,6 +127,7 @@ where &all_proof.stark_proofs[Table::Memory as usize].proof, &stark_challenges[Table::Memory as usize], &ctl_vars_per_table[Table::Memory as usize], + &ctl_challenges, config, )?; @@ -296,6 +305,7 @@ pub(crate) fn verify_stark_proof_with_challenges< proof: &StarkProof, challenges: &StarkProofChallenges, ctl_vars: &[CtlCheckVars], + ctl_challenges: &GrandProductChallengeSet, config: &StarkConfig, ) -> Result<()> where @@ -332,9 +342,10 @@ where ); let num_lookup_columns = stark.num_lookup_helper_columns(config); let lookup_challenges = (num_lookup_columns > 0).then(|| { - ctl_vars + ctl_challenges + .challenges .iter() - .map(|ch| ch.challenges.beta) + .map(|ch| ch.beta) .collect::>() });