Skip to content

Add sumcheck protocol #973

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

Merged
merged 14 commits into from
Mar 11, 2025
Merged

Add sumcheck protocol #973

merged 14 commits into from
Mar 11, 2025

Conversation

jotabulacios
Copy link
Contributor

@jotabulacios jotabulacios commented Feb 25, 2025

Add sumcheck protocol

Description

This PR introduces a basic naive implementation of the Sumcheck Protocol using Multilinear Polynomials.

Type of change

  • New feature
  • Bug fix
  • Optimization

@codecov-commenter
Copy link

codecov-commenter commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 95.57740% with 18 lines in your changes missing coverage. Please review.

Project coverage is 71.91%. Comparing base (9f798ad) to head (fa9c79c).

Files with missing lines Patch % Lines
provers/sumcheck/src/verifier.rs 95.19% 15 Missing ⚠️
math/src/polynomial/dense_multilinear_poly.rs 95.65% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #973      +/-   ##
==========================================
+ Coverage   71.66%   71.91%   +0.24%     
==========================================
  Files         156      159       +3     
  Lines       34316    34659     +343     
==========================================
+ Hits        24593    24924     +331     
- Misses       9723     9735      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jotabulacios jotabulacios marked this pull request as ready for review February 27, 2025 20:14
@jotabulacios jotabulacios requested a review from a team as a code owner February 27, 2025 20:14
poly_evals.push(FieldElement::zero());
}

DenseMultilinearPolynomial {
evals: poly_evals.clone(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be better if we can avoid this clone

let half = 1 << (n - 1);
let new_evals: Vec<FieldElement<F>> = (0..half)
.map(|j| {
let a = self.evals[j].clone();
Copy link
Collaborator

Choose a reason for hiding this comment

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

same, would be better to work with references

}
evaluations.push(self.evaluate(point).unwrap());
}
evaluations
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that we are in Lagrange basis, this is just returning the elements contained in the vector defining the polynomial


pub trait Channel<F: IsField> {
fn append_field_element(&mut self, element: &FieldElement<F>);
fn draw_felt(&mut self) -> FieldElement<F>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

i would use consistent naming

let eval_1 = univar.evaluate(&FieldElement::<F>::one());

if self.round == 0 {
println!(
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are we keeping the println? The way I see this, the protocol works so long as the polynomial is multilinear

@@ -9,3 +9,4 @@ pub mod errors;
pub mod fiat_shamir;
pub mod hash;
pub mod merkle_tree;
//pub mod sumcheck;
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you comment this line? it's better to remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to delete it. Fixed in c8f3822

@@ -9,3 +9,4 @@ pub mod errors;
pub mod fiat_shamir;
pub mod hash;
pub mod merkle_tree;
//pub mod sumcheck;
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this commented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to delete it. Fixed in c8f3822

}

/// Constructs a DenseMultilinearPolynomial from a vector of evaluations and the number of variables.
pub fn from_evaluations_vec(num_vars: usize, evaluations: Vec<FieldElement<F>>) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

this function could be implemented using the From trait

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented in 98320e4

});
}
} else {
let sum = eval_0.clone() + eval_1.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to sum without clonning the elements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved in c8f3822

/// Collapses the last variable by fixing it to 0 and 1,
/// sums the evaluations, and returns a univariate polynomial (as a Polynomial)
/// of the form: sum0 + (sum1 - sum0) * x.
pub fn to_univariate(&self) -> Polynomial<FieldElement<F>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the polynomial is linear, the prover can save work from the verifier by providing poly(0) and poly(1), and so the verifier just has to check poly(0) + poly(1) = sum. If the polynomial is not linear, this optimization is not as useful

where
<F as IsField>::BaseType: Send + Sync,
{
pub fn new(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the sumcheck is just for multilinear, having two evaluations per polynomial is more than enough, and no additional checks will be needed. However, if the degree is larger, then we must ensure that the maximum degree is bounded by d.

@jotabulacios jotabulacios added this pull request to the merge queue Mar 11, 2025
Merged via the queue into main with commit 1d57286 Mar 11, 2025
8 checks passed
@jotabulacios jotabulacios deleted the add_sumcheck branch March 11, 2025 19:14
@jotabulacios jotabulacios mentioned this pull request Mar 12, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants