Skip to content

Commit 62ea450

Browse files
committed
refactor(stm): separated key cache from srs degree
1 parent 7db3250 commit 62ea450

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

mithril-stm/src/circuits/test_utils/file_mutex.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,16 @@ mod tests {
166166
assert_ne!(baseline.directory(), other_depth.directory());
167167
assert_ne!(baseline.directory(), other_seed.directory());
168168

169-
// The IVC setup cache additionally folds in the SRS degree and both production verifying keys
170-
// as a circuit-version salt; a change in either must also resolve to a different directory.
169+
// The IVC setup cache folds in both production verifying keys as a circuit-version salt, like
170+
// the certificate-key cache and it omits the SRS degree for the same reason.
171171
let ivc_baseline = FileMutex::for_shared_cache(
172172
"ivc-setup",
173-
&[b"parameters-a", b"depth-4", b"degree-19", b"circuit-vk-1"],
174-
);
175-
let other_degree = FileMutex::for_shared_cache(
176-
"ivc-setup",
177-
&[b"parameters-a", b"depth-4", b"degree-20", b"circuit-vk-1"],
173+
&[b"parameters-a", b"depth-4", b"circuit-vk-1"],
178174
);
179175
let other_circuit_version = FileMutex::for_shared_cache(
180176
"ivc-setup",
181-
&[b"parameters-a", b"depth-4", b"degree-19", b"circuit-vk-2"],
177+
&[b"parameters-a", b"depth-4", b"circuit-vk-2"],
182178
);
183-
assert_ne!(ivc_baseline.directory(), other_degree.directory());
184179
assert_ne!(ivc_baseline.directory(), other_circuit_version.directory());
185180
}
186181
}

mithril-stm/src/circuits/trusted_setup.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ impl Default for TrustedSetupProvider {
192192
}
193193

194194
/// Seed for the deterministic unsafe SRS used by the tests; it pins the SRS's tau. Test key caches
195-
/// fold in this seed so they stay correct if it ever changes. The IVC setup cache also folds in the
196-
/// SRS degree; the certificate-key cache omits it, since keygen downsizes the seed-pinned SRS to the
197-
/// certificate circuit's own degree, so the oversized degree never affects the certificate key.
195+
/// fold in this seed so they stay correct if it ever changes. Both the certificate-key and IVC setup
196+
/// caches omit the SRS degree: keygen always downsizes the seed-pinned SRS to the target circuit
197+
/// degree before deriving keys, so the oversized starting degree never affects the derived keys —
198+
/// only `TrustedSetupProvider::with_unsafe_srs`'s own file layout, which nests by degree.
198199
#[cfg(any(test, feature = "benchmark-internals"))]
199200
pub(crate) const UNSAFE_SRS_SEED: u64 = 42;
200201

mithril-stm/src/proof_system/ivc_halo2_snark/prover_setup.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ impl IvcSnarkProverSetup {
156156

157157
/// Builds an [`IvcSnarkProverSetup`] from a deterministic, oversized unsafe SRS, exercising the
158158
/// real `load` path without the production SRS. Shared by the slow IVC tests through a
159-
/// content-keyed cache keyed by the protocol parameters, Merkle-tree depth, the unsafe SRS identity
160-
/// (degree and seed), and the production verifying keys as a circuit-version salt, so the recursive
161-
/// keys — the dominant cost — are computed once and reused across tests and runs.
159+
/// content-keyed cache keyed by the protocol parameters, Merkle-tree depth, the unsafe SRS seed,
160+
/// and the production verifying keys as a circuit-version salt — not the SRS degree, since `load`
161+
/// always downsizes to `RECURSIVE_CIRCUIT_DEGREE` before deriving keys, so any `unsafe_srs_degree`
162+
/// reproduces the same recursive keys — the dominant cost — letting calls at different degrees
163+
/// share one already-computed key cache instead of each paying for keygen separately.
162164
#[cfg(test)]
163165
pub(crate) fn build_for_test(
164166
parameters: &crate::Parameters,
@@ -182,7 +184,6 @@ impl IvcSnarkProverSetup {
182184
) -> StmResult<Self> {
183185
let parameters_bytes = parameters.to_bytes()?;
184186
let depth_bytes = merkle_tree_depth.to_le_bytes();
185-
let degree_bytes = unsafe_srs_degree.to_le_bytes();
186187
let seed_bytes = UNSAFE_SRS_SEED.to_le_bytes();
187188
let cache = FileMutex::for_shared_cache(
188189
"ivc-setup",
@@ -191,7 +192,6 @@ impl IvcSnarkProverSetup {
191192
RECURSIVE_CIRCUIT_VERIFICATION_KEY_FOR_PRODUCTION,
192193
&parameters_bytes,
193194
&depth_bytes,
194-
&degree_bytes,
195195
&seed_bytes,
196196
],
197197
);

0 commit comments

Comments
 (0)