diff --git a/crates/prover/src/constraint_framework/assert.rs b/crates/prover/src/constraint_framework/assert.rs index 9e5530bae..b61bbf51d 100644 --- a/crates/prover/src/constraint_framework/assert.rs +++ b/crates/prover/src/constraint_framework/assert.rs @@ -1,10 +1,12 @@ use num_traits::{One, Zero}; +use super::logup::LogupAtRow; use super::EvalAtRow; use crate::core::backend::{Backend, Column}; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE; +use crate::core::lookups::utils::Fraction; use crate::core::pcs::TreeVec; use crate::core::poly::circle::{CanonicCoset, CirclePoly}; use crate::core::utils::circle_domain_order_to_coset_order; @@ -14,6 +16,7 @@ pub struct AssertEvaluator<'a> { pub trace: &'a TreeVec>>, pub col_index: TreeVec, pub row: usize, + pub logup: LogupAtRow, } impl<'a> AssertEvaluator<'a> { pub fn new(trace: &'a TreeVec>>, row: usize) -> Self { @@ -21,6 +24,7 @@ impl<'a> AssertEvaluator<'a> { trace, col_index: TreeVec::new(vec![0; trace.len()]), row, + logup: LogupAtRow::dummy(), } } } @@ -57,6 +61,8 @@ impl<'a> EvalAtRow for AssertEvaluator<'a> { fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF { SecureField::from_m31_array(values) } + + super::logup_proxy!(); } pub fn assert_constraints( diff --git a/crates/prover/src/constraint_framework/cpu_domain.rs b/crates/prover/src/constraint_framework/cpu_domain.rs index d8aad0b8b..9acdc5e40 100644 --- a/crates/prover/src/constraint_framework/cpu_domain.rs +++ b/crates/prover/src/constraint_framework/cpu_domain.rs @@ -2,11 +2,13 @@ use std::ops::Mul; use num_traits::Zero; +use super::logup::LogupAtRow; use super::EvalAtRow; use crate::core::backend::CpuBackend; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE; +use crate::core::lookups::utils::Fraction; use crate::core::pcs::TreeVec; use crate::core::poly::circle::CircleEvaluation; use crate::core::poly::BitReversedOrder; @@ -22,6 +24,7 @@ pub struct CpuDomainEvaluator<'a> { pub constraint_index: usize, pub domain_log_size: u32, pub eval_domain_log_size: u32, + pub logup: LogupAtRow, } impl<'a> CpuDomainEvaluator<'a> { @@ -42,6 +45,7 @@ impl<'a> CpuDomainEvaluator<'a> { constraint_index: 0, domain_log_size, eval_domain_log_size: eval_log_size, + logup: LogupAtRow::dummy(), } } } @@ -88,4 +92,6 @@ impl<'a> EvalAtRow for CpuDomainEvaluator<'a> { fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF { SecureField::from_m31_array(values) } + + super::logup_proxy!(); } diff --git a/crates/prover/src/constraint_framework/expr.rs b/crates/prover/src/constraint_framework/expr.rs index a20d71516..f0b5eb775 100644 --- a/crates/prover/src/constraint_framework/expr.rs +++ b/crates/prover/src/constraint_framework/expr.rs @@ -2,10 +2,12 @@ use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub}; use num_traits::{One, Zero}; +use super::logup::LogupAtRow; use super::EvalAtRow; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; use crate::core::fields::FieldExpOps; +use crate::core::lookups::utils::Fraction; /// A single base field column at index `idx` of interaction `interaction`, at mask offset `offset`. #[derive(Clone, Debug, PartialEq)] @@ -149,8 +151,9 @@ impl AddAssign for Expr { /// An Evaluator that saves all constraint expressions. #[derive(Default)] struct ExprEvaluator { - cur_var_index: usize, - constraints: Vec, + pub cur_var_index: usize, + pub constraints: Vec, + pub logup: LogupAtRow, } impl EvalAtRow for ExprEvaluator { @@ -189,6 +192,8 @@ impl EvalAtRow for ExprEvaluator { Box::new(values[3].clone()), ]) } + + super::logup_proxy!(); } #[cfg(test)] diff --git a/crates/prover/src/constraint_framework/info.rs b/crates/prover/src/constraint_framework/info.rs index f7f062f0b..6d428178d 100644 --- a/crates/prover/src/constraint_framework/info.rs +++ b/crates/prover/src/constraint_framework/info.rs @@ -2,11 +2,13 @@ use std::ops::Mul; use num_traits::One; +use super::logup::LogupAtRow; use super::preprocessed_columns::PreprocessedColumn; use super::EvalAtRow; use crate::constraint_framework::PREPROCESSED_TRACE_IDX; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; +use crate::core::lookups::utils::Fraction; use crate::core::pcs::TreeVec; /// Collects information about the constraints. @@ -16,6 +18,7 @@ pub struct InfoEvaluator { pub mask_offsets: TreeVec>>, pub n_constraints: usize, pub preprocessed_columns: Vec, + pub logup: LogupAtRow, } impl InfoEvaluator { pub fn new() -> Self { @@ -60,4 +63,6 @@ impl EvalAtRow for InfoEvaluator { fn combine_ef(_values: [Self::F; 4]) -> Self::EF { SecureField::one() } + + super::logup_proxy!(); } diff --git a/crates/prover/src/constraint_framework/logup.rs b/crates/prover/src/constraint_framework/logup.rs index 81f1acfcb..32da8be76 100644 --- a/crates/prover/src/constraint_framework/logup.rs +++ b/crates/prover/src/constraint_framework/logup.rs @@ -44,6 +44,12 @@ pub struct LogupAtRow { /// See [`super::preprocessed_columns::gen_is_first()`]. pub is_first: E::F, } + +impl Default for LogupAtRow { + fn default() -> Self { + Self::dummy() + } +} impl LogupAtRow { pub fn new( interaction: usize, @@ -62,6 +68,19 @@ impl LogupAtRow { } } + // TODO(alont): Remove this once unnecessary LogupAtRows are gone. + pub fn dummy() -> Self { + Self { + interaction: 100, + total_sum: SecureField::one(), + claimed_sum: None, + prev_col_cumsum: E::EF::zero(), + cur_frac: None, + is_finalized: true, + is_first: E::F::zero(), + } + } + pub fn write_frac(&mut self, eval: &mut E, fraction: Fraction) { // Add a constraint that num / denom = diff. if let Some(cur_frac) = self.cur_frac.clone() { @@ -73,7 +92,7 @@ impl LogupAtRow { self.cur_frac = Some(fraction); } - pub fn finalize(mut self, eval: &mut E) { + pub fn finalize(&mut self, eval: &mut E) { assert!(!self.is_finalized, "LogupAtRow was already finalized"); let frac = self.cur_frac.clone().unwrap(); diff --git a/crates/prover/src/constraint_framework/mod.rs b/crates/prover/src/constraint_framework/mod.rs index a99caa44a..5b84fd45d 100644 --- a/crates/prover/src/constraint_framework/mod.rs +++ b/crates/prover/src/constraint_framework/mod.rs @@ -25,6 +25,7 @@ use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE; use crate::core::fields::FieldExpOps; +use crate::core::lookups::utils::Fraction; pub const PREPROCESSED_TRACE_IDX: usize = 0; pub const ORIGINAL_TRACE_IDX: usize = 1; @@ -109,4 +110,59 @@ pub trait EvalAtRow { /// Combines 4 base field values into a single extension field value. fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF; + + // TODO(alont): Remove these once LogupAtRow is no longer used. + fn init_logup( + &mut self, + _total_sum: SecureField, + _claimed_sum: Option, + _log_size: u32, + ) { + unimplemented!() + } + fn write_frac(&mut self, _fraction: Fraction) { + unimplemented!() + } + fn finalize_logup(&mut self) { + unimplemented!() + } +} + +/// Default implementation for evaluators that have an element called "logup" that works like a +/// LogupAtRow, where the logup functionality can be proxied. +/// TODO(alont): Remove once LogupAtRow is no longer used. +macro_rules! logup_proxy { + () => { + fn init_logup( + &mut self, + total_sum: SecureField, + claimed_sum: Option, + log_size: u32, + ) { + let is_first = self.get_preprocessed_column( + crate::constraint_framework::preprocessed_columns::PreprocessedColumn::IsFirst( + log_size, + ), + ); + self.logup = crate::constraint_framework::logup::LogupAtRow::new( + crate::constraint_framework::INTERACTION_TRACE_IDX, + total_sum, + claimed_sum, + is_first, + ); + } + + fn write_frac(&mut self, fraction: Fraction) { + let mut logup = std::mem::take(&mut self.logup); + logup.write_frac(self, fraction); + self.logup = logup; + } + + fn finalize_logup(&mut self) { + let mut logup = std::mem::take(&mut self.logup); + logup.finalize(self); + self.logup = logup; + } + }; } +pub(crate) use logup_proxy; diff --git a/crates/prover/src/constraint_framework/point.rs b/crates/prover/src/constraint_framework/point.rs index 6c6f72f81..309d5dd56 100644 --- a/crates/prover/src/constraint_framework/point.rs +++ b/crates/prover/src/constraint_framework/point.rs @@ -1,9 +1,11 @@ use std::ops::Mul; +use super::logup::LogupAtRow; use super::EvalAtRow; use crate::core::air::accumulation::PointEvaluationAccumulator; use crate::core::fields::qm31::SecureField; use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE; +use crate::core::lookups::utils::Fraction; use crate::core::pcs::TreeVec; use crate::core::ColumnVec; @@ -13,6 +15,7 @@ pub struct PointEvaluator<'a> { pub evaluation_accumulator: &'a mut PointEvaluationAccumulator, pub col_index: Vec, pub denom_inverse: SecureField, + pub logup: LogupAtRow, } impl<'a> PointEvaluator<'a> { pub fn new( @@ -26,6 +29,7 @@ impl<'a> PointEvaluator<'a> { evaluation_accumulator, col_index, denom_inverse, + logup: LogupAtRow::dummy(), } } } @@ -54,4 +58,6 @@ impl<'a> EvalAtRow for PointEvaluator<'a> { fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF { SecureField::from_partial_evals(values) } + + super::logup_proxy!(); } diff --git a/crates/prover/src/constraint_framework/simd_domain.rs b/crates/prover/src/constraint_framework/simd_domain.rs index 0ae32ebd3..dc71ebf82 100644 --- a/crates/prover/src/constraint_framework/simd_domain.rs +++ b/crates/prover/src/constraint_framework/simd_domain.rs @@ -2,6 +2,7 @@ use std::ops::Mul; use num_traits::Zero; +use super::logup::LogupAtRow; use super::EvalAtRow; use crate::core::backend::simd::column::VeryPackedBaseColumn; use crate::core::backend::simd::m31::LOG_N_LANES; @@ -13,6 +14,7 @@ use crate::core::backend::Column; use crate::core::fields::m31::BaseField; use crate::core::fields::qm31::SecureField; use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE; +use crate::core::lookups::utils::Fraction; use crate::core::pcs::TreeVec; use crate::core::poly::circle::CircleEvaluation; use crate::core::poly::BitReversedOrder; @@ -30,6 +32,7 @@ pub struct SimdDomainEvaluator<'a> { pub constraint_index: usize, pub domain_log_size: u32, pub eval_domain_log_size: u32, + pub logup: LogupAtRow, } impl<'a> SimdDomainEvaluator<'a> { pub fn new( @@ -48,6 +51,7 @@ impl<'a> SimdDomainEvaluator<'a> { constraint_index: 0, domain_log_size, eval_domain_log_size: eval_log_size, + logup: LogupAtRow::dummy(), } } } @@ -103,4 +107,6 @@ impl<'a> EvalAtRow for SimdDomainEvaluator<'a> { fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF { VeryPackedSecureField::from_very_packed_m31s(values) } + + super::logup_proxy!(); } diff --git a/crates/prover/src/examples/blake/round/constraints.rs b/crates/prover/src/examples/blake/round/constraints.rs index b5e415d14..4617e1a74 100644 --- a/crates/prover/src/examples/blake/round/constraints.rs +++ b/crates/prover/src/examples/blake/round/constraints.rs @@ -2,9 +2,9 @@ use itertools::{chain, Itertools}; use num_traits::One; use super::{BlakeXorElements, RoundElements}; -use crate::constraint_framework::logup::LogupAtRow; use crate::constraint_framework::EvalAtRow; use crate::core::fields::m31::BaseField; +use crate::core::fields::qm31::SecureField; use crate::core::lookups::utils::{Fraction, Reciprocal}; use crate::examples::blake::{Fu32, STATE_SIZE}; @@ -15,10 +15,12 @@ pub struct BlakeRoundEval<'a, E: EvalAtRow> { pub eval: E, pub xor_lookup_elements: &'a BlakeXorElements, pub round_lookup_elements: &'a RoundElements, - pub logup: LogupAtRow, + pub total_sum: SecureField, + pub log_size: u32, } impl<'a, E: EvalAtRow> BlakeRoundEval<'a, E> { pub fn eval(mut self) -> E { + self.eval.init_logup(self.total_sum, None, self.log_size); let mut v: [Fu32; STATE_SIZE] = std::array::from_fn(|_| self.next_u32()); let input_v = v.clone(); let m: [Fu32; STATE_SIZE] = std::array::from_fn(|_| self.next_u32()); @@ -65,22 +67,19 @@ impl<'a, E: EvalAtRow> BlakeRoundEval<'a, E> { ); // Yield `Round(input_v, output_v, message)`. - self.logup.write_frac( - &mut self.eval, - Fraction::new( - -E::EF::one(), - self.round_lookup_elements.combine( - &chain![ - input_v.iter().cloned().flat_map(Fu32::to_felts), - v.iter().cloned().flat_map(Fu32::to_felts), - m.iter().cloned().flat_map(Fu32::to_felts) - ] - .collect_vec(), - ), + self.eval.write_frac(Fraction::new( + -E::EF::one(), + self.round_lookup_elements.combine( + &chain![ + input_v.iter().cloned().flat_map(Fu32::to_felts), + v.iter().cloned().flat_map(Fu32::to_felts), + m.iter().cloned().flat_map(Fu32::to_felts) + ] + .collect_vec(), ), - ); + )); - self.logup.finalize(&mut self.eval); + self.eval.finalize_logup(); self.eval } fn next_u32(&mut self) -> Fu32 { @@ -197,9 +196,9 @@ impl<'a, E: EvalAtRow> BlakeRoundEval<'a, E> { lookup_elements.combine::(&[a[0].clone(), b[0].clone(), c[0].clone()]); let comb1 = lookup_elements.combine::(&[a[1].clone(), b[1].clone(), c[1].clone()]); - let frac = Reciprocal::new(comb0) + Reciprocal::new(comb1); - self.logup.write_frac(&mut self.eval, frac); + self.eval + .write_frac(Reciprocal::new(comb0) + Reciprocal::new(comb1)); c } } diff --git a/crates/prover/src/examples/blake/round/mod.rs b/crates/prover/src/examples/blake/round/mod.rs index b9046e6df..8c6e49a50 100644 --- a/crates/prover/src/examples/blake/round/mod.rs +++ b/crates/prover/src/examples/blake/round/mod.rs @@ -5,8 +5,7 @@ pub use gen::{generate_interaction_trace, generate_trace, BlakeRoundInput}; use num_traits::Zero; use super::{BlakeXorElements, N_ROUND_INPUT_FELTS}; -use crate::constraint_framework::logup::{LogupAtRow, LookupElements}; -use crate::constraint_framework::preprocessed_columns::PreprocessedColumn; +use crate::constraint_framework::logup::LookupElements; use crate::constraint_framework::{EvalAtRow, FrameworkComponent, FrameworkEval, InfoEvaluator}; use crate::core::fields::qm31::SecureField; @@ -14,8 +13,6 @@ pub type BlakeRoundComponent = FrameworkComponent; pub type RoundElements = LookupElements; -use crate::constraint_framework::INTERACTION_TRACE_IDX; - pub struct BlakeRoundEval { pub log_size: u32, pub xor_lookup_elements: BlakeXorElements, @@ -30,13 +27,13 @@ impl FrameworkEval for BlakeRoundEval { fn max_constraint_log_degree_bound(&self) -> u32 { self.log_size + 1 } - fn evaluate(&self, mut eval: E) -> E { - let is_first = eval.get_preprocessed_column(PreprocessedColumn::IsFirst(self.log_size())); + fn evaluate(&self, eval: E) -> E { let blake_eval = constraints::BlakeRoundEval { eval, xor_lookup_elements: &self.xor_lookup_elements, round_lookup_elements: &self.round_lookup_elements, - logup: LogupAtRow::new(INTERACTION_TRACE_IDX, self.total_sum, None, is_first), + total_sum: self.total_sum, + log_size: self.log_size, }; blake_eval.eval() } diff --git a/crates/prover/src/examples/blake/scheduler/constraints.rs b/crates/prover/src/examples/blake/scheduler/constraints.rs index ea0ad2c34..e9d919a57 100644 --- a/crates/prover/src/examples/blake/scheduler/constraints.rs +++ b/crates/prover/src/examples/blake/scheduler/constraints.rs @@ -2,8 +2,8 @@ use itertools::{chain, Itertools}; use num_traits::Zero; use super::BlakeElements; -use crate::constraint_framework::logup::LogupAtRow; use crate::constraint_framework::EvalAtRow; +use crate::core::fields::qm31::SecureField; use crate::core::lookups::utils::{Fraction, Reciprocal}; use crate::core::vcs::blake2s_ref::SIGMA; use crate::examples::blake::round::RoundElements; @@ -13,8 +13,10 @@ pub fn eval_blake_scheduler_constraints( eval: &mut E, blake_lookup_elements: &BlakeElements, round_lookup_elements: &RoundElements, - mut logup: LogupAtRow, + total_sum: SecureField, + log_size: u32, ) { + eval.init_logup(total_sum, None, log_size); let messages: [Fu32; STATE_SIZE] = std::array::from_fn(|_| eval_next_u32(eval)); let states: [[Fu32; STATE_SIZE]; N_ROUNDS + 1] = std::array::from_fn(|_| std::array::from_fn(|_| eval_next_u32(eval))); @@ -35,29 +37,26 @@ pub fn eval_blake_scheduler_constraints( .collect_vec(), ) }); - logup.write_frac(eval, Reciprocal::new(denom_i) + Reciprocal::new(denom_j)); + eval.write_frac(Reciprocal::new(denom_i) + Reciprocal::new(denom_j)); } let input_state = &states[0]; let output_state = &states[N_ROUNDS]; // TODO(alont): Remove blake interaction. - logup.write_frac( - eval, - Fraction::new( - E::EF::zero(), - blake_lookup_elements.combine( - &chain![ - input_state.iter().cloned().flat_map(Fu32::to_felts), - output_state.iter().cloned().flat_map(Fu32::to_felts), - messages.iter().cloned().flat_map(Fu32::to_felts) - ] - .collect_vec(), - ), + eval.write_frac(Fraction::new( + E::EF::zero(), + blake_lookup_elements.combine( + &chain![ + input_state.iter().cloned().flat_map(Fu32::to_felts), + output_state.iter().cloned().flat_map(Fu32::to_felts), + messages.iter().cloned().flat_map(Fu32::to_felts) + ] + .collect_vec(), ), - ); + )); - logup.finalize(eval); + eval.finalize_logup(); } fn eval_next_u32(eval: &mut E) -> Fu32 { diff --git a/crates/prover/src/examples/blake/scheduler/mod.rs b/crates/prover/src/examples/blake/scheduler/mod.rs index 9f275e925..d7616df28 100644 --- a/crates/prover/src/examples/blake/scheduler/mod.rs +++ b/crates/prover/src/examples/blake/scheduler/mod.rs @@ -7,11 +7,8 @@ use num_traits::Zero; use super::round::RoundElements; use super::N_ROUND_INPUT_FELTS; -use crate::constraint_framework::logup::{LogupAtRow, LookupElements}; -use crate::constraint_framework::preprocessed_columns::PreprocessedColumn; -use crate::constraint_framework::{ - EvalAtRow, FrameworkComponent, FrameworkEval, InfoEvaluator, INTERACTION_TRACE_IDX, -}; +use crate::constraint_framework::logup::LookupElements; +use crate::constraint_framework::{EvalAtRow, FrameworkComponent, FrameworkEval, InfoEvaluator}; use crate::core::fields::qm31::SecureField; pub type BlakeSchedulerComponent = FrameworkComponent; @@ -32,12 +29,12 @@ impl FrameworkEval for BlakeSchedulerEval { self.log_size + 1 } fn evaluate(&self, mut eval: E) -> E { - let is_first = eval.get_preprocessed_column(PreprocessedColumn::IsFirst(self.log_size())); eval_blake_scheduler_constraints( &mut eval, &self.blake_lookup_elements, &self.round_lookup_elements, - LogupAtRow::new(INTERACTION_TRACE_IDX, self.total_sum, None, is_first), + self.total_sum, + self.log_size(), ); eval } diff --git a/crates/prover/src/examples/blake/xor_table/constraints.rs b/crates/prover/src/examples/blake/xor_table/constraints.rs index e91cb3661..8244ec99a 100644 --- a/crates/prover/src/examples/blake/xor_table/constraints.rs +++ b/crates/prover/src/examples/blake/xor_table/constraints.rs @@ -5,18 +5,21 @@ use crate::constraint_framework::logup::{LogupAtRow, LookupElements}; use crate::constraint_framework::preprocessed_columns::PreprocessedColumn; use crate::constraint_framework::EvalAtRow; use crate::core::fields::m31::BaseField; +use crate::core::fields::qm31::SecureField; use crate::core::lookups::utils::Fraction; /// Constraints for the xor table. pub struct XorTableEval<'a, E: EvalAtRow, const ELEM_BITS: u32, const EXPAND_BITS: u32> { pub eval: E, pub lookup_elements: &'a XorElements, - pub logup: LogupAtRow, + pub claimed_sum: SecureField, + pub log_size: u32, } impl<'a, E: EvalAtRow, const ELEM_BITS: u32, const EXPAND_BITS: u32> XorTableEval<'a, E, ELEM_BITS, EXPAND_BITS> { pub fn eval(mut self) -> E { + self.eval.init_logup(self.claimed_sum, None, self.log_size); // al, bl are the constant columns for the inputs: All pairs of elements in [0, // 2^LIMB_BITS). // cl is the constant column for the xor: al ^ bl. @@ -59,9 +62,9 @@ impl<'a, E: EvalAtRow, const ELEM_BITS: u32, const EXPAND_BITS: u32> for frac_chunk in frac_chunks.chunks(2) { let sum_frac: Fraction = frac_chunk.iter().cloned().sum(); - self.logup.write_frac(&mut self.eval, sum_frac); + self.eval.write_frac(sum_frac); } - self.logup.finalize(&mut self.eval); + self.eval.finalize_logup(); self.eval } } diff --git a/crates/prover/src/examples/blake/xor_table/mod.rs b/crates/prover/src/examples/blake/xor_table/mod.rs index 5151b1efe..a5c2728f3 100644 --- a/crates/prover/src/examples/blake/xor_table/mod.rs +++ b/crates/prover/src/examples/blake/xor_table/mod.rs @@ -107,11 +107,11 @@ impl FrameworkEval column_bits::() + 1 } fn evaluate(&self, mut eval: E) -> E { - let is_first = eval.get_preprocessed_column(PreprocessedColumn::IsFirst(self.log_size())); let xor_eval = constraints::XorTableEval::<'_, _, ELEM_BITS, EXPAND_BITS> { eval, lookup_elements: &self.lookup_elements, - logup: LogupAtRow::new(INTERACTION_TRACE_IDX, self.claimed_sum, None, is_first), + claimed_sum: self.claimed_sum, + log_size: self.log_size(), }; xor_eval.eval() } diff --git a/crates/prover/src/examples/plonk/mod.rs b/crates/prover/src/examples/plonk/mod.rs index bbbc63f00..f9c4b4e8a 100644 --- a/crates/prover/src/examples/plonk/mod.rs +++ b/crates/prover/src/examples/plonk/mod.rs @@ -2,13 +2,10 @@ use itertools::Itertools; use num_traits::One; use tracing::{span, Level}; -use crate::constraint_framework::logup::{ - ClaimedPrefixSum, LogupAtRow, LogupTraceGenerator, LookupElements, -}; +use crate::constraint_framework::logup::{ClaimedPrefixSum, LogupTraceGenerator, LookupElements}; use crate::constraint_framework::preprocessed_columns::{gen_is_first, PreprocessedColumn}; use crate::constraint_framework::{ assert_constraints, EvalAtRow, FrameworkComponent, FrameworkEval, TraceLocationAllocator, - INTERACTION_TRACE_IDX, }; use crate::core::backend::simd::column::BaseColumn; use crate::core::backend::simd::m31::LOG_N_LANES; @@ -49,13 +46,7 @@ impl FrameworkEval for PlonkEval { } fn evaluate(&self, mut eval: E) -> E { - let is_first = eval.get_preprocessed_column(PreprocessedColumn::IsFirst(self.log_size())); - let mut logup = LogupAtRow::<_>::new( - INTERACTION_TRACE_IDX, - self.total_sum, - Some(self.claimed_sum), - is_first, - ); + eval.init_logup(self.total_sum, Some(self.claimed_sum), self.log_size()); let a_wire = eval.get_preprocessed_column(PreprocessedColumn::Plonk(0)); let b_wire = eval.get_preprocessed_column(PreprocessedColumn::Plonk(1)); @@ -77,19 +68,16 @@ impl FrameworkEval for PlonkEval { let denom_a: E::EF = self.lookup_elements.combine(&[a_wire, a_val]); let denom_b: E::EF = self.lookup_elements.combine(&[b_wire, b_val]); - logup.write_frac( - &mut eval, - Fraction::new(denom_a.clone() + denom_b.clone(), denom_a * denom_b), - ); - logup.write_frac( - &mut eval, - Fraction::new( - (-mult).into(), - self.lookup_elements.combine(&[c_wire, c_val]), - ), - ); + eval.write_frac(Fraction::new( + denom_a.clone() + denom_b.clone(), + denom_a * denom_b, + )); + eval.write_frac(Fraction::new( + (-mult).into(), + self.lookup_elements.combine(&[c_wire, c_val]), + )); - logup.finalize(&mut eval); + eval.finalize_logup(); eval } } diff --git a/crates/prover/src/examples/poseidon/mod.rs b/crates/prover/src/examples/poseidon/mod.rs index fcd825db4..78d7e8fea 100644 --- a/crates/prover/src/examples/poseidon/mod.rs +++ b/crates/prover/src/examples/poseidon/mod.rs @@ -5,10 +5,10 @@ use std::ops::{Add, AddAssign, Mul, Sub}; use itertools::Itertools; use tracing::{info, span, Level}; -use crate::constraint_framework::logup::{LogupAtRow, LogupTraceGenerator, LookupElements}; -use crate::constraint_framework::preprocessed_columns::{gen_is_first, PreprocessedColumn}; +use crate::constraint_framework::logup::{LogupTraceGenerator, LookupElements}; +use crate::constraint_framework::preprocessed_columns::gen_is_first; use crate::constraint_framework::{ - EvalAtRow, FrameworkComponent, FrameworkEval, TraceLocationAllocator, INTERACTION_TRACE_IDX, + EvalAtRow, FrameworkComponent, FrameworkEval, TraceLocationAllocator, }; use crate::core::backend::simd::column::BaseColumn; use crate::core::backend::simd::m31::{PackedBaseField, LOG_N_LANES}; @@ -60,9 +60,8 @@ impl FrameworkEval for PoseidonEval { self.log_n_rows + LOG_EXPAND } fn evaluate(&self, mut eval: E) -> E { - let is_first = eval.get_preprocessed_column(PreprocessedColumn::IsFirst(self.log_size())); - let logup = LogupAtRow::new(INTERACTION_TRACE_IDX, self.total_sum, None, is_first); - eval_poseidon_constraints(&mut eval, logup, &self.lookup_elements); + eval.init_logup(self.total_sum, None, self.log_size()); + eval_poseidon_constraints(&mut eval, &self.lookup_elements); eval } } @@ -140,11 +139,7 @@ fn pow5(x: F) -> F { x4 * x.clone() } -pub fn eval_poseidon_constraints( - eval: &mut E, - mut logup: LogupAtRow, - lookup_elements: &PoseidonElements, -) { +pub fn eval_poseidon_constraints(eval: &mut E, lookup_elements: &PoseidonElements) { for _ in 0..N_INSTANCES_PER_ROW { let mut state: [_; N_STATE] = std::array::from_fn(|_| eval.next_trace_mask()); @@ -192,13 +187,10 @@ pub fn eval_poseidon_constraints( // Provide state lookups. let final_state_denom: E::EF = lookup_elements.combine(&state); - logup.write_frac( - eval, - Reciprocal::new(initial_state_denom) - Reciprocal::new(final_state_denom), - ); + eval.write_frac(Reciprocal::new(initial_state_denom) - Reciprocal::new(final_state_denom)); } - logup.finalize(eval); + eval.finalize_logup(); } pub struct LookupData { @@ -399,11 +391,9 @@ mod tests { use itertools::Itertools; use num_traits::One; - use crate::constraint_framework::logup::{LogupAtRow, LookupElements}; + use crate::constraint_framework::logup::LookupElements; use crate::constraint_framework::preprocessed_columns::gen_is_first; - use crate::constraint_framework::{ - assert_constraints, EvalAtRow, INTERACTION_TRACE_IDX, PREPROCESSED_TRACE_IDX, - }; + use crate::constraint_framework::{assert_constraints, EvalAtRow}; use crate::core::air::Component; use crate::core::channel::Blake2sChannel; use crate::core::fields::m31::BaseField; @@ -482,12 +472,8 @@ mod tests { let trace_polys = traces.map(|trace| trace.into_iter().map(|c| c.interpolate()).collect_vec()); assert_constraints(&trace_polys, CanonicCoset::new(LOG_N_ROWS), |mut eval| { - let [is_first] = eval.next_interaction_mask(PREPROCESSED_TRACE_IDX, [0]); - eval_poseidon_constraints( - &mut eval, - LogupAtRow::new(INTERACTION_TRACE_IDX, total_sum, None, is_first), - &lookup_elements, - ); + eval.init_logup(total_sum, None, LOG_N_ROWS); + eval_poseidon_constraints(&mut eval, &lookup_elements); }); } diff --git a/crates/prover/src/examples/state_machine/components.rs b/crates/prover/src/examples/state_machine/components.rs index e58474375..85f6ba8df 100644 --- a/crates/prover/src/examples/state_machine/components.rs +++ b/crates/prover/src/examples/state_machine/components.rs @@ -1,10 +1,8 @@ use num_traits::{One, Zero}; -use crate::constraint_framework::logup::{ClaimedPrefixSum, LogupAtRow, LookupElements}; -use crate::constraint_framework::preprocessed_columns::PreprocessedColumn; +use crate::constraint_framework::logup::{ClaimedPrefixSum, LookupElements}; use crate::constraint_framework::{ - EvalAtRow, FrameworkComponent, FrameworkEval, InfoEvaluator, INTERACTION_TRACE_IDX, - PREPROCESSED_TRACE_IDX, + EvalAtRow, FrameworkComponent, FrameworkEval, InfoEvaluator, PREPROCESSED_TRACE_IDX, }; use crate::core::air::{Component, ComponentProver}; use crate::core::backend::simd::SimdBackend; @@ -43,13 +41,7 @@ impl FrameworkEval for StateTransitionEval self.log_n_rows + LOG_CONSTRAINT_DEGREE } fn evaluate(&self, mut eval: E) -> E { - let is_first = eval.get_preprocessed_column(PreprocessedColumn::IsFirst(self.log_size())); - let mut logup: LogupAtRow = LogupAtRow::new( - INTERACTION_TRACE_IDX, - self.total_sum, - Some(self.claimed_sum), - is_first, - ); + eval.init_logup(self.total_sum, Some(self.claimed_sum), self.log_size()); let input_state: [_; STATE_SIZE] = std::array::from_fn(|_| eval.next_trace_mask()); let input_denom: E::EF = self.lookup_elements.combine(&input_state); @@ -58,13 +50,12 @@ impl FrameworkEval for StateTransitionEval output_state[COORDINATE] += E::F::one(); let output_denom: E::EF = self.lookup_elements.combine(&output_state); - logup.write_frac( - &mut eval, + eval.write_frac( Fraction::new(E::EF::one(), input_denom) + Fraction::new(-E::EF::one(), output_denom.clone()), ); - logup.finalize(&mut eval); + eval.finalize_logup(); eval } }