• 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

75.0
/src/lib/pickles/wrap_hack.ml
1
open Core_kernel
10✔
2
open Backend
3
open Pickles_types
4

5
(* The actual "accumulator" for the wrap proof contains a vector of elements,
6
   each of which is a vector of bulletproof challenges.
7

8
   The number of such vectors is equal to the maximum proofs-verified
9
   amongst all the step branches that that proof is wrapping.
10

11
   To simplify the implementation when the number of proofs-verified
12
   varies across proof systems (being either 0, 1, or 2) we secretly
13
   pad the accumulator so that it always has exactly 2 vectors, padding
14
   with dummy vectors.
15

16
   We also then pad with the corresponding dummy commitments when proving
17
   wrap statements, as in `pad_accumulator` which is used in wrap.ml.
18

19
   We add them to the **front**, not the back, of the vector of the actual
20
   "real" accumulator values so that we can precompute the sponge states
21
   resulting from absorbing the padding challenges
22
*)
23

24
module Padded_length = Nat.N2
25

26
(* Pad up to length 2 by preprending dummy values. *)
27
let pad_vector (type a) ~dummy (v : (a, _) Vector.t) =
28
  Vector.extend_front_exn v Padded_length.n dummy
52✔
29

30
(* Specialized padding function. *)
31
let pad_challenges (chalss : (_ Vector.t, _) Vector.t) =
32
  pad_vector ~dummy:(Lazy.force Dummy.Ipa.Wrap.challenges_computed) chalss
×
33

34
(* Specialized padding function. *)
35
let pad_accumulator (xs : (Tock.Proof.Challenge_polynomial.t, _) Vector.t) =
36
  pad_vector xs
×
37
    ~dummy:
38
      { Tock.Proof.Challenge_polynomial.commitment =
39
          Lazy.force Dummy.Ipa.Wrap.sg
×
40
      ; challenges =
41
          Vector.to_array (Lazy.force Dummy.Ipa.Wrap.challenges_computed)
×
42
      }
43
  |> Vector.to_list
44

45
(* Hash the me only, padding first. *)
46
let hash_messages_for_next_wrap_proof (type n) (_max_proofs_verified : n Nat.t)
47
    (t :
48
      ( Tick.Curve.Affine.t
49
      , (_, n) Vector.t )
50
      Composition_types.Wrap.Proof_state.Messages_for_next_wrap_proof.t ) =
51
  let t =
×
52
    { t with
53
      old_bulletproof_challenges = pad_challenges t.old_bulletproof_challenges
×
54
    }
55
  in
56
  Tock_field_sponge.digest Tock_field_sponge.params
57
    (Composition_types.Wrap.Proof_state.Messages_for_next_wrap_proof
58
     .to_field_elements t ~g1:(fun ((x, y) : Tick.Curve.Affine.t) -> [ x; y ])
×
59
    )
60

61
(* Pad the messages_for_next_wrap_proof of a proof *)
62
let pad_proof (type mlmb) (T p : (mlmb, _) Proof.t) :
63
    Proof.Proofs_verified_max.t =
64
  T
×
65
    { p with
66
      statement =
67
        { p.statement with
68
          proof_state =
69
            { p.statement.proof_state with
70
              messages_for_next_wrap_proof =
71
                { p.statement.proof_state.messages_for_next_wrap_proof with
72
                  old_bulletproof_challenges =
73
                    pad_vector
×
74
                      p.statement.proof_state.messages_for_next_wrap_proof
75
                        .old_bulletproof_challenges
76
                      ~dummy:Dummy.Ipa.Wrap.challenges
77
                }
78
            }
79
        }
80
    }
81

82
module Checked = struct
83
  let pad_challenges (chalss : (_ Vector.t, _) Vector.t) =
84
    pad_vector
14✔
85
      ~dummy:
86
        (Vector.map ~f:Impls.Wrap.Field.constant
14✔
87
           (Lazy.force Dummy.Ipa.Wrap.challenges_computed) )
14✔
88
      chalss
89

90
  let pad_commitments (commitments : _ Vector.t) =
91
    pad_vector
38✔
92
      ~dummy:
93
        (Tuple_lib.Double.map ~f:Impls.Step.Field.constant
38✔
94
           (Lazy.force Dummy.Ipa.Wrap.sg) )
38✔
95
      commitments
96

97
  (* We precompute the sponge states that would result from absorbing
98
     0, 1, or 2 dummy challenge vectors. This is used to speed up hashing
99
     inside the circuit. *)
100
  let dummy_messages_for_next_wrap_proof_sponge_states =
101
    lazy
102
      (let module S = Tock_field_sponge.Field in
4✔
103
      let full_state s = (S.state s, s.sponge_state) in
12✔
104
      let sponge = S.create Tock_field_sponge.params in
105
      let s0 = full_state sponge in
4✔
106
      let chals = Lazy.force Dummy.Ipa.Wrap.challenges_computed in
4✔
107
      Vector.iter ~f:(S.absorb sponge) chals ;
4✔
108
      let s1 = full_state sponge in
4✔
109
      Vector.iter ~f:(S.absorb sponge) chals ;
4✔
110
      let s2 = full_state sponge in
4✔
111
      [| s0; s1; s2 |] )
4✔
112

113
  let hash_constant_messages_for_next_wrap_proof =
114
    hash_messages_for_next_wrap_proof
115

116
  (* TODO: No need to hash the entire bulletproof challenges. Could
117
     just hash the segment of the public input LDE corresponding to them
118
     that we compute when verifying the previous proof. That is a commitment
119
     to them. *)
120
  let hash_messages_for_next_wrap_proof (type n) (max_proofs_verified : n Nat.t)
121
      (t :
122
        ( Wrap_main_inputs.Inner_curve.t
123
        , ((Impls.Wrap.Field.t, Backend.Tock.Rounds.n) Vector.t, n) Vector.t )
124
        Composition_types.Wrap.Proof_state.Messages_for_next_wrap_proof.t ) =
125
    let open Wrap_main_inputs in
21✔
126
    let sponge =
127
      (* The sponge states we would reach if we absorbed the padding challenges *)
128
      let s = Sponge.create sponge_params in
129
      let state, sponge_state =
21✔
130
        (Lazy.force dummy_messages_for_next_wrap_proof_sponge_states).(2
21✔
131
                                                                       - Nat
132
                                                                         .to_int
21✔
133
                                                                           max_proofs_verified)
134
      in
135
      { s with
21✔
136
        state = Array.map state ~f:Impls.Wrap.Field.constant
21✔
137
      ; sponge_state
138
      }
139
    in
140
    Array.iter ~f:(Sponge.absorb sponge)
21✔
141
      (Composition_types.Wrap.Proof_state.Messages_for_next_wrap_proof
142
       .to_field_elements ~g1:Inner_curve.to_field_elements t ) ;
21✔
143
    Sponge.squeeze_field sponge
21✔
144
end
20✔
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