Security/zk verifier hardening#108
Merged
Merged
Conversation
A verifying key was registered with only a size check — its bytes were never deserialized and its arity never checked against the circuit. A wrong-arity or malformed key was accepted silently and only surfaced at proof time (failing, or worse, verifying over the wrong public inputs). Add expected_public_inputs() and VerifyingKey::num_public_inputs() to the primitive, and an ensure_vk_arity check in the pallet's register_verification_key and batch_register_verification_keys. The pallet test mock now builds real BN254 Groth16 VKs of the right arity. Genesis is unaffected (keys are registered post-genesis via extrinsic).
The bypass that lets benchmarks run with dummy proofs was gated on runtime-benchmarks, the same feature a release runtime enables to expose its benchmarks. Such a runtime accepted any proof, enabling trivial double-spends.
… count The verify_proof weight scales with the number of public inputs (one G1 scalar-mul per input), but the benchmark ran a fixed 7-input case, so the generated weight had no `n` component and did not match the `WeightInfo::verify_proof(n)` trait signature. Add `n: Linear<1, 32>`: the benchmark builds a synthetic VK of arity `n` via `synthetic_vk`, so the runner measures the real per-input slope and emits `fn verify_proof(n: u32) -> Weight`. The proof no longer needs to satisfy the VK — the pairing runs, fails, and `skip-proof-verification` records the weight anyway, removing the dependency on a verifiable fixture triple. Drop the now-unused vk_transfer.bin and public_inputs_transfer.bin fixtures. Rewrite generate-bench-fixtures.mjs to resolve circuit and proof-compressor artifacts from the @orbinum/circuits and @orbinum/groth16-proofs npm packages instead of local sibling checkouts, so fixtures can be regenerated on any VPS (cd scripts && npm install && node generate-bench-fixtures.mjs).
Measured on Hetzner CPX62 (16 vCPU AMD, 32 GB RAM), steps=50 repeat=20. verify_proof(n) now carries the measured per-input slope
Re-run pallet_zk_verifier benchmarks on reference hardware with the parametrized verify_proof(n) benchmark. Replaces the conservative placeholder (200ms/input) with the measured slope (~19us/input over an ~11ms Groth16 pairing base)
Removed batch_verify + field_utils, added arity-check APIs, canonical/LE parser fixes. Date the CHANGELOG Unreleased section.
Removed CircuitId::SHIELD, verify_proof rejects non-32-byte inputs, skip-proof-verification feature, measured verify_proof(n) weights.
skip-proof-verification feature + integrity_test mirroring the zk-verifier change. Cargo.lock picks up all three version bumps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.