Skip to content

Commit

Permalink
Merge pull request #15918 from MinaProtocol/feature/simplify-pickles-…
Browse files Browse the repository at this point in the history
…types1

Simplify some pickles types
  • Loading branch information
dannywillems authored Sep 11, 2024
2 parents fafc2ea + 68ad7ec commit cb47145
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 153 deletions.
45 changes: 10 additions & 35 deletions src/lib/pickles/common.mli
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ val hash_messages_for_next_step_proof :
Pickles_types.Vector.t
(* bulletproof challenges *) )
Import.Types.Step.Proof_state.Messages_for_next_step_proof.t
-> (int64, Composition_types.Digest.Limbs.n) Pickles_types.Vector.t
-> Import.Types.Digest.Constant.t

val tick_public_input_of_statement :
max_proofs_verified:'a Pickles_types.Nat.t
Expand All @@ -172,24 +172,13 @@ val tick_public_input_of_statement :
Composition_types.Bulletproof_challenge.t
, Pickles_types.Nat.z Backend.Tock.Rounds.plus_n )
Pickles_types.Vector.t
Pickles_types.Hlist0.Id.t
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, bool )
Composition_types.Step.Proof_state.Per_proof.In_circuit.t
, 'a )
Pickles_types.Vector.t
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
Pickles_types.Hlist0.Id.t
, ( ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, 'a )
Pickles_types.Vector.t
Pickles_types.Hlist0.Id.t )
, Import.Types.Digest.Constant.t
, (Import.Types.Digest.Constant.t, 'a) Pickles_types.Vector.t )
Import.Types.Step.Statement.t
-> Backend.Tick.Field.Vector.elt list

Expand All @@ -204,21 +193,14 @@ val tock_public_input_of_statement :
, Limb_vector.Challenge.Constant.t Composition_types.Scalar_challenge.t
option
, bool
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, Import.Types.Digest.Constant.t
, Import.Types.Digest.Constant.t
, ( Limb_vector.Challenge.Constant.t
Kimchi_backend_common.Scalar_challenge.t
Composition_types.Bulletproof_challenge.t
, Pickles_types.Nat.z Backend.Tick.Rounds.plus_n )
Pickles_types.Vector.t
Pickles_types.Hlist0.Id.t
, Composition_types.Branch_data.t )
Import.Types.Wrap.Statement.In_circuit.t
-> Backend.Tock.Field.Vector.elt list
Expand All @@ -234,21 +216,14 @@ val tock_unpadded_public_input_of_statement :
, Limb_vector.Challenge.Constant.t Composition_types.Scalar_challenge.t
option
, bool
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, Import.Types.Digest.Constant.t
, Import.Types.Digest.Constant.t
, ( Limb_vector.Challenge.Constant.t
Kimchi_backend_common.Scalar_challenge.t
Composition_types.Bulletproof_challenge.t
, Pickles_types.Nat.z Backend.Tick.Rounds.plus_n )
Pickles_types.Vector.t
Pickles_types.Hlist0.Id.t
, Composition_types.Branch_data.t )
Import.Types.Wrap.Statement.In_circuit.t
-> Backend.Tock.Field.Vector.elt list
12 changes: 4 additions & 8 deletions src/lib/pickles/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type ('max_proofs_verified, 'branches, 'prev_varss) wrap_main_generic =
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, (int64, Composition_types.Digest.Limbs.n) Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down Expand Up @@ -205,9 +205,7 @@ type ('max_proofs_verified, 'branches, 'prev_varss) wrap_main_generic =
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down Expand Up @@ -1265,7 +1263,7 @@ module Make_adversarial_test (M : sig
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, (int64, Composition_types.Digest.Limbs.n) Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down Expand Up @@ -1294,9 +1292,7 @@ module Make_adversarial_test (M : sig
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down
12 changes: 4 additions & 8 deletions src/lib/pickles/compile.mli
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ type ('max_proofs_verified, 'branches, 'prev_varss) wrap_main_generic =
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, (int64, Composition_types.Digest.Limbs.n) Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down Expand Up @@ -247,9 +247,7 @@ type ('max_proofs_verified, 'branches, 'prev_varss) wrap_main_generic =
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down Expand Up @@ -404,7 +402,7 @@ module Make_adversarial_test : functor
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, (int64, Composition_types.Digest.Limbs.n) Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down Expand Up @@ -433,9 +431,7 @@ module Make_adversarial_test : functor
, bool
, 'max_proofs_verified
Proof.Base.Messages_for_next_proof_over_same_field.Wrap.t
, ( Limb_vector.Constant.Hex64.t
, Composition_types.Digest.Limbs.n )
Pickles_types.Vector.vec
, Import.Types.Digest.Constant.t
, ( 'b
, ( Kimchi_pasta.Pallas_based_plonk.Proof.G.Affine.t
, 'actual_proofs_verified )
Expand Down
38 changes: 8 additions & 30 deletions src/lib/pickles/composition_types/composition_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -936,11 +936,7 @@ module Wrap : sig
representing it inside the circuit. *)
val spec :
'a Spec.impl
-> ( 'challenge1
, 'challenge2
, 'field1 Hlist0.Id.t
, 'field2 Hlist0.Id.t )
Lookup_parameters.t
-> ('challenge1, 'challenge2, 'field1, 'field2) Lookup_parameters.t
-> Opt.Flag.t Plonk_types.Features.t
-> ( ( 'field1
, 'challenge1
Expand Down Expand Up @@ -986,15 +982,13 @@ module Wrap : sig
(** Convert a statement (as structured data) into the flat data-based representation. *)
val to_data :
('a, 'b, 'c, 'fp_opt, 'd, 'bool, 'e, 'e, 'e, 'f, 'g) t
-> option_map:
('d -> f:('h -> ('h * unit) Hlist.HlistId.t) -> 'j Hlist0.Id.t)
-> option_map:('d -> f:('h -> ('h * unit) Hlist.HlistId.t) -> 'j)
-> ('c, 'a, 'b, 'e, 'f, 'g, 'j, 'fp_opt2, 'bool) flat_repr

(** Construct a statement (as structured data) from the flat data-based representation. *)
val of_data :
('a, 'b, 'c, 'd, 'e, 'f, 'g, 'fp option, 'bool) flat_repr
-> option_map:
('g Hlist0.Id.t -> f:(('h * unit) Hlist.HlistId.t -> 'h) -> 'j)
-> option_map:('g -> f:(('h * unit) Hlist.HlistId.t -> 'h) -> 'j)
-> ('b, 'c, 'a, 'fp_opt2, 'j, 'bool, 'd, 'd, 'd, 'e, 'f) t
end

Expand Down Expand Up @@ -1351,7 +1345,6 @@ module Step : sig
Bulletproof_challenge.t
, Backend.Tock.Rounds.n )
Vector.t
Hlist0.Id.t
, 'a Snarky_backendless.Cvar.t
, 'a Snarky_backendless.Cvar.t
Snarky_backendless__Snark_intf.Boolean0.t )
Expand All @@ -1363,8 +1356,7 @@ module Step : sig
Bulletproof_challenge.t
, Backend.Tock.Rounds.n )
Vector.t
Hlist0.Id.t
, (Limb_vector.Constant.Hex64.t, Digest.Limbs.n) Vector.t
, Digest.Constant.t
, bool )
In_circuit.t
, 'a )
Expand Down Expand Up @@ -1406,7 +1398,6 @@ module Step : sig
Bulletproof_challenge.t
, Backend.Tock.Rounds.n )
Vector.t
Hlist0.Id.t
, 'f Snarky_backendless.Cvar.t
, 'f Snarky_backendless.Cvar.t
Snarky_backendless__Snark_intf.Boolean0.t )
Expand All @@ -1422,13 +1413,12 @@ module Step : sig
Bulletproof_challenge.t
, Backend.Tock.Rounds.n )
Vector.t
Hlist0.Id.t
, (Limb_vector.Constant.Hex64.t, Digest.Limbs.n) Vector.t
, Digest.Constant.t
, bool )
Per_proof.In_circuit.t
, 'n )
Vector.t
, (Limb_vector.Constant.Hex64.t, Digest.Limbs.n) Vector.t )
, Digest.Constant.t )
t
, 'f )
Snarky_backendless.Typ.t
Expand All @@ -1446,13 +1436,7 @@ module Step : sig
[@@deriving sexp, compare, yojson]

val to_data :
( ( ( 'a
, 'b
, 'c
, 'e Hlist0.Id.t
, 'f
, 'g )
Proof_state.Per_proof.In_circuit.t
( ( ('a, 'b, 'c, 'e, 'f, 'g) Proof_state.Per_proof.In_circuit.t
, 'h )
Vector.t
, 'i
Expand Down Expand Up @@ -1480,13 +1464,7 @@ module Step : sig
Vector.t
* ('i * ('j * unit)) )
Hlist.HlistId.t
-> ( ( ( 'c
, 'd
, 'a
, 'e Hlist0.Id.t
, 'b
, 'f )
Proof_state.Per_proof.In_circuit.t
-> ( ( ('c, 'd, 'a, 'e, 'b, 'f) Proof_state.Per_proof.In_circuit.t
, 'h )
Vector.t
, 'i
Expand Down
21 changes: 9 additions & 12 deletions src/lib/pickles/composition_types/digest.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ type nat4 := Limbs.n
(** Alias for fixed typed-size vector of size 4 *)
type 'a v := ('a, nat4) Pickles_types.Vector.vec

type vector := int64 v

module Constant : sig
module A : sig
type 'a t = 'a v [@@deriving compare, sexp, yojson, hash, equal]
Expand Down Expand Up @@ -39,24 +37,23 @@ module Constant : sig

val length : int

type t = Limb_vector.Constant.Hex64.t A.t
[@@deriving compare, sexp, yojson, hash, equal]
type t = Stable.Latest.t [@@deriving compare, sexp, yojson, hash, equal]

val to_bits : vector -> bool list
val to_bits : t -> bool list

val of_bits : bool list -> vector
val of_bits : bool list -> t

val of_tock_field : Backend.Tock.Field.t -> vector
val of_tock_field : Backend.Tock.Field.t -> t

val dummy : t

val zero : t

val to_tick_field : vector -> Backend.Tick.Field.t
val to_tick_field : t -> Backend.Tick.Field.t

val to_tock_field : vector -> Backend.Tock.Field.t
val to_tock_field : t -> Backend.Tock.Field.t

val of_tick_field : Backend.Tick.Field.t -> vector
val of_tick_field : Backend.Tick.Field.t -> t
end

module Make (Impl : Snarky_backendless.Snark_intf.Run) : sig
Expand All @@ -69,8 +66,8 @@ module Make (Impl : Snarky_backendless.Snark_intf.Run) : sig
end

module Constant : sig
include module type of Constant
include module type of Constant with type Stable.V1.t = Constant.Stable.V1.t
end

val typ : (t, vector) Impl.Typ.t
val typ : (t, Constant.t) Impl.Typ.t
end
15 changes: 3 additions & 12 deletions src/lib/pickles/composition_types/spec.mli
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ val typ :
Bulletproof_challenge.t
; challenge1 : Limb_vector.Challenge.Constant.t
; challenge2 : 'a Limb_vector.Challenge.t
; digest1 :
( Limb_vector.Constant.Hex64.t
, Digest.Limbs.n )
Pickles_types.Vector.vec
; digest1 : Digest.Constant.t
; digest2 : 'a Snarky_backendless.Cvar.t
; field1 : 'c
; field2 : 'b
Expand Down Expand Up @@ -145,10 +142,7 @@ val packed_typ :
Bulletproof_challenge.t
; challenge1 : Limb_vector.Challenge.Constant.t
; challenge2 : 'a Snarky_backendless.Cvar.t
; digest1 :
( Limb_vector.Constant.Hex64.t
, Digest.Limbs.n )
Pickles_types.Vector.vec
; digest1 : Digest.Constant.t
; digest2 : 'a Snarky_backendless.Cvar.t
; field1 : 'c
; field2 : 'b
Expand All @@ -174,10 +168,7 @@ val pack :
Bulletproof_challenge.t
; challenge1 : Limb_vector.Challenge.Constant.t
; challenge2 : 'f Limb_vector.Challenge.t
; digest1 :
( Limb_vector.Constant.Hex64.t
, Digest.Limbs.n )
Pickles_types.Vector.vec
; digest1 : Digest.Constant.t
; digest2 : 'f Snarky_backendless.Cvar.t
; field1 : 'c
; field2 : 'd
Expand Down
Loading

0 comments on commit cb47145

Please sign in to comment.