Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#14206,#14205] Cosmetics for of_int, of_nat #14216

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/pickles/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let actual_wrap_domain_size ~log_2_domain_size =
| _ ->
assert false
in
Pickles_base.Proofs_verified.of_int d
Pickles_base.Proofs_verified.of_int_exn d

let hash_messages_for_next_step_proof ~app_state
(t : _ Types.Step.Proof_state.Messages_for_next_step_proof.t) =
Expand Down
3 changes: 2 additions & 1 deletion src/lib/pickles/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,8 @@ module Side_loaded = struct
Plonk_verification_key_evals.map (Lazy.force d.wrap_key) ~f:(fun x ->
x.(0) )
; max_proofs_verified =
Pickles_base.Proofs_verified.of_nat (Nat.Add.n d.max_proofs_verified)
Pickles_base.Proofs_verified.of_nat_exn
(Nat.Add.n d.max_proofs_verified)
; actual_wrap_domain_size
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/pickles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ module Make_str (_ : Wire_types.Concrete) = struct
Plonk_verification_key_evals.map (Lazy.force d.wrap_key)
~f:(fun x -> x.(0))
; max_proofs_verified =
Pickles_base.Proofs_verified.of_nat
Pickles_base.Proofs_verified.of_nat_exn
(Nat.Add.n d.max_proofs_verified)
; actual_wrap_domain_size
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/step.ml
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ struct
~f:(fun j acc (Pow_2_roots_of_unity domain) ->
if Int.equal domain domain_size then j else acc )
in
Pickles_base.Proofs_verified.of_int domain_index )
Pickles_base.Proofs_verified.of_int_exn domain_index )
in
k wrap_domain_indices
| _ -> (
Expand Down
11 changes: 7 additions & 4 deletions src/lib/pickles_base/proofs_verified.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let to_int : t -> int = function N0 -> 0 | N1 -> 1 | N2 -> 2

type proofs_verified = t

let of_nat (type n) (n : n Pickles_types.Nat.t) : t =
let of_nat_exn (type n) (n : n Pickles_types.Nat.t) : t =
let open Pickles_types.Nat in
match n with
| Z ->
Expand All @@ -50,9 +50,11 @@ let of_nat (type n) (n : n Pickles_types.Nat.t) : t =
| S (S Z) ->
N2
| S _ ->
failwithf "Proofs_verified.of_nat: got %d" (to_int n) ()
raise
(Invalid_argument
(Printf.sprintf "Proofs_verified.of_nat: got %d" (to_int n)) )

let of_int (n : int) : t =
let of_int_exn (n : int) : t =
match n with
| 0 ->
N0
Expand All @@ -61,7 +63,8 @@ let of_int (n : int) : t =
| 2 ->
N2
| _ ->
failwithf "Proofs_verified.of_int: got %d" n ()
raise
(Invalid_argument (Printf.sprintf "Proofs_verified.of_int: got %d" n))

type 'f boolean = 'f Snarky_backendless.Cvar.t Snarky_backendless.Boolean.t

Expand Down
8 changes: 4 additions & 4 deletions src/lib/pickles_base/proofs_verified.mli
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ end
type t = Stable.V1.t = N0 | N1 | N2
[@@deriving sexp, compare, yojson, hash, equal]

(** [of_nat t_n] converts the type level natural [t_n] to the data type natural.
(** [of_nat_exn t_n] converts the type level natural [t_n] to the data type natural.
Raise an exception if [t_n] represents a value above or equal to 3 *)
val of_nat : 'n Pickles_types.Nat.t -> t
val of_nat_exn : 'n Pickles_types.Nat.t -> t

(** [of_int n] converts the runtime natural [n] to the data type natural. Raise
(** [of_int_exn n] converts the runtime natural [n] to the data type natural. Raise
an exception if the value [n] is above or equal to 3 *)
val of_int : int -> t
val of_int_exn : int -> t

(** [to_int v] converts the value [v] to the corresponding integer, i.e [N0 ->
0], [N1 -> 1] and [N2 -> 2] *)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/snarkyjs