Skip to content

Commit 6961849

Browse files
authored
Merge pull request #17791 from MinaProtocol/dw/export-circuit-blobs-for-mina-rust
Export circuit blobs for the Mina Rust node
2 parents 95947b2 + f1ba27d commit 6961849

File tree

5 files changed

+300
-48
lines changed

5 files changed

+300
-48
lines changed

src/lib/crypto/kimchi_backend/common/poly_comm.ml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,6 @@ module Make (Inputs : Inputs_intf) = struct
110110
in
111111
`With_degree_bound { unshifted; shifted }
112112

113-
(*
114-
type 'a t =
115-
[ `With_degree_bound of
116-
('a * 'a) Plonkish_prelude.Or_infinity.t
117-
Plonk_types.Poly_comm.With_degree_bound.t
118-
| `Without_degree_bound of
119-
('a * 'a) Plonk_types.Poly_comm.Without_degree_bound.t
120-
]
121-
*)
122-
123113
let of_backend_without_degree_bound (t : Backend.t) =
124114
let open Plonk_types.Poly_comm in
125115
let unshifted = Backend.unshifted t in
Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,172 @@
1+
(** Interface definitions for the Kimchi backend constraint system.
2+
3+
This module defines the interfaces for working with the Kimchi constraint system
4+
over the Pasta curves (Pallas and Vesta). It provides functionality for
5+
building, managing, and finalizing constraint systems. *)
6+
17
open Core_kernel
28

9+
(** Basic accessors for constraint system properties.
10+
11+
This module type defines the fundamental operations for creating and
12+
accessing properties of a constraint system, including input sizes,
13+
row counts, and challenge parameters. *)
314
module type With_accessors = sig
15+
(** The constraint system type. *)
416
type t
517

18+
(** Create a new empty constraint system. *)
619
val create : unit -> t
720

21+
(** Get the public input size (can only be set once). *)
822
val get_public_input_size : t -> int Set_once.t
923

24+
(** Get the number of primary (public) inputs. *)
1025
val get_primary_input_size : t -> int
1126

27+
(** Set the number of primary (public) inputs. *)
1228
val set_primary_input_size : t -> int -> unit
1329

30+
(** Get the number of auxiliary (private witness) inputs. *)
1431
val get_auxiliary_input_size : t -> int
1532

33+
(** Set the number of auxiliary (private witness) inputs. *)
1634
val set_auxiliary_input_size : t -> int -> unit
1735

36+
(** Get the number of previous challenges used in recursive proofs.
37+
Returns [None] if not set. *)
1838
val get_prev_challenges : t -> int option
1939

40+
(** Set the number of previous challenges for recursive proofs. *)
2041
val set_prev_challenges : t -> int -> unit
2142

43+
(** Get the total number of rows in the constraint system. *)
2244
val get_rows_len : t -> int
2345

46+
(** Get the total number of constraints added to the system. *)
2447
val num_constraints : t -> int
2548

49+
(** Get the index of the next available row for adding constraints. *)
2650
val next_row : t -> int
2751
end
2852

53+
(** Complete constraint system interface with all operations.
54+
55+
This module type extends [With_accessors] with constraint management,
56+
witness computation, lookup tables, and finalization operations. *)
2957
module type Full = sig
58+
(** Field element type (either Pallas or Vesta scalar field). *)
3059
type fp
3160

61+
(** Variable type representing field elements in constraints. *)
3262
type field_var
3363

64+
(** Gate collection type for the compiled constraint system. *)
3465
type gates
3566

67+
(** Constraint types and operations.
68+
69+
This module provides different types of constraints that can be added
70+
to the constraint system, along with evaluation and debugging functions. *)
3671
module Constraint : sig
72+
(** A basic Plonk constraint over field variables and field elements. *)
3773
type t =
3874
( field_var
3975
, fp )
4076
Kimchi_pasta_snarky_backend.Plonk_constraint_system.Plonk_constraint.basic
4177
[@@deriving sexp]
4278

79+
(** Create a boolean constraint: x * (x - 1) = 0.
80+
Ensures the variable is either 0 or 1. *)
4381
val boolean : field_var -> t
4482

83+
(** Create an equality constraint: x = y. *)
4584
val equal : field_var -> field_var -> t
4685

86+
(** Create an R1CS constraint: a * b = c.
87+
This is the fundamental constraint type in R1CS systems. *)
4788
val r1cs : field_var -> field_var -> field_var -> t
4889

90+
(** Create a square constraint: x * x = y. *)
4991
val square : field_var -> field_var -> t
5092

93+
(** Evaluate a constraint given a variable assignment.
94+
Returns [true] if the constraint is satisfied. *)
5195
val eval : t -> (field_var -> fp) -> bool
5296

97+
(** Generate a human-readable string representation of the constraint
98+
with the given variable assignment for debugging. *)
5399
val log_constraint : t -> (field_var -> fp) -> string
54100
end
55101

102+
(** Alias for constraint type. *)
56103
type constraint_ = Constraint.t
57104

58105
include
59106
With_accessors
60107
with type t = (fp, gates) Kimchi_backend_common.Plonk_constraint_system.t
61108

109+
(** Add a constraint to the constraint system. *)
62110
val add_constraint : t -> Constraint.t -> unit
63111

112+
(** Compute the witness for the constraint system.
113+
114+
In this context, "witness" refers to the entire execution trace,
115+
including both public inputs and private values.
116+
117+
@param t The constraint system
118+
@param int -> fp Function mapping variable indices to field values
119+
@return A pair of:
120+
- The witness (full trace) columns as a 2D array
121+
- Runtime lookup tables *)
64122
val compute_witness :
65123
t -> (int -> fp) -> fp array array * fp Kimchi_types.runtime_table array
66124

125+
(** Finalize the constraint system, preparing it for proof generation.
126+
This must be called before generating proofs. *)
67127
val finalize : t -> unit
68128

129+
(** Finalize the constraint system and extract the gates and lookup tables.
130+
131+
@return A triple of:
132+
- Compiled gates
133+
- Fixed lookup tables
134+
- Runtime lookup table configurations *)
69135
val finalize_and_get_gates :
70136
t
71137
-> gates
72138
* fp Kimchi_types.lookup_table array
73139
* fp Kimchi_types.runtime_table_cfg array
74140

75141
(** Return the size of all the fixed lookup tables concatenated, without the
76-
built-in XOR and RangeCheck tables *)
142+
built-in XOR and RangeCheck tables. *)
77143
val get_concatenated_fixed_lookup_table_size : t -> int
78144

79-
(** Return the size of all the runtime lookup tables concatenated *)
145+
(** Return the size of all the runtime lookup tables concatenated. *)
80146
val get_concatenated_runtime_lookup_table_size : t -> int
81147

82-
(** Finalize the fixed lookup tables. The function can not be called twice *)
148+
(** Finalize the fixed lookup tables. The function can not be called twice. *)
83149
val finalize_fixed_lookup_tables : t -> unit
84150

85-
(** Finalize the runtime lookup table configurations. The function can not be called twice. *)
151+
(** Finalize the runtime lookup table configurations. The function can not be
152+
called twice. *)
86153
val finalize_runtime_lookup_tables : t -> unit
87154

155+
(** Compute an MD5 digest of the constraint system.
156+
Useful for caching and verification of constraint system integrity. *)
88157
val digest : t -> Md5.t
89158

159+
(** Serialize the constraint system to JSON format.
160+
Useful for debugging and external analysis. *)
90161
val to_json : t -> string
162+
163+
(** Dump extra circuit data to a file for use by external systems.
164+
165+
This function exports additional circuit metadata and configuration
166+
that is needed by the Mina Rust node for circuit verification and
167+
proof processing.
168+
169+
@param t The constraint system
170+
@param string The file path where the circuit data should be written *)
171+
val dump_extra_circuit_data : t -> string -> unit
91172
end

0 commit comments

Comments
 (0)