• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 2863

05 Nov 2024 06:20PM UTC coverage: 30.754% (-16.6%) from 47.311%
2863

push

buildkite

web-flow
Merge pull request #16296 from MinaProtocol/dkijania/more_multi_jobs

more multi jobs in CI

20276 of 65930 relevant lines covered (30.75%)

8631.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.54
/src/lib/pickles/composition_types/branch_data.ml
1
(** See documentation of the {!Mina_wire_types} library *)
11✔
2
module Wire_types = Mina_wire_types.Pickles_composition_types.Branch_data
3

4
module Make_sig (A : Wire_types.Types.S) = struct
5
  module type S =
6
    Branch_data_intf.S
7
      with type Domain_log2.Stable.V1.t = A.Domain_log2.V1.t
8
       and type Stable.V1.t = A.V1.t
9
end
10

11
module Make_str (A : Wire_types.Concrete) = struct
12
  (** Data specific to a branch of a proof-system that's necessary for
13
    finalizing the deferred-values in a wrap proof of that branch. *)
14

15
  module Proofs_verified = Pickles_base.Proofs_verified
16

17
  module Domain_log2 = struct
18
    [%%versioned
19
    module Stable = struct
20
      module V1 = struct
21
        type t = char [@@deriving compare, sexp, yojson, hash, equal]
×
22

23
        let to_latest = Fn.id
24
      end
25
    end]
26

27
    let of_int_exn : int -> t = Char.of_int_exn
28

29
    let of_bits_msb (bs : bool list) : t =
30
      List.fold bs ~init:0 ~f:(fun acc b ->
×
31
          let acc = acc lsl 1 in
×
32
          if b then acc + 1 else acc )
×
33
      |> of_int_exn
34

35
    let of_field_exn (type f)
36
        (module Impl : Snarky_backendless.Snark_intf.Run with type field = f)
37
        (x : f) : t =
38
      Impl.Field.Constant.unpack x
×
39
      |> Fn.flip List.take 8 |> List.rev |> of_bits_msb
×
40
  end
41

42
  (* We pack this into a single field element as follows:
43
     First 2 bits: proofs_verified
44
     Next 8 bits: domain_log2 *)
45
  [%%versioned
46
  module Stable = struct
47
    module V1 = struct
48
      type t = A.V1.t =
22✔
49
        { proofs_verified : Proofs_verified.Stable.V1.t
×
50
        ; domain_log2 : Domain_log2.Stable.V1.t
×
51
        }
52
      [@@deriving hlist, compare, sexp, yojson, hash, equal]
55✔
53

54
      let to_latest = Fn.id
55
    end
56
  end]
57

58
  let length_in_bits = 10
59

60
  let pack (type f)
61
      (module Impl : Snarky_backendless.Snark_intf.Run with type field = f)
62
      ({ proofs_verified; domain_log2 } : t) : f =
63
    let open Impl.Field.Constant in
×
64
    let double x = x + x in
×
65
    let times4 x = double (double x) in
×
66
    let domain_log2 = of_int (Char.to_int domain_log2) in
×
67
    (* shift domain_log2 over by 2 bits (multiply by 4) *)
68
    times4 domain_log2
×
69
    + project
×
70
        (Pickles_types.Vector.to_list
×
71
           (Proofs_verified.Prefix_mask.there proofs_verified) )
×
72

73
  let unpack (type f)
74
      (module Impl : Snarky_backendless.Snark_intf.Run with type field = f)
75
      (x : f) : t =
76
    match Impl.Field.Constant.unpack x with
×
77
    | x0 :: x1 :: y0 :: y1 :: y2 :: y3 :: y4 :: y5 :: y6 :: y7 :: _ ->
×
78
        { proofs_verified = Proofs_verified.Prefix_mask.back [ x0; x1 ]
×
79
        ; domain_log2 =
80
            Domain_log2.of_bits_msb [ y7; y6; y5; y4; y3; y2; y1; y0 ]
×
81
        }
82
    | _ ->
83
        assert false
84

85
  module Checked = struct
86
    type 'f t =
76✔
87
      { proofs_verified_mask : 'f Proofs_verified.Prefix_mask.Checked.t
88
      ; domain_log2 : 'f Snarky_backendless.Cvar.t
89
      }
90
    [@@deriving hlist]
91

92
    let pack (type f)
93
        (module Impl : Snarky_backendless.Snark_intf.Run with type field = f)
94
        ({ proofs_verified_mask; domain_log2 } : f t) : Impl.Field.t =
95
      let open Impl.Field in
45✔
96
      let four = of_int 4 in
97
      (four * domain_log2)
45✔
98
      + pack (Pickles_types.Vector.to_list proofs_verified_mask)
45✔
99
  end
100

101
  let packed_typ (type f)
102
      (module Impl : Snarky_backendless.Snark_intf.Run with type field = f) =
103
    Impl.Typ.transport Impl.Typ.field
49✔
104
      ~there:(pack (module Impl))
49✔
105
      ~back:(unpack (module Impl))
49✔
106

107
  let typ (type f)
108
      (module Impl : Snarky_backendless.Snark_intf.Run with type field = f)
109
      ~(* We actually only need it to be less than 252 bits in order to pack
110
          the whole branch_data struct safely, but it's cheapest to check that it's
111
          under 16 bits *)
112
      (assert_16_bits : Impl.Field.t -> unit) : (f Checked.t, t) Impl.Typ.t =
113
    let open Impl in
38✔
114
    let proofs_verified_mask :
115
        (f Proofs_verified.Prefix_mask.Checked.t, Proofs_verified.t) Typ.t =
116
      Proofs_verified.Prefix_mask.typ (module Impl)
38✔
117
    in
118
    let domain_log2 : (Field.t, Domain_log2.t) Typ.t =
119
      let (Typ t) =
120
        Typ.transport Field.typ
121
          ~there:(fun (x : char) -> Field.Constant.of_int (Char.to_int x))
×
122
          ~back:(Domain_log2.of_field_exn (module Impl))
38✔
123
      in
124
      let check (x : Field.t) = make_checked (fun () -> assert_16_bits x) in
38✔
125
      Typ { t with check }
126
    in
127
    Typ.of_hlistable
128
      [ proofs_verified_mask; domain_log2 ]
129
      ~value_of_hlist:of_hlist ~value_to_hlist:to_hlist
130
      ~var_to_hlist:Checked.to_hlist ~var_of_hlist:Checked.of_hlist
131

132
  let domain { domain_log2; _ } =
133
    Pickles_base.Domain.Pow_2_roots_of_unity (Char.to_int domain_log2)
×
134
end
135

136
include Wire_types.Make (Make_sig) (Make_str)
22✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc