Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in sum instead of writing our own ad-hoc version #738

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions ceno_zkvm/src/uint/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ impl<const M: usize, const C: usize, E: ExtensionField> UIntLimbs<M, C, E> {
.into_iter()
.unzip();

let sum_expr = is_equal_per_limb
.iter()
.fold(Expression::ZERO, |acc, flag| acc.clone() + flag.expr());
let sum_expr = is_equal_per_limb.iter().map(ToExpr::expr).sum();

let sum_flag = WitIn::from_expr(|| "sum_flag", circuit_builder, sum_expr, false)?;
let (is_equal, diff_inv) =
Expand Down
4 changes: 1 addition & 3 deletions mpcs/src/sum_check/classic/coeff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ impl<E: ExtensionField> ClassicSumCheckRoundMessage<E> for Coefficients<E> {
}

fn sum(&self) -> E {
self[1..]
.iter()
.fold(self[0].double(), |acc, coeff| acc + coeff)
self[0] + self[..].iter().sum::<E>()
Copy link
Collaborator Author

@matthiasgoergens matthiasgoergens Dec 12, 2024

Choose a reason for hiding this comment

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

Doubling the first element is a bit weird. But the tests seem to expect it. What's the reason for it?

@yczhangsjtu I think you wrote that code? Could you please enlighten me? (I'll probably make a documenting comment out of your answer later.) Thanks!

}

fn evaluate(&self, _: &Self::Auxiliary, challenge: &E) -> E {
Expand Down