From 0fc6e3182fc4469f0cd185aeedd8f53a0184d6aa Mon Sep 17 00:00:00 2001 From: Mikhail Volkhov Date: Tue, 26 Sep 2023 11:50:42 +0100 Subject: [PATCH] [#14206,#14205] Cosmetics for of_int, of_nat --- src/lib/pickles/common.ml | 2 +- src/lib/pickles/compile.ml | 3 ++- src/lib/pickles/pickles.ml | 2 +- src/lib/pickles/step.ml | 2 +- src/lib/pickles_base/proofs_verified.ml | 11 +++++++---- src/lib/pickles_base/proofs_verified.mli | 4 ++-- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/lib/pickles/common.ml b/src/lib/pickles/common.ml index ce75b44a45db..2203f62f7322 100644 --- a/src/lib/pickles/common.ml +++ b/src/lib/pickles/common.ml @@ -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) = diff --git a/src/lib/pickles/compile.ml b/src/lib/pickles/compile.ml index 478401383ae2..0e538911146c 100644 --- a/src/lib/pickles/compile.ml +++ b/src/lib/pickles/compile.ml @@ -849,7 +849,8 @@ module Side_loaded = struct { wrap_vk = Some (Lazy.force d.wrap_vk) ; wrap_index = Lazy.force d.wrap_key ; 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 } diff --git a/src/lib/pickles/pickles.ml b/src/lib/pickles/pickles.ml index 000ef7f94520..253bf6a91343 100644 --- a/src/lib/pickles/pickles.ml +++ b/src/lib/pickles/pickles.ml @@ -211,7 +211,7 @@ module Make_str (_ : Wire_types.Concrete) = struct { wrap_vk = Some (Lazy.force d.wrap_vk) ; wrap_index = Lazy.force d.wrap_key ; 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 } diff --git a/src/lib/pickles/step.ml b/src/lib/pickles/step.ml index 48df56feaf5b..d36a24985f7c 100644 --- a/src/lib/pickles/step.ml +++ b/src/lib/pickles/step.ml @@ -752,7 +752,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 | _ -> ( diff --git a/src/lib/pickles_base/proofs_verified.ml b/src/lib/pickles_base/proofs_verified.ml index 7f7dd662270a..5560daf957da 100644 --- a/src/lib/pickles_base/proofs_verified.ml +++ b/src/lib/pickles_base/proofs_verified.ml @@ -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 -> @@ -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 @@ -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 diff --git a/src/lib/pickles_base/proofs_verified.mli b/src/lib/pickles_base/proofs_verified.mli index 68cb088a4541..30524be773cc 100644 --- a/src/lib/pickles_base/proofs_verified.mli +++ b/src/lib/pickles_base/proofs_verified.mli @@ -12,9 +12,9 @@ end type t = Stable.V1.t = N0 | N1 | N2 [@@deriving sexp, compare, yojson, hash, equal] -val of_nat : 'n Pickles_types.Nat.t -> t +val of_nat_exn : 'n Pickles_types.Nat.t -> t -val of_int : int -> t +val of_int_exn : int -> t val to_int : t -> int