Skip to content

WHIR switch to Plonky3 #858

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 149 commits into from
Apr 16, 2025
Merged

WHIR switch to Plonky3 #858

merged 149 commits into from
Apr 16, 2025

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
@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?

Copy link
Collaborator

@hero78119 hero78119 left a comment

Choose a reason for hiding this comment

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

Awesome work with huge clean up! 👍
Some sub-crate within whir didnt review in detail: ntt/sumcheck as I feel they should be able to combine with other existing functionality in Ceno.

Overall LGTM! except other review's comments regarding to minor optimisation, I think it's good to go and have enhancement in subsequent PR.

@hero78119 hero78119 added this pull request to the merge queue Apr 16, 2025
Merged via the queue into master with commit 63b8738 Apr 16, 2025
4 checks passed
@hero78119 hero78119 deleted the feat/whir/switch-to-plonky3 branch April 16, 2025 08:51
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