Skip to content

Commit

Permalink
Logup - rename claimed_sum to total_sum (#825)
Browse files Browse the repository at this point in the history
Rename claimed_sum to total_sum
Take total_sum from cum_sum column
  • Loading branch information
shaharsamocha7 authored Sep 24, 2024
2 parents e9c6ba2 + 62932c1 commit 75b94f9
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 43 deletions.
35 changes: 16 additions & 19 deletions crates/prover/src/constraint_framework/logup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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;
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};
Expand All @@ -25,8 +25,8 @@ use crate::core::ColumnVec;
pub struct LogupAtRow<E: EvalAtRow> {
/// 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<Fraction<E::EF, E::EF>>,
Expand All @@ -36,10 +36,10 @@ pub struct LogupAtRow<E: EvalAtRow> {
pub is_first: E::F,
}
impl<E: EvalAtRow> LogupAtRow<E> {
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,
Expand All @@ -66,8 +66,8 @@ impl<E: EvalAtRow> LogupAtRow<E> {
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);
Expand Down Expand Up @@ -171,19 +171,16 @@ impl LogupTraceGenerator {
ColumnVec<CircleEvaluation<SimdBackend, BaseField, BitReversedOrder>>,
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
Expand All @@ -194,7 +191,7 @@ impl LogupTraceGenerator {
})
})
.collect_vec();
(trace, claimed_sum)
(trace, total_sum)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/examples/blake/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
)
})
Expand Down
10 changes: 5 additions & 5 deletions crates/prover/src/examples/blake/round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
Expand All @@ -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())
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions crates/prover/src/examples/blake/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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())
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions crates/prover/src/examples/blake/xor_table/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ pub fn generate_interaction_trace<const ELEM_BITS: u32, const EXPAND_BITS: u32>(
}
}

let (interaction_trace, claimed_sum) = logup_gen.finalize();
(interaction_trace, claimed_sum)
logup_gen.finalize()
}

/// Generates the constant trace for the xor table.
Expand Down
8 changes: 4 additions & 4 deletions crates/prover/src/examples/plonk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub type PlonkComponent = FrameworkComponent<PlonkEval>;
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,
Expand All @@ -46,7 +46,7 @@ impl FrameworkEval for PlonkEval {

fn evaluate<E: EvalAtRow>(&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]);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub type PoseidonElements = LookupElements<N_STATE>;
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 {
Expand All @@ -61,7 +61,7 @@ impl FrameworkEval for PoseidonEval {
}
fn evaluate<E: EvalAtRow>(&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
}
Expand Down Expand Up @@ -363,7 +363,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);
Expand All @@ -383,7 +383,7 @@ pub fn prove_poseidon(
PoseidonEval {
log_n_rows,
lookup_elements,
claimed_sum,
total_sum,
},
);
let proof = prove(&[&component], channel, commitment_scheme).unwrap();
Expand Down Expand Up @@ -472,7 +472,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)]]);
Expand All @@ -482,7 +482,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,
);
});
Expand Down

0 comments on commit 75b94f9

Please sign in to comment.