Skip to content

Fix prover loading proving key with safe ReadFrom (subgroup checks) [M-02] - #127

Closed
viaweb3 wants to merge 1 commit into
binance:mainfrom
viaweb3:fix/prover-safe-readfrom
Closed

viaweb3 wants to merge 1 commit into
binance:mainfrom
viaweb3:fix/prover-safe-readfrom

Conversation

@viaweb3

@viaweb3 viaweb3 commented Aug 13, 2026

Copy link
Copy Markdown

Summary

The prover loaded its Groth16 proving key with UnsafeReadFrom, which skips elliptic-curve subgroup membership checks on the deserialized G1/G2 points. The verifier, however, loads the verifying key with the safe ReadFrom (which performs the checks). This inconsistency means a tampered or corrupted .pk file (e.g. via a supply-chain or storage-compromise attack) could be loaded by the prover and used to generate proofs that still verify against an honest verifier — the exact gap described in security report M-02.

Root cause

src/prover/prover/prover.go:343 used p.ProvingKey.UnsafeReadFrom(buf) while the R1CS (ReadFrom) and verifying key (ReadFrom) already used the safe variant.

Fix

Switch the proving-key load to the safe ReadFrom so prover and verifier enforce the same safety level:

n, err = p.ProvingKey.ReadFrom(buf)

This makes the prover reject malformed/tampered proving keys, closing the inconsistency reported in #113.

Verification

  • go build ./... in src/prover passes.
  • The existing prover test package compiles.

Fixes #113

…checks

Switch the Groth16 proving-key deserialization from UnsafeReadFrom to the
safe ReadFrom so the prover enforces the same subgroup membership checks as
the verifier, closing security report M-02.

Fixes binance#113
buf = bytes.NewBuffer(pkFromFile)
p.ProvingKey = groth16.NewProvingKey(ecc.BN254)
n, err = p.ProvingKey.UnsafeReadFrom(buf)
// Use the safe ReadFrom (which performs subgroup membership checks) to be

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Level Hash
5,0 b10b869daf4bf055
5,1 64b3993941c4989c
5,2 8044c03e6febd79f
5,3 2d0b235fe7f455ea
5,4 a344071991f8e304
5,5 6dfb1a56a4babe6f
5,6 cc609edbd5a1105f
5,7 d58230484586facd
5,8 1b749d2a915193f8
5,9 535f8cb5e74f6c5e

@viaweb3 viaweb3 closed this Sep 29, 2026
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.

[Security] UnsafeReadFrom for Proving Key Skips Subgroup Checks

2 participants