From ffa166655ac4ec8e4195893b913dd3f7c1a70e34 Mon Sep 17 00:00:00 2001 From: Shahar Samocha Date: Sun, 8 Sep 2024 17:59:10 +0300 Subject: [PATCH] Logup - rename claimed_sum to total_sum Take total_sum from cum_sum column --- .../prover/src/constraint_framework/logup.rs | 35 +++++++++---------- crates/prover/src/examples/blake/air.rs | 4 +-- crates/prover/src/examples/blake/round/mod.rs | 10 +++--- .../src/examples/blake/scheduler/mod.rs | 10 +++--- .../src/examples/blake/xor_table/gen.rs | 3 +- crates/prover/src/examples/plonk/mod.rs | 8 ++--- crates/prover/src/examples/poseidon/mod.rs | 12 +++---- 7 files changed, 39 insertions(+), 43 deletions(-) diff --git a/crates/prover/src/constraint_framework/logup.rs b/crates/prover/src/constraint_framework/logup.rs index 89982a5c5..69860bd31 100644 --- a/crates/prover/src/constraint_framework/logup.rs +++ b/crates/prover/src/constraint_framework/logup.rs @@ -5,7 +5,7 @@ use num_traits::{One, Zero}; use super::EvalAtRow; use crate::core::backend::simd::column::SecureColumn; -use crate::core::backend::simd::m31::{PackedBaseField, LOG_N_LANES}; +use crate::core::backend::simd::m31::LOG_N_LANES; use crate::core::backend::simd::prefix_sum::inclusive_prefix_sum; use crate::core::backend::simd::qm31::PackedSecureField; use crate::core::backend::simd::SimdBackend; @@ -13,7 +13,7 @@ use crate::core::backend::Column; use crate::core::channel::Channel; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; -use crate::core::fields::secure_column::{SecureColumnByCoords, SECURE_EXTENSION_DEGREE}; +use crate::core::fields::secure_column::SecureColumnByCoords; use crate::core::fields::FieldExpOps; use crate::core::lookups::utils::Fraction; use crate::core::poly::circle::{CanonicCoset, CircleEvaluation}; @@ -25,8 +25,8 @@ use crate::core::ColumnVec; pub struct LogupAtRow { /// The index of the interaction used for the cumulative sum columns. pub interaction: usize, - /// The claimed sum of all the fractions. - pub claimed_sum: SecureField, + /// The total sum of all the fractions. + pub total_sum: SecureField, /// The evaluation of the last cumulative sum column. pub prev_col_cumsum: E::EF, cur_frac: Option>, @@ -36,10 +36,10 @@ pub struct LogupAtRow { pub is_first: E::F, } impl LogupAtRow { - pub fn new(interaction: usize, claimed_sum: SecureField, is_first: E::F) -> Self { + pub fn new(interaction: usize, total_sum: SecureField, is_first: E::F) -> Self { Self { interaction, - claimed_sum, + total_sum, prev_col_cumsum: E::EF::zero(), cur_frac: None, is_finalized: false, @@ -66,8 +66,8 @@ impl LogupAtRow { let [cur_cumsum, prev_row_cumsum] = eval.next_extension_interaction_mask(self.interaction, [0, -1]); - // Fix `prev_row_cumsum` by subtracting `claimed_sum` if this is the first row. - let fixed_prev_row_cumsum = prev_row_cumsum - self.is_first * self.claimed_sum; + // Fix `prev_row_cumsum` by subtracting `total_sum` if this is the first row. + let fixed_prev_row_cumsum = prev_row_cumsum - self.is_first * self.total_sum; let diff = cur_cumsum - fixed_prev_row_cumsum - self.prev_col_cumsum; eval.add_constraint(diff * frac.denominator - frac.numerator); @@ -163,19 +163,16 @@ impl LogupTraceGenerator { ColumnVec>, SecureField, ) { - // Compute claimed sum. - let last_col_coords = self.trace.pop().unwrap().columns; - let packed_sums: [PackedBaseField; SECURE_EXTENSION_DEGREE] = last_col_coords - .each_ref() - .map(|c| c.data.iter().copied().sum()); - let base_sums = packed_sums.map(|s| s.pointwise_sum()); - let claimed_sum = SecureField::from_m31_array(base_sums); - // Prefix sum the last column. + let last_col_coords = self.trace.pop().unwrap().columns; let coord_prefix_sum = last_col_coords.map(inclusive_prefix_sum); - self.trace.push(SecureColumnByCoords { + let secure_prefix_sum = SecureColumnByCoords { columns: coord_prefix_sum, - }); + }; + + // The last element in bit-reversed circle domain order is at index 1. + let total_sum = secure_prefix_sum.at(1); + self.trace.push(secure_prefix_sum); let trace = self .trace @@ -186,7 +183,7 @@ impl LogupTraceGenerator { }) }) .collect_vec(); - (trace, claimed_sum) + (trace, total_sum) } } diff --git a/crates/prover/src/examples/blake/air.rs b/crates/prover/src/examples/blake/air.rs index a91e02700..fae130930 100644 --- a/crates/prover/src/examples/blake/air.rs +++ b/crates/prover/src/examples/blake/air.rs @@ -128,7 +128,7 @@ impl BlakeComponents { log_size: stmt0.log_size, blake_lookup_elements: all_elements.blake_elements.clone(), round_lookup_elements: all_elements.round_elements.clone(), - claimed_sum: stmt1.scheduler_claimed_sum, + total_sum: stmt1.scheduler_claimed_sum, }, ), round_components: ROUND_LOG_SPLIT @@ -141,7 +141,7 @@ impl BlakeComponents { log_size: stmt0.log_size + l, xor_lookup_elements: all_elements.xor_elements.clone(), round_lookup_elements: all_elements.round_elements.clone(), - claimed_sum, + total_sum: claimed_sum, }, ) }) diff --git a/crates/prover/src/examples/blake/round/mod.rs b/crates/prover/src/examples/blake/round/mod.rs index 68156cde5..807d85525 100644 --- a/crates/prover/src/examples/blake/round/mod.rs +++ b/crates/prover/src/examples/blake/round/mod.rs @@ -17,7 +17,7 @@ pub struct BlakeRoundEval { pub log_size: u32, pub xor_lookup_elements: BlakeXorElements, pub round_lookup_elements: RoundElements, - pub claimed_sum: SecureField, + pub total_sum: SecureField, } impl FrameworkEval for BlakeRoundEval { @@ -33,7 +33,7 @@ impl FrameworkEval for BlakeRoundEval { eval, xor_lookup_elements: &self.xor_lookup_elements, round_lookup_elements: &self.round_lookup_elements, - logup: LogupAtRow::new(1, self.claimed_sum, is_first), + logup: LogupAtRow::new(1, self.total_sum, is_first), }; blake_eval.eval() } @@ -44,7 +44,7 @@ pub fn blake_round_info() -> InfoEvaluator { log_size: 1, xor_lookup_elements: BlakeXorElements::dummy(), round_lookup_elements: RoundElements::dummy(), - claimed_sum: SecureField::zero(), + total_sum: SecureField::zero(), }; component.evaluate(InfoEvaluator::default()) } @@ -84,7 +84,7 @@ mod tests { let xor_lookup_elements = BlakeXorElements::dummy(); let round_lookup_elements = RoundElements::dummy(); - let (interaction_trace, claimed_sum) = generate_interaction_trace( + let (interaction_trace, total_sum) = generate_interaction_trace( LOG_SIZE, lookup_data, &xor_lookup_elements, @@ -98,7 +98,7 @@ mod tests { log_size: LOG_SIZE, xor_lookup_elements, round_lookup_elements, - claimed_sum, + total_sum, }; crate::constraint_framework::assert_constraints( &trace_polys, diff --git a/crates/prover/src/examples/blake/scheduler/mod.rs b/crates/prover/src/examples/blake/scheduler/mod.rs index e43c8d88d..e795ebfd8 100644 --- a/crates/prover/src/examples/blake/scheduler/mod.rs +++ b/crates/prover/src/examples/blake/scheduler/mod.rs @@ -19,7 +19,7 @@ pub struct BlakeSchedulerEval { pub log_size: u32, pub blake_lookup_elements: BlakeElements, pub round_lookup_elements: RoundElements, - pub claimed_sum: SecureField, + pub total_sum: SecureField, } impl FrameworkEval for BlakeSchedulerEval { fn log_size(&self) -> u32 { @@ -34,7 +34,7 @@ impl FrameworkEval for BlakeSchedulerEval { &mut eval, &self.blake_lookup_elements, &self.round_lookup_elements, - LogupAtRow::new(1, self.claimed_sum, is_first), + LogupAtRow::new(1, self.total_sum, is_first), ); eval } @@ -45,7 +45,7 @@ pub fn blake_scheduler_info() -> InfoEvaluator { log_size: 1, blake_lookup_elements: BlakeElements::dummy(), round_lookup_elements: RoundElements::dummy(), - claimed_sum: SecureField::zero(), + total_sum: SecureField::zero(), }; component.evaluate(InfoEvaluator::default()) } @@ -81,7 +81,7 @@ mod tests { let round_lookup_elements = RoundElements::dummy(); let blake_lookup_elements = BlakeElements::dummy(); - let (interaction_trace, claimed_sum) = gen_interaction_trace( + let (interaction_trace, total_sum) = gen_interaction_trace( LOG_SIZE, lookup_data, &round_lookup_elements, @@ -95,7 +95,7 @@ mod tests { log_size: LOG_SIZE, blake_lookup_elements, round_lookup_elements, - claimed_sum, + total_sum, }; crate::constraint_framework::assert_constraints( &trace_polys, diff --git a/crates/prover/src/examples/blake/xor_table/gen.rs b/crates/prover/src/examples/blake/xor_table/gen.rs index bf6e43ad6..59d3fd92d 100644 --- a/crates/prover/src/examples/blake/xor_table/gen.rs +++ b/crates/prover/src/examples/blake/xor_table/gen.rs @@ -132,8 +132,7 @@ pub fn generate_interaction_trace( } } - let (interaction_trace, claimed_sum) = logup_gen.finalize(); - (interaction_trace, claimed_sum) + logup_gen.finalize() } /// Generates the constant trace for the xor table. diff --git a/crates/prover/src/examples/plonk/mod.rs b/crates/prover/src/examples/plonk/mod.rs index ae7a29b7c..5ebb5aa57 100644 --- a/crates/prover/src/examples/plonk/mod.rs +++ b/crates/prover/src/examples/plonk/mod.rs @@ -29,7 +29,7 @@ pub type PlonkComponent = FrameworkComponent; pub struct PlonkEval { pub log_n_rows: u32, pub lookup_elements: LookupElements<2>, - pub claimed_sum: SecureField, + pub total_sum: SecureField, pub base_trace_location: TreeSubspan, pub interaction_trace_location: TreeSubspan, pub constants_trace_location: TreeSubspan, @@ -46,7 +46,7 @@ impl FrameworkEval for PlonkEval { fn evaluate(&self, mut eval: E) -> E { let [is_first] = eval.next_interaction_mask(2, [0]); - let mut logup = LogupAtRow::<_>::new(1, self.claimed_sum, is_first); + let mut logup = LogupAtRow::<_>::new(1, self.total_sum, is_first); let [a_wire] = eval.next_interaction_mask(2, [0]); let [b_wire] = eval.next_interaction_mask(2, [0]); @@ -197,7 +197,7 @@ pub fn prove_fibonacci_plonk( // Interaction trace. let span = span!(Level::INFO, "Interaction").entered(); - let (trace, claimed_sum) = gen_interaction_trace(log_n_rows, &circuit, &lookup_elements); + let (trace, total_sum) = gen_interaction_trace(log_n_rows, &circuit, &lookup_elements); let mut tree_builder = commitment_scheme.tree_builder(); let interaction_trace_location = tree_builder.extend_evals(trace); tree_builder.commit(channel); @@ -227,7 +227,7 @@ pub fn prove_fibonacci_plonk( PlonkEval { log_n_rows, lookup_elements, - claimed_sum, + total_sum, base_trace_location, interaction_trace_location, constants_trace_location, diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index 33072ec91..067334cd7 100644 --- a/crates/prover/src/examples/poseidon/mod.rs +++ b/crates/prover/src/examples/poseidon/mod.rs @@ -50,7 +50,7 @@ pub type PoseidonElements = LookupElements; pub struct PoseidonEval { pub log_n_rows: u32, pub lookup_elements: PoseidonElements, - pub claimed_sum: SecureField, + pub total_sum: SecureField, } impl FrameworkEval for PoseidonEval { fn log_size(&self) -> u32 { @@ -61,7 +61,7 @@ impl FrameworkEval for PoseidonEval { } fn evaluate(&self, mut eval: E) -> E { let [is_first] = eval.next_interaction_mask(2, [0]); - let logup = LogupAtRow::new(1, self.claimed_sum, is_first); + let logup = LogupAtRow::new(1, self.total_sum, is_first); eval_poseidon_constraints(&mut eval, logup, &self.lookup_elements); eval } @@ -362,7 +362,7 @@ pub fn prove_poseidon( // Interaction trace. let span = span!(Level::INFO, "Interaction").entered(); - let (trace, claimed_sum) = gen_interaction_trace(log_n_rows, lookup_data, &lookup_elements); + let (trace, total_sum) = gen_interaction_trace(log_n_rows, lookup_data, &lookup_elements); let mut tree_builder = commitment_scheme.tree_builder(); tree_builder.extend_evals(trace); tree_builder.commit(channel); @@ -382,7 +382,7 @@ pub fn prove_poseidon( PoseidonEval { log_n_rows, lookup_elements, - claimed_sum, + total_sum, }, ); let proof = prove(&[&component], channel, commitment_scheme).unwrap(); @@ -471,7 +471,7 @@ mod tests { // Trace. let (trace0, interaction_data) = gen_trace(LOG_N_ROWS); let lookup_elements = LookupElements::dummy(); - let (trace1, claimed_sum) = + let (trace1, total_sum) = gen_interaction_trace(LOG_N_ROWS, interaction_data, &lookup_elements); let traces = TreeVec::new(vec![trace0, trace1, vec![gen_is_first(LOG_N_ROWS)]]); @@ -481,7 +481,7 @@ mod tests { let [is_first] = eval.next_interaction_mask(2, [0]); eval_poseidon_constraints( &mut eval, - LogupAtRow::new(1, claimed_sum, is_first), + LogupAtRow::new(1, total_sum, is_first), &lookup_elements, ); });