Skip to content

Commit

Permalink
fix: remove deadcode
Browse files Browse the repository at this point in the history
  • Loading branch information
eigmax committed Jan 11, 2025
1 parent 66c0e48 commit 41846a4
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 169 deletions.
15 changes: 4 additions & 11 deletions prover/src/cross_table_lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,6 @@ pub(crate) fn eval_cross_table_lookup_checks_circuit<
pub(crate) fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D: usize>(
cross_table_lookups: &[CrossTableLookup<F>],
ctl_zs_first: [Vec<F>; NUM_TABLES],
ctl_extra_looking_sums: Vec<Vec<F>>,
config: &StarkConfig,
) -> Result<()> {
let mut ctl_zs_openings = ctl_zs_first.iter().map(|v| v.iter()).collect::<Vec<_>>();
Expand All @@ -1427,19 +1426,17 @@ pub(crate) fn verify_cross_table_lookups<F: RichField + Extendable<D>, const D:
},
) in cross_table_lookups.iter().enumerate()
{
let extra_sum_vec = &ctl_extra_looking_sums[looked_table.table as usize];
let mut filtered_looking_tables = vec![];
for table in looking_tables {
if !filtered_looking_tables.contains(&(table.table as usize)) {
filtered_looking_tables.push(table.table as usize);
}
}
for c in 0..config.num_challenges {
for _c in 0..config.num_challenges {
let looking_zs_sum = filtered_looking_tables
.iter()
.map(|&table| *ctl_zs_openings[table].next().unwrap())
.sum::<F>()
+ extra_sum_vec[c];
.sum::<F>();

let looked_z = *ctl_zs_openings[looked_table.table as usize].next().unwrap();
ensure!(
Expand All @@ -1458,7 +1455,6 @@ pub(crate) fn verify_cross_table_lookups_circuit<F: RichField + Extendable<D>, c
builder: &mut CircuitBuilder<F, D>,
cross_table_lookups: Vec<CrossTableLookup<F>>,
ctl_zs_first: [Vec<Target>; NUM_TABLES],
ctl_extra_looking_sums: Vec<Vec<Target>>,
inner_config: &StarkConfig,
) {
let mut ctl_zs_openings = ctl_zs_first.iter().map(|v| v.iter()).collect::<Vec<_>>();
Expand All @@ -1467,22 +1463,19 @@ pub(crate) fn verify_cross_table_lookups_circuit<F: RichField + Extendable<D>, c
looked_table,
} in cross_table_lookups.into_iter()
{
let extra_sum_vec = &ctl_extra_looking_sums[looked_table.table as usize];
let mut filtered_looking_tables = vec![];
for table in looking_tables {
if !filtered_looking_tables.contains(&(table.table as usize)) {
filtered_looking_tables.push(table.table as usize);
}
}
for c in 0..inner_config.num_challenges {
let mut looking_zs_sum = builder.add_many(
for _c in 0..inner_config.num_challenges {
let looking_zs_sum = builder.add_many(
filtered_looking_tables
.iter()
.map(|&table| *ctl_zs_openings[table].next().unwrap()),
);

looking_zs_sum = builder.add(looking_zs_sum, extra_sum_vec[c]);

let looked_z = *ctl_zs_openings[looked_table.table as usize].next().unwrap();
builder.connect(looked_z, looking_zs_sum);
}
Expand Down
6 changes: 0 additions & 6 deletions prover/src/fixed_recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,11 @@ where
}
}

// Extra sums to add to the looked last value.
// Only necessary for the Memory values.
let extra_looking_sums =
vec![vec![builder.zero(); stark_config.num_challenges]; NUM_TABLES];

// Verify the CTL checks.
verify_cross_table_lookups_circuit::<F, D>(
&mut builder,
all_cross_table_lookups(),
pis.map(|p| p.ctl_zs_first),
extra_looking_sums,
stark_config,
);

Expand Down
2 changes: 0 additions & 2 deletions prover/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ where
check_ctls(
&trace_poly_values,
&all_stark.cross_table_lookups,
// &get_memory_extra_looking_values(&public_values),
);
log::debug!("check_ctls done.");
}
Expand Down Expand Up @@ -224,7 +223,6 @@ where
check_ctls(
&trace_poly_values,
&all_stark.cross_table_lookups,
&get_memory_extra_looking_values(&public_values),
);
}
*/
Expand Down
42 changes: 0 additions & 42 deletions prover/src/recursive_verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::cross_table_lookup::{
use crate::evaluation_frame::StarkEvaluationFrame;
use crate::lookup::LookupCheckVarsTarget;

use crate::memory::VALUE_LIMBS;
use crate::proof::{
MemRoots, MemRootsTarget, PublicValues, PublicValuesTarget, StarkOpeningSetTarget, StarkProof,
StarkProofChallengesTarget, StarkProofTarget, StarkProofWithMetadata,
Expand Down Expand Up @@ -434,47 +433,6 @@ fn verify_stark_proof_with_challenges_circuit<
);
}

fn add_data_write<F: RichField + Extendable<D>, const D: usize>(
builder: &mut CircuitBuilder<F, D>,
challenge: GrandProductChallenge<Target>,
running_sum: Target,
segment: Target,
idx: usize,
val: &[Target],
) -> Target {
debug_assert!(val.len() <= VALUE_LIMBS);
let len = core::cmp::min(val.len(), VALUE_LIMBS);

let zero = builder.zero();
let one = builder.one();

let row = builder.add_virtual_targets(13);
// is_read
builder.connect(row[0], zero);
// context
builder.connect(row[1], zero);
// segment
builder.connect(row[2], segment);
// virtual
let field_target = builder.constant(F::from_canonical_usize(idx));
builder.connect(row[3], field_target);

// values
for j in 0..len {
builder.connect(row[4 + j], val[j]);
}
for j in len..VALUE_LIMBS {
builder.connect(row[4 + j], zero);
}

// timestamp
builder.connect(row[12], one);

let combined = challenge.combine_base_circuit(builder, &row);
let inverse = builder.inverse(combined);
builder.add(running_sum, inverse)
}

fn eval_l_0_and_l_last_circuit<F: RichField + Extendable<D>, const D: usize>(
builder: &mut CircuitBuilder<F, D>,
log_n: usize,
Expand Down
110 changes: 2 additions & 108 deletions prover/src/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
use crate::all_stark::{AllStark, Table, NUM_TABLES};
use crate::all_stark::{AllStark, Table};
use crate::config::StarkConfig;
use crate::constraint_consumer::ConstraintConsumer;

use crate::cross_table_lookup::{
num_ctl_helper_columns_by_table, verify_cross_table_lookups, CtlCheckVars,
GrandProductChallenge, GrandProductChallengeSet,
GrandProductChallengeSet,
};
use crate::evaluation_frame::StarkEvaluationFrame;
use crate::lookup::LookupCheckVars;

use crate::memory::VALUE_LIMBS;
use crate::proof::PublicValues;
use anyhow::{ensure, Result};
use itertools::Itertools;
use plonky2::field::extension::{Extendable, FieldExtension};
use plonky2::field::types::Field;
use plonky2::fri::verifier::verify_fri_proof;
Expand Down Expand Up @@ -136,80 +133,15 @@ where
config,
)?;

let public_values = all_proof.public_values;

// Extra sums to add to the looked last value.
// Only necessary for the Memory values.
let mut extra_looking_sums = vec![vec![F::ZERO; config.num_challenges]; NUM_TABLES];

// Memory
extra_looking_sums[Table::Memory as usize] = (0..config.num_challenges)
.map(|i| get_memory_extra_looking_sum(&public_values, ctl_challenges.challenges[i]))
.collect_vec();

verify_cross_table_lookups::<F, D>(
cross_table_lookups,
all_proof
.stark_proofs
.map(|p| p.proof.openings.ctl_zs_first),
extra_looking_sums,
config,
)
}

/// Computes the extra product to multiply to the looked value. It contains memory operations not in the CPU trace:
/// - trie roots writes before kernel bootstrapping.
pub(crate) fn get_memory_extra_looking_sum<F, const D: usize>(
_public_values: &PublicValues,
_challenge: GrandProductChallenge<F>,
) -> F
where
F: RichField + Extendable<D>,
{
/*
// Add metadata and state root writes. Skip due to not enabling
let fields = [
(
GlobalMetadata::StateTrieRootDigestBefore,
public_values.roots_before.root,
),
(
GlobalMetadata::StateTrieRootDigestAfter,
public_values.roots_after.root,
),
];
let segment = F::from_canonical_u32(Segment::GlobalMetadata as u32);
fields.map(|(field, val)| prod = add_data_write(challenge, segment, prod, field as usize, val));
*/

F::ZERO
}

fn add_data_write<F, const D: usize>(
challenge: GrandProductChallenge<F>,
segment: F,
running_sum: F,
index: usize,
val: u32,
) -> F
where
F: RichField + Extendable<D>,
{
let mut row = [F::ZERO; 13];
row[0] = F::ZERO; // is_read
row[1] = F::ZERO; // context
row[2] = segment;
row[3] = F::from_canonical_usize(index);

for j in 0..VALUE_LIMBS {
row[j + 4] = F::from_canonical_u32(val >> (j * 32));
}
row[5] = F::ONE; // timestamp
running_sum * challenge.combine(row.iter())
}

pub(crate) fn verify_stark_proof_with_challenges<
F: RichField + Extendable<D>,
C: GenericConfig<D, F = F>,
Expand Down Expand Up @@ -388,44 +320,6 @@ fn eval_l_0_and_l_last<F: Field>(log_n: usize, x: F) -> (F, F) {
(z_x * invs[0], z_x * invs[1])
}

#[cfg(test)]
pub(crate) mod testutils {
use super::*;

/// Output all the extra memory rows that don't appear in the CPU trace but are
/// necessary to correctly check the MemoryStark CTL.
pub(crate) fn get_memory_extra_looking_values<F, const D: usize>(
_public_values: &PublicValues,
) -> Vec<Vec<F>>
where
F: RichField + Extendable<D>,
{
/*
let fields = [{}];
fields.map(|(field, val)| {
extra_looking_rows.push(add_extra_looking_row(segment, field as usize, val))
});
*/
Vec::new()
}

fn add_extra_looking_row<F, const D: usize>(segment: F, index: usize, val: u32) -> Vec<F>
where
F: RichField + Extendable<D>,
{
let mut row = vec![F::ZERO; 13];
row[0] = F::ZERO; // is_read
row[1] = F::ZERO; // context
row[2] = segment;
row[3] = F::from_canonical_usize(index);

row[4] = F::from_canonical_u32(val);
// FIXME
row[12] = F::ONE; // timestamp
row
}
}

#[cfg(test)]
mod tests {
use plonky2::field::goldilocks_field::GoldilocksField;
Expand Down

0 comments on commit 41846a4

Please sign in to comment.