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

WHIR switch to Plonky3 #858

Open
wants to merge 135 commits into
base: master
Choose a base branch
from
Open

Conversation

yczhangsjtu
Copy link
Collaborator

@yczhangsjtu yczhangsjtu commented Mar 13, 2025

Compilation and tests passed.

Current benchmark results:

  • 64 Polys with 20 variables
    • Commit: 5.9639 s
    • Open: 199.75 ms
    • Verify: 55.735 ms
    • Proof size: 3395312 Bytes
  • 1 Poly with 20 variables
    • Commit: 87.098 ms
    • Open: 165.82 ms
    • Verify: 14.413
    • Proof size: 169712 Bytes

@yczhangsjtu yczhangsjtu marked this pull request as draft March 13, 2025 08:44
@kunxian-xia kunxian-xia self-requested a review April 3, 2025 06:29
@yczhangsjtu
Copy link
Collaborator Author

Current benchmarking result:

  • 64 Polys with 20 variables
    • Commit: 2.5761 s
    • Open: 216.90 ms
    • Verify: 2.5568 ms
    • Proof size: 285748 Bytes
  • 1 Poly with 20 variables
    • Commit: 51.557 ms
    • Open: 164.77 ms
    • Verify: 1.4908 ms
    • Proof size: 115196 Bytes

{
match digest {
Digest::Base(digest) => {
digest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to avoid the clone by implementing Iterator on digest? I tried but it wasn't as easy as I thought. Perhaps you can find a better way?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed with Yuncong on this similar issue and unfortunately we dont have easier way to avoid this after introducing field-agnostic generalization. But clone on digest is ok and the prover cost is negligible for now.

let mut res = Vec::with_capacity(folding_factor);

for _ in 0..folding_factor {
let sumcheck_poly = self.sumcheck_prover.compute_sumcheck_polynomial();
merlin.add_scalars(sumcheck_poly.evaluations())?;
let [folding_randomness]: [F; 1] = merlin.challenge_scalars()?;
sumcheck_polys.push(sumcheck_poly.evaluations().to_vec());
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about:

let sumcheck_poly = self.sumcheck_prover.compute_sumcheck_polynomial();
transcript.append_field_element_exts(sumcheck_poly.evaluations());
let folding_randomness = transcript
    .sample_and_append_challenge(b"folding_randomness")
    .elements;
res.push(folding_randomness);

self.sumcheck_prover
    .compress(E::ONE, &[folding_randomness], &sumcheck_poly);
sumcheck_polys.push(sumcheck_poly.evaluations);

Need to make sumcheck_poly.evaluations public but avoids a to_vec().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense. But the save is very small, because sumcheck_poly is just a three-coefficient polynomial.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can submit a PR to this branch.

@@ -103,80 +67,104 @@ where

#[cfg(test)]
mod tests {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these tests all pass? I seem to encounter a problem with batch_commit

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They all pass on my laptop. Can you share the error message?

let mut res = Vec::with_capacity(folding_factor);

for _ in 0..folding_factor {
let sumcheck_poly = self.sumcheck_prover.compute_sumcheck_polynomial();
merlin.add_scalars(sumcheck_poly.evaluations())?;
let [folding_randomness]: [F; 1] = merlin.challenge_scalars()?;
sumcheck_polys.push(sumcheck_poly.evaluations().to_vec());
Copy link
Collaborator

@Jiangkm3 Jiangkm3 Apr 10, 2025

Choose a reason for hiding this comment

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

Move to bottom to avoid to_vec(). Same as above,

let n = p3::util::log2_strict_usize(evals.height());

evals.par_row_chunks_mut(2).for_each(|mut chunk| {
let to_subtract = chunk.row(0).collect::<Vec<_>>();
Copy link
Collaborator

@Jiangkm3 Jiangkm3 Apr 10, 2025

Choose a reason for hiding this comment

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

Would chunk by 1 and then iterate by 2 prevent the copy of row 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The compiler complains I can't have both mutable and immutable reference to the chunk when I try to subtract the second row from the first row by only referencing into them without copying.

Can you provide the code for your suggestion?

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.

3 participants