Skip to content

fix: sanitize groth16 verification key reading#1307

Merged
ivokub merged 14 commits into
masterfrom
fix/sanitize-readfrom
Oct 31, 2024
Merged

fix: sanitize groth16 verification key reading#1307
ivokub merged 14 commits into
masterfrom
fix/sanitize-readfrom

Conversation

@ivokub
Copy link
Copy Markdown
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 type: bug Something isn't working src: 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
Copy Markdown
Collaborator Author

ivokub commented Oct 30, 2024

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

Copy link
Copy Markdown
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

src: fuzzing Issue found using a fuzzing tool type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants