Fix indices in CTL functions

This commit is contained in:
Hamy Ratoanina 2023-05-10 15:37:05 -04:00 committed by Robin Salen
parent f97deab8a7
commit 1590c1d0be
No known key found for this signature in database
GPG Key ID: FB87BACFB3CB2007
4 changed files with 40 additions and 44 deletions

View File

@ -537,16 +537,12 @@ pub(crate) fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D:
config: &StarkConfig,
) -> Result<()> {
let mut ctl_zs_openings = ctl_zs_lasts.iter().map(|v| v.iter()).collect::<Vec<_>>();
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<F: RichField + Extendable<D>, c
inner_config: &StarkConfig,
) {
let mut ctl_zs_openings = ctl_zs_lasts.iter().map(|v| v.iter()).collect::<Vec<_>>();
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

View File

@ -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.

View File

@ -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],

View File

@ -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::<F, C, D>::new(
&all_stark,
&[16..17, 14..15, 14..15, 9..10, 12..13, 18..19], // Minimal ranges to prove an empty list