Skip to content

Commit

Permalink
Rename total_sum to claimed_sum (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
shaharsamocha7 authored Jan 15, 2025
2 parents c2a584e + a4f21f1 commit 438c107
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 81 deletions.
8 changes: 4 additions & 4 deletions crates/prover/src/constraint_framework/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ impl<'a> AssertEvaluator<'a> {
trace: &'a TreeVec<Vec<Vec<BaseField>>>,
row: usize,
log_size: u32,
total_sum: SecureField,
claimed_sum: SecureField,
) -> Self {
Self {
trace,
col_index: TreeVec::new(vec![0; trace.len()]),
row,
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, total_sum, log_size),
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, claimed_sum, log_size),
}
}
}
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn assert_constraints<B: Backend>(
trace_polys: &TreeVec<Vec<CirclePoly<B>>>,
trace_domain: CanonicCoset,
assert_func: impl Fn(AssertEvaluator<'_>),
total_sum: SecureField,
claimed_sum: SecureField,
) {
let traces = trace_polys.as_ref().map(|tree| {
tree.iter()
Expand All @@ -94,7 +94,7 @@ pub fn assert_constraints<B: Backend>(
.collect()
});
for row in 0..trace_domain.size() {
let eval = AssertEvaluator::new(&traces, row, trace_domain.log_size(), total_sum);
let eval = AssertEvaluator::new(&traces, row, trace_domain.log_size(), claimed_sum);

assert_func(eval);
}
Expand Down
16 changes: 8 additions & 8 deletions crates/prover/src/constraint_framework/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,16 @@ pub struct FrameworkComponent<C: FrameworkEval> {
trace_locations: TreeVec<TreeSubspan>,
info: InfoEvaluator,
preprocessed_column_indices: Vec<usize>,
total_sum: SecureField,
claimed_sum: SecureField,
}

impl<E: FrameworkEval> FrameworkComponent<E> {
pub fn new(
location_allocator: &mut TraceLocationAllocator,
eval: E,
total_sum: SecureField,
claimed_sum: SecureField,
) -> Self {
let info = eval.evaluate(InfoEvaluator::new(eval.log_size(), vec![], total_sum));
let info = eval.evaluate(InfoEvaluator::new(eval.log_size(), vec![], claimed_sum));
let trace_locations = location_allocator.next_for_structure(&info.mask_offsets);

let preprocessed_column_indices = info
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<E: FrameworkEval> FrameworkComponent<E> {
trace_locations,
info,
preprocessed_column_indices,
total_sum,
claimed_sum,
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@ impl<E: FrameworkEval> Component for FrameworkComponent<E> {
evaluation_accumulator,
coset_vanishing(CanonicCoset::new(self.eval.log_size()).coset, point).inverse(),
self.eval.log_size(),
self.total_sum,
self.claimed_sum,
));
}
}
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<E: FrameworkEval + Sync> ComponentProver<SimdBackend> for FrameworkComponen
trace_domain.log_size(),
eval_domain.log_size(),
self.eval.log_size(),
self.total_sum,
self.claimed_sum,
);
let row_res = self.eval.evaluate(eval).row_res;

Expand Down Expand Up @@ -347,7 +347,7 @@ impl<E: FrameworkEval + Sync> ComponentProver<SimdBackend> for FrameworkComponen
// Define any `self` values outside the loop to prevent the compiler thinking there is a
// `Sync` requirement on `Self`.
let self_eval = &self.eval;
let self_total_sum = self.total_sum;
let self_claimed_sum = self.claimed_sum;

iter.for_each(|(chunk_idx, mut chunk)| {
let trace_cols = trace.as_cols_ref().map_cols(|c| c.as_ref());
Expand All @@ -362,7 +362,7 @@ impl<E: FrameworkEval + Sync> ComponentProver<SimdBackend> for FrameworkComponen
trace_domain.log_size(),
eval_domain.log_size(),
self_eval.log_size(),
self_total_sum,
self_claimed_sum,
);
let row_res = self_eval.evaluate(eval).row_res;

Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/constraint_framework/cpu_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a> CpuDomainEvaluator<'a> {
domain_log_size: u32,
eval_log_size: u32,
log_size: u32,
total_sum: SecureField,
claimed_sum: SecureField,
) -> Self {
Self {
trace_eval,
Expand All @@ -47,7 +47,7 @@ impl<'a> CpuDomainEvaluator<'a> {
constraint_index: 0,
domain_log_size,
eval_domain_log_size: eval_log_size,
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, total_sum, log_size),
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, claimed_sum, log_size),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/prover/src/constraint_framework/expr/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::core::lookups::utils::Fraction;

pub struct FormalLogupAtRow {
pub interaction: usize,
pub total_sum: ExtExpr,
pub claimed_sum: ExtExpr,
pub fracs: Vec<Fraction<ExtExpr, ExtExpr>>,
pub is_finalized: bool,
pub is_first: BaseExpr,
Expand All @@ -20,16 +20,16 @@ pub struct FormalLogupAtRow {

impl FormalLogupAtRow {
pub fn new(interaction: usize, log_size: u32) -> Self {
let total_sum_name = "total_sum".to_string();
let claimed_sum_name = "claimed_sum".to_string();

Self {
interaction,
// TODO(alont): Should these be Expr::SecureField?
total_sum: ExtExpr::Param(total_sum_name.clone()),
claimed_sum: ExtExpr::Param(claimed_sum_name.clone()),
fracs: vec![],
is_finalized: true,
is_first: BaseExpr::zero(),
cumsum_shift: ExtExpr::Param(total_sum_name)
cumsum_shift: ExtExpr::Param(claimed_sum_name)
* BaseExpr::Inv(Box::new(BaseExpr::pow(
&BaseExpr::Const(M31(2)),
log_size as u128,
Expand Down Expand Up @@ -207,7 +207,7 @@ mod tests {
\
let constraint_1 = (QM31Impl::from_partial_evals([trace_2_column_3_offset_0, trace_2_column_4_offset_0, trace_2_column_5_offset_0, trace_2_column_6_offset_0]) \
- (QM31Impl::from_partial_evals([trace_2_column_3_offset_neg_1, trace_2_column_4_offset_neg_1, trace_2_column_5_offset_neg_1, trace_2_column_6_offset_neg_1])) \
+ (total_sum) * (qm31(32768, 0, 0, 0))) \
+ (claimed_sum) * (qm31(32768, 0, 0, 0))) \
* (intermediate1) \
- (qm31(1, 0, 0, 0));"
.to_string();
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/constraint_framework/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ impl InfoEvaluator {
pub fn new(
log_size: u32,
preprocessed_columns: Vec<PreProcessedColumnId>,
total_sum: SecureField,
claimed_sum: SecureField,
) -> Self {
Self {
mask_offsets: Default::default(),
n_constraints: Default::default(),
preprocessed_columns,
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, total_sum, log_size),
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, claimed_sum, log_size),
arithmetic_counts: Default::default(),
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/prover/src/constraint_framework/logup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::core::poly::BitReversedOrder;
use crate::core::ColumnVec;

/// Evaluates constraints for batched logups.
/// These constraint enforce the sum of multiplicity_i / (z + sum_j alpha^j * x_j) = total_sum.
/// These constraint enforce the sum of multiplicity_i / (z + sum_j alpha^j * x_j) = claimed_sum.
pub struct LogupAtRow<E: EvalAtRow> {
/// The index of the interaction used for the cumulative sum columns.
pub interaction: usize,
Expand All @@ -39,10 +39,10 @@ impl<E: EvalAtRow> Default for LogupAtRow<E> {
}
}
impl<E: EvalAtRow> LogupAtRow<E> {
pub fn new(interaction: usize, total_sum: SecureField, log_size: u32) -> Self {
pub fn new(interaction: usize, claimed_sum: SecureField, log_size: u32) -> Self {
Self {
interaction,
cumsum_shift: total_sum / BaseField::from_u32_unchecked(1 << log_size),
cumsum_shift: claimed_sum / BaseField::from_u32_unchecked(1 << log_size),
fracs: vec![],
is_finalized: true,
log_size,
Expand Down Expand Up @@ -167,8 +167,8 @@ impl LogupTraceGenerator {
.sum::<PackedBaseField>()
.pointwise_sum()
});
let total_sum = SecureField::from_m31_array(coordinate_sums);
let cumsum_shift = total_sum / BaseField::from_u32_unchecked(1 << self.log_size);
let claimed_sum = SecureField::from_m31_array(coordinate_sums);
let cumsum_shift = claimed_sum / BaseField::from_u32_unchecked(1 << self.log_size);
let packed_cumsum_shift = PackedSecureField::broadcast(cumsum_shift);

last_col_coords.iter_mut().enumerate().for_each(|(i, c)| {
Expand All @@ -190,7 +190,7 @@ impl LogupTraceGenerator {
})
})
.collect_vec();
(trace, total_sum)
(trace, claimed_sum)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/constraint_framework/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ impl<'a> PointEvaluator<'a> {
evaluation_accumulator: &'a mut PointEvaluationAccumulator,
denom_inverse: SecureField,
log_size: u32,
total_sum: SecureField,
claimed_sum: SecureField,
) -> Self {
let col_index = vec![0; mask.len()];
Self {
mask,
evaluation_accumulator,
col_index,
denom_inverse,
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, total_sum, log_size),
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, claimed_sum, log_size),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/prover/src/constraint_framework/simd_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'a> SimdDomainEvaluator<'a> {
domain_log_size: u32,
eval_log_size: u32,
log_size: u32,
total_sum: SecureField,
claimed_sum: SecureField,
) -> Self {
Self {
trace_eval,
Expand All @@ -53,7 +53,7 @@ impl<'a> SimdDomainEvaluator<'a> {
constraint_index: 0,
domain_log_size,
eval_domain_log_size: eval_log_size,
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, total_sum, log_size),
logup: LogupAtRow::new(INTERACTION_TRACE_IDX, claimed_sum, log_size),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/prover/src/examples/blake/air.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl BlakeComponents {
log_size: stmt0.log_size,
blake_lookup_elements: all_elements.blake_elements.clone(),
round_lookup_elements: all_elements.round_elements.clone(),
total_sum: stmt1.scheduler_claimed_sum,
claimed_sum: stmt1.scheduler_claimed_sum,
},
stmt1.scheduler_claimed_sum,
),
Expand All @@ -223,7 +223,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(),
total_sum: claimed_sum,
claimed_sum,
},
claimed_sum,
)
Expand Down Expand Up @@ -532,7 +532,7 @@ pub fn verify_blake<MC: MerkleChannel>(
let components = BlakeComponents::new(&stmt0, &all_elements, &stmt1);

// Check that all sums are correct.
let total_sum = stmt1.scheduler_claimed_sum
let claimed_sum = stmt1.scheduler_claimed_sum
+ stmt1.round_claimed_sums.iter().sum::<SecureField>()
+ stmt1.xor12_claimed_sum
+ stmt1.xor9_claimed_sum
Expand All @@ -541,7 +541,7 @@ pub fn verify_blake<MC: MerkleChannel>(
+ stmt1.xor4_claimed_sum;

// TODO(shahars): Add inputs to sum, and constraint them.
assert_eq!(total_sum, SecureField::zero());
assert_eq!(claimed_sum, SecureField::zero());

verify(
&components.components(),
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/examples/blake/round/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct BlakeRoundEval<'a, E: EvalAtRow> {
pub xor_lookup_elements: &'a BlakeXorElements,
pub round_lookup_elements: &'a RoundElements,
// TODO(first): validate logup.
pub _total_sum: SecureField,
pub _claimed_sum: SecureField,
pub _log_size: u32,
}
impl<E: EvalAtRow> BlakeRoundEval<'_, E> {
Expand Down
12 changes: 6 additions & 6 deletions crates/prover/src/examples/blake/round/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct BlakeRoundEval {
pub log_size: u32,
pub xor_lookup_elements: BlakeXorElements,
pub round_lookup_elements: RoundElements,
pub total_sum: SecureField,
pub claimed_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,
_total_sum: self.total_sum,
_claimed_sum: self.claimed_sum,
_log_size: self.log_size,
};
blake_eval.eval()
Expand All @@ -45,7 +45,7 @@ pub fn blake_round_info() -> InfoEvaluator {
log_size: 1,
xor_lookup_elements: BlakeXorElements::dummy(),
round_lookup_elements: RoundElements::dummy(),
total_sum: SecureField::zero(),
claimed_sum: SecureField::zero(),
};
component.evaluate(InfoEvaluator::empty())
}
Expand Down Expand Up @@ -85,7 +85,7 @@ mod tests {

let xor_lookup_elements = BlakeXorElements::dummy();
let round_lookup_elements = RoundElements::dummy();
let (interaction_trace, total_sum) = generate_interaction_trace(
let (interaction_trace, claimed_sum) = generate_interaction_trace(
LOG_SIZE,
lookup_data,
&xor_lookup_elements,
Expand All @@ -103,15 +103,15 @@ mod tests {
log_size: LOG_SIZE,
xor_lookup_elements,
round_lookup_elements,
total_sum,
claimed_sum,
};
crate::constraint_framework::assert_constraints(
&trace_polys,
CanonicCoset::new(LOG_SIZE),
|eval| {
component.evaluate(eval);
},
total_sum,
claimed_sum,
)
}
}
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 @@ -22,7 +22,7 @@ pub struct BlakeSchedulerEval {
pub blake_lookup_elements: BlakeElements,
pub round_lookup_elements: RoundElements,
// TODO(first): validate logup.
pub total_sum: SecureField,
pub claimed_sum: SecureField,
}
impl FrameworkEval for BlakeSchedulerEval {
fn log_size(&self) -> u32 {
Expand All @@ -46,7 +46,7 @@ pub fn blake_scheduler_info() -> InfoEvaluator {
log_size: 1,
blake_lookup_elements: BlakeElements::dummy(),
round_lookup_elements: RoundElements::dummy(),
total_sum: SecureField::zero(),
claimed_sum: SecureField::zero(),
};
component.evaluate(InfoEvaluator::empty())
}
Expand Down Expand Up @@ -82,7 +82,7 @@ mod tests {

let round_lookup_elements = RoundElements::dummy();
let blake_lookup_elements = BlakeElements::dummy();
let (interaction_trace, total_sum) = gen_interaction_trace(
let (interaction_trace, claimed_sum) = gen_interaction_trace(
LOG_SIZE,
lookup_data,
&round_lookup_elements,
Expand All @@ -100,15 +100,15 @@ mod tests {
log_size: LOG_SIZE,
blake_lookup_elements,
round_lookup_elements,
total_sum,
claimed_sum,
};
crate::constraint_framework::assert_constraints(
&trace_polys,
CanonicCoset::new(LOG_SIZE),
|eval| {
component.evaluate(eval);
},
total_sum,
claimed_sum,
)
}
}
Loading

0 comments on commit 438c107

Please sign in to comment.