Skip to content

Commit

Permalink
Added From<G> in add_constraint.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alon-Ti committed Nov 27, 2024
1 parent d53fec3 commit 7320a5d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
12 changes: 8 additions & 4 deletions crates/prover/src/constraint_framework/assert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use num_traits::{One, Zero};
use num_traits::Zero;

use super::logup::{LogupAtRow, LogupSums};
use super::{EvalAtRow, INTERACTION_TRACE_IDX};
Expand Down Expand Up @@ -54,13 +54,17 @@ impl<'a> EvalAtRow for AssertEvaluator<'a> {

fn add_constraint<G>(&mut self, constraint: G)
where
Self::EF: std::ops::Mul<G, Output = Self::EF>,
Self::EF: std::ops::Mul<G, Output = Self::EF> + From<G>,
{
// Cast to SecureField.
let res = SecureField::one() * constraint;
// The constraint should be zero at the given row, since we are evaluating on the trace
// domain.
assert_eq!(res, SecureField::zero(), "row: {}", self.row);
assert_eq!(
Self::EF::from(constraint),
SecureField::zero(),
"row: {}",
self.row
);
}

fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF {
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/constraint_framework/cpu_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<'a> EvalAtRow for CpuDomainEvaluator<'a> {

fn add_constraint<G>(&mut self, constraint: G)
where
Self::EF: Mul<G, Output = Self::EF>,
Self::EF: Mul<G, Output = Self::EF> + From<G>,
{
self.row_res += self.random_coeff_powers[self.constraint_index] * constraint;
self.constraint_index += 1;
Expand Down
12 changes: 2 additions & 10 deletions crates/prover/src/constraint_framework/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,9 @@ impl EvalAtRow for ExprEvaluator {

fn add_constraint<G>(&mut self, constraint: G)
where
Self::EF: std::ops::Mul<G, Output = Self::EF>,
Self::EF: From<G>,
{
match Expr::one() * constraint {
Expr::Mul(one, constraint) => {
assert_eq!(*one, Expr::one());
self.constraints.push(*constraint);
}
_ => {
unreachable!();
}
}
self.constraints.push(constraint.into());
}

fn combine_ef(values: [Self::F; 4]) -> Self::EF {
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/constraint_framework/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub trait EvalAtRow {
/// Adds a constraint to the component.
fn add_constraint<G>(&mut self, constraint: G)
where
Self::EF: Mul<G, Output = Self::EF>;
Self::EF: Mul<G, Output = Self::EF> + From<G>;

/// Combines 4 base field values into a single extension field value.
fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF;
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/constraint_framework/simd_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'a> EvalAtRow for SimdDomainEvaluator<'a> {
}
fn add_constraint<G>(&mut self, constraint: G)
where
Self::EF: Mul<G, Output = Self::EF>,
Self::EF: Mul<G, Output = Self::EF> + From<G>,
{
self.row_res +=
VeryPackedSecureField::broadcast(self.random_coeff_powers[self.constraint_index])
Expand Down

0 comments on commit 7320a5d

Please sign in to comment.