Skip to content

Add quadratic and cubic sumcheck #1003

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
8 changes: 5 additions & 3 deletions crates/provers/stark/src/constraints/transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use itertools::Itertools;
use lambdaworks_math::field::element::FieldElement;
use lambdaworks_math::field::traits::{IsFFTField, IsField, IsSubFieldOf};
use lambdaworks_math::polynomial::Polynomial;
use num_integer::Integer;

/// TransitionConstraint represents the behaviour that a transition constraint
/// over the computation that wants to be proven must comply with.
pub trait TransitionConstraint<F, E>: Send + Sync
Expand Down Expand Up @@ -117,11 +117,12 @@ where

// If there is an exemptions period defined for this constraint, the evaluations are calculated directly
// by computing P_exemptions(x) / Zerofier(x)
#[expect(clippy::incompatible_msrv)]
if let Some(exemptions_period) = self.exemptions_period() {
// FIXME: Rather than making this assertions here, it would be better to handle these
// errors or make these checks when the AIR is initialized.

debug_assert!(exemptions_period.is_multiple_of(&self.period()));
debug_assert!(exemptions_period.is_multiple_of(self.period()));

debug_assert!(self.periodic_exemptions_offset().is_some());

Expand Down Expand Up @@ -218,8 +219,9 @@ where
) -> FieldElement<E> {
let end_exemptions_poly = self.end_exemptions_poly(trace_primitive_root, trace_length);

#[expect(clippy::incompatible_msrv)]
if let Some(exemptions_period) = self.exemptions_period() {
debug_assert!(exemptions_period.is_multiple_of(&self.period()));
debug_assert!(exemptions_period.is_multiple_of(self.period()));

debug_assert!(self.periodic_exemptions_offset().is_some());

Expand Down
47 changes: 37 additions & 10 deletions crates/provers/sumcheck/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sumcheck Protocol

A naive implementation of the Sumcheck Protocol.
A naive implementation of the Sumcheck Protocol with support for linear, quadratic, and cubic polynomials.

## Overview

Expand All @@ -10,6 +10,14 @@ It is an essential building block for many SNARK protocols, given that it reduce

The protocol proceeds in rounds, with one round per variable of the multivariate polynomial. In each round, the prover sends a univariate polynomial, and the verifier responds with a random challenge. This process reduces a claim about a multivariate polynomial to a claim about a single evaluation point.

### Convenience Wrapper Functions

This implementation provides the following convenience **wrapper functions** for common interaction degrees:
- `prove_linear` / `verify_linear` (Sum of P(x))
- `prove_quadratic` / `verify_quadratic` (Sum of P₁(x)P₂(x))
- `prove_cubic` / `verify_cubic` (Sum of P₁(x)P₂(x)P₃(x))



## Example

Expand All @@ -23,22 +31,41 @@ use lambdaworks_sumcheck::{prove, verify};

// Define the field
type F = U64PrimeField<17>;
type FE = FieldElement<F>;

// Create a multilinear polynomial
// P(x1, x2) = evals [3, 4, 5, 7]
let evaluations = vec![
FieldElement::<F>::from(3),
FieldElement::<F>::from(4),
FieldElement::<F>::from(5),
FieldElement::<F>::from(7),
FE::from(3),
FE::from(4),
FE::from(5),
FE::from(7),
];
let poly = DenseMultilinearPolynomial::new(evaluations);
let num_vars = poly.num_vars();

// Generate a proof using the linear wrapper
let prove_result = prove_linear(poly.clone());
assert!(prove_result.is_ok());
let (claimed_sum, proof_polys) = prove_result.unwrap();

// Verify the proof using the linear wrapper
let verification_result = verify_linear(num_vars, claimed_sum, proof_polys, poly);
assert!(verification_result.is_ok() && verification_result.unwrap());
println!("Simple verification successful!");
```
To use the quadratic wrapper, you can use the `prove_quadratic` and `verify_quadratic` functions.

// Generate a proof
let (claimed_sum, proof) = prove(poly);
```rust
let prove_result = prove_quadratic(poly1, poly2);
let verification_result = verify_quadratic(num_vars, claimed_sum, proof_polys, poly1, poly2);
```

// Verify the proof
let result = verify(poly.num_vars(), claimed_sum, proof, Some(poly));
assert!(result.is_ok() && result.unwrap());
To use the cubic wrapper, you can use the `prove_cubic` and `verify_cubic` functions.

```rust
let prove_result = prove_cubic(poly1, poly2, poly3);
let verification_result = verify_cubic(num_vars, claimed_sum, proof_polys, poly1, poly2, poly3);
```


Expand Down
Loading
Loading