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

fix: sanitize groth16 verification key reading #1307

Merged
merged 14 commits into from
Oct 31, 2024
Merged

Conversation

ivokub
Copy link
Collaborator

@ivokub ivokub commented Oct 30, 2024

Description

See the related security advisory GHSA-cph5-3pgr-c82g (will publish once PR has been reviewed and tested) for full description and POC.

The main issue is that serialized Groth16 verification key includes in a header number of expected Pedersen verification keys which is used for initializing a slice. When modifying the serialized file, we may allocate huge slice, leading to OOM.

In this PR instead of allocating the slice beforehand, we instead try to read all the existing commitment keys in the file and then compare that the number of read commitment keys corresponds to the expected. This prevents using heuristics on the number of commitment keys and bounds the size of the in-memory full verification key to the serialized file size.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

Tested against the POC in the advisory. Does not OOM anymore.

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@ivokub ivokub added bug Something isn't working fuzzing Issue found using a fuzzing tool labels Oct 30, 2024
@ivokub ivokub added this to the v0.11.N milestone Oct 30, 2024
@ivokub ivokub requested a review from gbotrel October 30, 2024 13:51
@ivokub ivokub self-assigned this Oct 30, 2024
@ivokub
Copy link
Collaborator Author

ivokub commented Oct 30, 2024

@gbotrel - it is done now :) I didn't anticipate making that much bugs :/

Copy link
Collaborator

@gbotrel gbotrel left a comment

Choose a reason for hiding this comment

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

lgtm, suggestion for perf to avoid many re-allocations in some cases

@ivokub ivokub merged commit 47ae846 into master Oct 31, 2024
5 checks passed
@ivokub ivokub deleted the fix/sanitize-readfrom branch October 31, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fuzzing Issue found using a fuzzing tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants