Skip to content

Commit

Permalink
Added From<G> in add_constraint. (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alon-Ti authored Nov 28, 2024
1 parent b6ea512 commit e0d930e
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

1 comment on commit e0d930e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: e0d930e Previous: cd8b37b Ratio
iffts/simd ifft/22 12658731 ns/iter (± 512993) 6306399 ns/iter (± 210024) 2.01
merkle throughput/simd merkle 30451137 ns/iter (± 712930) 13712527 ns/iter (± 579195) 2.22

This comment was automatically generated by workflow using github-action-benchmark.

CC: @shaharsamocha7

Please sign in to comment.