package tezos-protocol-013-PtJakart

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file tx_rollup_errors_repr.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2022 Marigold <contact@marigold.dev>                        *)
(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com>                *)
(* Copyright (c) 2022 Oxhead Alpha <info@oxhead-alpha.com>                   *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

type error +=
  | Tx_rollup_already_exists of Tx_rollup_repr.t
  | Tx_rollup_does_not_exist of Tx_rollup_repr.t
  | Submit_batch_burn_exceeded of {burn : Tez_repr.t; limit : Tez_repr.t}
  | Inbox_does_not_exist of Tx_rollup_repr.t * Tx_rollup_level_repr.t
  | Inbox_size_would_exceed_limit of Tx_rollup_repr.t
  | Inbox_count_would_exceed_limit of Tx_rollup_repr.t
  | No_uncommitted_inbox
  | Message_size_exceeds_limit
  | Too_many_inboxes
  | Too_many_commitments
  | Too_many_withdrawals
  | Wrong_batch_count
  | Commitment_too_early of {
      provided : Tx_rollup_level_repr.t;
      expected : Tx_rollup_level_repr.t;
    }
  | Level_already_has_commitment of Tx_rollup_level_repr.t
  | Wrong_inbox_hash
  | Bond_does_not_exist of Signature.public_key_hash
  | Bond_in_use of Signature.public_key_hash
  | No_commitment_to_finalize
  | No_commitment_to_remove
  | Commitment_does_not_exist of Tx_rollup_level_repr.t
  | Wrong_predecessor_hash of {
      provided : Tx_rollup_commitment_repr.Hash.t option;
      expected : Tx_rollup_commitment_repr.Hash.t option;
    }
  | Internal_error of string
  | Wrong_message_position of {
      level : Tx_rollup_level_repr.t;
      position : int;
      length : int;
    }
  | Wrong_path_depth of {
      kind : [`Inbox | `Commitment];
      provided : int;
      limit : int;
    }
  | Wrong_message_path of {expected : Tx_rollup_inbox_repr.Merkle.root}
  | No_finalized_commitment_for_level of {
      level : Tx_rollup_level_repr.t;
      window : (Tx_rollup_level_repr.t * Tx_rollup_level_repr.t) option;
    }
  | Withdraw_invalid_path
  | Withdraw_already_consumed
  | Withdrawals_invalid_path
  | Withdrawals_already_dispatched
  | Invalid_committer
  | Commitment_bond_negative of int
  | Cannot_reject_level of {
      provided : Tx_rollup_level_repr.t;
      accepted_range : (Tx_rollup_level_repr.t * Tx_rollup_level_repr.t) option;
    }
  | Wrong_rejection_hash of {
      provided : Tx_rollup_message_result_hash_repr.t;
      expected :
        [ `Valid_path of Tx_rollup_commitment_repr.Merkle.h * int
        | `Hash of Tx_rollup_message_result_hash_repr.t ];
    }
  | Ticket_payload_size_limit_exceeded of {payload_size : int; limit : int}
  | Wrong_deposit_parameters
  | Proof_failed_to_reject
  | Proof_produced_rejected_state
  | Proof_invalid_before of {agreed : Context_hash.t; provided : Context_hash.t}
  | No_withdrawals_to_dispatch

let check_path_depth kind provided ~count_limit =
  let limit = Merkle_list.max_depth ~count_limit in
  error_when Compare.Int.(limit < provided)
  @@ Wrong_path_depth {kind; provided; limit}

let () =
  let open Data_encoding in
  (* Tx_rollup_submit_batch_burn_exceeded *)
  register_error_kind
    `Temporary
    ~id:"operation.tx_rollup_submit_batch_burn_exceeded"
    ~title:"Submit batch exceeded burn limit"
    ~description:
      "The submit batch would exceed the burn limit, we withdraw the submit."
    ~pp:(fun ppf (burn, limit) ->
      Format.fprintf
        ppf
        "Cannot submit the batch of L2 operations as the cost (%a) would \
         exceed the burn limit (%a)"
        Tez_repr.pp
        burn
        Tez_repr.pp
        limit)
    Data_encoding.(
      obj2 (req "burn" Tez_repr.encoding) (req "limit" Tez_repr.encoding))
    (function
      | Submit_batch_burn_exceeded {burn; limit} -> Some (burn, limit)
      | _ -> None)
    (fun (burn, limit) -> Submit_batch_burn_exceeded {burn; limit}) ;
  (* Tx_rollup_inbox_does_not_exist *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_inbox_does_not_exist"
    ~title:"Missing transaction rollup inbox"
    ~description:"The transaction rollup does not have an inbox at this level"
    ~pp:(fun ppf (addr, level) ->
      Format.fprintf
        ppf
        "Transaction rollup %a does not have an inbox at level %a"
        Tx_rollup_repr.pp
        addr
        Tx_rollup_level_repr.pp
        level)
    (obj2
       (req "tx_rollup_address" Tx_rollup_repr.encoding)
       (req "raw_level" Tx_rollup_level_repr.encoding))
    (function
      | Inbox_does_not_exist (rollup, level) -> Some (rollup, level) | _ -> None)
    (fun (rollup, level) -> Inbox_does_not_exist (rollup, level)) ;
  register_error_kind
    `Temporary
    ~id:"tx_rollup_inbox_size_would_exceed_limit"
    ~title:"Transaction rollup inbox’s size would exceed the limit"
    ~description:
      "Transaction rollup inbox’s size in bytes would exceed the limit"
    ~pp:(fun ppf addr ->
      Format.fprintf
        ppf
        "Adding the submitted message would make the inbox of %a exceed the \
         authorized size in bytes at this level"
        Tx_rollup_repr.pp
        addr)
    (obj1 (req "tx_rollup_address" Tx_rollup_repr.encoding))
    (function Inbox_size_would_exceed_limit rollup -> Some rollup | _ -> None)
    (fun rollup -> Inbox_size_would_exceed_limit rollup) ;
  (* Tx_rollup_message_count_would_exceed_limit *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_inbox_count_would_exceed_limit"
    ~title:"Transaction rollup inbox’s message count would exceed the limit"
    ~description:
      "Transaction rollup inbox’s message count would exceed the limit"
    ~pp:(fun ppf addr ->
      Format.fprintf
        ppf
        "Adding the submitted message would make the inbox of %a exceed the \
         authorized message count at this level"
        Tx_rollup_repr.pp
        addr)
    (obj1 (req "tx_rollup_address" Tx_rollup_repr.encoding))
    (function
      | Inbox_count_would_exceed_limit rollup -> Some rollup | _ -> None)
    (fun rollup -> Inbox_count_would_exceed_limit rollup) ;
  (* Tx_rollup_message_size_exceed_limit *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_no_uncommitted_inbox"
    ~title:"There is no inbox awaiting a commitment."
    ~description:"There is no inbox awaiting a commitment."
    empty
    (function No_uncommitted_inbox -> Some () | _ -> None)
    (fun () -> No_uncommitted_inbox) ;
  (* Tx_rollup_message_size_exceed_limit *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_message_size_exceeds_limit"
    ~title:"A message submitted to a transaction rollup inbox exceeds limit"
    ~description:
      "A message submitted to a transaction rollup inbox exceeds limit"
    empty
    (function Message_size_exceeds_limit -> Some () | _ -> None)
    (fun () -> Message_size_exceeds_limit) ;
  (* Tx_rollup_too_many_inboxes *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_too_many_inboxes"
    ~title:"Cannot create a new inbox because there are too many already"
    ~description:"Cannot create a new inbox because there are too many already"
    empty
    (function Too_many_inboxes -> Some () | _ -> None)
    (fun () -> Too_many_inboxes) ;
  (* Tx_rollup_too_many_commitments *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_too_many_commitments"
    ~title:"Too many commitments"
    ~description:
      "Cannot create a new commitment because there are too many already"
    empty
    (function Too_many_commitments -> Some () | _ -> None)
    (fun () -> Too_many_commitments) ;
  (* Tx_rollup_too_many_withdrawals *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_too_many_withdrawals"
    ~title:"Cannot dispatch that many withdrawals"
    ~description:"Cannot dispatch that many withdrawals"
    empty
    (function Too_many_withdrawals -> Some () | _ -> None)
    (fun () -> Too_many_withdrawals) ;
  (* Wrong_batch_count *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_wrong_batch_count"
    ~title:"This commitment has the wrong number of batches"
    ~description:
      "This commitment has a different number of batches than its inbox"
    unit
    (function Wrong_batch_count -> Some () | _ -> None)
    (fun () -> Wrong_batch_count) ;
  (* Commitment_too_early *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_commitment_too_early"
    ~title:"Cannot submit a commitment for this level yet"
    ~description:
      "It is not possible to submit a commitment for this level just yet."
    (obj2
       (req "provided" Tx_rollup_level_repr.encoding)
       (req "expected" Tx_rollup_level_repr.encoding))
    (function
      | Commitment_too_early {provided; expected} -> Some (provided, expected)
      | _ -> None)
    (fun (provided, expected) -> Commitment_too_early {provided; expected}) ;
  (* Level_already_has_commitment *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_level_already_has_commitment"
    ~title:"This commitment is for a level that already has a commitment"
    ~description:"This commitment is for a level that already has a commitment"
    (obj1 (req "level" Tx_rollup_level_repr.encoding))
    (function Level_already_has_commitment level -> Some level | _ -> None)
    (fun level -> Level_already_has_commitment level) ;
  (* Wrong_inbox_hash *)
  register_error_kind
    `Branch
    ~id:"Wrong_inbox_hash"
    ~title:"This commitment has the wrong inbox hash"
    ~description:"This commitment has a different hash than its inbox"
    unit
    (function Wrong_inbox_hash -> Some () | _ -> None)
    (fun () -> Wrong_inbox_hash) ;
  (* Bond_does_not_exist *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_bond_does_not_exist"
    ~title:"This account does not have a bond for this rollup"
    ~description:"This account does not have a bond for this rollup"
    (obj1 (req "contract" Signature.Public_key_hash.encoding))
    (function Bond_does_not_exist contract -> Some contract | _ -> None)
    (fun contract -> Bond_does_not_exist contract) ;
  (* Bond_in_use *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_bond_in_use"
    ~title:"This account's bond is in use for one or more commitments"
    ~description:"This account's bond is in use for one or more commitments"
    (obj1 (req "contract" Signature.Public_key_hash.encoding))
    (function Bond_in_use contract -> Some contract | _ -> None)
    (fun contract -> Bond_in_use contract) ;
  (* No_commitment_to_finalize *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_no_commitment_to_finalize"
    ~title:"There is no commitment to finalize"
    ~description:"There is no commitment to finalize"
    empty
    (function No_commitment_to_finalize -> Some () | _ -> None)
    (fun () -> No_commitment_to_finalize) ;
  (* No_commitment_to_remove *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_no_commitment_to_remove"
    ~title:"There is no commitment to remove"
    ~description:"There is no commitment to remove"
    empty
    (function No_commitment_to_remove -> Some () | _ -> None)
    (fun () -> No_commitment_to_remove) ;
  (* Commitment_does_not_exist *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_commitment_does_not_exist"
    ~title:"There is no commitment at the requested level"
    ~description:"There is no commitment at the requested level"
    (obj1 (req "provided" Tx_rollup_level_repr.encoding))
    (function Commitment_does_not_exist l -> Some l | _ -> None)
    (fun l -> Commitment_does_not_exist l) ;
  (* Wrong_predecessor_hash *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_wrong_predecessor_hash"
    ~title:"The commitment refers to a commitment that is not in the context"
    ~description:
      "The commitment refers to a commitment that is not in the context"
    (obj2
       (req "provided" (option Tx_rollup_commitment_repr.Hash.encoding))
       (req "expected" (option Tx_rollup_commitment_repr.Hash.encoding)))
    (function
      | Wrong_predecessor_hash {provided; expected} -> Some (provided, expected)
      | _ -> None)
    (fun (provided, expected) -> Wrong_predecessor_hash {provided; expected}) ;
  (* Tx_rollup_already_exists *)
  register_error_kind
    `Permanent
    ~id:"tx_rollup_already_exists"
    ~title:"Transaction rollup was already created"
    ~description:
      "The protocol tried to originate the same transaction rollup twice"
    ~pp:(fun ppf addr ->
      Format.fprintf
        ppf
        "Transaction rollup %a is already used for an existing transaction \
         rollup. This should not happen, and indicates there is a bug in the \
         protocol. If you can, please report this bug \
         (https://gitlab.com/tezos/tezos/-/issues.)"
        Tx_rollup_repr.pp
        addr)
    (obj1 (req "rollup_address" Tx_rollup_repr.encoding))
    (function Tx_rollup_already_exists rollup -> Some rollup | _ -> None)
    (fun rollup -> Tx_rollup_already_exists rollup) ;
  (* Tx_rollup_does_not_exist *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_does_not_exist"
    ~title:"Transaction rollup does not exist"
    ~description:"An invalid transaction rollup address was submitted"
    ~pp:(fun ppf addr ->
      Format.fprintf
        ppf
        "Invalid transaction rollup address %a"
        Tx_rollup_repr.pp
        addr)
    (obj1 (req "rollup_address" Tx_rollup_repr.encoding))
    (function Tx_rollup_does_not_exist rollup -> Some rollup | _ -> None)
    (fun rollup -> Tx_rollup_does_not_exist rollup) ;
  (* Internal_error *)
  register_error_kind
    `Permanent
    ~id:"tx_rollup_internal_error"
    ~title:"An internal error occurred"
    ~description:"An internal error occurred"
    (obj1 (req "description" string))
    (function Internal_error str -> Some str | _ -> None)
    (fun str -> Internal_error str) ;
  (* Wrong_message_position *)
  register_error_kind
    `Branch
    ~id:"tx_rollup_wrong_message_position"
    ~title:"Wrong message index in rejection"
    ~description:
      "The rejection references the {position}^th message of the inbox {l} \
       which contains only {inbox_length} messages"
    (obj3
       (req "level" Tx_rollup_level_repr.encoding)
       (req "position" int31)
       (req "length" int31))
    (function
      | Wrong_message_position {level; position; length} ->
          Some (level, position, length)
      | _ -> None)
    (fun (level, position, length) ->
      Wrong_message_position {level; position; length}) ;
  (* Wrong_path_depth *)
  register_error_kind
    `Permanent
    ~id:"tx_rollup_wrong_message_path_depth"
    ~title:"Wrong message path depth"
    ~description:
      "A path submitted as argument of this operation exceeds the maximum \
       depth that can be witnessed."
    (obj3
       (req
          "target"
          (union
             [
               case
                 (Tag 0)
                 ~title:"Inbox"
                 (constant "inbox")
                 (function `Inbox -> Some () | _ -> None)
                 (fun () -> `Inbox);
               case
                 (Tag 1)
                 ~title:"Commitment"
                 (constant "commitment")
                 (function `Commitment -> Some () | _ -> None)
                 (fun () -> `Commitment);
             ]))
       (req "provided" int31)
       (req "limit" int31))
    (function
      | Wrong_path_depth {kind; provided; limit} -> Some (kind, provided, limit)
      | _ -> None)
    (fun (kind, provided, limit) -> Wrong_path_depth {kind; provided; limit}) ;
  (* Wrong_message_hash *)
  register_error_kind
    `Branch
    ~id:"tx_rollup_wrong_message_path"
    ~title:"Wrong message path in rejection."
    ~description:
      "This rejection has sent a message and a path that does not fit the \
       current merkle root hash in the corresponding inbox"
    (obj1
       (req "expected_merkle_root" Tx_rollup_inbox_repr.Merkle.root_encoding))
    (function Wrong_message_path {expected} -> Some expected | _ -> None)
    (fun expected -> Wrong_message_path {expected}) ;
  (* No_finalized_commitment_for_level *)
  register_error_kind
    `Temporary
    ~id:"operation.tx_rollup_no_finalized_commitment_for_level"
    ~title:"Operation is about a commitment that is not yet finalized"
    ~description:"This operation must be about a finalized commitment"
    ~pp:(fun ppf (level, window) ->
      match window with
      | Some (first, last) ->
          Format.fprintf
            ppf
            "This operation is only allowed on finalized and existing \
             commitments, but its level %a is not in the existing and \
             finalized window of commitments: [%a; %a]."
            Tx_rollup_level_repr.pp
            level
            Tx_rollup_level_repr.pp
            first
            Tx_rollup_level_repr.pp
            last
      | None ->
          Format.fprintf
            ppf
            "This operation was about level %a but no finalized commitment \
             exists yet."
            Tx_rollup_level_repr.pp
            level)
    Data_encoding.(
      obj2
        (req "received" Tx_rollup_level_repr.encoding)
        (req
           "commitment_head_level"
           (option
              (tup2 Tx_rollup_level_repr.encoding Tx_rollup_level_repr.encoding))))
    (function
      | No_finalized_commitment_for_level {level; window} -> Some (level, window)
      | _ -> None)
    (fun (level, window) -> No_finalized_commitment_for_level {level; window}) ;
  (* Withdraw_invalid_proof *)
  register_error_kind
    `Branch
    ~id:"tx_rollup_withdraw_invalid_path"
    ~title:"The validation path submitted for a withdrawal is invalid"
    ~description:
      "The validation path submitted for a withdrawal is not valid for the \
       given withdrawal and message index"
    empty
    (function Withdraw_invalid_path -> Some () | _ -> None)
    (fun () -> Withdraw_invalid_path) ;
  (* Withdrawals_invalid_path *)
  register_error_kind
    `Branch
    ~id:"tx_rollup_withdrawals_invalid_path"
    ~title:"The validation path submitted for a withdrawal is invalid"
    ~description:
      "The validation path submitted for a withdrawal is not valid for the \
       given withdrawal and message index"
    empty
    (function Withdrawals_invalid_path -> Some () | _ -> None)
    (fun () -> Withdrawals_invalid_path) ;
  (* Withdrawals_already_dispatched *)
  register_error_kind
    `Branch
    ~id:"operation.withdrawals_already_dispatched"
    ~title:"withdrawals already dispatched"
    ~description:
      "The withdrawals have already been dispatched to their layer-1 \
       beneficiary"
    Data_encoding.unit
    (function Withdrawals_already_dispatched -> Some () | _ -> None)
    (fun () -> Withdrawals_already_dispatched) ;
  register_error_kind
    `Temporary
    ~id:"operation.withdraw_already_consumed"
    ~title:"withdraw already consumed"
    ~description:"The submitted withdraw has already been consumed"
    ~pp:(fun ppf () ->
      Format.fprintf
        ppf
        "The submitted withdraw exists but it has already been consumed \
         earlier.")
    Data_encoding.unit
    (function Withdraw_already_consumed -> Some () | _ -> None)
    (fun () -> Withdraw_already_consumed) ;
  (* Invalid_committer *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_invalid_committer"
    ~title:"Committer cannot propose a commitment for this level"
    ~description:
      "The committer is trying to propose a commitment, but their bond is \
       about to be slashed because a commitment they authored will be \
       overwritten."
    Data_encoding.unit
    (function Invalid_committer -> Some () | _ -> None)
    (fun () -> Invalid_committer) ;
  register_error_kind
    `Permanent
    ~id:"tx_rollup_commitment_bond_negative"
    ~title:
      "The number of commitments associated with an implicit account is \
       negative"
    ~description:
      "A negative number of commitment is associated with an implicit account \
       and its associated bound. This error is internal and should never \
       happen."
    ~pp:(fun ppf count ->
      Format.fprintf
        ppf
        "The number of commitments %d associated with this implicit account is \
         negative"
        count)
    (obj1 (req "count" Data_encoding.int31))
    (function Commitment_bond_negative count -> Some count | _ -> None)
    (fun count -> Commitment_bond_negative count) ;
  (* Cannot_reject_level *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_cannot_reject_level"
    ~title:"Cannot reject a commitment at the requested level"
    ~description:"Cannot reject a commitment at the requested level"
    (obj2
       (req "provided" Tx_rollup_level_repr.encoding)
       (req
          "accepted_range"
          (option
             (obj2
                (req "min" Tx_rollup_level_repr.encoding)
                (req "max" Tx_rollup_level_repr.encoding)))))
    (function
      | Cannot_reject_level {provided; accepted_range} ->
          Some (provided, accepted_range)
      | _ -> None)
    (fun (provided, accepted_range) ->
      Cannot_reject_level {provided; accepted_range}) ;
  (* Wrong_rejection_hash *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_wrong_rejection_hashes"
    ~title:
      "The message result hash recomputed from the rejection argument is \
       invalid"
    ~description:
      "The message result hash recomputed from the rejection argument is \
       invalid"
    (obj2
       (req "provided" Tx_rollup_message_result_hash_repr.encoding)
       (req
          "expected"
          (union
             [
               case
                 (Tag 0)
                 ~title:"hash"
                 Tx_rollup_message_result_hash_repr.encoding
                 (function `Hash h -> Some h | _ -> None)
                 (fun h -> `Hash h);
               case
                 (Tag 1)
                 ~title:"valid_path"
                 (obj2
                    (req "root" Tx_rollup_commitment_repr.Merkle_hash.encoding)
                    (req "index" int31))
                 (function `Valid_path (h, i) -> Some (h, i) | _ -> None)
                 (fun (h, i) -> `Valid_path (h, i));
             ])))
    (function
      | Wrong_rejection_hash {provided; expected} -> Some (provided, expected)
      | _ -> None)
    (fun (provided, expected) -> Wrong_rejection_hash {provided; expected}) ;
  (* ticket_payload_size_limit_exceeded *)
  register_error_kind
    `Permanent
    ~id:"tx_rollup_ticket_payload_size_limit_exceeded"
    ~title:"The payload of the deposited ticket exceeded the size limit"
    ~description:"The payload of the deposited ticket exceeded the size limit"
    (obj2 (req "payload_size" int31) (req "limit" int31))
    (function
      | Ticket_payload_size_limit_exceeded {payload_size; limit} ->
          Some (payload_size, limit)
      | _ -> None)
    (fun (payload_size, limit) ->
      Ticket_payload_size_limit_exceeded {payload_size; limit}) ;
  (* Proof_failed_to_reject *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_proof_failed_to_reject"
    ~title:"Proof failed to reject the commitment"
    ~description:
      "The proof verification failed and was unable to reject the commitment"
    empty
    (function Proof_failed_to_reject -> Some () | _ -> None)
    (fun () -> Proof_failed_to_reject) ;
  (* Proof_produced_rejected_state *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_proof_produced_rejected_state"
    ~title:"Proof produced the rejected state"
    ~description:
      "The proof submitted did not refute the rejected commitment. The proof \
       produced the same committed state"
    empty
    (function Proof_produced_rejected_state -> Some () | _ -> None)
    (fun () -> Proof_produced_rejected_state) ;
  (* Proof_invalid_before *)
  register_error_kind
    `Temporary
    ~id:"tx_rollup_proof_invalid_before"
    ~title:"Proof started from an invalid hash"
    ~description:
      "The proof started from a hash which is not the one agreed on (i.e. in \
       the previous commitment)"
    (obj2
       (req "agreed" Context_hash.encoding)
       (req "provided" Context_hash.encoding))
    (function
      | Proof_invalid_before {agreed; provided} -> Some (agreed, provided)
      | _ -> None)
    (fun (agreed, provided) -> Proof_invalid_before {agreed; provided}) ;
  register_error_kind
    `Permanent
    ~id:"tx_rollup_no_withdrawals_to_dispatch"
    ~title:"Trying to dispatch withdrawals when none happened"
    ~description:"Cannot dispatch an empty list of withdrawals"
    empty
    (function No_withdrawals_to_dispatch -> Some () | _ -> None)
    (fun () -> No_withdrawals_to_dispatch)
OCaml

Innovation. Community. Security.