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

MinaProtocol / mina / 80

14 Apr 2025 10:52PM UTC coverage: 60.82% (+24.9%) from 35.871%
80

push

buildkite

web-flow
Merge pull request #16871 from MinaProtocol/georgeee/last-before-zkapp-stable-hash-removal

Some changes required for hash removal from Zkapp_command.Stable

2 of 3 new or added lines in 2 files covered. (66.67%)

1322 existing lines in 28 files now uncovered.

49978 of 82173 relevant lines covered (60.82%)

475582.51 hits per line

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

93.75
/src/lib/zkapp_command_builder/zkapp_command_builder.ml
1
(* zkapp_command_builder.ml -- combinators to build Zkapp_command.t for tests *)
2

94✔
3
open Core_kernel
4
open Mina_base
5

6
let mk_forest ps :
7
    (Account_update.Body.Simple.t, unit, unit) Zkapp_command.Call_forest.t =
8
  List.map ps ~f:(fun p -> { With_stack_hash.elt = p; stack_hash = () })
78✔
9

10
let mk_node account_update calls : _ Zkapp_command.Call_forest.Tree.t =
11
  { account_update; account_update_digest = (); calls = mk_forest calls }
78✔
12

13
let mk_account_update_body ?preconditions ?(increment_nonce = false)
72✔
14
    ?(update = Account_update.Update.noop) authorization_kind may_use_token kp
40✔
15
    token_id balance_change : Account_update.Body.Simple.t =
16
  let open Signature_lib in
72✔
17
  let preconditions =
18
    Option.value preconditions
19
      ~default:
20
        Account_update.Preconditions.
21
          { network = Zkapp_precondition.Protocol_state.accept
22
          ; account = Zkapp_precondition.Account.accept
23
          ; valid_while = Ignore
24
          }
25
  in
26
  { update
72✔
27
  ; public_key = Public_key.compress kp.Keypair.public_key
72✔
28
  ; token_id
29
  ; balance_change =
30
      Currency.Amount.Signed.create
31
        ~magnitude:
32
          (Currency.Amount.of_nanomina_int_exn (Int.abs balance_change))
72✔
33
        ~sgn:(if Int.is_negative balance_change then Sgn.Neg else Pos)
20✔
34
  ; increment_nonce
35
  ; events = []
36
  ; actions = []
37
  ; call_data = Pickles.Impls.Step.Field.Constant.zero
38
  ; call_depth = 0
39
  ; preconditions
40
  ; use_full_commitment = true
41
  ; implicit_account_creation_fee = false
42
  ; may_use_token
43
  ; authorization_kind
44
  }
45

46
let mk_zkapp_command ?memo ~fee ~fee_payer_pk ~fee_payer_nonce account_updates :
47
    Zkapp_command.t =
48
  let fee_payer : Account_update.Fee_payer.t =
51✔
49
    { body =
50
        { public_key = fee_payer_pk
51
        ; fee = Currency.Fee.of_nanomina_int_exn fee
51✔
52
        ; valid_until = None
53
        ; nonce = fee_payer_nonce
54
        }
55
    ; authorization = Signature.dummy
56
    }
57
  in
58
  let memo =
59
    Option.value_map memo ~default:Signed_command_memo.dummy
60
      ~f:Signed_command_memo.create_from_string_exn
61
  in
62
  { fee_payer
51✔
63
  ; memo
64
  ; account_updates =
65
      account_updates
66
      |> Zkapp_command.Call_forest.map
51✔
67
           ~f:(fun (p : Account_update.Body.Simple.t) : Account_update.t ->
68
             let authorization =
78✔
69
               match p.authorization_kind with
70
               | None_given ->
4✔
71
                   Control.Poly.None_given
72
               | Proof _ ->
3✔
73
                   Control.Poly.Proof
74
                     (Lazy.force Mina_base.Proof.blockchain_dummy)
3✔
75
               | Signature ->
71✔
76
                   Control.Poly.Signature Signature.dummy
77
             in
78
             { body = Account_update.Body.of_simple p; authorization } )
78✔
79
      |> Zkapp_command.Call_forest.accumulate_hashes_predicated
51✔
80
  }
81

82
(* replace dummy signatures, proofs with valid ones for fee payer, other zkapp_command
83
   [keymap] maps compressed public keys to private keys
84
*)
85
let replace_authorizations ?prover ~keymap (zkapp_command : Zkapp_command.t) :
86
    Zkapp_command.t Async_kernel.Deferred.t =
87
  let txn_commitment, full_txn_commitment =
683✔
88
    Zkapp_command.get_transaction_commitments zkapp_command
89
  in
90
  let sign_for_account_update ~use_full_commitment sk =
683✔
91
    let commitment =
3,489✔
92
      if use_full_commitment then full_txn_commitment else txn_commitment
548✔
93
    in
94
    Signature_lib.Schnorr.Chunked.sign sk
95
      (Random_oracle.Input.Chunked.field commitment)
3,489✔
96
  in
97
  let fee_payer_sk =
98
    Signature_lib.Public_key.Compressed.Map.find_exn keymap
99
      zkapp_command.fee_payer.body.public_key
100
  in
101
  let fee_payer_signature =
683✔
102
    sign_for_account_update ~use_full_commitment:true fee_payer_sk
103
  in
104
  let fee_payer_with_valid_signature =
683✔
105
    { zkapp_command.fee_payer with authorization = fee_payer_signature }
106
  in
107
  let open Async_kernel.Deferred.Let_syntax in
108
  let%map account_updates_with_valid_authorizations =
109
    Zkapp_command.Call_forest.deferred_mapi zkapp_command.account_updates
683✔
110
      ~f:(fun _ndx ({ body; authorization } : Account_update.t) tree ->
111
        let%map valid_authorization =
112
          match authorization with
113
          | Control.Poly.Signature _dummy ->
2,806✔
114
              let pk = body.public_key in
115
              let sk =
116
                match
117
                  Signature_lib.Public_key.Compressed.Map.find keymap pk
118
                with
119
                | Some sk ->
2,806✔
120
                    sk
121
                | None ->
×
UNCOV
122
                    failwithf
×
123
                      "Could not find private key for public key %s in keymap"
UNCOV
124
                      (Signature_lib.Public_key.Compressed.to_base58_check pk)
×
125
                      ()
126
              in
127
              let use_full_commitment = body.use_full_commitment in
128
              let signature = sign_for_account_update ~use_full_commitment sk in
129
              return (Control.Poly.Signature signature)
2,806✔
130
          | Proof _proof -> (
154✔
131
              match prover with
132
              | None ->
145✔
133
                  return authorization
145✔
134
              | Some prover ->
9✔
135
                  let txn_stmt = Zkapp_statement.of_tree tree in
136
                  let handler
9✔
137
                      (Snarky_backendless.Request.With { request; respond }) =
138
                    match request with _ -> respond Unhandled
2,288✔
139
                  in
140
                  let%map (), (), proof =
141
                    prover ?handler:(Some handler) txn_stmt
9✔
142
                  in
143
                  Control.Poly.Proof proof )
9✔
144
          | None_given ->
385✔
145
              return authorization
385✔
146
        in
147
        { Account_update.Poly.body; authorization = valid_authorization } )
3,345✔
148
  in
149
  { zkapp_command with
683✔
150
    fee_payer = fee_payer_with_valid_signature
151
  ; account_updates = account_updates_with_valid_authorizations
152
  }
188✔
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