mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-10 17:53:06 +00:00
Fix BytePacking range-check. Fix lookup challenges
This commit is contained in:
parent
c9c0f8b7e5
commit
17f661f90f
@ -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<F: RichField + Extendable<D>, const D: usize> BytePackingStark<F, D> {
|
||||
// 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<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for BytePackingSt
|
||||
FE: FieldExtension<D2, BaseField = F>,
|
||||
P: PackedField<Scalar = FE>,
|
||||
{
|
||||
// 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<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for BytePackingSt
|
||||
vars: StarkEvaluationTargets<D, { Self::COLUMNS }>,
|
||||
yield_constr: &mut RecursiveConstraintConsumer<F, D>,
|
||||
) {
|
||||
// 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<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for BytePackingSt
|
||||
fn constraint_degree(&self) -> usize {
|
||||
3
|
||||
}
|
||||
|
||||
fn lookups(&self) -> Vec<Lookup> {
|
||||
vec![Lookup {
|
||||
columns: (value_bytes(0)..value_bytes(NUM_BYTES)).collect(),
|
||||
table_column: RANGE_COUNTER,
|
||||
frequencies_column: RC_FREQUENCIES,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@ -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<usize> = 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;
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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<F, C, const D: usize>(
|
||||
trace_commitments: Vec<PolynomialBatch<F, C, D>>,
|
||||
ctl_data_per_table: [CtlData<F>; NUM_TABLES],
|
||||
challenger: &mut Challenger<F, C::Hasher>,
|
||||
ctl_challenges: GrandProductChallengeSet<F>,
|
||||
ctl_challenges: &GrandProductChallengeSet<F>,
|
||||
timing: &mut TimingTree,
|
||||
) -> Result<[StarkProofWithMetadata<F, C, D>; 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<F, C, S, const D: usize>(
|
||||
trace_poly_values: &[PolynomialValues<F>],
|
||||
trace_commitment: &PolynomialBatch<F, C, D>,
|
||||
ctl_data: &CtlData<F>,
|
||||
ctl_challenges: GrandProductChallengeSet<F>,
|
||||
ctl_challenges: &GrandProductChallengeSet<F>,
|
||||
challenger: &mut Challenger<F, C::Hasher>,
|
||||
timing: &mut TimingTree,
|
||||
) -> Result<StarkProofWithMetadata<F, C, D>>
|
||||
|
||||
@ -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<F, C, D>,
|
||||
challenges: &StarkProofChallenges<F, D>,
|
||||
ctl_vars: &[CtlCheckVars<F, F::Extension, F::Extension, D>],
|
||||
ctl_challenges: &GrandProductChallengeSet<F>,
|
||||
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::<Vec<_>>()
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user