feat(stm): cache the circuit keys and reuse the prover setups - #3532
feat(stm): cache the circuit keys and reuse the prover setups#3532jpraynaud wants to merge 2 commits into
Conversation
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.
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.
| static CERTIFICATE_SETUP: SetupSlot<SnarkProverSetup> = SetupSlot::new(); | ||
|
|
||
| /// The IVC setup of this process. | ||
| static IVC_SETUP: SetupSlot<IvcProverSetup> = SetupSlot::new(); |
| /// Create a new prover with a non-deterministic randomness source (`OsRng`) over `setup`. | ||
| /// | ||
| /// This is the constructor intended for production use. | ||
| pub fn try_new_non_deterministic( | ||
| parameters: &Parameters, | ||
| merkle_tree_depth: u32, | ||
| ) -> StmResult<Self> { | ||
| Ok(Self { | ||
| setup: SnarkProverSetup::try_new(parameters, merkle_tree_depth) | ||
| .with_context(|| "Failed to initialize SNARK setup (SRS, circuit, keys)")?, | ||
| /// This is the constructor intended for production use. The setup is provided by the factory, | ||
| /// which owns whether it is reused across aggregations. | ||
| pub fn new_non_deterministic(setup: Arc<SnarkProverSetup>) -> Self { |
Test Results 5 files ± 0 221 suites ±0 1h 35m 15s ⏱️ - 7m 3s Results for commit dc2b80a. ± Comparison against base commit cccb650. This pull request removes 17 and adds 9 tests. Note that renamed tests count towards both. |
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)
Relates to #3424