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

MinaProtocol / mina / 2903

15 Nov 2024 01:59PM UTC coverage: 36.723% (-25.0%) from 61.682%
2903

Pull #16342

buildkite

dkijania
Merge branch 'dkijania/remove_publish_job_from_pr_comp' into dkijania/remove_publish_job_from_pr_dev
Pull Request #16342: [DEV] Publish debians only on nightly and stable

15 of 40 new or added lines in 14 files covered. (37.5%)

15175 existing lines in 340 files now uncovered.

24554 of 66863 relevant lines covered (36.72%)

20704.91 hits per line

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

8.22
/src/lib/verifier/common.ml
1
open Core_kernel
2
open Mina_base
3

4
type invalid =
16✔
5
  [ `Invalid_keys of Signature_lib.Public_key.Compressed.Stable.Latest.t list
×
6
  | `Invalid_signature of
7
    Signature_lib.Public_key.Compressed.Stable.Latest.t list
×
8
  | `Invalid_proof of (Error.t[@to_yojson Error_json.error_to_yojson])
×
9
  | `Missing_verification_key of
10
    Signature_lib.Public_key.Compressed.Stable.Latest.t list
×
11
  | `Unexpected_verification_key of
12
    Signature_lib.Public_key.Compressed.Stable.Latest.t list
×
13
  | `Mismatched_authorization_kind of
14
    Signature_lib.Public_key.Compressed.Stable.Latest.t list ]
×
15
[@@deriving bin_io_unversioned, to_yojson]
64✔
16

17
let invalid_to_error (invalid : invalid) : Error.t =
UNCOV
18
  let keys_to_string keys =
×
19
    List.map keys ~f:(fun key ->
×
20
        Signature_lib.Public_key.Compressed.to_base58_check key )
×
21
    |> String.concat ~sep:";"
×
22
  in
23
  match invalid with
24
  | `Invalid_keys keys ->
×
25
      Error.createf "Invalid_keys: [%s]" (keys_to_string keys)
×
26
  | `Invalid_signature keys ->
×
27
      Error.createf "Invalid_signature: [%s]" (keys_to_string keys)
×
28
  | `Missing_verification_key keys ->
×
29
      Error.createf "Missing_verification_key: [%s]" (keys_to_string keys)
×
30
  | `Unexpected_verification_key keys ->
×
31
      Error.createf "Unexpected_verification_key: [%s]" (keys_to_string keys)
×
32
  | `Mismatched_authorization_kind keys ->
×
33
      Error.createf "Mismatched_authorization_kind: [%s]" (keys_to_string keys)
×
UNCOV
34
  | `Invalid_proof err ->
×
35
      Error.tag ~tag:"Invalid_proof" err
36

37
let check :
38
       User_command.Verifiable.t With_status.t
39
    -> [ `Valid of User_command.Valid.t
40
       | `Valid_assuming of User_command.Valid.t * _ list
41
       | invalid ] = function
42
  | { With_status.data = User_command.Signed_command c; status = _ } -> (
480✔
43
      if not (Signed_command.check_valid_keys c) then
480✔
44
        `Invalid_keys (Signed_command.public_keys c)
×
45
      else
46
        match Signed_command.check_only_for_signature c with
480✔
47
        | Some c ->
480✔
48
            `Valid (User_command.Signed_command c)
49
        | None ->
×
50
            `Invalid_signature (Signed_command.public_keys c) )
×
UNCOV
51
  | { With_status.data =
×
52
        Zkapp_command
53
          ({ fee_payer; account_updates; memo } as zkapp_command_with_vk)
54
    ; status
55
    } ->
56
      with_return (fun { return } ->
UNCOV
57
          let account_updates_hash =
×
58
            Zkapp_command.Call_forest.hash account_updates
59
          in
UNCOV
60
          let tx_commitment =
×
61
            Zkapp_command.Transaction_commitment.create ~account_updates_hash
62
          in
63
          let full_tx_commitment =
64
            Zkapp_command.Transaction_commitment.create_complete tx_commitment
UNCOV
65
              ~memo_hash:(Signed_command_memo.hash memo)
×
66
              ~fee_payer_hash:
UNCOV
67
                (Zkapp_command.Digest.Account_update.create
×
UNCOV
68
                   (Account_update.of_fee_payer fee_payer) )
×
69
          in
UNCOV
70
          let check_signature s pk msg =
×
UNCOV
71
            match Signature_lib.Public_key.decompress pk with
×
72
            | None ->
×
73
                return (`Invalid_keys [ pk ])
