@@ -777,7 +777,7 @@ module V = struct
777777 (* * An internal variable is generated to hold an intermediate value
778778 (e.g., in reducing linear combinations to single PLONK positions).
779779 *)
780- [@@ deriving compare , hash , sexp ]
780+ [@@ deriving compare , hash , sexp , bin_io ]
781781 end
782782
783783 include T
@@ -1003,6 +1003,8 @@ module Make
10031003 val digest : t -> Md5 .t
10041004
10051005 val to_json : t -> string
1006+
1007+ val dump_extra_circuit_data : t -> string -> unit
10061008end = struct
10071009 open Core_kernel
10081010 module Constraint = Plonk_constraint. Make (Fp )
@@ -2434,4 +2436,36 @@ end = struct
24342436 Option. try_with (fun () -> reduce_to_v values.(i)) )
24352437 in
24362438 add_row sys values kind coeffs
2439+
2440+ (* ((Fp.t * V.t) list * Fp.t option) *)
2441+ type concrete_table = ((Fp .t * V .t ) list * Fp .t option ) Internal_var.Table .t
2442+ [@@ deriving bin_io ]
2443+
2444+ (* V.t option array list *)
2445+ type concrete_rows_rev = V .t option array list [@@ deriving bin_io ]
2446+
2447+ let dump_extra_circuit_data (sys : t ) base_path =
2448+ let rows_rev_name = base_path ^ " _rows_rev.bin" in
2449+ let internal_vars_name = base_path ^ " _internal_vars.bin" in
2450+ let gates_json_name = base_path ^ " _gates.json" in
2451+ if Sys. file_exists rows_rev_name then Sys. remove rows_rev_name ;
2452+ if Sys. file_exists internal_vars_name then Sys. remove internal_vars_name ;
2453+ if Sys. file_exists gates_json_name then Sys. remove gates_json_name ;
2454+
2455+ let table : concrete_rows_rev = sys.rows_rev in
2456+ let size = bin_size_concrete_rows_rev table in
2457+ let buf = Bigstring. create size in
2458+ ignore (bin_write_concrete_rows_rev buf ~pos: 0 table : int ) ;
2459+ Core_kernel.Out_channel. write_all rows_rev_name
2460+ ~data: (Bigstring. to_string buf) ;
2461+
2462+ let table : concrete_table = sys.internal_vars in
2463+ let size = bin_size_concrete_table table in
2464+ let buf = Bigstring. create size in
2465+ ignore (bin_write_concrete_table buf ~pos: 0 table : int ) ;
2466+ Core_kernel.Out_channel. write_all internal_vars_name
2467+ ~data: (Bigstring. to_string buf) ;
2468+
2469+ let gates_json = to_json sys in
2470+ Core_kernel.Out_channel. write_all gates_json_name ~data: gates_json
24372471end
0 commit comments