1- (* Cache interfaces *)
1+ (* * Cache management for Pickles proof system keys.
22
3+ This module provides caching functionality for both proving and verification
4+ keys used in the Pickles recursive SNARK system. It handles two types of
5+ circuits:
6+ - Step circuits: intermediate proof steps (using Tick field)
7+ - Wrap circuits: final proof wrapping (using Tock field)
8+
9+ The cache system supports disk persistence and lazy generation of keys. *)
10+
11+ (* * Step circuit key caching.
12+
13+ Step circuits are the intermediate proof steps in the recursive composition.
14+ They operate over the Tick field and handle the main computation logic. *)
315module Step : sig
16+ (* * Key types and identifiers for caching. *)
417 module Key : sig
18+ (* * Proving key identifiers and metadata. *)
519 module Proving : sig
20+ (* * A proving key is uniquely identified by:
21+ - Type ID: unique identifier for the circuit type
22+ - Header: metadata about the SNARK keys
23+ - Index: position in the step chain
24+ - Constraint system: the R1CS constraint system for the circuit *)
625 type t =
726 Core_kernel.Type_equal.Id.Uid .t
827 * Snark_keys_header .t
928 * int
1029 * Backend.Tick.R1CS_constraint_system .t
1130
31+ (* * Convert proving key identifier to a human-readable string. *)
1232 val to_string : t -> string
1333 end
1434
35+ (* * Verification key identifiers and metadata. *)
1536 module Verification : sig
16- (* * id * header * index * hash *)
37+ (* * A verification key is uniquely identified by:
38+ - Type ID: unique identifier for the circuit type
39+ - Header: metadata about the SNARK keys
40+ - Index: position in the step chain
41+ - Hash: MD5 hash for integrity checking *)
1742 type t =
1843 Core_kernel.Type_equal.Id.Uid .t
1944 * Snark_keys_header .t
2045 * int
2146 * Core_kernel.Md5 .t
2247
48+ (* * Convert verification key identifier to a human-readable string. *)
2349 val to_string : t -> string
2450 end
2551 end
2652
53+ (* * Type for disk-storable proving keys.
54+ Maps proving key identifiers to actual Tick keypairs. *)
2755 type storable =
2856 (Key.Proving .t , Backend.Tick.Keypair .t ) Key_cache.Sync.Disk_storable .t
2957
58+ (* * Type for disk-storable verification keys.
59+ Maps verification key identifiers to Kimchi verifier indices. *)
3060 type vk_storable =
3161 ( Key.Verification .t
3262 , Kimchi_bindings.Protocol.VerifierIndex.Fp .t )
3363 Key_cache.Sync.Disk_storable .t
3464
65+ (* * Default disk storage handler for proving keys. *)
3566 val storable : storable
3667
68+ (* * Default disk storage handler for verification keys. *)
3769 val vk_storable : vk_storable
3870
71+ (* * Read keys from cache or generate them if not found.
72+
73+ @param prev_challenges Number of previous challenges in the circuit
74+ @param Key_cache.Spec.t list List of cache specifications (paths, URLs, etc.)
75+ @param s_p Optional custom storage handler for proving keys
76+ @param s_v Optional custom storage handler for verification keys
77+ @param lazy_mode If true, defer key generation until actually needed
78+ @param Key.Proving.t Promise.t Lazy.t Lazy promise for generating proving key
79+ @param Key.Verification.t Promise.t Lazy.t Lazy promise for generating
80+ verification key
81+
82+ @return A pair of lazy promises containing:
83+ - Proving key with status indicator
84+ - Verification key with status indicator
85+
86+ Status indicators:
87+ - [`Cache_hit]: Key was found in cache
88+ - [`Generated_something]: Key was generated (possibly by another
89+ process)
90+ - [`Locally_generated]: Key was generated by this process *)
3991 val read_or_generate :
4092 prev_challenges :int
4193 -> Key_cache.Spec .t list
@@ -55,41 +107,87 @@ module Step : sig
55107 Lazy .t
56108end
57109
110+ (* * Wrap circuit key caching.
111+
112+ Wrap circuits provide the final wrapping step that produces the recursive
113+ proof. They operate over the Tock field and handle proof aggregation. *)
58114module Wrap : sig
115+ (* * Key types and identifiers for wrap circuit caching. *)
59116 module Key : sig
117+ (* * Proving key identifiers for wrap circuits. *)
60118 module Proving : sig
119+ (* * A wrap proving key is uniquely identified by:
120+ - Type ID: unique identifier for the circuit type
121+ - Header: metadata about the SNARK keys
122+ - Constraint system: the R1CS constraint system for the wrap
123+ circuit *)
61124 type t =
62125 Core_kernel.Type_equal.Id.Uid .t
63126 * Snark_keys_header .t
64127 * Backend.Tock.R1CS_constraint_system .t
65128
129+ (* * Convert proving key identifier to a human-readable string. *)
66130 val to_string : t -> string
67131 end
68132
133+ (* * Verification key identifiers for wrap circuits. *)
69134 module Verification : sig
70- (* * id * header * hash *)
135+ (* * A wrap verification key is uniquely identified by:
136+ - Type ID: unique identifier for the circuit type
137+ - Header: metadata about the SNARK keys
138+ - Hash: MD5 hash for integrity checking *)
71139 type t =
72140 Core_kernel.Type_equal.Id.Uid .t
73141 * Snark_keys_header .t
74142 * Core_kernel.Md5 .t
75143 [@@ deriving sexp ]
76144
145+ (* * Convert verification key identifier to a human-readable string. *)
77146 val to_string : t -> string
78147
148+ (* * Check equality of two verification key identifiers. *)
79149 val equal : t -> t -> bool
80150 end
81151 end
82152
153+ (* * Type for disk-storable wrap proving keys.
154+ Maps proving key identifiers to actual Tock keypairs. *)
83155 type storable =
84156 (Key.Proving .t , Backend.Tock.Keypair .t ) Key_cache.Sync.Disk_storable .t
85157
158+ (* * Type for disk-storable wrap verification keys.
159+ Maps verification key identifiers to verification key structures. *)
86160 type vk_storable =
87161 (Key.Verification .t , Verification_key .t ) Key_cache.Sync.Disk_storable .t
88162
163+ (* * Default disk storage handler for wrap proving keys. *)
89164 val storable : storable
90165
166+ (* * Default disk storage handler for wrap verification keys. *)
91167 val vk_storable : vk_storable
92168
169+ (* * Read wrap keys from cache or generate them if not found.
170+
171+ @param prev_challenges Number of previous challenges in the wrap circuit
172+ @param Key_cache.Spec.t list List of cache specifications (paths, URLs,
173+ etc.)
174+ @param s_p Optional custom storage handler for proving keys
175+ @param s_v Optional custom storage handler for verification keys
176+ @param lazy_mode If true, defer key generation until actually needed
177+ @param Key.Proving.t Promise.t Lazy.t Lazy promise for generating proving
178+ key
179+ @param Key.Verification.t Promise.t Lazy.t Lazy promise for generating
180+ verification key
181+
182+ @return A pair of lazy promises containing:
183+ - Wrap proving key with status indicator
184+ - Wrap verification key with status indicator
185+
186+ Status indicators:
187+ - [`Cache_hit]: Key was found in cache
188+ - [`Generated_something]: Key was generated (possibly by another
189+ process)
190+ - [`Locally_generated]: Key was generated by this process *)
93191 val read_or_generate :
94192 prev_challenges :Core_kernel .Int .t
95193 -> Key_cache.Spec .t list
0 commit comments