Skip to content

Commit

Permalink
Separated Xor table types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alon-Ti committed Nov 17, 2024
1 parent 599a366 commit cc7d9bd
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 416 deletions.
11 changes: 6 additions & 5 deletions crates/prover/src/constraint_framework/assert.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use num_traits::{One, Zero};

use super::logup::{LogupAtRow, LogupSums};
use super::{EvalAtRow, INTERACTION_TRACE_IDX};
use super::{EvalAtRow, EvalAtRowWithLogup, INTERACTION_TRACE_IDX};
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;
Expand All @@ -16,7 +15,7 @@ pub struct AssertEvaluator<'a> {
pub trace: &'a TreeVec<Vec<Vec<BaseField>>>,
pub col_index: TreeVec<usize>,
pub row: usize,
pub logup: LogupAtRow<Self>,
pub logup: LogupAtRow<<Self as EvalAtRow>::F, <Self as EvalAtRow>::EF>,
}
impl<'a> AssertEvaluator<'a> {
pub fn new(
Expand All @@ -33,7 +32,7 @@ impl<'a> AssertEvaluator<'a> {
}
}
}
impl<'a> EvalAtRow for AssertEvaluator<'a> {
impl<'a> EvalAtRowWithLogup for AssertEvaluator<'a> {
type F = BaseField;
type EF = SecureField;

Expand Down Expand Up @@ -67,7 +66,9 @@ impl<'a> EvalAtRow for AssertEvaluator<'a> {
SecureField::from_m31_array(values)
}

super::logup_proxy!();
fn get_logup(&mut self) -> &mut LogupAtRow<Self::F, Self::EF> {
&mut self.logup
}
}

pub fn assert_constraints<B: Backend>(
Expand Down
11 changes: 6 additions & 5 deletions crates/prover/src/constraint_framework/cpu_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use std::ops::Mul;
use num_traits::Zero;

use super::logup::{LogupAtRow, LogupSums};
use super::{EvalAtRow, INTERACTION_TRACE_IDX};
use super::{EvalAtRow, EvalAtRowWithLogup, INTERACTION_TRACE_IDX};
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;
Expand All @@ -24,7 +23,7 @@ pub struct CpuDomainEvaluator<'a> {
pub constraint_index: usize,
pub domain_log_size: u32,
pub eval_domain_log_size: u32,
pub logup: LogupAtRow<Self>,
pub logup: LogupAtRow<<Self as EvalAtRow>::F, <Self as EvalAtRow>::EF>,
}

impl<'a> CpuDomainEvaluator<'a> {
Expand Down Expand Up @@ -52,7 +51,7 @@ impl<'a> CpuDomainEvaluator<'a> {
}
}

impl<'a> EvalAtRow for CpuDomainEvaluator<'a> {
impl<'a> EvalAtRowWithLogup for CpuDomainEvaluator<'a> {
type F = BaseField;
type EF = SecureField;

Expand Down Expand Up @@ -95,5 +94,7 @@ impl<'a> EvalAtRow for CpuDomainEvaluator<'a> {
SecureField::from_m31_array(values)
}

super::logup_proxy!();
fn get_logup(&mut self) -> &mut LogupAtRow<Self::F, Self::EF> {
&mut self.logup
}
}
11 changes: 6 additions & 5 deletions crates/prover/src/constraint_framework/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub};
use num_traits::{One, Zero};

use super::logup::{LogupAtRow, LogupSums};
use super::{EvalAtRow, INTERACTION_TRACE_IDX};
use super::{EvalAtRow, EvalAtRowWithLogup, INTERACTION_TRACE_IDX};
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)]
Expand Down Expand Up @@ -153,7 +152,7 @@ impl AddAssign<BaseField> for Expr {
struct ExprEvaluator {
pub cur_var_index: usize,
pub constraints: Vec<Expr>,
pub logup: LogupAtRow<Self>,
pub logup: LogupAtRow<<Self as EvalAtRow>::F, <Self as EvalAtRow>::EF>,
}

impl ExprEvaluator {
Expand All @@ -166,7 +165,7 @@ impl ExprEvaluator {
}
}

impl EvalAtRow for ExprEvaluator {
impl EvalAtRowWithLogup for ExprEvaluator {
// TODO(alont): Should there be a version of this that disallows Secure fields for F?
type F = Expr;
type EF = Expr;
Expand Down Expand Up @@ -203,7 +202,9 @@ impl EvalAtRow for ExprEvaluator {
])
}

super::logup_proxy!();
fn get_logup(&mut self) -> &mut LogupAtRow<Self::F, Self::EF> {
&mut self.logup
}
}

#[cfg(test)]
Expand Down
11 changes: 6 additions & 5 deletions crates/prover/src/constraint_framework/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use num_traits::One;

