From 1590c1d0beb910fb296b55bed5a0188771f08cca Mon Sep 17 00:00:00 2001 From: Hamy Ratoanina Date: Wed, 10 May 2023 15:37:05 -0400 Subject: [PATCH] Fix indices in CTL functions --- evm/src/cross_table_lookup.rs | 28 ++++++++++----------------- evm/src/fixed_recursive_verifier.rs | 30 ++++++++++++++--------------- evm/src/verifier.rs | 24 +++++++++++++---------- evm/tests/empty_txn_list.rs | 2 +- 4 files changed, 40 insertions(+), 44 deletions(-) diff --git a/evm/src/cross_table_lookup.rs b/evm/src/cross_table_lookup.rs index f1876049..86e370d3 100644 --- a/evm/src/cross_table_lookup.rs +++ b/evm/src/cross_table_lookup.rs @@ -537,16 +537,12 @@ pub(crate) fn verify_cross_table_lookups, const D: config: &StarkConfig, ) -> Result<()> { let mut ctl_zs_openings = ctl_zs_lasts.iter().map(|v| v.iter()).collect::>(); - for ( - CrossTableLookup { - looking_tables, - looked_table, - }, - extra_product_vec, - ) in cross_table_lookups - .iter() - .zip(ctl_extra_looking_products.iter()) + for CrossTableLookup { + looking_tables, + looked_table, + } in cross_table_lookups.iter() { + let extra_product_vec = &ctl_extra_looking_products[looked_table.table as usize]; for c in 0..config.num_challenges { let mut looking_zs_prod = looking_tables .iter() @@ -575,16 +571,12 @@ pub(crate) fn verify_cross_table_lookups_circuit, c inner_config: &StarkConfig, ) { let mut ctl_zs_openings = ctl_zs_lasts.iter().map(|v| v.iter()).collect::>(); - for ( - CrossTableLookup { - looking_tables, - looked_table, - }, - extra_product_vec, - ) in cross_table_lookups - .into_iter() - .zip(ctl_extra_looking_products.iter()) + for CrossTableLookup { + looking_tables, + looked_table, + } in cross_table_lookups.into_iter() { + let extra_product_vec = &ctl_extra_looking_products[looked_table.table as usize]; for c in 0..inner_config.num_challenges { let mut looking_zs_prod = builder.mul_many( looking_tables diff --git a/evm/src/fixed_recursive_verifier.rs b/evm/src/fixed_recursive_verifier.rs index df56f4d0..1e5ab459 100644 --- a/evm/src/fixed_recursive_verifier.rs +++ b/evm/src/fixed_recursive_verifier.rs @@ -467,40 +467,40 @@ where // Extra products to add to the looked last value let mut extra_looking_products = Vec::new(); + for _ in 0..NUM_TABLES { + extra_looking_products.push(Vec::new()); + } // Arithmetic - extra_looking_products.push(Vec::new()); for _ in 0..stark_config.num_challenges { - extra_looking_products[0].push(builder.constant(F::ONE)); + extra_looking_products[Table::Arithmetic as usize].push(builder.constant(F::ONE)); } // KeccakSponge - extra_looking_products.push(Vec::new()); for _ in 0..stark_config.num_challenges { - extra_looking_products[1].push(builder.constant(F::ONE)); + extra_looking_products[Table::KeccakSponge as usize].push(builder.constant(F::ONE)); } // Keccak - extra_looking_products.push(Vec::new()); for _ in 0..stark_config.num_challenges { - extra_looking_products[2].push(builder.constant(F::ONE)); + extra_looking_products[Table::Keccak as usize].push(builder.constant(F::ONE)); } // Logic - extra_looking_products.push(Vec::new()); for _ in 0..stark_config.num_challenges { - extra_looking_products[3].push(builder.constant(F::ONE)); + extra_looking_products[Table::Logic as usize].push(builder.constant(F::ONE)); } // Memory - extra_looking_products.push(Vec::new()); for c in 0..stark_config.num_challenges { - extra_looking_products[4].push(Self::get_memory_extra_looking_products_circuit( - &mut builder, - public_values, - cpu_trace_len, - ctl_challenges.challenges[c], - )); + extra_looking_products[Table::Memory as usize].push( + Self::get_memory_extra_looking_products_circuit( + &mut builder, + public_values, + cpu_trace_len, + ctl_challenges.challenges[c], + ), + ); } // Verify the CTL checks. diff --git a/evm/src/verifier.rs b/evm/src/verifier.rs index 59e60172..ea504760 100644 --- a/evm/src/verifier.rs +++ b/evm/src/verifier.rs @@ -9,7 +9,7 @@ use plonky2::hash::hash_types::RichField; use plonky2::plonk::config::GenericConfig; use plonky2::plonk::plonk_common::reduce_with_powers; -use crate::all_stark::{AllStark, Table}; +use crate::all_stark::{AllStark, Table, NUM_TABLES}; use crate::arithmetic::arithmetic_stark::ArithmeticStark; use crate::config::StarkConfig; use crate::constraint_consumer::ConstraintConsumer; @@ -114,30 +114,34 @@ where // Extra products to add to the looked last value. let mut extra_looking_products = Vec::new(); + for _ in 0..NUM_TABLES { + extra_looking_products.push(Vec::new()); + } + + // Arithmetic + for _ in 0..config.num_challenges { + extra_looking_products[Table::Arithmetic as usize].push(F::ONE); + } // KeccakSponge - extra_looking_products.push(Vec::new()); for _ in 0..config.num_challenges { - extra_looking_products[0].push(F::ONE); + extra_looking_products[Table::KeccakSponge as usize].push(F::ONE); } // Keccak - extra_looking_products.push(Vec::new()); for _ in 0..config.num_challenges { - extra_looking_products[1].push(F::ONE); + extra_looking_products[Table::Keccak as usize].push(F::ONE); } // Logic - extra_looking_products.push(Vec::new()); for _ in 0..config.num_challenges { - extra_looking_products[2].push(F::ONE); + extra_looking_products[Table::Logic as usize].push(F::ONE); } // Memory - extra_looking_products.push(Vec::new()); - let cpu_trace_len = 1 << all_proof.stark_proofs[0].proof.recover_degree_bits(config); + let cpu_trace_len = 1 << all_proof.stark_proofs[1].proof.recover_degree_bits(config); for c in 0..config.num_challenges { - extra_looking_products[3].push(get_memory_extra_looking_products( + extra_looking_products[Table::Memory as usize].push(get_memory_extra_looking_products( &public_values, cpu_trace_len, ctl_challenges.challenges[c], diff --git a/evm/tests/empty_txn_list.rs b/evm/tests/empty_txn_list.rs index 4ead2e4a..59913787 100644 --- a/evm/tests/empty_txn_list.rs +++ b/evm/tests/empty_txn_list.rs @@ -95,7 +95,7 @@ fn test_empty_txn_list() -> anyhow::Result<()> { verify_proof(&all_stark, proof.clone(), &config)?; - let cpu_trace_len = 1 << proof.stark_proofs[0].proof.recover_degree_bits(&config); + let cpu_trace_len = 1 << proof.stark_proofs[1].proof.recover_degree_bits(&config); let all_circuits = AllRecursiveCircuits::::new( &all_stark, &[16..17, 14..15, 14..15, 9..10, 12..13, 18..19], // Minimal ranges to prove an empty list