Skip to content

Commit

Permalink
[#14206,#14205] Cosmetics for of_int, of_nat
Browse files Browse the repository at this point in the history
  • Loading branch information
volhovm committed Sep 26, 2023
1 parent e85cf69 commit 0fc6e31
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
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 @@ -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
}

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 @@ -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
}
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 @@ -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
| _ -> (
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
4 changes: 2 additions & 2 deletions src/lib/pickles_base/proofs_verified.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0fc6e31

Please sign in to comment.