use super::logup::{LogupAtRow, LogupSums};
use super::preprocessed_columns::PreprocessedColumn;
use super::{EvalAtRow, INTERACTION_TRACE_IDX};
use super::{EvalAtRow, EvalAtRowWithLogup, INTERACTION_TRACE_IDX};
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.
Expand All @@ -18,7 +17,7 @@ pub struct InfoEvaluator {
pub mask_offsets: TreeVec<Vec<Vec<isize>>>,
pub n_constraints: usize,
pub preprocessed_columns: Vec<PreprocessedColumn>,
pub logup: LogupAtRow<Self>,
pub logup: LogupAtRow<<Self as EvalAtRow>::F, <Self as EvalAtRow>::EF>,
}
impl InfoEvaluator {
pub fn new(
Expand All @@ -40,7 +39,7 @@ impl InfoEvaluator {
Self::new(16, vec![], (SecureField::default(), None))
}
}
impl EvalAtRow for InfoEvaluator {
impl EvalAtRowWithLogup for InfoEvaluator {
type F = BaseField;
type EF = SecureField;

Expand Down Expand Up @@ -79,5 +78,7 @@ impl EvalAtRow for InfoEvaluator {
SecureField::one()
}

super::logup_proxy!();
fn get_logup(&mut self) -> &mut LogupAtRow<Self::F, Self::EF> {
&mut self.logup
}
}
24 changes: 12 additions & 12 deletions crates/prover/src/constraint_framework/logup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ops::{Mul, Sub};
use itertools::Itertools;
use num_traits::{One, Zero};

use super::EvalAtRow;
use super::RelationEFTraitBound;
use crate::core::backend::simd::column::SecureColumn;
use crate::core::backend::simd::m31::LOG_N_LANES;
use crate::core::backend::simd::prefix_sum::inclusive_prefix_sum;
Expand All @@ -29,7 +29,7 @@ pub type LogupSums = (SecureField, Option<ClaimedPrefixSum>);

/// Evaluates constraints for batched logups.
/// These constraint enforce the sum of multiplicity_i / (z + sum_j alpha^j * x_j) = claimed_sum.
pub struct LogupAtRow<E: EvalAtRow> {
pub struct LogupAtRow<F: Clone, EF: RelationEFTraitBound<F>> {
/// The index of the interaction used for the cumulative sum columns.
pub interaction: usize,
/// The total sum of all the fractions.
Expand All @@ -39,21 +39,21 @@ pub struct LogupAtRow<E: EvalAtRow> {
/// None if the claimed_sum is the total_sum.
pub claimed_sum: Option<ClaimedPrefixSum>,
/// The evaluation of the last cumulative sum column.
pub prev_col_cumsum: E::EF,
pub cur_frac: Option<Fraction<E::EF, E::EF>>,
pub prev_col_cumsum: EF,
pub cur_frac: Option<Fraction<EF, EF>>,
pub is_finalized: bool,
/// The value of the `is_first` constant column at current row.
/// See [`super::preprocessed_columns::gen_is_first()`].
pub is_first: E::F,
pub is_first: F,
pub log_size: u32,
}

impl<E: EvalAtRow> Default for LogupAtRow<E> {
impl<F: Clone + Zero, EF: RelationEFTraitBound<F>> Default for LogupAtRow<F, EF> {
fn default() -> Self {
Self::dummy()
}
}
impl<E: EvalAtRow> LogupAtRow<E> {
impl<F: Clone + Zero, EF: RelationEFTraitBound<F>> LogupAtRow<F, EF> {
pub fn new(
interaction: usize,
total_sum: SecureField,
Expand All @@ -64,10 +64,10 @@ impl<E: EvalAtRow> LogupAtRow<E> {
interaction,
total_sum,
claimed_sum,
prev_col_cumsum: E::EF::zero(),
prev_col_cumsum: EF::zero(),
cur_frac: None,
is_finalized: true,
is_first: E::F::zero(),
is_first: F::zero(),
log_size,
}
}
Expand All @@ -78,18 +78,18 @@ impl<E: EvalAtRow> LogupAtRow<E> {
interaction: 100,
total_sum: SecureField::one(),
claimed_sum: None,
prev_col_cumsum: E::EF::zero(),
prev_col_cumsum: EF::zero(),
cur_frac: None,
is_finalized: true,
is_first: E::F::zero(),
is_first: F::zero(),
log_size: 10,
}
}
}

/// Ensures that the LogupAtRow is finalized.
/// LogupAtRow should be finalized exactly once.
impl<E: EvalAtRow> Drop for LogupAtRow<E> {
impl<F: Clone, EF: RelationEFTraitBound<F>> Drop for LogupAtRow<F, EF> {
fn drop(&mut self) {
assert!(self.is_finalized, "LogupAtRow was not finalized");
}
Expand Down
Loading

0 comments on commit cc7d9bd

Please sign in to comment.