Skip to content

Commit f1ba27d

Browse files
committed
Pickles/cache: dump circuit data
1 parent 29f5bd0 commit f1ba27d

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/lib/pickles/cache.ml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
open Core_kernel
22

3+
(* Check if circuit data dumping is enabled via environment variable *)
4+
let should_dump_circuit_data () =
5+
match Sys.getenv_opt "MINA_DUMP_CIRCUIT_DATA" with
6+
| Some "true" | Some "1" | Some "yes" ->
7+
true
8+
| _ ->
9+
false
10+
311
module Step = struct
412
module Key = struct
513
module Proving = struct
@@ -53,7 +61,14 @@ module Step = struct
5361
[%test_eq: string] header.constraint_system_hash
5462
header_read.constraint_system_hash ;
5563
{ Backend.Tick.Keypair.index; cs } ) )
56-
(fun (_, header, _, _) t path ->
64+
(fun (_, header, _, cs) t path ->
65+
(* Conditionally dump extra circuit data based on environment variable *)
66+
if should_dump_circuit_data () then (
67+
let logger = Logger.create () in
68+
Logger.info logger ~module_:__MODULE__ ~location:__LOC__
69+
"Dumping Step circuit data to %s" path ;
70+
Kimchi_pasta_constraint_system.Vesta_constraint_system
71+
.dump_extra_circuit_data cs path ) ;
5772
Or_error.try_with (fun () ->
5873
Snark_keys_header.write_with_header
5974
~expected_max_size_log2:33 (* 8 GB should be enough *)
@@ -185,7 +200,14 @@ module Wrap = struct
185200
[%test_eq: string] header.constraint_system_hash
186201
header_read.constraint_system_hash ;
187202
{ Backend.Tock.Keypair.index; cs } ) )
188-
(fun (_, header, _) t path ->
203+
(fun (_, header, cs) t path ->
204+
(* Conditionally dump extra circuit data based on environment variable *)
205+
if should_dump_circuit_data () then (
206+
let logger = Logger.create () in
207+
Logger.info logger ~module_:__MODULE__ ~location:__LOC__
208+
"Dumping Wrap circuit data to %s" path ;
209+
Kimchi_pasta_constraint_system.Pallas_constraint_system
210+
.dump_extra_circuit_data cs path ) ;
189211
Or_error.try_with (fun () ->
190212
Snark_keys_header.write_with_header
191213
~expected_max_size_log2:33 (* 8 GB should be enough *)

src/lib/pickles/cache.mli

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ module Step : sig
6262
, Kimchi_bindings.Protocol.VerifierIndex.Fp.t )
6363
Key_cache.Sync.Disk_storable.t
6464

65-
(** Default disk storage handler for proving keys. *)
65+
(** Default disk storage handler for proving keys.
66+
67+
When writing keys to disk, this storage handler will optionally dump
68+
extra circuit data (constraint system details) based on the
69+
MINA_DUMP_CIRCUIT_DATA environment variable. The dumping is disabled
70+
by default. Set MINA_DUMP_CIRCUIT_DATA to "true", "1", or "yes" to enable. *)
6671
val storable : storable
6772

6873
(** Default disk storage handler for verification keys. *)
@@ -160,7 +165,12 @@ module Wrap : sig
160165
type vk_storable =
161166
(Key.Verification.t, Verification_key.t) Key_cache.Sync.Disk_storable.t
162167

163-
(** Default disk storage handler for wrap proving keys. *)
168+
(** Default disk storage handler for wrap proving keys.
169+
170+
When writing keys to disk, this storage handler will optionally dump
171+
extra circuit data (constraint system details) based on the
172+
MINA_DUMP_CIRCUIT_DATA environment variable. The dumping is disabled
173+
by default. Set MINA_DUMP_CIRCUIT_DATA to "true", "1", or "yes" to enable. *)
164174
val storable : storable
165175

166176
(** Default disk storage handler for wrap verification keys. *)

0 commit comments

Comments
 (0)