feat(stm): cache the circuit keys and reuse the prover setups - #3532
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The in-memory setup cache can reuse incompatible keys across configurations and must be scoped or configuration-keyed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR reduces SNARK aggregation latency by reusing prover setups in memory and making on-disk circuit-key caches configuration-aware.
Changes:
- Adds process-wide setup reuse through the prover factory.
- Fingerprints disk caches by configuration and SRS metadata.
- Refactors SNARK/IVC setup construction and centralizes production parameters.
File summaries
| File | Reviewed changes |
|---|---|
mithril-stm/src/protocol/aggregate_signature/clerk.rs |
Enables setup reuse for production clerks. |
mithril-stm/src/proof_system/snark_setup_cache.rs |
Adds process-wide setup caching. Critical (3 votes): cache entries are keyed only by setup type, allowing incompatible parameters or certificate depths to reuse the wrong keys. |
mithril-stm/src/proof_system/snark_prover_factory.rs |
Loads cached setups into provers. |
mithril-stm/src/proof_system/mod.rs |
Registers and exports cache components. |
mithril-stm/src/proof_system/halo2_snark/proof.rs |
Uses shared SNARK setups. Nit (2 votes): documentation references the removed try_new_non_deterministic constructor. |
mithril-stm/src/proof_system/halo2_ivc_snark/prover_setup.rs |
Adds production IVC setup construction. |
mithril-stm/src/proof_system/halo2_ivc_snark/proof.rs |
Uses shared IVC setups. |
mithril-stm/src/proof_system/halo2_ivc_snark/mod.rs |
Exposes IVC setup support. |
mithril-stm/src/circuits/verification_key_digest.rs |
Disables setup reuse for arbitrary digest computations. |
mithril-stm/src/circuits/trusted_setup.rs |
Exposes the SRS fingerprint. |
mithril-stm/src/circuits/key_provider.rs |
Keys disk caches by circuit configuration. |
mithril-stm/src/circuits/halo2/tests/verification_key_computation.rs |
Uses centralized production parameters. |
mithril-stm/src/circuits/halo2/mod.rs |
Defines production circuit parameters. |
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Test Results 5 files ±0 221 suites ±0 1h 28m 36s ⏱️ - 11m 20s Results for commit 7e8bf86. ± Comparison against base commit cccb650. This pull request removes 17 and adds 11 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
hjeljeli32
left a comment
There was a problem hiding this comment.
LGTM apart from the issue already raised by Copilot.
dc2b80a to
2b17269
Compare
Keys derived outside the production parameters never matched the embedded verifying key and were recomputed on every read; they now cache in a fingerprinted directory.
Every aggregation rebuilt the setup, reading the SRS and deserializing the keys again; the prover factory now resolves it through a process-wide cache.
A setup loaded for one set of protocol parameters was served to callers asking for another, whose circuit its keys do not fit.
* mithril-stm from `0.12.16` to `0.12.17`
2b17269 to
7e8bf86
Compare
Content
This PR includes the changes that stop a node from rebuilding its SNARK prover setup for every aggregation:
NonDeterministicSnarkProverFactory::new: enabled for the clerk, disabled for the circuit key digest computation.Pre-submit checklist
Comments
Issue(s)
Closes #3424