-
Notifications
You must be signed in to change notification settings - Fork 69
Reduce memory in SumCheck::prove via move semantics #326
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,13 +93,14 @@ impl<F: Field> SumCheck<F> { | |
| /// Generate proof of the sum of polynomial over {0,1}^`num_vars` | ||
| /// | ||
| /// The polynomial is represented in the form of a VirtualPolynomial. | ||
| /// Takes ownership of poly_list to avoid cloning internally. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| pub fn prove( | ||
| poly_list: &SumOfProductsPoly<F>, | ||
| poly_list: SumOfProductsPoly<F>, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| transcript: &mut impl Transcript, | ||
| ) -> IOPProof<F> { | ||
| let num_vars = poly_list.num_vars(); | ||
|
|
||
| let mut prover_state = IOPProverState::prover_init(poly_list); | ||
| let mut prover_state = IOPProverState::prover_init_owned(poly_list); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| let mut challenge = None; | ||
| let mut prover_msgs = Vec::with_capacity(num_vars); | ||
| for _ in 0..num_vars { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,32 @@ impl<F: Field> IOPProverState<F> { | |
| } | ||
| } | ||
|
|
||
| /// Initialize the prover state by taking ownership of the polynomials, | ||
| /// avoiding the clone in `prover_init`. | ||
|
Comment on lines
+34
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| pub fn prover_init_owned(polynomials: SumOfProductsPoly<F>) -> Self { | ||
| let num_vars = polynomials.num_vars(); | ||
| let init_sum_of_vals: Vec<F> = polynomials | ||
| .f_and_g_pairs | ||
| .par_iter() | ||
| .map(|(f, g)| { | ||
| f.coeffs | ||
| .iter() | ||
| .zip(g.coeffs.iter()) | ||
| .map(|(&f, &g)| f * g) | ||
| .sum::<F>() | ||
| }) | ||
| .collect(); | ||
| let eq_prefix = vec![F::one(); polynomials.f_and_g_pairs.len()]; | ||
| Self { | ||
| challenges: Vec::with_capacity(num_vars), | ||
| round: 0, | ||
| init_num_vars: num_vars, | ||
| mle_list: polynomials, | ||
| init_sum_of_vals, | ||
| eq_prefix, | ||
| } | ||
|
Comment on lines
+36
to
+57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| /// Receive message from verifier, generate prover message, and proceed to | ||
| /// next round. | ||
| /// | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,7 +89,7 @@ fn test_sumcheck_e2e() { | |
|
|
||
| // prover | ||
| let mut transcript = BytesHashTranscript::<Keccak256hasher>::new(); | ||
| let proof = SumCheck::<Fr>::prove(&mle_list, &mut transcript); | ||
| let proof = SumCheck::<Fr>::prove(mle_list.clone(), &mut transcript); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // verifier | ||
| let mut transcript = BytesHashTranscript::<Keccak256hasher>::new(); | ||
|
|
@@ -119,7 +119,7 @@ fn test_sumcheck_generic_padding_helper<F: Field, T: Transcript>() { | |
| }; | ||
| let claimed_sum = mle_list.sum(); | ||
|
|
||
| let proof = SumCheck::prove(&mle_list, &mut T::new()); | ||
| let proof = SumCheck::prove(mle_list.clone(), &mut T::new()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| let padded_mle_list = SumOfProductsPoly { | ||
| f_and_g_pairs: mle_list | ||
|
|
@@ -135,7 +135,7 @@ fn test_sumcheck_generic_padding_helper<F: Field, T: Transcript>() { | |
| .collect(), | ||
| }; | ||
|
|
||
| let proof_with_padded_mle_list = SumCheck::prove(&padded_mle_list, &mut T::new()); | ||
| let proof_with_padded_mle_list = SumCheck::prove(padded_mle_list, &mut T::new()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| assert_eq!(proof, proof_with_padded_mle_list); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing
SumCheck::<C::Scalar>::proveto takesumcheck_polyby value (move semantics) directly addresses the PR's goal of reducing memory consumption by avoiding an implicit clone. This is a crucial optimization for large polynomial workloads.