This project implements a simplified version of the Sumcheck Protocol using randomly generated multivariate polynomials. The protocol involves a Prover that generates and evaluates a polynomial, and a Verifier that checks the correctness of the Prover's computations. The core functionality includes generating random polynomials, evaluating them, reducing multivariate polynomials to univariate polynomials, and verifying the sum over all possible inputs.
The project is organized into several modules, each encapsulating a specific functionality related to polynomial generation, evaluation, and the Sumcheck Protocol. The modules are divided into separate files for improved readability and maintainability:
/src
├── lib.rs
├── prover.rs
├── verifier.rs
├── polynomial.rs
└── tests.rs
Implements the Prover logic for the Sumcheck Protocol. Key components include:
- Struct:
pub struct Prover<F: Field> { pub polynomial: SparsePolynomial<F, SparseTerm>, pub num_variables: usize, pub steps: Vec<F>, }
- Methods: Constructors for initializing with a random or given polynomial, methods for reducing polynomials to univariate forms, and functions for calculating sums over inputs.
Defines the Verifier functionality, crucial for ensuring the correctness of the Prover's computations. Key components include:
- Struct:
pub struct Verifier<F: Field> { pub num_variables: usize, pub expected_sum: F, pub challenge_values: Vec<F>, }
- Methods: Initialization, random challenge generation, polynomial verification, and a method to facilitate rounds of challenges and verifications.
Manages polynomial structures and operations essential to the protocol. Key components include:
- Struct:
#[derive(Debug, Clone)] struct Polynomial { terms: Vec<Term>, // A polynomial consists of multiple terms }
- Functionality: Includes methods for generating random polynomials and evaluating them. The structure of terms within a polynomial is managed to support various operations.
These descriptions provide a quick overview of each module's role within the project, highlighting the structures and key methods involved. If further detail is needed or any adjustments are required, please let me know!
The Sumcheck Protocol follows a multi-round interaction between a Prover and a Verifier, which involves the following steps:
-
Prover's Initial Step:
- The Prover computes the sum of the polynomial for all possible binary inputs of the variables.
- The Prover sends this sum to the Verifier.
-
Verifier's Challenge and Prover's Response:
- The Verifier challenges the Prover by asking for a reduction of the polynomial, fixing values of all variables except one.
- The Prover responds with a univariate polynomial for the challenged variable.
-
Verification of Reduced Polynomials:
- The Verifier checks the reduced polynomial by evaluating it at
0
and1
and comparing the results with the expected sum. - This process continues for each variable until all variables are verified.
- The Verifier checks the reduced polynomial by evaluating it at
-
Final Check:
- The Verifier evaluates the final reduced polynomial to confirm correctness.
lib.rs
defines key global constants for the polynomial calculations. These constants can be easily modified to generate more complex or simpler polynomials.
const MAX_DEGREE: usize = 3; //
const MAX_TERMS: usize = 10; // Controls the maximum degree that any variable can have in a term.
const MAX_NUM_VARIABLES: usize = 2;
tests.rs
contains automated tests to ensure that the Sumcheck Protocol, as implemented across different components, functions correctly. To run all tests, use the following command:
cargo test
If you want to run a specific test and see the output as the test progresses, you can use the '--nocapture option'. For example, to run the 'test_sumcheck_protocol' test and view the inputs and outputs:
cargo test test_sumcheck_protocol -- --nocapture