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

perf,memory: lighter plonk ProvingKey (no trace) #957

Merged
merged 9 commits into from
Dec 21, 2023
Merged

Conversation

gbotrel
Copy link
Collaborator

@gbotrel gbotrel commented Dec 11, 2023

For a 500k constraint circuit:

BenchmarkSetup/bn254-10          357047889      204335417      -42.77%
BenchmarkSetup/bls12_377-10      551201334      304352802      -44.78%
BenchmarkSetup/bw6_761-10        2798877250     1690444708     -39.60%
BenchmarkProver/bn254-10         731693458      770120688      +5.25%
BenchmarkProver/bls12_377-10     964496188      1016455625     +5.39%
BenchmarkProver/bw6_761-10       4322171083     4459419875     +3.18%

This PR removes the Trace from the ProvingKey; the Prover computes it at runtime, it's not super expensive but avoids doing some Clone() (memallocs).
Setup time is also faster because we now use the kzg in Lagrange form to commit, and don't need to compute the large fft.Domain.

Memory wise on bw6 for example, we go in the Prover from:

begin Alloc = 246 MiB   TotalAlloc = 1051 MiB   Sys = 394 MiB   NumGC = 22
end Alloc = 388 MiB     TotalAlloc = 1193 MiB   Sys = 446 MiB   NumGC = 22

to

begin Alloc = 150 MiB   TotalAlloc = 739 MiB    Sys = 246 MiB   NumGC = 21
end Alloc = 285 MiB     TotalAlloc = 957 MiB    Sys = 344 MiB   NumGC = 23

so a practical ~22% less memory allocated .

  • in practice saves a lot of time on ProvingKey deserialization.

// coefficients of the constraints.
// Size is the size of the system that is next power of 2 (nb_constraints+nb_public_variables)
// The permutation is also computed and stored in the Trace.
func NewTrace(spr *cs.SparseR1CS, domain *fft.Domain) *Trace {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Normally domain.Cardinality should match size := ecc.NextPowerOfTwo(sizeSystem), don't know if we should add this sanity check...

Copy link
Collaborator

@ivokub ivokub left a comment

Choose a reason for hiding this comment

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

Looks good!

gbotrel and others added 2 commits December 21, 2023 11:34
* feat: update to latest gnark crypto fft stuff

* test: all test OK

* chore(deps): bump golang.org/x/crypto from 0.12.0 to 0.17.0 (#973)

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.12.0 to 0.17.0.
- [Commits](golang/crypto@v0.12.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* perf(ecdsa): use GLV in JointScalarMulBase

* fix: swith points order in JointScalarMulBase

* chore: adapt changes from native Fiat-Shamir transcript (#974)

* chore: update go.mod

* chore: follow native transcript

* chore: follow native transcript

* chore: go generate

* fix: do not pad challenge in fri

* chore: gnark-crypto update

* feat: pad challenge always to full field element

* fix: remove domain separation in test

* fix: report actual block size for compatibility

* chore: go mod update

* revert: remove domain separation

* chore: follow gnark-crypto options

* chore: go generate

* chore: remove constant package

* chore: go mod update

* refactor: remove constant/ generation

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Youssef El Housni <youssef.housni21@gmail.com>
Co-authored-by: Youssef El Housni <youssef.elhousni@consensys.net>
Co-authored-by: Ivo Kubjas <ivo.kubjas@consensys.net>
@gbotrel gbotrel merged commit 8f954aa into master Dec 21, 2023
7 checks passed
@gbotrel gbotrel deleted the feat/smallerpk branch December 21, 2023 17:45
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