UNCOV
74
            | Some pk ->
×
75
                if
76
                  not
UNCOV
77
                    (Signature_lib.Schnorr.Chunked.verify s
×
UNCOV
78
                       (Backend.Tick.Inner_curve.of_affine pk)
×
UNCOV
79
                       (Random_oracle_input.Chunked.field msg) )
×
80
                then
81
                  return
×
82
                    (`Invalid_signature [ Signature_lib.Public_key.compress pk ])
×
UNCOV
83
                else ()
×
84
          in
85
          check_signature fee_payer.authorization fee_payer.body.public_key
86
            full_tx_commitment ;
UNCOV
87
          let zkapp_command_with_hashes_list =
×
88
            account_updates |> Zkapp_statement.zkapp_statements_of_forest'
UNCOV
89
            |> Zkapp_command.Call_forest.With_hashes_and_data
×
90
               .to_zkapp_command_with_hashes_list
91
          in
UNCOV
92
          let valid_assuming =
×
93
            List.filter_map zkapp_command_with_hashes_list
94
              ~f:(fun ((p, (vk_opt, stmt)), _at_account_update) ->
UNCOV
95
                let commitment =
×
UNCOV
96
                  if p.body.use_full_commitment then full_tx_commitment
×
UNCOV
97
                  else tx_commitment
×
98
                in
99
                match (p.authorization, p.body.authorization_kind) with
UNCOV
100
                | Signature s, Signature ->
×
101
                    check_signature s p.body.public_key commitment ;
UNCOV
102
                    None
×
UNCOV
103
                | None_given, None_given ->
×
104
                    None
UNCOV
105
                | Proof pi, Proof vk_hash -> (
×
106
                    match status with
UNCOV
107
                    | Applied -> (
×
108
                        match vk_opt with
109
                        | None ->
×
110
                            return
111
                              (`Missing_verification_key
112
                                [ Account_id.public_key
×
113
                                  @@ Account_update.account_id p
×
114
                                ] )
UNCOV
115
                        | Some (vk : _ With_hash.t) ->
×
116
                            if
117
                              (* check that vk expected for proof is the one being used *)
118
                              Snark_params.Tick.Field.equal vk_hash
UNCOV
119
                                (With_hash.hash vk)
×
UNCOV
120
                            then Some (vk.data, stmt, pi)
×
121
                            else
122
                              return
×
123
                                (`Unexpected_verification_key
124
                                  [ Account_id.public_key
×
125
                                    @@ Account_update.account_id p
×
126
                                  ] ) )
UNCOV
127
                    | Failed _ ->
×
128
                        (* Don't verify the proof if it has failed. *)
129
                        None )
130
                | _ ->
×
131
                    return
132
                      (`Mismatched_authorization_kind
133
                        [ Account_id.public_key @@ Account_update.account_id p ]
×
134
                        ) )
135
          in
UNCOV
136
          let v : User_command.Valid.t =
×
137
            (* Verification keys should be present if it reaches here *)
138
            let zkapp_command =
139
              Zkapp_command.Valid.of_verifiable zkapp_command_with_vk
140
            in
UNCOV
141
            User_command.Poly.Zkapp_command zkapp_command
×
142
          in
143
          match valid_assuming with
UNCOV
144
          | [] ->
×
145
              `Valid v
UNCOV
146
          | _ :: _ ->
×
147
              `Valid_assuming (v, valid_assuming) )
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