From e0be27ede13b6de56d00bd5ee0c62cdcac9eaf06 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 1 Sep 2022 19:13:00 +0800 Subject: [PATCH 1/8] Proto: disallow tickets of zero amount --- .../lib_benchmarks_proto/ticket_benchmarks.ml | 1 - .../lib_protocol/sc_rollup_operations.ml | 5 +- .../lib_protocol/ticket_accounting.ml | 12 +---- .../lib_protocol/ticket_lazy_storage_diff.ml | 1 - .../lib_protocol/ticket_operations_diff.ml | 42 ++++----------- .../lib_protocol/ticket_operations_diff.mli | 10 ++-- .../lib_protocol/ticket_scanner.ml | 54 ++++--------------- .../lib_protocol/ticket_scanner.mli | 2 - 8 files changed, 26 insertions(+), 101 deletions(-) diff --git a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml index 6b1e614378b1..0796b2bb5b34 100644 --- a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml @@ -285,7 +285,6 @@ module Collect_tickets_benchmark : Benchmark.S = struct (Ticket_scanner.tickets_of_value ctxt ~include_lazy:true - ~allow_zero_amount_tickets:true has_tickets boxed_ticket_list)) in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_operations.ml b/src/proto_alpha/lib_protocol/sc_rollup_operations.ml index 36835da925d9..e639c91c33d0 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_operations.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_operations.ml @@ -480,10 +480,7 @@ let execute_outbox_message ctxt ~validate_and_decode_output_proof rollup as they cannot be tracked by the ticket-balance table. *) let* ticket_token_diffs, ctxt = - Ticket_operations_diff.ticket_diffs_of_operations - ctxt - ~allow_zero_amount_tickets:false - operations + Ticket_operations_diff.ticket_diffs_of_operations ctxt operations in (* Update the ticket-balance table by transferring ticket-tokens to new destinations for each transaction. This fails in case the rollup does not diff --git a/src/proto_alpha/lib_protocol/ticket_accounting.ml b/src/proto_alpha/lib_protocol/ticket_accounting.ml index 64c2273f18fd..eff0753f365a 100644 --- a/src/proto_alpha/lib_protocol/ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/ticket_accounting.ml @@ -74,12 +74,7 @@ module Ticket_token_map = struct end let ticket_balances_of_value ctxt ~include_lazy ty value = - Ticket_scanner.tickets_of_value - ~include_lazy - ~allow_zero_amount_tickets:true - ctxt - ty - value + Ticket_scanner.tickets_of_value ~include_lazy ctxt ty value >>=? fun (tickets, ctxt) -> List.fold_left_e (fun (acc, ctxt) ticket -> @@ -220,10 +215,7 @@ let update_ticket_balances ctxt ~self ~ticket_diffs operations = (Compare.Z.(Script_int.to_zint amount <= Z.neg balance_diff), ctxt) in (* Collect diffs from operations *) - Ticket_operations_diff.ticket_diffs_of_operations - ~allow_zero_amount_tickets:true - ctxt - operations + Ticket_operations_diff.ticket_diffs_of_operations ctxt operations >>=? fun (ticket_op_diffs, ctxt) -> (* Update balances for self-contract. *) Ticket_token_map.to_list ctxt ticket_diffs >>?= fun (ticket_diffs, ctxt) -> diff --git a/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml b/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml index cb495f2c4f16..0d38e380f39a 100644 --- a/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml @@ -81,7 +81,6 @@ let collect_token_diffs_of_node ctxt has_tickets node ~get_token_and_amount acc (* It's currently not possible to have nested lazy structures, but this is for future proofing. *) ~include_lazy:true - ~allow_zero_amount_tickets:true has_tickets (Micheline.root node) >>=? fun (ex_tickets, ctxt) -> diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index c3db21d23593..41c3a74e4271 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -142,36 +142,24 @@ module Ticket_token_map = struct map end -let tickets_of_transaction ctxt ~allow_zero_amount_tickets ~destination - ~parameters_ty ~parameters = +let tickets_of_transaction ctxt ~destination ~parameters_ty ~parameters = Ticket_scanner.type_has_tickets ctxt parameters_ty >>?= fun (has_tickets, ctxt) -> - Ticket_scanner.tickets_of_value - ~include_lazy:true - ~allow_zero_amount_tickets - ctxt - has_tickets - parameters + Ticket_scanner.tickets_of_value ~include_lazy:true ctxt has_tickets parameters >>=? fun (tickets, ctxt) -> return (Some {destination; tickets}, ctxt) (** Extract tickets of an origination operation by scanning the storage. *) -let tickets_of_origination ctxt ~allow_zero_amount_tickets ~preorigination - ~storage_type ~storage = +let tickets_of_origination ctxt ~preorigination ~storage_type ~storage = (* Extract any tickets from the storage. Note that if the type of the contract storage does not contain tickets, storage is not scanned. *) Ticket_scanner.type_has_tickets ctxt storage_type >>?= fun (has_tickets, ctxt) -> - Ticket_scanner.tickets_of_value - ctxt - ~include_lazy:true - ~allow_zero_amount_tickets - has_tickets - storage + Ticket_scanner.tickets_of_value ctxt ~include_lazy:true has_tickets storage >|=? fun (tickets, ctxt) -> let destination = Destination.Contract (Originated preorigination) in (Some {tickets; destination}, ctxt) -let tickets_of_operation ctxt ~allow_zero_amount_tickets +let tickets_of_operation ctxt (Script_typed_ir.Internal_operation {source = _; operation; nonce = _}) = match operation with | Transaction_to_implicit _ -> return (None, ctxt) @@ -187,7 +175,6 @@ let tickets_of_operation ctxt ~allow_zero_amount_tickets } -> tickets_of_transaction ctxt - ~allow_zero_amount_tickets ~destination:(Destination.Contract (Originated destination)) ~parameters_ty ~parameters @@ -212,10 +199,8 @@ let tickets_of_operation ctxt ~allow_zero_amount_tickets unparsed_parameters = _; } -> (* Note that zero-amount tickets to a rollup is not permitted. *) - let allow_zero_amount_tickets = false in tickets_of_transaction ctxt - ~allow_zero_amount_tickets ~destination:(Destination.Sc_rollup destination) ~parameters_ty ~parameters @@ -229,12 +214,7 @@ let tickets_of_operation ctxt ~allow_zero_amount_tickets storage_type; storage; } -> - tickets_of_origination - ctxt - ~allow_zero_amount_tickets - ~preorigination - ~storage_type - ~storage + tickets_of_origination ctxt ~preorigination ~storage_type ~storage | Delegation _ | Event _ -> return (None, ctxt) let add_transfer_to_token_map ctxt token_map {destination; tickets} = @@ -247,11 +227,10 @@ let add_transfer_to_token_map ctxt token_map {destination; tickets} = (token_map, ctxt) tickets -let ticket_token_map_of_operations ctxt ~allow_zero_amount_tickets ops = +let ticket_token_map_of_operations ctxt ops = List.fold_left_es (fun (token_map, ctxt) op -> - tickets_of_operation ctxt ~allow_zero_amount_tickets op - >>=? fun (res, ctxt) -> + tickets_of_operation ctxt op >>=? fun (res, ctxt) -> match res with | Some ticket_trans -> add_transfer_to_token_map ctxt token_map ticket_trans @@ -260,9 +239,8 @@ let ticket_token_map_of_operations ctxt ~allow_zero_amount_tickets ops = ops (** Traverses a list of operations and scans for tickets. *) -let ticket_diffs_of_operations ctxt ~allow_zero_amount_tickets operations = - ticket_token_map_of_operations ctxt ~allow_zero_amount_tickets operations - >>=? fun (token_map, ctxt) -> +let ticket_diffs_of_operations ctxt operations = + ticket_token_map_of_operations ctxt operations >>=? fun (token_map, ctxt) -> Ticket_token_map.fold ctxt (fun ctxt acc ticket_token destination_map -> diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.mli b/src/proto_alpha/lib_protocol/ticket_operations_diff.mli index 79d35af1d6e8..b2ca7987ee6e 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.mli +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.mli @@ -39,18 +39,16 @@ type ticket_token_diff = private { (Alpha_context.Destination.t * Script_int.n Script_int.num) list; } -(** [ticket_diffs_of_operations ctxt ~allow_zero_amount_tickets ops] returns a +(** [ticket_diffs_of_operations ctxt ops] returns a list of ticket-tokens diffs given a context, [ctxt], and list of packed operations, [ops]. The diffs result from either a [Transaction] operation with parameters containing tickets, or an [Origination] operation with the initial storage containing tickets. - The flag [allow_zero_amount_tickets] decides whether or not tickets with - amount zero are allowed. If the flag is set to [false] and a zero-amount - ticket is encountered, an {!Ticket_scanner.Forbidden_zero_ticket_quantity} - error is returned. *) + Tickets with amount zero are *not* allowed. If a zero-amount ticket is + encountered, a {!Ticket_scanner.Forbidden_zero_ticket_quantity} error is + returned. *) val ticket_diffs_of_operations : Alpha_context.context -> - allow_zero_amount_tickets:bool -> Script_typed_ir.packed_internal_operation list -> (ticket_token_diff list * Alpha_context.context) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/ticket_scanner.ml b/src/proto_alpha/lib_protocol/ticket_scanner.ml index 84dcdc19bdce..fcd879b311c4 100644 --- a/src/proto_alpha/lib_protocol/ticket_scanner.ml +++ b/src/proto_alpha/lib_protocol/ticket_scanner.ml @@ -322,7 +322,6 @@ module Ticket_collection = struct let rec tickets_of_value : type a ac ret. include_lazy:bool -> - allow_zero_amount_tickets:bool -> context -> a Ticket_inspection.has_tickets -> (a, ac) Script_typed_ir.ty -> @@ -330,7 +329,7 @@ module Ticket_collection = struct accumulator -> ret continuation -> ret tzresult Lwt.t = - fun ~include_lazy ~allow_zero_amount_tickets ctxt hty ty x acc k -> + fun ~include_lazy ctxt hty ty x acc k -> let open Script_typed_ir in consume_gas_steps ctxt ~num_steps:1 >>?= fun ctxt -> match (hty, ty) with @@ -339,7 +338,6 @@ module Ticket_collection = struct let l, r = x in (tickets_of_value [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt hty1 ty1 @@ -348,7 +346,6 @@ module Ticket_collection = struct (fun ctxt acc -> (tickets_of_value [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt hty2 ty2 @@ -360,7 +357,6 @@ module Ticket_collection = struct | L v -> (tickets_of_value [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt htyl tyl @@ -370,7 +366,6 @@ module Ticket_collection = struct | R v -> (tickets_of_value [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt htyr tyr @@ -382,7 +377,6 @@ module Ticket_collection = struct | Some x -> (tickets_of_value [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt el_hty el_ty @@ -395,7 +389,6 @@ module Ticket_collection = struct (tickets_of_list [@ocaml.tailcall]) ctxt ~include_lazy - ~allow_zero_amount_tickets el_hty el_ty elements @@ -412,7 +405,6 @@ module Ticket_collection = struct (tickets_of_map [@ocaml.tailcall]) ctxt ~include_lazy - ~allow_zero_amount_tickets val_hty val_ty x @@ -420,20 +412,12 @@ module Ticket_collection = struct k) | Big_map_ht (_, val_hty), Big_map_t (key_ty, _, _) -> if include_lazy then - (tickets_of_big_map [@ocaml.tailcall]) - ctxt - ~allow_zero_amount_tickets - val_hty - key_ty - x - acc - k + (tickets_of_big_map [@ocaml.tailcall]) ctxt val_hty key_ty x acc k else (k [@ocaml.tailcall]) ctxt acc | True_ht, Ticket_t (comp_ty, _) -> let Script_typed_ir.{ticketer = _; contents = _; amount} = x in fail_when - ((not allow_zero_amount_tickets) - && Compare.Int.(Script_int.compare amount Script_int.zero_n = 0)) + Compare.Int.(Script_int.compare amount Script_int.zero_n = 0) Forbidden_zero_ticket_quantity >>=? fun () -> (k [@ocaml.tailcall]) ctxt (Ex_ticket (comp_ty, x) :: acc) @@ -441,20 +425,18 @@ module Ticket_collection = struct type a ac ret. context -> include_lazy:bool -> - allow_zero_amount_tickets:bool -> a Ticket_inspection.has_tickets -> (a, ac) Script_typed_ir.ty -> a list -> accumulator -> ret continuation -> ret tzresult Lwt.t = - fun ctxt ~include_lazy ~allow_zero_amount_tickets el_hty el_ty elements acc k -> + fun ctxt ~include_lazy el_hty el_ty elements acc k -> consume_gas_steps ctxt ~num_steps:1 >>?= fun ctxt -> match elements with | elem :: elems -> (tickets_of_value [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt el_hty el_ty @@ -463,7 +445,6 @@ module Ticket_collection = struct (fun ctxt acc -> (tickets_of_list [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt el_hty el_ty @@ -475,7 +456,6 @@ module Ticket_collection = struct and tickets_of_map : type k v vc ret. include_lazy:bool -> - allow_zero_amount_tickets:bool -> context -> v Ticket_inspection.has_tickets -> (v, vc) Script_typed_ir.ty -> @@ -483,7 +463,7 @@ module Ticket_collection = struct accumulator -> ret continuation -> ret tzresult Lwt.t = - fun ~include_lazy ~allow_zero_amount_tickets ctxt val_hty val_ty map acc k -> + fun ~include_lazy ctxt val_hty val_ty map acc k -> let (module M) = Script_map.get_module map in consume_gas_steps ctxt ~num_steps:1 >>?= fun ctxt -> (* Pay gas for folding over the values *) @@ -491,7 +471,6 @@ module Ticket_collection = struct let values = M.OPS.fold (fun _ v vs -> v :: vs) M.boxed [] in (tickets_of_list [@ocaml.tailcall]) ~include_lazy - ~allow_zero_amount_tickets ctxt val_hty val_ty @@ -502,7 +481,6 @@ module Ticket_collection = struct and tickets_of_big_map : type k v ret. context -> - allow_zero_amount_tickets:bool -> v Ticket_inspection.has_tickets -> k Script_typed_ir.comparable_ty -> (k, v) Script_typed_ir.big_map -> @@ -510,7 +488,6 @@ module Ticket_collection = struct ret continuation -> ret tzresult Lwt.t = fun ctxt - ~allow_zero_amount_tickets val_hty key_ty (Big_map {id; diff = {map = _; size}; key_type = _; value_type}) @@ -539,7 +516,6 @@ module Ticket_collection = struct List.fold_left_es accum ([], ctxt) exps >>=? fun (values, ctxt) -> (tickets_of_list [@ocaml.tailcall]) ~include_lazy:true - ~allow_zero_amount_tickets ctxt val_hty value_type @@ -562,20 +538,13 @@ let type_has_tickets ctxt ty = Ticket_inspection.has_tickets_of_ty ctxt ty >|? fun (has_tickets, ctxt) -> (Has_tickets (has_tickets, ty), ctxt) -let tickets_of_value ctxt ~include_lazy ~allow_zero_amount_tickets - (Has_tickets (ht, ty)) = - Ticket_collection.tickets_of_value - ctxt - ~include_lazy - ~allow_zero_amount_tickets - ht - ty +let tickets_of_value ctxt ~include_lazy (Has_tickets (ht, ty)) = + Ticket_collection.tickets_of_value ctxt ~include_lazy ht ty let has_tickets (Has_tickets (ht, _)) = match ht with Ticket_inspection.False_ht -> false | _ -> true -let tickets_of_node ctxt ~include_lazy ~allow_zero_amount_tickets has_tickets - expr = +let tickets_of_node ctxt ~include_lazy has_tickets expr = let (Has_tickets (ht, ty)) = has_tickets in match ht with | Ticket_inspection.False_ht -> return ([], ctxt) @@ -587,9 +556,4 @@ let tickets_of_node ctxt ~include_lazy ~allow_zero_amount_tickets has_tickets ty expr >>=? fun (value, ctxt) -> - tickets_of_value - ctxt - ~include_lazy - ~allow_zero_amount_tickets - has_tickets - value + tickets_of_value ctxt ~include_lazy has_tickets value diff --git a/src/proto_alpha/lib_protocol/ticket_scanner.mli b/src/proto_alpha/lib_protocol/ticket_scanner.mli index bb6be0d5e850..96947fec0325 100644 --- a/src/proto_alpha/lib_protocol/ticket_scanner.mli +++ b/src/proto_alpha/lib_protocol/ticket_scanner.mli @@ -65,7 +65,6 @@ val type_has_tickets : val tickets_of_value : Alpha_context.context -> include_lazy:bool -> - allow_zero_amount_tickets:bool -> 'a has_tickets -> 'a -> (ex_ticket list * Alpha_context.context) tzresult Lwt.t @@ -86,7 +85,6 @@ val tickets_of_value : val tickets_of_node : Alpha_context.context -> include_lazy:bool -> - allow_zero_amount_tickets:bool -> 'a has_tickets -> Alpha_context.Script.node -> (ex_ticket list * Alpha_context.context) tzresult Lwt.t -- GitLab From dcc18df8e527ab614380765629867c7789879687 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 1 Sep 2022 19:14:31 +0800 Subject: [PATCH 2/8] Proto: deprecate old I_TICKET and introduce new ticketing instruction --- .../interpreter_workload.ml | 3 +- src/proto_alpha/lib_plugin/RPC.ml | 1 + .../lib_protocol/alpha_context.mli | 1 + .../lib_protocol/michelson_v1_primitives.ml | 13 +++++--- .../lib_protocol/michelson_v1_primitives.mli | 1 + .../lib_protocol/script_interpreter.ml | 31 ++++++++++++++++--- .../lib_protocol/script_interpreter_defs.ml | 2 +- .../script_interpreter_logging.ml | 11 ++++++- .../lib_protocol/script_ir_translator.ml | 13 ++++++++ .../lib_protocol/script_typed_ir.ml | 7 +++++ .../lib_protocol/script_typed_ir.mli | 5 +++ .../lib_protocol/script_typed_ir_size.ml | 4 +++ 12 files changed, 81 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml index 17146ea2f305..0721772f1894 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml @@ -1417,7 +1417,8 @@ let extract_ir_sized_step : | IComb_get (_, n, _, _), _ -> Instructions.comb_get (Size.of_int n) | IComb_set (_, n, _, _), _ -> Instructions.comb_set (Size.of_int n) | IDup_n (_, n, _, _), _ -> Instructions.dupn (Size.of_int n) - | ITicket (_, _, _), _ -> Instructions.ticket + | ITicket (_, _, _), _ | ITicket_deprecated (_, _, _), _ -> + Instructions.ticket | IRead_ticket (_, _, _), _ -> Instructions.read_ticket | ISplit_ticket (_, _), (_ticket, ((amount_a, amount_b), _)) -> Instructions.split_ticket (Size.integer amount_a) (Size.integer amount_b) diff --git a/src/proto_alpha/lib_plugin/RPC.ml b/src/proto_alpha/lib_plugin/RPC.ml index 94b2c9a6d001..f03f5b1ce3ec 100644 --- a/src/proto_alpha/lib_plugin/RPC.ml +++ b/src/proto_alpha/lib_plugin/RPC.ml @@ -806,6 +806,7 @@ module Scripts = struct | IComb_set _ -> pp_print_string fmt "UPDATE" | IDup_n _ -> pp_print_string fmt "DUP" | ITicket _ -> pp_print_string fmt "TICKET" + | ITicket_deprecated _ -> pp_print_string fmt "TICKET_DEPRECATED" | IRead_ticket _ -> pp_print_string fmt "READ_TICKET" | ISplit_ticket _ -> pp_print_string fmt "SPLIT_TICKET" | IJoin_tickets _ -> pp_print_string fmt "JOIN_TICKETS" diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 02d9d09902aa..434e90807de9 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -633,6 +633,7 @@ module Script : sig | I_SHA3 | I_PAIRING_CHECK | I_TICKET + | I_TICKET_DEPRECATED | I_READ_TICKET | I_SPLIT_TICKET | I_JOIN_TICKETS diff --git a/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml b/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml index 118f5df397c8..b8ae12fc1997 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml +++ b/src/proto_alpha/lib_protocol/michelson_v1_primitives.ml @@ -149,6 +149,7 @@ type prim = | I_SHA3 | I_PAIRING_CHECK | I_TICKET + | I_TICKET_DEPRECATED | I_READ_TICKET | I_SPLIT_TICKET | I_JOIN_TICKETS @@ -219,8 +220,9 @@ let namespace = function | I_SAPLING_VERIFY_UPDATE | I_SELF | I_SELF_ADDRESS | I_SENDER | I_SET_DELEGATE | I_SHA256 | I_SHA512 | I_SHA3 | I_SIZE | I_SLICE | I_SOME | I_SOURCE | I_SPLIT_TICKET | I_STEPS_TO_QUOTA | I_SUB | I_SUB_MUTEZ | I_SWAP - | I_TICKET | I_TOTAL_VOTING_POWER | I_TRANSFER_TOKENS | I_UNIT | I_UNPACK - | I_UNPAIR | I_UPDATE | I_VOTING_POWER | I_XOR | I_OPEN_CHEST | I_EMIT -> + | I_TICKET | I_TICKET_DEPRECATED | I_TOTAL_VOTING_POWER | I_TRANSFER_TOKENS + | I_UNIT | I_UNPACK | I_UNPAIR | I_UPDATE | I_VOTING_POWER | I_XOR + | I_OPEN_CHEST | I_EMIT -> Instr_namespace | T_address | T_tx_rollup_l2_address | T_big_map | T_bool | T_bytes | T_chain_id | T_contract | T_int | T_key | T_key_hash | T_lambda | T_list @@ -357,6 +359,7 @@ let string_of_prim = function | I_SHA3 -> "SHA3" | I_PAIRING_CHECK -> "PAIRING_CHECK" | I_TICKET -> "TICKET" + | I_TICKET_DEPRECATED -> "TICKET_DEPRECATED" | I_READ_TICKET -> "READ_TICKET" | I_SPLIT_TICKET -> "SPLIT_TICKET" | I_JOIN_TICKETS -> "JOIN_TICKETS" @@ -514,6 +517,7 @@ let prim_of_string = function | "VOTING_POWER" -> ok I_VOTING_POWER | "TOTAL_VOTING_POWER" -> ok I_TOTAL_VOTING_POWER | "TICKET" -> ok I_TICKET + | "TICKET_DEPRECATED" -> ok I_TICKET_DEPRECATED | "READ_TICKET" -> ok I_READ_TICKET | "SPLIT_TICKET" -> ok I_SPLIT_TICKET | "JOIN_TICKETS" -> ok I_JOIN_TICKETS @@ -746,7 +750,7 @@ let prim_encoding = ("ticket", T_ticket); (* /!\ NEW INSTRUCTIONS MUST BE ADDED AT THE END OF THE STRING_ENUM, FOR BACKWARD COMPATIBILITY OF THE ENCODING. *) (* Alpha_008 addition *) - ("TICKET", I_TICKET); + ("TICKET_DEPRECATED", I_TICKET_DEPRECATED); ("READ_TICKET", I_READ_TICKET); ("SPLIT_TICKET", I_SPLIT_TICKET); ("JOIN_TICKETS", I_JOIN_TICKETS); @@ -770,7 +774,8 @@ let prim_encoding = ("EMIT", I_EMIT); (* Alpha_015 addition *) ("Lambda_rec", D_Lambda_rec); - ("LAMBDA_REC", I_LAMBDA_REC) + ("LAMBDA_REC", I_LAMBDA_REC); + ("TICKET", I_TICKET) (* New instructions must be added here, for backward compatibility of the encoding. *) (* Keep the comment above at the end of the list *); ] diff --git a/src/proto_alpha/lib_protocol/michelson_v1_primitives.mli b/src/proto_alpha/lib_protocol/michelson_v1_primitives.mli index 69660958351d..349285c9c958 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_primitives.mli +++ b/src/proto_alpha/lib_protocol/michelson_v1_primitives.mli @@ -162,6 +162,7 @@ type prim = | I_SHA3 | I_PAIRING_CHECK | I_TICKET + | I_TICKET_DEPRECATED | I_READ_TICKET | I_SPLIT_TICKET | I_JOIN_TICKETS diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 535d2e5c14bc..44ebf43376aa 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -116,6 +116,8 @@ type error += Cannot_serialize_storage type error += Michelson_too_many_recursive_calls +type error += Ticket_amount_zero of Script.location + let () = let open Data_encoding in let trace_encoding = @@ -192,7 +194,15 @@ let () = "The returned storage was too big to be serialized with the provided gas" Data_encoding.empty (function Cannot_serialize_storage -> Some () | _ -> None) - (fun () -> Cannot_serialize_storage) + (fun () -> Cannot_serialize_storage) ; + register_error_kind + `Temporary + ~id:"michelson_v1.ticket_amount_zero" + ~title:"Ticket amount is zero" + ~description:"A ticket of amount zero is not allowed" + (obj1 (req "location" Script.location_encoding)) + (function Ticket_amount_zero loc -> Some loc | _ -> None) + (fun loc -> Ticket_amount_zero loc) (* @@ -1479,11 +1489,22 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let accu = aux witness stack in (step [@ocaml.tailcall]) g gas k ks accu stack (* Tickets *) + | ITicket_deprecated (loc, _, k) -> + let contents = accu and amount, stack = stack in + if Compare.Int.(Script_int.(compare amount zero_n) = 0) then + fail (Ticket_amount_zero loc) + else + let ticketer = Contract.Originated sc.self in + let accu = {ticketer; contents; amount} in + (step [@ocaml.tailcall]) g gas k ks accu stack | ITicket (_, _, k) -> let contents = accu and amount, stack = stack in - let ticketer = Contract.Originated sc.self in - let accu = {ticketer; contents; amount} in - (step [@ocaml.tailcall]) g gas k ks accu stack + if Compare.Int.(Script_int.(compare amount zero_n) = 0) then + (step [@ocaml.tailcall]) g gas k ks None stack + else + let ticketer = Contract.Originated sc.self in + let accu = Some {ticketer; contents; amount} in + (step [@ocaml.tailcall]) g gas k ks accu stack | IRead_ticket (_, _, k) -> let {ticketer; contents; amount} = accu in let stack = (accu, stack) in @@ -1497,6 +1518,8 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = if Compare.Int.( Script_int.(compare (add_n amount_a amount_b) ticket.amount) = 0) + && Compare.Int.(Script_int.(compare amount_a zero_n) > 0) + && Compare.Int.(Script_int.(compare amount_b zero_n) > 0) then Some ( {ticket with amount = amount_a}, diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index ca1c4d82f92f..ab0c2464303a 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -350,7 +350,7 @@ let cost_of_instr : type a s r f. (a, s, r, f) kinstr -> a -> s -> Gas.cost = | IUncomb (_, n, _, _) -> Interp_costs.uncomb n | IComb_get (_, n, _, _) -> Interp_costs.comb_get n | IComb_set (_, n, _, _) -> Interp_costs.comb_set n - | ITicket _ -> Interp_costs.ticket + | ITicket _ | ITicket_deprecated _ -> Interp_costs.ticket | IRead_ticket _ -> Interp_costs.read_ticket | IOpen_chest _ -> let _chest_key = accu and chest, (time, _) = stack in diff --git a/src/proto_alpha/lib_protocol/script_interpreter_logging.ml b/src/proto_alpha/lib_protocol/script_interpreter_logging.ml index 31f10c4f49d1..d09762eca53a 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_logging.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_logging.ml @@ -1545,7 +1545,7 @@ let kinstr_split : reconstruct = (fun k -> IDup_n (loc, n, p, k)); } | ITicket (loc, cty, k), Item_t (_, Item_t (_, s)) -> - ticket_t dummy (assert_some cty) >|? fun t -> + ticket_t dummy (assert_some cty) >>? option_t loc >|? fun t -> let s = Item_t (t, s) in Ex_split_kinstr { @@ -1553,6 +1553,15 @@ let kinstr_split : continuation = k; reconstruct = (fun k -> ITicket (loc, cty, k)); } + | ITicket_deprecated (loc, cty, k), Item_t (_, Item_t (_, s)) -> + ticket_t dummy (assert_some cty) >|? fun t -> + let s = Item_t (t, s) in + Ex_split_kinstr + { + cont_init_stack = s; + continuation = k; + reconstruct = (fun k -> ITicket_deprecated (loc, cty, k)); + } | IRead_ticket (loc, a, k), s -> pair_t dummy (assert_some a) nat_t >>? fun (Ty_ex_c p) -> pair_t dummy address_t p >|? fun (Ty_ex_c t) -> diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 42db9ea6c7a4..0b9166cd0bde 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -4158,8 +4158,21 @@ and parse_instr : check_comparable loc t >>?= fun Eq -> ticket_t loc t >>?= fun res_ty -> let instr = {apply = (fun k -> ITicket (loc, for_logging_only t, k))} in + option_t loc res_ty >>?= fun res_ty -> let stack = Item_t (res_ty, rest) in typed ctxt loc instr stack + | Prim (loc, I_TICKET_DEPRECATED, [], annot), Item_t (t, Item_t (Nat_t, rest)) + -> + if legacy then + check_var_annot loc annot >>?= fun () -> + check_comparable loc t >>?= fun Eq -> + ticket_t loc t >>?= fun res_ty -> + let instr = + {apply = (fun k -> ITicket_deprecated (loc, for_logging_only t, k))} + in + let stack = Item_t (res_ty, rest) in + typed ctxt loc instr stack + else fail (Deprecated_instruction I_TICKET_DEPRECATED) | ( Prim (loc, I_READ_TICKET, [], annot), (Item_t (Ticket_t (t, _), _) as full_stack) ) -> check_var_annot loc annot >>?= fun () -> diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 94b3d4a4bdd9..0d4af45f03ca 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1063,6 +1063,11 @@ and ('before_top, 'before, 'result_top, 'result) kinstr = * ('t, 'a * ('b * 's), 'r, 'f) kinstr -> ('a, 'b * 's, 'r, 'f) kinstr | ITicket : + Script.location + * 'a comparable_ty option + * ('a ticket option, 's, 'r, 'f) kinstr + -> ('a, n num * 's, 'r, 'f) kinstr + | ITicket_deprecated : Script.location * 'a comparable_ty option * ('a ticket, 's, 'r, 'f) kinstr -> ('a, n num * 's, 'r, 'f) kinstr | IRead_ticket : @@ -1603,6 +1608,7 @@ let kinstr_location : type a s b f. (a, s, b, f) kinstr -> Script.location = | IComb_set (loc, _, _, _) -> loc | IDup_n (loc, _, _, _) -> loc | ITicket (loc, _, _) -> loc + | ITicket_deprecated (loc, _, _) -> loc | IRead_ticket (loc, _, _) -> loc | ISplit_ticket (loc, _) -> loc | IJoin_tickets (loc, _, _) -> loc @@ -2004,6 +2010,7 @@ let kinstr_traverse i init f = | IComb_set (_, _, _, k) -> (next [@ocaml.tailcall]) k | IDup_n (_, _, _, k) -> (next [@ocaml.tailcall]) k | ITicket (_, _, k) -> (next [@ocaml.tailcall]) k + | ITicket_deprecated (_, _, k) -> (next [@ocaml.tailcall]) k | IRead_ticket (_, _, k) -> (next [@ocaml.tailcall]) k | ISplit_ticket (_, k) -> (next [@ocaml.tailcall]) k | IJoin_tickets (_, _, k) -> (next [@ocaml.tailcall]) k diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index e7b46c891783..cbaf6f5855a0 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1060,6 +1060,11 @@ and ('before_top, 'before, 'result_top, 'result) kinstr = * ('t, 'a * ('b * 's), 'r, 'f) kinstr -> ('a, 'b * 's, 'r, 'f) kinstr | ITicket : + Script.location + * 'a comparable_ty option + * ('a ticket option, 's, 'r, 'f) kinstr + -> ('a, n num * 's, 'r, 'f) kinstr + | ITicket_deprecated : Script.location * 'a comparable_ty option * ('a ticket, 's, 'r, 'f) kinstr -> ('a, n num * 's, 'r, 'f) kinstr | IRead_ticket : diff --git a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml index 58e525803b8a..6e72d57ee6a4 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml @@ -653,6 +653,10 @@ and kinstr_size : ret_succ_adding accu (base1 loc k +! ty_for_logging_size cty +! word_size) + | ITicket_deprecated (loc, cty, k) -> + ret_succ_adding + accu + (base1 loc k +! ty_for_logging_size cty +! word_size) | IRead_ticket (loc, ty, k) -> ret_succ_adding accu (base1 loc k +! ty_for_logging_size ty +! word_size) | ISplit_ticket (loc, k) -> ret_succ_adding accu (base1 loc k) -- GitLab From 5085a69573d162dd49ecabfd0c335cb8a51fa13d Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 1 Sep 2022 19:15:19 +0800 Subject: [PATCH 3/8] Doc: explain the deprecated ITicket instruction and update Michelson reference manual --- docs/alpha/michelson.rst | 6 +++--- docs/alpha/transaction_rollups.rst | 2 ++ docs/kathmandu/michelson.rst | 2 +- docs/michelson/michelson-meta.yaml | 4 +++- docs/michelson/michelson.ott | 11 ++++++++--- docs/protocols/alpha.rst | 6 ++++++ 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/alpha/michelson.rst b/docs/alpha/michelson.rst index 9d37863c945b..bfadf2f4222f 100644 --- a/docs/alpha/michelson.rst +++ b/docs/alpha/michelson.rst @@ -2304,11 +2304,11 @@ This process can happen without the need to interact with a centralized NFT cont simplifying the code. - ``TICKET``: Create a ticket with the given content and amount. The ticketer is the address - of `SELF`. + of `SELF`. The resulting value is ``NONE`` if the amount is zero. :: - :: 'a : nat : 'S -> ticket 'a : 'S + :: 'a : nat : 'S -> option ticket 'a : 'S Type ``'a`` must be comparable (the ``COMPARE`` primitive must be defined over it). @@ -2322,7 +2322,7 @@ Type ``'a`` must be comparable (the ``COMPARE`` primitive must be defined over i same content and ticketer as the original, but with the new provided amounts. (This can be used to easily implement UTXOs.) Return None iff the ticket's original amount is not equal to the sum of the - provided amounts. + provided amounts, or one of the provided amounts is zero. :: diff --git a/docs/alpha/transaction_rollups.rst b/docs/alpha/transaction_rollups.rst index 5c937986add1..b3270031a1aa 100644 --- a/docs/alpha/transaction_rollups.rst +++ b/docs/alpha/transaction_rollups.rst @@ -203,6 +203,7 @@ tickets to a Transaction Rollup:: PUSH nat 10; PUSH unit Unit; TICKET; + ASSERT_SOME; PAIR ; @@ -723,6 +724,7 @@ rollup can be found in the integration tests of the feature.:: CAR; UNPAIR 4; TICKET; + ASSERT_SOME; PAIR; SWAP; CONTRACT %deposit (pair (ticket string) tx_rollup_l2_address); diff --git a/docs/kathmandu/michelson.rst b/docs/kathmandu/michelson.rst index 779f9cb05b14..4b38be14f384 100644 --- a/docs/kathmandu/michelson.rst +++ b/docs/kathmandu/michelson.rst @@ -2310,7 +2310,7 @@ Type ``'a`` must be comparable (the ``COMPARE`` primitive must be defined over i same content and ticketer as the original, but with the new provided amounts. (This can be used to easily implement UTXOs.) Return None iff the ticket's original amount is not equal to the sum of the - provided amounts. + provided amounts, or one of the provided amounts is zero. :: diff --git a/docs/michelson/michelson-meta.yaml b/docs/michelson/michelson-meta.yaml index ad64c8e8b15b..be0f550b55a1 100644 --- a/docs/michelson/michelson-meta.yaml +++ b/docs/michelson/michelson-meta.yaml @@ -1725,7 +1725,9 @@ instructions: proposed-in: ['PtEdoTezd3RHSC31mpxxo1npxFjoWWcFgQtxapi51Z8TLu6v6Uq'] documentation_short: Create a ticket documentation: | - Create a ticket with the given content and amount. The ticketer is the address of ``SELF``. + Creates a value ``Some t`` where ``t`` is a ticket with the given content and amount. + The ticketer is the address of ``SELF``. + Returns ``None`` iff the amount is zero. READ_TICKET: category: tickets diff --git a/docs/michelson/michelson.ott b/docs/michelson/michelson.ott index 1657e0e0d6e7..2c3423eeb490 100644 --- a/docs/michelson/michelson.ott +++ b/docs/michelson/michelson.ott @@ -1099,7 +1099,7 @@ Typing :: 't_' ::= ------------------------------------------------ :: TICKET - ctx :- TICKET :: cty : nat : A => ticket cty : A + ctx :- TICKET :: cty : nat : A => option ( ticket cty ) : A ------------------------------------------------ :: READ_TICKET ctx :- READ_TICKET :: ticket cty : A => pair address cty nat : ticket cty : A @@ -2259,8 +2259,13 @@ UNPACK ty / byt : S => unpack ty byt : S % tickets: -------------------------------------------------- :: TICKET -TICKET / x : n : S => Pair (address self) x n : S +n = 0 +------------------------------------------------- :: TICKET_zero +TICKET / x : n : S => None : S + +n <> 0 +------------------------------------------------- :: TICKET_nonzero +TICKET / x : n : S => Some (Pair (address self) x n) : S ----------------------------------------------------------- :: READ_TICKET READ_TICKET / Pair s x n : S => Pair s x n : Pair s x n : S diff --git a/docs/protocols/alpha.rst b/docs/protocols/alpha.rst index 529363514f97..7b9e6a800016 100644 --- a/docs/protocols/alpha.rst +++ b/docs/protocols/alpha.rst @@ -196,6 +196,12 @@ Breaking Changes safer version of timelock will come in a future procotol. (MR :gl: `!6260`) - Rename the parameter ``tokens_per_roll`` to ``minimal_stake``. (MR :gl:`!5897`) +- Disallow creation, transfer and storage of tickets with zero amounts. + ``TICKET`` instruction now returns ``option ticket 'a`` instead of ``ticket 'a``. + For contracts already originated, their ``TICKET`` instructions are renamed to ``TICKET_DEPRECATED``. + Note that it is not possible to originate contracts containing ``TICKET_DEPRECATED`` + after the migration. + (MR :gl:`!5963`) RPC Changes ----------- -- GitLab From 67cd874a787febaba72c73de78f9fcf457e1cb93 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 1 Sep 2022 19:16:26 +0800 Subject: [PATCH 4/8] Test: update tests to avoid zero tickets and make sure proper handling of zero tickets --- .../michelson/test_ticket_balance.ml | 132 ++-- .../michelson/test_ticket_manager.ml | 18 +- .../michelson/test_ticket_operations_diff.ml | 167 ++---- .../michelson/test_ticket_scanner.ml | 149 ++--- .../operations/contracts/tx_rollup_deposit.tz | 1 + .../tx_rollup_deposit_incorrect_entrypoint.tz | 1 + .../contracts/tx_rollup_deposit_one_mutez.tz | 1 + .../tx_rollup_deposit_pair_string.tz | 1 + .../contracts/tx_rollup_deposit_string.tz | 1 + .../operations/test_sc_rollup_transfer.ml | 11 +- .../integration/operations/test_tx_rollup.ml | 173 +----- .../test_sc_rollup_management_protocol.ml | 2 +- tests_python/.python-version | 1 + .../ill_typed/ticket_in_ticket.tz | 1 + .../mini_scenarios/add_clear_tickets.tz | 2 +- .../mini_scenarios/send_tickets_in_big_map.tz | 1 + .../mini_scenarios/ticket_builder_fungible.tz | 2 +- .../ticket_builder_non_fungible.tz | 2 +- .../opcodes/ticket_big_store.tz | 2 +- .../contracts_alpha/opcodes/ticketer-2.tz | 2 +- .../contracts_alpha/opcodes/ticketer.tz | 1 + tests_python/contracts_alpha/opcodes/utxor.tz | 1 + ...t_add_clear_tickets_add_first_transfer.out | 10 +- ..._add_clear_tickets_add_second_transfer.out | 8 +- ...t_add_clear_tickets_add_third_transfer.out | 10 +- ...:test_add_clear_tickets_clear_transfer.out | 2 +- ...ts::test_add_clear_tickets_origination.out | 34 +- ..._hash[client_regtest_custom_scrubber0].out | 16 +- ...InBigMap::test_send_tickets_in_big_map.out | 214 +++---- ...test_send_tickets_in_big_map_originate.out | 25 +- ...[mini_scenarios--add_clear_tickets.tz].out | 5 +- ...scenarios--send_tickets_in_big_map.tz].out | 5 +- ...scenarios--ticket_builder_fungible.tz].out | 5 +- ...arios--ticket_builder_non_fungible.tz].out | 5 +- ...ypecheck[opcodes--ticket_big_store.tz].out | 5 +- ...test_typecheck[opcodes--ticketer-2.tz].out | 4 +- ...::test_typecheck[opcodes--ticketer.tz].out | 5 +- ...eck::test_typecheck[opcodes--utxor.tz].out | 5 +- .../proto_alpha/tx_rollup_deposit.tz | 1 + .../proto_current_mainnet/tickets.tz | 2 +- .../tx_rollup_deposit.tz | 20 + tezt/tests/iticket_migration.ml | 565 ++++++++++++++++++ tezt/tests/main.ml | 3 +- tezt/tests/tx_rollup.ml | 7 +- tezt/tests/tx_rollup_l2_node.ml | 32 +- 45 files changed, 1050 insertions(+), 610 deletions(-) create mode 100644 tests_python/.python-version create mode 100644 tezt/tests/contracts/proto_current_mainnet/tx_rollup_deposit.tz create mode 100644 tezt/tests/iticket_migration.ml diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml index f3d74a420ebb..b8ae0972f0ef 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_balance.ml @@ -204,6 +204,7 @@ let test_add_strict () = PUSH nat 1; PUSH string "Red"; TICKET; + ASSERT_SOME; CONS; NIL operation ; PAIR } } @@ -258,6 +259,7 @@ let test_add_remove () = PUSH nat 1 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; CONS ; NIL operation ; PAIR } @@ -322,6 +324,7 @@ let test_add_to_big_map () = PUSH nat 1 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; SOME ; DUP 3 ; GET_AND_UPDATE ; @@ -381,6 +384,7 @@ let test_swap_big_map () = PUSH nat 1 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; SOME ; DIG 3 ; GET_AND_UPDATE ; @@ -482,6 +486,7 @@ let test_send_tickets () = PUSH nat 1 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; TRANSFER_TOKENS ; PUSH unit Unit ; NIL operation ; @@ -532,6 +537,7 @@ let test_send_and_store_zero_amount_tickets () = DIG 2 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; TRANSFER_TOKENS ; PUSH unit Unit ; NIL operation ; @@ -616,15 +622,14 @@ let test_send_and_store_zero_amount_tickets () = "%store") in let token_red = string_token ~ticketer:ticket_minter "Red" in - (* Mint and send a ticket with amount 0 to [ticket_store_1]. After the - transaction: + (* Mint and send a ticket with amount 0 to [ticket_store_1], which fails. + After the transaction: [ticket_store_1]: - [ - (TM, "Red", 0) - ] + [ ] *) - let* block = mint_and_send_to_storer_1 block 0 in + let*! result = mint_and_send_to_storer_1 block 0 in + assert (Result.is_error result) ; let* () = assert_token_balance ~loc:__LOC__ block token_red ticket_store_1 None in @@ -634,7 +639,6 @@ let test_send_and_store_zero_amount_tickets () = [ticket_store_1]: [ (TM, "Red", 10) - (TM, "Red", 0) ] *) let* block = mint_and_send_to_storer_1 block 10 in @@ -645,9 +649,7 @@ let test_send_and_store_zero_amount_tickets () = ticket (TM, "Red", 10). After the transaction: ticket_store_1: - [ - (TM, "Red", 0) - ] + [ ] ticket_store_2: [ (TM, "Red", 10) @@ -660,18 +662,19 @@ let test_send_and_store_zero_amount_tickets () = let* () = assert_token_balance ~loc:__LOC__ block token_red ticket_store_2 (Some 10) in - (* Send the top of [ticket_store_1]'s stack to [ticket_store_2]. That is the - ticket (TM, "Red", 0). Now, [ticket_store_2] holds both tickets. + (* Send the top of [ticket_store_1]'s stack to [ticket_store_2]. + However, this fails because [ticket_store_1]'s stack is empty. + Now, [ticket_store_2] holds both tickets. ticket_store_1: [ ] [ticket_store_2]: [ (TM, "Red", 10) - (TM, "Red", 0) ] *) - let* block = send_from_store_1_to_store_2 block in + let*! result = send_from_store_1_to_store_2 block in + assert (Result.is_error result) ; let* () = assert_token_balance ~loc:__LOC__ block token_red ticket_store_1 None in @@ -688,7 +691,6 @@ let test_send_and_store_zero_amount_tickets () = [ticket_store_2]: [ (TM, "Red", 10) - (TM, "Red", 0) ] *) let* block = mint_and_send_to_storer_1 block 5 in @@ -705,7 +707,6 @@ let test_send_and_store_zero_amount_tickets () = [ (TM, "Red", 5) (TM, "Red", 10) - (TM, "Red", 0) ] *) let* block = send_from_store_1_to_store_2 block in @@ -754,6 +755,7 @@ let test_send_tickets_in_big_map () = PUSH nat 1 ; DIG 3 ; TICKET ; + ASSERT_SOME ; SOME ; DIG 2 ; GET_AND_UPDATE ; @@ -861,6 +863,7 @@ let test_modify_big_map () = PUSH nat 1 ; DIG 3 ; TICKET ; + ASSERT_SOME ; SOME ; DIG 2 ; GET_AND_UPDATE ; @@ -962,6 +965,7 @@ let test_send_tickets_in_big_map_and_drop () = PUSH nat 1 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; SOME ; PUSH int 1 ; GET_AND_UPDATE ; @@ -1019,6 +1023,7 @@ let test_create_contract_with_ticket () = UNPAIR ; UNPAIR ; TICKET ; + ASSERT_SOME ; PUSH mutez 0 ; DIG 2 ; SOME ; @@ -1070,10 +1075,11 @@ let test_join_tickets () = code { CDR ; IF_NONE { PUSH nat 1 ; PUSH string "Red" ; - TICKET ; SOME ; NIL operation ; PAIR } + TICKET ; ASSERT_SOME ; SOME ; NIL operation ; PAIR } { PUSH nat 1 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; PAIR ; JOIN_TICKETS ; NIL operation ; @@ -1141,7 +1147,7 @@ let ticket_builder = DUP @manager 2; SENDER; ASSERT_CMPEQ; UNPAIR; - SWAP; UNIT; TICKET; + SWAP; UNIT; TICKET; ASSERT_SOME; PUSH mutez 0; SWAP; TRANSFER_TOKENS; NIL operation; SWAP; CONS }; @@ -1220,18 +1226,33 @@ let ticket_wallet = READ_TICKET; GET @total_amount 4; DUP @amount 5; - SWAP; SUB; ISNAT; ASSERT_SOME @remaining_amount; + SWAP; SUB; + DUP; EQ; + IF + { + # Drop @remaining_amount because it is zero + DROP; + # Drop @amount because this is now irrelevant + DIG 3; DROP; + # Drop @ticketer because we are not storing any ticket in this wallet + DIG 3; DROP; + # Bring the big map to the stack top since the ticket entry is already striked out + DUG 3 + } + { + ISNAT; ASSERT_SOME @remaining_amount; - # Split the ticket - DIG 4; PAIR; SWAP; SPLIT_TICKET; - ASSERT_SOME; UNPAIR @to_send @to_keep; + # Split the ticket + DIG 4; PAIR; SWAP; SPLIT_TICKET; + ASSERT_SOME; UNPAIR @to_send @to_keep; - # Store the ticket to keep - DUG 5; - SOME; - DIG 3; - GET_AND_UPDATE; - ASSERT_NONE; + # Store the ticket to keep + DUG 5; + SOME; + DIG 3; + GET_AND_UPDATE; + ASSERT_NONE; + }; DIG 2; PAIR; # Send the ticket @@ -1409,6 +1430,7 @@ let test_ticket_storage () = PUSH nat 1 ; PUSH string "Red" ; TICKET ; + ASSERT_SOME ; PAIR ; TRANSFER_TOKENS ; PUSH unit Unit ; @@ -1532,7 +1554,7 @@ let test_storage_for_create_and_remove_tickets () = storage (list (ticket string)) ; code { UNPAIR ; IF_LEFT - { UNPAIR ; DIG 2 ; SWAP ; DIG 2 ; TICKET ; CONS ; NIL operation ; PAIR } + { UNPAIR ; DIG 2 ; SWAP ; DIG 2 ; TICKET ; ASSERT_SOME ; CONS ; NIL operation ; PAIR } { DROP 2 ; NIL (ticket string) ; NIL operation ; PAIR } } } |} ~storage:"{}" @@ -1556,22 +1578,22 @@ let test_storage_for_create_and_remove_tickets () = ~recipient:ticket_manager ~parameters:"Unit" in - (* Initially the used and paid contract storage size is 115. *) + (* Initially the used and paid contract storage size is 141. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 115 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 141 in let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 115 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 141 in (* Add 1000 units of "A" tickets. *) let* block = add block 1000 "A" in (* After adding one block the new used and paid storage grows to accommodate - for the new ticket. The size is 115 + 40 (size of ticket) = 155. *) + for the new ticket. The size is 141 + 40 (size of ticket) = 181. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 155 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 181 in let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 155 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 181 in (* The size of used and paid-for ticket storage is 67 bytes. (65 for hash and 2 for amount). *) @@ -1581,10 +1603,10 @@ let test_storage_for_create_and_remove_tickets () = let* block = add block 1000 "B" in (* The new used and paid for contract storage grow to 155 + 40 = 195. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 195 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 221 in let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 195 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 221 in (* The new used and paid for ticket storage doubles (2 * 67 = 134). *) let* () = assert_used_ticket_storage ~loc:__LOC__ block 134 in @@ -1594,10 +1616,10 @@ let test_storage_for_create_and_remove_tickets () = (* We're back to 115 base-line for the used contract storage and keep 195 for paid. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 115 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 141 in let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 195 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 221 in (* Since the ticket-table is empty it does not take up any space. However, we've already paid for 134 bytes. *) @@ -1605,14 +1627,14 @@ let test_storage_for_create_and_remove_tickets () = let* () = assert_paid_ticket_storage ~loc:__LOC__ block 134 in (* Add one unit of "C" tickets. *) let* block = add block 1 "C" in - (* The new used storage is 115 + 39 (size of ticket) = 154. The size is 39 + (* The new used storage is 141 + 39 (size of ticket) = 180. The size is 39 rather than 40 because it carries a smaller amount payload. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 154 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 180 in - (* We still have paid for 195 contract storage. *) + (* We still have paid for 221 contract storage. *) let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 195 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 221 in (* There is one row in the ticket table with size 65 (for the hash) + 1 (for the amount) = 65 bytes. *) @@ -1621,13 +1643,13 @@ let test_storage_for_create_and_remove_tickets () = let* () = assert_paid_ticket_storage ~loc:__LOC__ block 134 in (* Add yet another "C" ticket. *) let* block = add block 1 "C" in - (* The new used storage is 154 + 39 (size of ticket) = 193. *) + (* The new used storage is 180 + 39 (size of ticket) = 219. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 193 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 219 in - (* We still have paid for 195 contract storage. *) + (* We still have paid for 221 contract storage. *) let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 195 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 221 in (* There is still only one row in the ticket table with size 66. *) let* () = assert_used_ticket_storage ~loc:__LOC__ block 66 in @@ -1635,26 +1657,26 @@ let test_storage_for_create_and_remove_tickets () = let* () = assert_paid_ticket_storage ~loc:__LOC__ block 134 in (* Add a "D" ticket. *) let* block = add block 1 "D" in - (* The new used storage is 193 + 39 (size of ticket) = 193. *) + (* The new used storage is 219 + 39 (size of ticket) = 258. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 232 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 258 in - (* The paid storage also increases to 232. *) + (* The paid storage also increases to 258. *) let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 232 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 258 in (* There are now two rows in the ticket table: 2 x 66 = 132 *) let* () = assert_used_ticket_storage ~loc:__LOC__ block 132 in (* And we've still paid for 134 bytes. *) let* () = assert_paid_ticket_storage ~loc:__LOC__ block 134 in let* block = add block 1 "E" in - (* The new used storage is 232 + 39 (size of ticket) = 193. *) + (* The new used storage is 258 + 39 (size of ticket) = 297. *) let* () = - assert_used_contract_storage ~loc:__LOC__ block ticket_manager 271 + assert_used_contract_storage ~loc:__LOC__ block ticket_manager 297 in - (* The paid storage also increases to 271. *) + (* The paid storage also increases to 297. *) let* () = - assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 271 + assert_paid_contract_storage ~loc:__LOC__ block ticket_manager 297 in (* There are now three rows in the ticket table: 3 x 66 = 198. *) let* () = assert_used_ticket_storage ~loc:__LOC__ block 198 in diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml index 8fe2cdd70f02..281b3aa47b40 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml @@ -65,12 +65,7 @@ let collect_token_amounts ctxt tickets = let tokens_of_value ~include_lazy ctxt ty x = let*? has_tickets, ctxt = Ticket_scanner.type_has_tickets ctxt ty in let* tickets, ctxt = - Ticket_scanner.tickets_of_value - ~include_lazy - ~allow_zero_amount_tickets:true - ctxt - has_tickets - x + Ticket_scanner.tickets_of_value ~include_lazy ctxt has_tickets x in let* tas, ctxt = collect_token_amounts ctxt tickets in let* bm, ctxt = @@ -290,6 +285,7 @@ module Ticket_manager = struct DUP 3 ; DUP 6 ; TICKET ; + ASSERT_SOME ; SOME ; DUP 5 ; GET_AND_UPDATE ; @@ -297,6 +293,7 @@ module Ticket_manager = struct DUP 3 ; DUP 6 ; TICKET ; + ASSERT_SOME ; SOME ; DUP 5 ; GET_AND_UPDATE ; @@ -304,6 +301,7 @@ module Ticket_manager = struct DIG 2 ; DIG 4 ; TICKET ; + ASSERT_SOME ; SOME ; DIG 3 ; GET_AND_UPDATE ; @@ -320,6 +318,7 @@ module Ticket_manager = struct DIG 3 ; DIG 3 ; TICKET ; + ASSERT_SOME ; CONS ; PAIR ; NIL operation ; @@ -330,6 +329,7 @@ module Ticket_manager = struct DUP 3 ; DUG 2 ; TICKET ; + ASSERT_SOME ; PUSH mutez 0 ; DIG 2 ; SOME ; @@ -346,6 +346,7 @@ module Ticket_manager = struct PUSH nat 99 ; PUSH string "NEW_TICKET_IN_ORIGINATED_CONTRACT" ; TICKET ; + ASSERT_SOME ; SOME ; PUSH int 1 ; GET_AND_UPDATE ; @@ -408,6 +409,7 @@ module Ticket_manager = struct PUSH nat 1 ; PUSH string "ADDED_BY_REPLACE_BIG_MAP" ; TICKET ; + ASSERT_SOME ; SOME ; PUSH int 11 ; GET_AND_UPDATE ; @@ -419,6 +421,7 @@ module Ticket_manager = struct PUSH nat 1 ; PUSH string "ADDED_BY_REPLACE_BIG_MAP" ; TICKET ; + ASSERT_SOME ; SOME ; PUSH int 11 ; GET_AND_UPDATE ; @@ -479,6 +482,7 @@ module Ticket_manager = struct DIG 5 ; DIG 5 ; TICKET ; + ASSERT_SOME ; TRANSFER_TOKENS ; DUG 2 ; PAIR ; @@ -508,6 +512,7 @@ module Ticket_manager = struct PUSH nat 1 ; PUSH string "ADDED_BY_SEND_SELF_REPLACE" ; TICKET ; + ASSERT_SOME ; SOME ; PUSH int 10 ; GET_AND_UPDATE ; @@ -528,6 +533,7 @@ module Ticket_manager = struct PUSH nat 1 ; PUSH string "ADDED_BY_SEND_SELF_REPLACE_TO_STORAGE" ; TICKET ; + ASSERT_SOME ; SOME ; PUSH int 11 ; GET_AND_UPDATE ; diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index 14ffa19610bf..3b77f2deb1a9 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -363,11 +363,10 @@ let transfer_operation_to_tx_rollup ~incr ~src ~parameters_ty ~parameters }, incr ) -let ticket_diffs_of_operations incr ~allow_zero_amount_tickets operations = +let ticket_diffs_of_operations incr operations = wrap @@ Ticket_operations_diff.ticket_diffs_of_operations (Incremental.alpha_ctxt incr) - ~allow_zero_amount_tickets operations let unit_script = @@ -415,9 +414,7 @@ let test_non_ticket_operations () = let* _baker, src, block = init () in let* incr = Incremental.begin_construction block in let operations = [delegation_operation ~src] in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true operations - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr operations in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] (** Test transfer to a contract that does not take tickets. *) @@ -440,9 +437,7 @@ let test_transfer_to_non_ticket_contract () = ~parameters_ty:unit_t ~parameters:() in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] (** Test transfer an empty list of tickets. *) @@ -460,9 +455,7 @@ let test_transfer_empty_ticket_list () = let* operation, incr = transfer_tickets_operation ~incr ~src ~destination:orig_contract [] in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] (** Test transfer a list of one ticket. *) @@ -485,9 +478,7 @@ let test_transfer_one_ticket () = ~destination:orig_contract [(ticketer, "white", 1)] in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -530,36 +521,29 @@ let test_transfer_multiple_tickets () = ] in let orig_contract = Contract.Originated orig_contract in - let test allow_zero_amount_tickets = - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets [operation] - in - assert_equal_ticket_token_diffs - ctxt - ~loc:__LOC__ - ticket_diffs - ~expected: - [ - { - ticket_token = string_token ~ticketer "red"; - total_amount = nat 5; - destinations = [(Destination.Contract orig_contract, nat 5)]; - }; - { - ticket_token = string_token ~ticketer "blue"; - total_amount = nat 2; - destinations = [(Destination.Contract orig_contract, nat 2)]; - }; - { - ticket_token = string_token ~ticketer "green"; - total_amount = nat 3; - destinations = [(Destination.Contract orig_contract, nat 3)]; - }; - ] - in - (* Check for both value of the allow-zero-amount-tickets flag. *) - let* () = test true in - test false + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in + assert_equal_ticket_token_diffs + ctxt + ~loc:__LOC__ + ticket_diffs + ~expected: + [ + { + ticket_token = string_token ~ticketer "red"; + total_amount = nat 5; + destinations = [(Destination.Contract orig_contract, nat 5)]; + }; + { + ticket_token = string_token ~ticketer "blue"; + total_amount = nat 2; + destinations = [(Destination.Contract orig_contract, nat 2)]; + }; + { + ticket_token = string_token ~ticketer "green"; + total_amount = nat 3; + destinations = [(Destination.Contract orig_contract, nat 3)]; + }; + ] (** Test transfer a list of tickets of different types. *) let test_transfer_different_tickets () = @@ -592,9 +576,7 @@ let test_transfer_different_tickets () = ] in let destination = Destination.Contract (Originated destination) in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -666,10 +648,7 @@ let test_transfer_to_two_contracts_with_different_tickets () = transfer_tickets_operation ~incr ~src ~destination:destination2 parameters in let* ticket_diffs, ctxt = - ticket_diffs_of_operations - incr - ~allow_zero_amount_tickets:true - [operation1; operation2] + ticket_diffs_of_operations incr [operation1; operation2] in assert_equal_ticket_token_diffs ctxt @@ -718,9 +697,7 @@ let test_originate_non_ticket_contract () = ~storage:"Unit" ~forges_tickets:false in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] (** Test originate a contract with an empty list of tickets. *) @@ -736,9 +713,7 @@ let test_originate_with_empty_tickets_list () = ~storage ~forges_tickets:false in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] (** Test originate a contract with a single ticket. *) @@ -757,9 +732,7 @@ let test_originate_with_one_ticket () = ~storage ~forges_tickets:true in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations ctxt ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations ctxt [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -800,9 +773,7 @@ let test_originate_with_multiple_tickets () = ~storage ~forges_tickets:true in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations ctxt ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations ctxt [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -864,9 +835,7 @@ let test_originate_with_different_tickets () = ~storage ~forges_tickets:true in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations ctxt ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations ctxt [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -937,10 +906,7 @@ let test_originate_two_contracts_with_different_tickets () = ~forges_tickets:true in let* ticket_diffs, ctxt = - ticket_diffs_of_operations - incr - ~allow_zero_amount_tickets:true - [operation1; operations2] + ticket_diffs_of_operations incr [operation1; operations2] in assert_equal_ticket_token_diffs ctxt @@ -1016,10 +982,7 @@ let test_originate_and_transfer () = [(ticketer, "red", 1); (ticketer, "green", 1); (ticketer, "blue", 1)] in let* ticket_diffs, ctxt = - ticket_diffs_of_operations - incr - ~allow_zero_amount_tickets:true - [operation1; operation2] + ticket_diffs_of_operations incr [operation1; operation2] in assert_equal_ticket_token_diffs ctxt @@ -1090,9 +1053,7 @@ let test_originate_big_map_with_tickets () = ~storage ~forges_tickets:true in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -1172,9 +1133,7 @@ let test_transfer_big_map_with_tickets () = ~parameters_ty ~parameters in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in let destination = Destination.Contract (Originated orig_contract) in assert_equal_ticket_token_diffs ctxt @@ -1242,9 +1201,7 @@ let test_tx_rollup_deposit_one_ticket () = ~parameters_ty ~parameters in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in + let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -1259,8 +1216,8 @@ let test_tx_rollup_deposit_one_ticket () = ] (** Test transferring a list of multiple tickets where two of them have zero - amounts. This should work when zero-tickets are enabled. *) -let test_transfer_multiple_zero_tickets () = + amounts fails. *) +let test_transfer_fails_on_multiple_zero_tickets () = let* baker, src, block = init () in let* ticketer = one_ticketer block in let* orig_contract, incr = @@ -1285,35 +1242,10 @@ let test_transfer_multiple_zero_tickets () = (ticketer, "green", 3); ] in - let* ticket_diffs, ctxt = - ticket_diffs_of_operations incr ~allow_zero_amount_tickets:true [operation] - in - let orig_contract = Contract.Originated orig_contract in - assert_equal_ticket_token_diffs - ctxt - ~loc:__LOC__ - ticket_diffs - ~expected: - [ - { - ticket_token = string_token ~ticketer "blue"; - total_amount = nat 0; - destinations = [(Destination.Contract orig_contract, nat 0)]; - }; - { - ticket_token = string_token ~ticketer "red"; - total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; - }; - { - ticket_token = string_token ~ticketer "green"; - total_amount = nat 5; - destinations = [(Destination.Contract orig_contract, nat 5)]; - }; - ] + assert_fails ~loc:__LOC__ ~error:Ticket_scanner.Forbidden_zero_ticket_quantity + @@ ticket_diffs_of_operations incr [operation] -(** Test that zero-amount tickets are detected and that an error is yielded - when the [allow_zero_amount_tickets] flag is set to [false]. *) +(** Test that zero-amount tickets are detected and that an error is yielded. *) let test_fail_on_zero_amount_tickets () = let* baker, src, block = init () in let* ticketer = one_ticketer block in @@ -1345,10 +1277,7 @@ let test_fail_on_zero_amount_tickets () = assert_fails ~loc:__LOC__ ~error:Ticket_scanner.Forbidden_zero_ticket_quantity - (ticket_diffs_of_operations - ctxt - ~allow_zero_amount_tickets:false - [operation]) + (ticket_diffs_of_operations ctxt [operation]) let tests = [ @@ -1418,9 +1347,9 @@ let tests = `Quick test_tx_rollup_deposit_one_ticket; Tztest.tztest - "Test transfer multiple zero tickets" + "Test transfer fails on multiple zero tickets" `Quick - test_transfer_multiple_zero_tickets; + test_transfer_fails_on_multiple_zero_tickets; Tztest.tztest "Test fail in zero-amount tickets" `Quick diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml index 7ecfe356d03b..1e2b71eecb4a 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml @@ -125,8 +125,7 @@ let assert_equals_ex_tickets ctxt ~loc ex_tickets expected = (List.sort String.compare str_tickets) (List.sort String.compare str_tickets_expected) -let tickets_of_value ctxt ~include_lazy ~allow_zero_amount_tickets ~type_exp - ~value_exp = +let tickets_of_value ctxt ~include_lazy ~type_exp ~value_exp = let Script_typed_ir.Ex_ty ty, ctxt = let node = Micheline.root @@ Expr.from_string type_exp in Result.value_f @@ -146,35 +145,17 @@ let tickets_of_value ctxt ~include_lazy ~allow_zero_amount_tickets ~type_exp let* ht, ctxt = wrap @@ Lwt.return @@ Ticket_scanner.type_has_tickets ctxt ty in - wrap - @@ Ticket_scanner.tickets_of_value - ctxt - ~include_lazy - ~allow_zero_amount_tickets - ht - value - -let assert_contains_tickets ctxt ~loc ~include_lazy ~allow_zero_amount_tickets - ~type_exp ~value_exp expected = + wrap @@ Ticket_scanner.tickets_of_value ctxt ~include_lazy ht value + +let assert_contains_tickets ctxt ~loc ~include_lazy ~type_exp ~value_exp + expected = let* ex_tickets, _ = - tickets_of_value - ctxt - ~include_lazy - ~allow_zero_amount_tickets - ~type_exp - ~value_exp + tickets_of_value ctxt ~include_lazy ~type_exp ~value_exp in assert_equals_ex_tickets ctxt ~loc ex_tickets expected -let assert_fail_non_empty_overlay ctxt ~loc ~include_lazy - ~allow_zero_amount_tickets ~type_exp ~value_exp = - tickets_of_value - ctxt - ~include_lazy - ~allow_zero_amount_tickets - ~type_exp - ~value_exp - >>= fun res -> +let assert_fail_non_empty_overlay ctxt ~loc ~include_lazy ~type_exp ~value_exp = + tickets_of_value ctxt ~include_lazy ~type_exp ~value_exp >>= fun res -> match res with | Error [x] -> let x = Format.kasprintf Fun.id "%a" Error_monad.pp x in @@ -263,7 +244,6 @@ let assert_big_map_int_ticket_string_ref ~loc ~pre_populated ~big_map_exp assert_contains_tickets ctxt ~include_lazy:true - ~allow_zero_amount_tickets:true ~loc ~type_exp:"big_map int (ticket string)" ~value_exp @@ -275,7 +255,6 @@ let assert_fail_non_empty_overlay_with_big_map_ref ~loc ~pre_populated assert_fail_non_empty_overlay ctxt ~include_lazy:true - ~allow_zero_amount_tickets:true ~loc ~type_exp:"big_map int (ticket string)" ~value_exp @@ -283,40 +262,22 @@ let assert_fail_non_empty_overlay_with_big_map_ref ~loc ~pre_populated let assert_string_tickets ~loc ~include_lazy ~type_exp ~value_exp ~expected = let* ctxt = new_ctxt () in let* ex_tickets, ctxt = make_string_tickets ctxt expected in - let contains_zero_amount_tickets = - List.exists (fun (_, _, amount) -> amount = 0) expected - in let* () = assert_contains_tickets ctxt ~include_lazy - ~allow_zero_amount_tickets:true ~loc ~type_exp ~value_exp ex_tickets in - if contains_zero_amount_tickets then - assert_fails - ~loc:__LOC__ - ~error:Ticket_scanner.Forbidden_zero_ticket_quantity - (tickets_of_value - ctxt - ~include_lazy - ~allow_zero_amount_tickets:false - ~type_exp - ~value_exp) - else - (* If there are no zero-amount tickets we still want them to pass with - [allow_zero_amount_tickets] flag set to false. *) - assert_contains_tickets - ctxt - ~include_lazy - ~allow_zero_amount_tickets:false - ~loc - ~type_exp - ~value_exp - ex_tickets + assert_contains_tickets + ctxt + ~include_lazy + ~loc + ~type_exp + ~value_exp + ex_tickets (** Test that the ticket can be extracted from a a single unit ticket *) let test_tickets_in_unit_ticket () = @@ -335,11 +296,31 @@ let test_tickets_in_unit_ticket () = ctxt ~loc:__LOC__ ~include_lazy:false - ~allow_zero_amount_tickets:true ~type_exp ~value_exp [ex_ticket] +let assert_string_tickets_fail_on_zero_amount ~loc ~include_lazy ~type_exp + ~value_exp = + let* ctxt = new_ctxt () in + assert_fails ~loc ~error:Ticket_scanner.Forbidden_zero_ticket_quantity + @@ tickets_of_value ctxt ~include_lazy ~type_exp ~value_exp + +let test_tickets_in_list_with_zero_amount () = + assert_string_tickets_fail_on_zero_amount + ~loc:__LOC__ + ~include_lazy:false + ~type_exp:"list(ticket(string))" + ~value_exp: + {| + { + Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1; + Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "green" 2; + Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 3; + Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "orange" 0; + } + |} + (** Test that all tickets can be extracted from a list of tickets *) let test_tickets_in_list () = assert_string_tickets @@ -352,7 +333,6 @@ let test_tickets_in_list () = Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1; Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "green" 2; Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 3; - Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "orange" 0; } |} ~expected: @@ -360,29 +340,53 @@ let test_tickets_in_list () = ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "red", 1); ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "green", 2); ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "blue", 3); - ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "orange", 0); ] +let test_tickets_in_pair_with_zero_amount () = + assert_string_tickets_fail_on_zero_amount + ~loc:__LOC__ + ~include_lazy:false + ~type_exp:"pair (ticket string) (ticket string) (ticket string)" + ~value_exp: + {| + Pair + (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1) + (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "green" 2) + (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 0) + |} + (** Test that all tickets can be extracted from a pair of tickets *) let test_tickets_in_pair () = assert_string_tickets ~loc:__LOC__ ~include_lazy:false - ~type_exp:"pair (ticket string) (ticket string) (ticket string)" + ~type_exp:"pair (ticket string) (ticket string)" ~value_exp: {| Pair (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1) (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "green" 2) - (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 0) |} ~expected: [ ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "red", 1); ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "green", 2); - ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "blue", 0); ] +let test_tickets_in_map_with_zero_amount () = + assert_string_tickets_fail_on_zero_amount + ~loc:__LOC__ + ~include_lazy:false + ~type_exp:"map int (ticket string)" + ~value_exp: + {| + { + Elt 1 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1); + Elt 2 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "green" 2); + Elt 3 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 0); + } + |} + (** Test that all tickets from a map can be extracted. *) let test_tickets_in_map () = assert_string_tickets @@ -394,14 +398,12 @@ let test_tickets_in_map () = { Elt 1 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1); Elt 2 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "green" 2); - Elt 3 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 0); } |} ~expected: [ ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "red", 1); ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "green", 2); - ("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "blue", 0); ] (** Test that all tickets from a big-map with non-empty overlay fails. @@ -414,7 +416,6 @@ let test_tickets_in_big_map () = ctxt ~loc:__LOC__ ~include_lazy:true - ~allow_zero_amount_tickets:false ~type_exp:"big_map int (ticket string)" ~value_exp: {| @@ -451,7 +452,6 @@ let test_tickets_in_list_in_big_map () = ctxt ~loc:__LOC__ ~include_lazy:true - ~allow_zero_amount_tickets:true ~type_exp:"(big_map int (list(ticket string)))" ~value_exp: {| @@ -501,15 +501,14 @@ let test_tickets_in_or_left () = ~value_exp:{| Left (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1) |} ~expected:[("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "red", 1)] -(** Test that tickets can be extracted from the left side of an or-expression - with zero-amount ticket. *) +(** Test that tickets from the left side of an or-expression with zero amount + are rejected. *) let test_tickets_in_or_left_with_zero_amount () = - assert_string_tickets + assert_string_tickets_fail_on_zero_amount ~loc:__LOC__ ~include_lazy:false ~type_exp:"or (ticket string) int" ~value_exp:{| Left (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 0) |} - ~expected:[("KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq", "red", 0)] (** Test that tickets can be extracted from the right side of an or-expression. *) let test_tickets_in_or_right () = @@ -635,8 +634,20 @@ let tests = `Quick test_tickets_in_unit_ticket; Tztest.tztest "Test tickets in list" `Quick test_tickets_in_list; + Tztest.tztest + "Test tickets in list with zero amount" + `Quick + test_tickets_in_list_with_zero_amount; Tztest.tztest "Test tickets in pair" `Quick test_tickets_in_pair; + Tztest.tztest + "Test tickets in pair with zero amount" + `Quick + test_tickets_in_pair_with_zero_amount; Tztest.tztest "Test tickets in map" `Quick test_tickets_in_map; + Tztest.tztest + "Test tickets in map with zero amount" + `Quick + test_tickets_in_map_with_zero_amount; Tztest.tztest "Test tickets in big map" `Quick test_tickets_in_big_map; Tztest.tztest "Test tickets in big map with include lazy set to false" @@ -653,7 +664,7 @@ let tests = test_tickets_in_pair_big_map_and_list_strict_only; Tztest.tztest "Test tickets in or left" `Quick test_tickets_in_or_left; Tztest.tztest - "Test tickets in or left" + "Test tickets in or left with zero amount" `Quick test_tickets_in_or_left_with_zero_amount; Tztest.tztest "Test tickets in or right" `Quick test_tickets_in_or_right; diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit.tz b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit.tz index c016f9bf9c4e..e07e83aa7195 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit.tz +++ b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit.tz @@ -17,6 +17,7 @@ code { PUSH nat 100000; PUSH unit Unit; TICKET; + ASSERT_SOME; PAIR ; diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_incorrect_entrypoint.tz b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_incorrect_entrypoint.tz index 3ad04d1bc018..f029a2583085 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_incorrect_entrypoint.tz +++ b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_incorrect_entrypoint.tz @@ -17,6 +17,7 @@ code { PUSH nat 10; PUSH unit Unit; TICKET; + ASSERT_SOME; PAIR ; diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_one_mutez.tz b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_one_mutez.tz index 58eb3095cdea..82aa389266a5 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_one_mutez.tz +++ b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_one_mutez.tz @@ -17,6 +17,7 @@ code { PUSH nat 10; PUSH unit Unit; TICKET; + ASSERT_SOME; PAIR ; diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_pair_string.tz b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_pair_string.tz index de50754c46d7..d554c713f056 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_pair_string.tz +++ b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_pair_string.tz @@ -16,6 +16,7 @@ code { UNIT; PAIR; TICKET; + ASSERT_SOME; PAIR; # amount for transfering diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_string.tz b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_string.tz index af81b322b564..977698a30239 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_string.tz +++ b/src/proto_alpha/lib_protocol/test/integration/operations/contracts/tx_rollup_deposit_string.tz @@ -14,6 +14,7 @@ code { PUSH nat 10; SWAP; TICKET; + ASSERT_SOME; PAIR; # amount for transfering diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup_transfer.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup_transfer.ml index c3e004e07b53..18965a83f8bd 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup_transfer.ml @@ -110,6 +110,7 @@ let contract_originate block account = PUSH nat 0; PUSH string "ticket payload"; TICKET; + ASSERT_SOME; TRANSFER_TOKENS; } { IF_LEFT { @@ -118,6 +119,7 @@ let contract_originate block account = PUSH nat 137; PUSH string "G"; TICKET; + ASSERT_SOME; TRANSFER_TOKENS; } { NEVER @@ -334,9 +336,12 @@ let test_transfer_zero_amount_ticket () = ~param ~entrypoint:"transfer_zero_ticket" ~expect_apply_failure: - (check_proto_error ~loc:__LOC__ ~exp:"Forbidden_zero_ticket_quantity" - @@ function - | [Ticket_scanner.Forbidden_zero_ticket_quantity] -> return_unit + (check_proto_error ~loc:__LOC__ ~exp:"Script_rejected" @@ function + | [ + Script_interpreter.Runtime_contract_error _; + Script_interpreter.Reject _; + ] -> + return_unit | _ -> raise Unexpected_error) in return_unit diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml index 60876263147f..5ab504d79889 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml @@ -548,6 +548,7 @@ module Nat_ticket = struct PUSH nat %a; PUSH %s %d; TICKET; + ASSERT_SOME; PAIR ; TRANSFER_TOKENS; PUSH unit Unit; @@ -4082,6 +4083,7 @@ module Withdraw = struct { UNPAIR; TICKET; + ASSERT_SOME; CONS; NIL operation; PAIR @@ -5523,173 +5525,6 @@ module Withdraw = struct assert_tx_rollup_ticket_balance ~__LOC__ block (Some 10) >>=? fun () -> assert_account_ticket_balance ~__LOC__ block None - let test_0_amount_tickets () = - context_init1 () >>=? fun (block, account) -> - originate block account >>=? fun (block, tx_rollup) -> - originate_forge_withdraw_deposit_contract account block - >>=? fun (forge_withdraw_deposit_contract, block) -> - let forge_ticket block = - Op.transaction - (B block) - ~entrypoint:Entrypoint.default - ~parameters: - (Expr_common.( - pair_n [int (Z.of_int Nat_ticket.contents_nat); int Z.zero]) - |> Tezos_micheline.Micheline.strip_locations |> Script.lazy_expr) - ~fee:Tez.one - account - forge_withdraw_deposit_contract - (Tez.of_mutez_exn 0L) - >>=? fun operation -> Block.bake ~operation block - in - let failing_deposit_ticket block = - Op.transaction - (B block) - ~entrypoint:(Entrypoint.of_string_strict_exn "deposit") - ~parameters: - (Expr_common.( - pair_n - [ - string (Tx_rollup.to_b58check tx_rollup); - string "tz4MSfZsn6kMDczShy8PMeB628TNukn9hi2K"; - ]) - |> Tezos_micheline.Micheline.strip_locations |> Script.lazy_expr) - ~fee:Tez.one - account - forge_withdraw_deposit_contract - (Tez.of_mutez_exn 0L) - >>=? fun operation -> - Incremental.begin_construction block >>=? fun incr -> - Incremental.add_operation - ~expect_apply_failure: - (check_proto_error Ticket_scanner.Forbidden_zero_ticket_quantity) - incr - operation - >>=? fun _incr -> return_unit - in - let failing_dispatch_ticket block = - Nat_ticket.withdrawal - ~amount:Tx_rollup_l2_qty.zero - (B block) - ~ticketer:forge_withdraw_deposit_contract - ~claimer:account - tx_rollup - >>=? fun (withdraw, ticket_info) -> - let message_index = 0 in - finalize_all_commitment_with_withdrawals - ~batches:["batch"] - ~account - ~tx_rollup - ~withdrawals:[(message_index, [withdraw])] - block - >>=? fun (commitment, context_hash_list, committed_level, block) -> - let context_hash = - WithExceptions.Option.get - ~loc:__LOC__ - (List.nth context_hash_list message_index) - in - let message_result_path = - compute_message_result_path commitment ~message_position:message_index - in - Op.tx_rollup_dispatch_tickets - (B block) - ~source:account - ~message_index - ~message_result_path - tx_rollup - committed_level - context_hash - [ticket_info] - >>=? fun operation -> - Incremental.begin_construction block >>=? fun incr -> - Incremental.add_operation - ~expect_apply_failure: - (check_proto_error Ticket_scanner.Forbidden_zero_ticket_quantity) - incr - operation - >>=? fun _incr -> return_unit - in - let failing_transfer_ticket block = - Op.transfer_ticket - (B block) - ~source:account - ~contents:(Script.lazy_expr Nat_ticket.contents) - ~ty:(Script.lazy_expr Nat_ticket.ty) - ~ticketer:forge_withdraw_deposit_contract - Z.zero - ~destination:forge_withdraw_deposit_contract - (Entrypoint.of_string_strict_exn "withdraw") - >>=? fun operation -> - Incremental.begin_construction block >>=? fun incr -> - Incremental.add_operation - ~expect_apply_failure: - (check_proto_error Ticket_scanner.Forbidden_zero_ticket_quantity) - incr - operation - >>=? fun _incr -> return_unit - in - let token_one = - Nat_ticket.ex_token ~ticketer:forge_withdraw_deposit_contract - in - let assert_ticket_in_storage block = - let expected_storage = - Expr_common.( - seq - [ - pair - (address forge_withdraw_deposit_contract) - (pair (int (Z.of_int Nat_ticket.contents_nat)) (int Z.zero)); - ]) - |> Tezos_micheline.Micheline.strip_locations |> Option.some - in - Incremental.begin_construction block >>=? fun incr -> - let ctxt = Incremental.alpha_ctxt incr in - Contract.get_storage ctxt forge_withdraw_deposit_contract - >>=?? fun (_ctxt, found_storage) -> - if expected_storage = found_storage then return_unit - else - Alcotest.fail - (Format.sprintf - "Found storage: %s@,expected storage: %s@," - (match found_storage with - | Some s -> Expr.to_string s - | None -> "None") - (match expected_storage with - | Some s -> Expr.to_string s - | None -> "None")) - in - let assert_contract_ticket_balance ~__LOC__ block balance = - assert_ticket_balance - ~loc:__LOC__ - block - token_one - (Contract forge_withdraw_deposit_contract) - balance - in - let assert_account_ticket_balance ~__LOC__ block balance = - assert_ticket_balance - ~loc:__LOC__ - block - token_one - (Contract account) - balance - in - let assert_tx_rollup_ticket_balance ~__LOC__ block balance = - assert_ticket_balance - ~loc:__LOC__ - block - token_one - (Tx_rollup tx_rollup) - balance - in - forge_ticket block >>=? fun block -> - assert_ticket_in_storage block >>=? fun () -> - assert_contract_ticket_balance ~__LOC__ block None >>=? fun () -> - assert_tx_rollup_ticket_balance ~__LOC__ block None >>=? fun () -> - assert_account_ticket_balance ~__LOC__ block None >>=? fun () -> - failing_deposit_ticket block >>=? fun () -> - failing_dispatch_ticket block >>=? fun () -> failing_transfer_ticket block - let tests = [ Tztest.tztest "Test withdraw" `Quick test_valid_withdraw; @@ -5736,10 +5571,6 @@ module Withdraw = struct batches" `Quick test_forge_deposit_withdraw_deposit; - Tztest.tztest - "Test to deposit/dispatch/transfer 0 tickets" - `Quick - test_0_amount_tickets; ] end diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml index 186f88bb2f88..64341fdbd929 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml @@ -202,7 +202,7 @@ let add_or_clear = storage (list (ticket string)) ; code { UNPAIR ; IF_LEFT - { UNPAIR ; DIG 2 ; SWAP ; DIG 2 ; TICKET ; CONS ; NIL operation ; PAIR } + { UNPAIR ; DIG 2 ; SWAP ; DIG 2 ; TICKET ; ASSERT_SOME ; CONS ; NIL operation ; PAIR } { DROP 2 ; NIL (ticket string) ; NIL operation ; PAIR } } } |} diff --git a/tests_python/.python-version b/tests_python/.python-version new file mode 100644 index 000000000000..29c9b940b643 --- /dev/null +++ b/tests_python/.python-version @@ -0,0 +1 @@ +tezos diff --git a/tests_python/contracts_alpha/ill_typed/ticket_in_ticket.tz b/tests_python/contracts_alpha/ill_typed/ticket_in_ticket.tz index ee6bdf238723..ef6a1dcb49fe 100644 --- a/tests_python/contracts_alpha/ill_typed/ticket_in_ticket.tz +++ b/tests_python/contracts_alpha/ill_typed/ticket_in_ticket.tz @@ -9,6 +9,7 @@ code { PUSH nat 0; SWAP; TICKET; + ASSERT_SOME; READ_TICKET; CDR; CAR; SWAP; READ_TICKET; CDR; CAR; SWAP; DROP; diff --git a/tests_python/contracts_alpha/mini_scenarios/add_clear_tickets.tz b/tests_python/contracts_alpha/mini_scenarios/add_clear_tickets.tz index 9275b38a2c39..ed8cf6ce2b6d 100644 --- a/tests_python/contracts_alpha/mini_scenarios/add_clear_tickets.tz +++ b/tests_python/contracts_alpha/mini_scenarios/add_clear_tickets.tz @@ -2,5 +2,5 @@ parameter (or (pair %add nat string) (unit %clear)) ; storage (list (ticket string)) ; code { UNPAIR ; IF_LEFT - { UNPAIR ; DIG 2 ; SWAP ; DIG 2 ; TICKET ; CONS ; NIL operation ; PAIR } + { UNPAIR ; DIG 2 ; SWAP ; DIG 2 ; TICKET ; ASSERT_SOME ; CONS ; NIL operation ; PAIR } { DROP 2 ; NIL (ticket string) ; NIL operation ; PAIR } } diff --git a/tests_python/contracts_alpha/mini_scenarios/send_tickets_in_big_map.tz b/tests_python/contracts_alpha/mini_scenarios/send_tickets_in_big_map.tz index e8c27faf3098..050d64cd6071 100644 --- a/tests_python/contracts_alpha/mini_scenarios/send_tickets_in_big_map.tz +++ b/tests_python/contracts_alpha/mini_scenarios/send_tickets_in_big_map.tz @@ -27,6 +27,7 @@ code { CAR ; PUSH nat 1 ; PUSH string "BLUE" ; TICKET ; + ASSERT_SOME ; DIG 3 ; SWAP ; SOME ; diff --git a/tests_python/contracts_alpha/mini_scenarios/ticket_builder_fungible.tz b/tests_python/contracts_alpha/mini_scenarios/ticket_builder_fungible.tz index 674ae800771d..17a0be3750ac 100644 --- a/tests_python/contracts_alpha/mini_scenarios/ticket_builder_fungible.tz +++ b/tests_python/contracts_alpha/mini_scenarios/ticket_builder_fungible.tz @@ -32,7 +32,7 @@ code DUP @manager 2; SENDER; ASSERT_CMPEQ; UNPAIR; - SWAP; UNIT; TICKET; + SWAP; UNIT; TICKET; ASSERT_SOME; PUSH mutez 0; SWAP; TRANSFER_TOKENS; NIL operation; SWAP; CONS }; diff --git a/tests_python/contracts_alpha/mini_scenarios/ticket_builder_non_fungible.tz b/tests_python/contracts_alpha/mini_scenarios/ticket_builder_non_fungible.tz index ae669d17ad60..df7e19a4f349 100644 --- a/tests_python/contracts_alpha/mini_scenarios/ticket_builder_non_fungible.tz +++ b/tests_python/contracts_alpha/mini_scenarios/ticket_builder_non_fungible.tz @@ -34,7 +34,7 @@ code # Mint the token PUSH @amount nat 1; DUP @counter 4; - TICKET; + TICKET; ASSERT_SOME; # This is safe because the amount is not zero # Send it PUSH mutez 0; SWAP; TRANSFER_TOKENS; diff --git a/tests_python/contracts_alpha/opcodes/ticket_big_store.tz b/tests_python/contracts_alpha/opcodes/ticket_big_store.tz index 6d1de845235e..05cb7725bfaf 100644 --- a/tests_python/contracts_alpha/opcodes/ticket_big_store.tz +++ b/tests_python/contracts_alpha/opcodes/ticket_big_store.tz @@ -1,3 +1,3 @@ parameter nat ; storage (big_map unit (ticket nat)); -code { UNPAIR ; PUSH nat 1 ; SWAP ; TICKET ; SOME ; UNIT ; UPDATE ; NIL operation ; PAIR } ; +code { UNPAIR ; PUSH nat 1 ; SWAP ; TICKET ; ASSERT_SOME; SOME ; UNIT ; UPDATE ; NIL operation ; PAIR } ; diff --git a/tests_python/contracts_alpha/opcodes/ticketer-2.tz b/tests_python/contracts_alpha/opcodes/ticketer-2.tz index bce940ccabe2..fe81daf47632 100644 --- a/tests_python/contracts_alpha/opcodes/ticketer-2.tz +++ b/tests_python/contracts_alpha/opcodes/ticketer-2.tz @@ -2,7 +2,7 @@ parameter (pair (pair address nat) nat) ; storage unit; code { CAR ; UNPAIR ; UNPAIR ; CONTRACT (ticket nat) ; ASSERT_SOME ; - DIP { TICKET } ; + DIP { TICKET ; ASSERT_SOME } ; SWAP ; DIP { PUSH mutez 0 } ; TRANSFER_TOKENS ; NIL operation ; SWAP ; CONS ; diff --git a/tests_python/contracts_alpha/opcodes/ticketer.tz b/tests_python/contracts_alpha/opcodes/ticketer.tz index c8ec4565398a..d6660d1fe600 100644 --- a/tests_python/contracts_alpha/opcodes/ticketer.tz +++ b/tests_python/contracts_alpha/opcodes/ticketer.tz @@ -4,6 +4,7 @@ code { UNPAIR ; DIP { DUP } ; SWAP ; PUSH nat 1 ; SWAP ; TICKET ; + ASSERT_SOME ; DIP { CONTRACT (ticket nat) ; ASSERT_SOME ; PUSH mutez 0 } ; TRANSFER_TOKENS ; NIL operation ; SWAP ; CONS ; diff --git a/tests_python/contracts_alpha/opcodes/utxor.tz b/tests_python/contracts_alpha/opcodes/utxor.tz index 81d9632d35d2..1720512520c3 100644 --- a/tests_python/contracts_alpha/opcodes/utxor.tz +++ b/tests_python/contracts_alpha/opcodes/utxor.tz @@ -4,6 +4,7 @@ code { UNPAIR ; DIP { DUP } ; SWAP ; PUSH nat 5 ; SWAP ; TICKET ; + ASSERT_SOME ; PUSH nat 2 ; PUSH nat 3 ; PAIR ; SWAP ; SPLIT_TICKET ; diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_first_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_first_transfer.out index 692ca6800884..f704ab041f3d 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_first_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_first_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestCreateRemoveTickets::test_add_clear_tickets_add_first_transfer Node is bootstrapped. -Estimated gas: 2576.032 units (will add 100 for safety) +Estimated gas: 2579.990 units (will add 100 for safety) Estimated storage: 105 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -14,7 +14,7 @@ This sequence of operations was run: From: [CONTRACT_HASH] Fee to the baker: ꜩ0.000535 Expected counter: [EXPECTED_COUNTER] - Gas limit: 2677 + Gas limit: 2680 Storage limit: 125 bytes Balance updates: [CONTRACT_HASH] ... -ꜩ0.000535 @@ -27,10 +27,10 @@ This sequence of operations was run: Parameter: (Pair 1 "A") This transaction was successfully applied Updated storage: - { Pair 0x0134d794a355dbb7027075d278a68494e91c6709ed00 (Pair "A" 1) } - Storage size: 154 bytes + { Pair 0x01d15749b3c834ffbb675a2515090953c7dc0f432f00 (Pair "A" 1) } + Storage size: 180 bytes Paid storage size diff: 105 bytes - Consumed gas: 2576.032 + Consumed gas: 2579.990 Balance updates: [CONTRACT_HASH] ... -ꜩ0.02625 storage fees ........................... +ꜩ0.02625 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_second_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_second_transfer.out index ccd1f9583c78..3f68e78e2f56 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_second_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_second_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestCreateRemoveTickets::test_add_clear_tickets_add_second_transfer Node is bootstrapped. -Estimated gas: 1657.462 units (will add 100 for safety) +Estimated gas: 1657.492 units (will add 100 for safety) Estimated storage: no bytes added Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -27,8 +27,8 @@ This sequence of operations was run: Parameter: (Pair 1 "B") This transaction was successfully applied Updated storage: - { Pair 0x0134d794a355dbb7027075d278a68494e91c6709ed00 (Pair "B" 1) } - Storage size: 154 bytes - Consumed gas: 1657.462 + { Pair 0x01d15749b3c834ffbb675a2515090953c7dc0f432f00 (Pair "B" 1) } + Storage size: 180 bytes + Consumed gas: 1657.492 Injected block at minimal timestamp diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_third_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_third_transfer.out index ad35a6c8f131..a706045dea23 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_third_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_add_third_transfer.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestCreateRemoveTickets::test_add_clear_tickets_add_third_transfer Node is bootstrapped. -Estimated gas: 2333.201 units (will add 100 for safety) +Estimated gas: 2333.231 units (will add 100 for safety) Estimated storage: 105 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -27,11 +27,11 @@ This sequence of operations was run: Parameter: (Pair 1 "C") This transaction was successfully applied Updated storage: - { Pair 0x0134d794a355dbb7027075d278a68494e91c6709ed00 (Pair "C" 1) ; - Pair 0x0134d794a355dbb7027075d278a68494e91c6709ed00 (Pair "B" 1) } - Storage size: 193 bytes + { Pair 0x01d15749b3c834ffbb675a2515090953c7dc0f432f00 (Pair "C" 1) ; + Pair 0x01d15749b3c834ffbb675a2515090953c7dc0f432f00 (Pair "B" 1) } + Storage size: 219 bytes Paid storage size diff: 105 bytes - Consumed gas: 2333.201 + Consumed gas: 2333.231 Balance updates: [CONTRACT_HASH] ... -ꜩ0.02625 storage fees ........................... +ꜩ0.02625 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_clear_transfer.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_clear_transfer.out index f462a647b1ef..415e932bb967 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_clear_transfer.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_clear_transfer.out @@ -26,7 +26,7 @@ This sequence of operations was run: Entrypoint: clear This transaction was successfully applied Updated storage: {} - Storage size: 115 bytes + Storage size: 141 bytes Consumed gas: 1845.841 Injected block at minimal timestamp diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_origination.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_origination.out index 55c8551ac754..7d952f8e2c5f 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_origination.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestCreateRemoveTickets::test_add_clear_tickets_origination.out @@ -1,8 +1,8 @@ tests_alpha/test_contract.py::TestCreateRemoveTickets::test_add_clear_tickets_origination Node is bootstrapped. -Estimated gas: 1427.437 units (will add 100 for safety) -Estimated storage: 372 bytes added (will add 20 for safety) +Estimated gas: 1432.985 units (will add 100 for safety) +Estimated storage: 398 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' NOT waiting for the operation to be included. @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000498 + Fee to the baker: ꜩ0.000525 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1528 - Storage limit: 392 bytes + Gas limit: 1533 + Storage limit: 418 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000498 - payload fees(the block proposer) ....... +ꜩ0.000498 + [CONTRACT_HASH] ... -ꜩ0.000525 + payload fees(the block proposer) ....... +ꜩ0.000525 Origination: From: [CONTRACT_HASH] Credit: ꜩ200 @@ -27,19 +27,27 @@ This sequence of operations was run: storage (list (ticket string)) ; code { UNPAIR ; IF_LEFT - { UNPAIR ; DIG 2 ; SWAP ; DIG 2 ; TICKET ; CONS ; NIL operation ; PAIR } + { UNPAIR ; + DIG 2 ; + SWAP ; + DIG 2 ; + TICKET ; + ASSERT_SOME ; + CONS ; + NIL operation ; + PAIR } { DROP 2 ; NIL (ticket string) ; NIL operation ; PAIR } } } Initial storage: {} No delegate for this contract This origination was successfully applied Originated contracts: [CONTRACT_HASH] - Storage size: 115 bytes - Paid storage size diff: 115 bytes - Consumed gas: 1427.437 + Storage size: 141 bytes + Paid storage size diff: 141 bytes + Consumed gas: 1432.985 Balance updates: - [CONTRACT_HASH] ... -ꜩ0.02875 - storage fees ........................... +ꜩ0.02875 + [CONTRACT_HASH] ... -ꜩ0.03525 + storage fees ........................... +ꜩ0.03525 [CONTRACT_HASH] ... -ꜩ0.06425 storage fees ........................... +ꜩ0.06425 [CONTRACT_HASH] ... -ꜩ200 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out index b9ecd1631d6d..2665db42079e 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestScriptHashRegression::test_contract_hash[client_regtest_custom_scrubber0].out @@ -63,7 +63,7 @@ exprtw4kigYCiREgky6KBKryS7JkaGih6ju8jkjaXtpdcWYrYukRKX [CONTRACT_PATH]/macros/pa exprtxutG1Nu8d198ebiCraNuQ8a6iYYqJYfGXq19aykNPB1uECc8w [CONTRACT_PATH]/macros/set_caddaadr.tz exprvCE6JDXrzEfZuxTQzSgxWXtxX5GoNxvidL84CN2TAm6Hk3kuK6 [CONTRACT_PATH]/macros/take_my_money.tz exprunGqZLZZwm9mY31NFGbBemCgXGevYqLRKdeRKQArPf824Npnni [CONTRACT_PATH]/macros/unpair_macro.tz -expru9ZhqLGykU3yRksBDWe4uDwxavSM19B8WfKukQA3fkgok4hGTE [CONTRACT_PATH]/mini_scenarios/add_clear_tickets.tz +expruwYQvEdTgNzbm3228Xp6srt9FbG2v7w2F8yVH7BCK1P2NJTJUi [CONTRACT_PATH]/mini_scenarios/add_clear_tickets.tz exprufRUAYF6r5QHQvK8CzWkKQcdvYkPx5fjEYzWPXc35Dry77KDT1 [CONTRACT_PATH]/mini_scenarios/authentication.tz exprtjdvZr5J7WfN4SyNgKueLnxX4fALUYJ4cmi675EHJdUu5yyg2n [CONTRACT_PATH]/mini_scenarios/big_map_entrypoints.tz exprtfWRfK4RoY8CF9VXvcHeBxizfjMMPAkLojfUTuoZkMSyiPKoyK [CONTRACT_PATH]/mini_scenarios/big_map_magic.tz @@ -92,9 +92,9 @@ exprvJ8zXaBkyXMhJ2eKtPwdwbg5NLrggvW8MEpVK3hk3nAe215PQ6 [CONTRACT_PATH]/mini_scen exprtuiYUMjM6d8XxPda1yfKeN61ko6riom35PzybC31NKXkVhgBQy [CONTRACT_PATH]/mini_scenarios/reveal_signed_preimage.tz expruB4maBvk1y4JaeSLpDXWC3zKiXK5QFYv4B3R5KfdGEt4B5VvTT [CONTRACT_PATH]/mini_scenarios/self_address_receiver.tz exprvTG7hjtWXeogStj3pzM1MCVcNg1q6KnivqNVzQjviUrJvsjfQn [CONTRACT_PATH]/mini_scenarios/self_address_sender.tz -expru1Ks3BYyWcJeiRxtPC2htppzguP4vDCh5ULwtvHxD8sbP24pQb [CONTRACT_PATH]/mini_scenarios/send_tickets_in_big_map.tz -expru9ASRmfbXX8Ajf5uDeiZDbNwonrCiS1e6UaDXUstKU3yuwQwdZ [CONTRACT_PATH]/mini_scenarios/ticket_builder_fungible.tz -exprtXrMgaXhLsw6ioNNPThqPF1yDyLjqGdJeB6yMRKLUQZfkTD6jy [CONTRACT_PATH]/mini_scenarios/ticket_builder_non_fungible.tz +expru6tUaVWpaR7D5invwY7inJnPZGPXTcDqFvirrHPMRxSeHki5Fz [CONTRACT_PATH]/mini_scenarios/send_tickets_in_big_map.tz +expruaFvFLsin2MWRuDkLRfe56pdPTUQ8RK9k1ks1rUTjBnwryPyPx [CONTRACT_PATH]/mini_scenarios/ticket_builder_fungible.tz +expruMFhigCZpXrGaL5sMyjGw5k7CanAa7XRkHFemCoCwMfJFJjDuD [CONTRACT_PATH]/mini_scenarios/ticket_builder_non_fungible.tz exprthFU1n1xhXLi4D2G4andPJsLcem1g1UtKiKJjXkCfVHztC393b [CONTRACT_PATH]/mini_scenarios/ticket_wallet_fungible.tz expruoGtEJH3sXXm2ruNG6DGTFE3GM6fjAS6fzDZKtdaMnRzHvi3Xd [CONTRACT_PATH]/mini_scenarios/ticket_wallet_non_fungible.tz exprtnBz8poqNTrK4rzTXZFKQx7HWpx4WidHB5wxcM2oTS8NcrkAUt [CONTRACT_PATH]/mini_scenarios/tzip4_view.tz @@ -276,14 +276,14 @@ exprv4UZUuBDCZZjtW5kaezZjaKqpi1GN6vxHsvQNNkFktnaEbDb1M [CONTRACT_PATH]/opcodes/s expruVuXhQmoBMzZjPeY7VQSuJxefBBTuPyNR7PGnYhwouo9zKg3T1 [CONTRACT_PATH]/opcodes/subset.tz exprtz2jbsXuMMPAXYAGJZqjuBp8iF38XadE3YuZoC2W5NkyhhHMuq [CONTRACT_PATH]/opcodes/tez_add_sub.tz exprugbVFDGWcSSozyN3EK3AcdwtPeES3ao45HNogWc5V8fsJ8NsSP [CONTRACT_PATH]/opcodes/ticket_bad.tz -exprtvedUmBuu66gdQXWpEJNQBU96bnUVQmrWWLAbcdsCLV4Rwa34K [CONTRACT_PATH]/opcodes/ticket_big_store.tz +expruwtzPEyCm4Vaq42Fct7QG5eD1MzXzkJbRqm6EVQH6YSV2QLkr1 [CONTRACT_PATH]/opcodes/ticket_big_store.tz expruqx789AMcKUYwDeeeRvSnwdCw8gMVvWA6vuzPzBQwBM2qcDXJB [CONTRACT_PATH]/opcodes/ticket_join.tz exprvMp1LX8aeyEq9NiMXGyD34J4offZDANGRwFTxoEWXumEsDdAP8 [CONTRACT_PATH]/opcodes/ticket_read.tz exprtvtEFi6v3awAwbHivJkjki6mDNivewiCBeJDJT78PqWtq7VyUD [CONTRACT_PATH]/opcodes/ticket_split.tz exprtifPFaLqHvR9uGWbeLj5r3YVBnKaawt12q3BMhM9wsUdM9dFNy [CONTRACT_PATH]/opcodes/ticket_store-2.tz exprvJGjz1EDdnAPWZQ7ZngDNDDDXnxA2VY6SHdHKu8LxqcVHd3E6z [CONTRACT_PATH]/opcodes/ticket_store.tz -expruhNaUWmTNpmFWSXUgf1ZjgcUXmjtXGaMumzteyFYzT9CMmU4wc [CONTRACT_PATH]/opcodes/ticketer-2.tz -exprvPfYzs3x1V67saypcaPGwj5rnuKsb3tFi2VtqX7gtP4W3sjfye [CONTRACT_PATH]/opcodes/ticketer.tz +exprvDjqte3hX8aieidgPA2qyPWA5eYuVrvb3KKZ8aYkeDotovgkQ4 [CONTRACT_PATH]/opcodes/ticketer-2.tz +exprvSU3oSiKqMLpWgBhwJZbEMDnvKiNW57MYQ8YG787N7jocXMEuR [CONTRACT_PATH]/opcodes/ticketer.tz expruhV9RSEPAtKAUhBbdTw5gPFdjcKk8zr7cVLSsGtmJuH3o7VXXo [CONTRACT_PATH]/opcodes/transfer_amount.tz expru3MSjYZRmQi3yiN6gYa4X6rs88XLWH4H8ivzrCvxs8z8cJfu4Z [CONTRACT_PATH]/opcodes/transfer_tokens.tz exprtbACDcFtDfEwsBA5LAG13uMRAjnQsFjzNELMS7jQ87bcqgdE6r [CONTRACT_PATH]/opcodes/uncomb.tz @@ -291,7 +291,7 @@ exprufJpS3BWpgv4QBaBEMucbn1jsVpdqEGLLMfXjDuKGPRGCpZUkj [CONTRACT_PATH]/opcodes/u exprtqjpmEs9GUjSEzJYSnN3skiCb8js2bY48R9Lhxk9JW1CKnm6VP [CONTRACT_PATH]/opcodes/unpair_field_annotation_mismatch.tz exprv4ACaZe4aECCfG93NGVVHbQBNQ5Atxtju5vWASZSEp5sLECcjg [CONTRACT_PATH]/opcodes/update_big_map.tz expruWzM36ATA3fAee4WHDS4vvMeewkwhya1fZaa6HFPbjwt9vvGpg [CONTRACT_PATH]/opcodes/utxo_read.tz -expru3YgRPQBAnTWgKytSMs3tRj7dMgtWUxo75b1pUFrTLscKy2byF [CONTRACT_PATH]/opcodes/utxor.tz +expruNCoB4n3KQTeXbDJWLwynT32T6dz2Nxw5f7SwaqRNkQSBog79A [CONTRACT_PATH]/opcodes/utxor.tz expruJxgC2Q8Ubt8tPyQbZ41j6w4b8yw5f6bxjrMMM81TmMC9x5Lrc [CONTRACT_PATH]/opcodes/view_fib.tz expru9EavkgPCUAwHccJf9j1t4aTTssPKoBkCqC4YNr12kxXSwqFqD [CONTRACT_PATH]/opcodes/view_mutual_recursion.tz exprv4QXQuZtQE7CpKyecjrXJ8U2ovU1qjUKtw37J6kAEmu3fAKyN5 [CONTRACT_PATH]/opcodes/view_op_add.tz diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map.out index cfa26de12043..d05270c3ff67 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map.out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestSendTicketsInBigMap::test_send_tickets_in_big_map Node is bootstrapped. -Estimated gas: 100143.520 units (will add 100 for safety) +Estimated gas: 100150.481 units (will add 100 for safety) Estimated storage: 10767 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.010321 + Fee to the baker: ꜩ0.010322 Expected counter: [EXPECTED_COUNTER] - Gas limit: 100244 + Gas limit: 100251 Storage limit: 10787 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.010321 - payload fees(the block proposer) ....... +ꜩ0.010321 + [CONTRACT_HASH] ... -ꜩ0.010322 + payload fees(the block proposer) ....... +ꜩ0.010322 Transaction: Amount: ꜩ0 From: [CONTRACT_HASH] @@ -28,109 +28,109 @@ This sequence of operations was run: Updated storage: Unit Updated big_maps: New temp(1) of type (big_map int (ticket string)) - Set temp(1)[22] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[48] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[20] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[67] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[30] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[33] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[42] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[13] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[50] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[84] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[44] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[41] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[4] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[73] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[5] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[28] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[19] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[9] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[86] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[76] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[8] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[97] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[80] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[45] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[87] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[1] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[26] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[38] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[65] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[99] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[69] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[2] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[81] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[82] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[64] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[92] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[90] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[98] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[37] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[66] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[32] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[71] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[51] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[56] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[14] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[12] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[85] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[47] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[74] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[18] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[10] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[35] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[96] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[27] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[77] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[62] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[58] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[25] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[94] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[60] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[7] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[53] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[11] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[17] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[83] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[72] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[6] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[88] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[75] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[3] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[70] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[52] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[95] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[68] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[78] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[23] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[79] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[59] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[100] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[24] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[21] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[49] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[93] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[39] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[63] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[55] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[15] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[16] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[31] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[43] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[29] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[54] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[89] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[36] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[46] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[91] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[61] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[34] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[57] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Set temp(1)[40] to (Pair 0x013fdf9fa7cb678c9c1da3bbfdd83a77ca36efa00300 (Pair "BLUE" 1)) - Storage size: 294 bytes + Set temp(1)[22] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[48] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[20] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[67] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[30] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[33] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[42] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[13] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[50] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[84] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[44] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[41] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[4] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[73] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[5] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[28] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[19] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[9] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[86] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[76] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[8] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[97] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[80] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[45] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[87] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[1] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[26] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[38] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[65] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[99] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[69] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[2] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[81] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[82] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[64] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[92] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[90] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[98] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[37] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[66] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[32] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[71] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[51] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[56] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[14] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[12] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[85] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[47] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[74] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[18] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[10] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[35] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[96] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[27] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[77] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[62] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[58] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[25] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[94] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[60] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[7] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[53] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[11] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[17] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[83] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[72] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[6] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[88] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[75] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[3] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[70] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[52] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[95] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[68] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[78] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[23] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[79] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[59] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[100] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[24] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[21] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[49] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[93] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[39] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[63] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[55] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[15] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[16] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[31] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[43] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[29] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[54] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[89] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[36] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[46] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[91] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[61] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[34] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[57] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Set temp(1)[40] to (Pair 0x019712e28563749c441ac346e7b697488f68059a2300 (Pair "BLUE" 1)) + Storage size: 320 bytes Paid storage size diff: 67 bytes - Consumed gas: 50522.350 + Consumed gas: 50529.311 Balance updates: [CONTRACT_HASH] ... -ꜩ0.01675 storage fees ........................... +ꜩ0.01675 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map_originate.out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map_originate.out index 26ac386869da..f1e983098a4a 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map_originate.out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestSendTicketsInBigMap::test_send_tickets_in_big_map_originate.out @@ -1,8 +1,8 @@ tests_alpha/test_contract.py::TestSendTicketsInBigMap::test_send_tickets_in_big_map_originate Node is bootstrapped. -Estimated gas: 1479.953 units (will add 100 for safety) -Estimated storage: 551 bytes added (will add 20 for safety) +Estimated gas: 1485.567 units (will add 100 for safety) +Estimated storage: 577 bytes added (will add 20 for safety) Operation successfully injected in the node. Operation hash is '[BLOCK_HASH]' NOT waiting for the operation to be included. @@ -12,13 +12,13 @@ and/or an external block explorer to make sure that it has been included. This sequence of operations was run: Manager signed operations: From: [CONTRACT_HASH] - Fee to the baker: ꜩ0.000682 + Fee to the baker: ꜩ0.000709 Expected counter: [EXPECTED_COUNTER] - Gas limit: 1580 - Storage limit: 571 bytes + Gas limit: 1586 + Storage limit: 597 bytes Balance updates: - [CONTRACT_HASH] ... -ꜩ0.000682 - payload fees(the block proposer) ....... +ꜩ0.000682 + [CONTRACT_HASH] ... -ꜩ0.000709 + payload fees(the block proposer) ....... +ꜩ0.000709 Origination: From: [CONTRACT_HASH] Credit: ꜩ200 @@ -50,6 +50,7 @@ This sequence of operations was run: PUSH nat 1 ; PUSH string "BLUE" ; TICKET ; + ASSERT_SOME ; DIG 3 ; SWAP ; SOME ; @@ -72,12 +73,12 @@ This sequence of operations was run: This origination was successfully applied Originated contracts: [CONTRACT_HASH] - Storage size: 294 bytes - Paid storage size diff: 294 bytes - Consumed gas: 1479.953 + Storage size: 320 bytes + Paid storage size diff: 320 bytes + Consumed gas: 1485.567 Balance updates: - [CONTRACT_HASH] ... -ꜩ0.0735 - storage fees ........................... +ꜩ0.0735 + [CONTRACT_HASH] ... -ꜩ0.08 + storage fees ........................... +ꜩ0.08 [CONTRACT_HASH] ... -ꜩ0.06425 storage fees ........................... +ꜩ0.06425 [CONTRACT_HASH] ... -ꜩ200 diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--add_clear_tickets.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--add_clear_tickets.tz].out index e4d7ef6dd70b..e4c1396edeec 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--add_clear_tickets.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--add_clear_tickets.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[mini_scenarios/add_clear_tickets.tz] Well typed -Gas remaining: 1039990.715 units remaining +Gas remaining: 1039988.509 units remaining { parameter (or (pair %add nat string) (unit %clear)) ; storage (list (ticket string)) ; code { UNPAIR @@ -16,7 +16,8 @@ Gas remaining: 1039990.715 units remaining DIG 2 /* [ string : nat : list (ticket string) ] */ ; TICKET - /* [ ticket string : list (ticket string) ] */ ; + /* [ option (ticket string) : list (ticket string) ] */ ; + ASSERT_SOME ; CONS /* [ list (ticket string) ] */ ; NIL operation diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--send_tickets_in_big_map.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--send_tickets_in_big_map.tz].out index bdfe87e4c2c8..01a8967082cc 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--send_tickets_in_big_map.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--send_tickets_in_big_map.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[mini_scenarios/send_tickets_in_big_map.tz] Well typed -Gas remaining: 1039969.352 units remaining +Gas remaining: 1039967.113 units remaining { parameter address ; storage unit ; code { CAR @@ -76,8 +76,9 @@ Gas remaining: 1039969.352 units remaining /* [ string : nat : big_map int (ticket string) : int : int : contract (big_map int (ticket string)) ] */ ; TICKET - /* [ ticket string : big_map int (ticket string) : int : int + /* [ option (ticket string) : big_map int (ticket string) : int : int : contract (big_map int (ticket string)) ] */ ; + ASSERT_SOME ; DIG 3 /* [ int : ticket string : big_map int (ticket string) : int : contract (big_map int (ticket string)) ] */ ; diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_fungible.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_fungible.tz].out index 7f4476b13b1b..3c5c447d53c4 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_fungible.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_fungible.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[mini_scenarios/ticket_builder_fungible.tz] Well typed -Gas remaining: 1039976.245 units remaining +Gas remaining: 1039974.006 units remaining { parameter (or (ticket %burn unit) (pair %mint (contract %destination (ticket unit)) (nat %amount))) ; @@ -40,7 +40,8 @@ Gas remaining: 1039976.245 units remaining UNIT /* [ unit : nat : contract (ticket unit) : address ] */ ; TICKET - /* [ ticket unit : contract (ticket unit) : address ] */ ; + /* [ option (ticket unit) : contract (ticket unit) : address ] */ ; + ASSERT_SOME ; PUSH mutez 0 /* [ mutez : ticket unit : contract (ticket unit) : address ] */ ; SWAP diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_non_fungible.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_non_fungible.tz].out index 8851a7f9e691..1752d084e472 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_non_fungible.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[mini_scenarios--ticket_builder_non_fungible.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[mini_scenarios/ticket_builder_non_fungible.tz] Well typed -Gas remaining: 1039973.758 units remaining +Gas remaining: 1039971.519 units remaining { parameter (or (ticket %burn nat) (contract %mint_destination (ticket nat))) ; storage (pair (address %manager) (nat %counter)) ; code { AMOUNT @@ -35,7 +35,8 @@ Gas remaining: 1039973.758 units remaining DUP @counter 4 /* [ nat : nat : contract (ticket nat) : address : nat ] */ ; TICKET - /* [ ticket nat : contract (ticket nat) : address : nat ] */ ; + /* [ option (ticket nat) : contract (ticket nat) : address : nat ] */ ; + ASSERT_SOME ; PUSH mutez 0 /* [ mutez : ticket nat : contract (ticket nat) : address : nat ] */ ; SWAP diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticket_big_store.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticket_big_store.tz].out index 67cb8462f56c..d6caaeff2bbc 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticket_big_store.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticket_big_store.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[opcodes/ticket_big_store.tz] Well typed -Gas remaining: 1039994.150 units remaining +Gas remaining: 1039991.976 units remaining { parameter nat ; storage (big_map unit (ticket nat)) ; code { UNPAIR @@ -11,7 +11,8 @@ Gas remaining: 1039994.150 units remaining SWAP /* [ nat : nat : big_map unit (ticket nat) ] */ ; TICKET - /* [ ticket nat : big_map unit (ticket nat) ] */ ; + /* [ option (ticket nat) : big_map unit (ticket nat) ] */ ; + ASSERT_SOME ; SOME /* [ option (ticket nat) : big_map unit (ticket nat) ] */ ; UNIT diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer-2.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer-2.tz].out index 94abe47b83a4..58ee20944006 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer-2.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer-2.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[opcodes/ticketer-2.tz] Well typed -Gas remaining: 1039988.434 units remaining +Gas remaining: 1039986.226 units remaining { parameter (pair (pair address nat) nat) ; storage unit ; code { CAR @@ -13,7 +13,7 @@ Gas remaining: 1039988.434 units remaining CONTRACT (ticket nat) /* [ option (contract (ticket nat)) : nat : nat ] */ ; ASSERT_SOME ; - DIP { TICKET /* [ ticket nat ] */ } + DIP { TICKET /* [ option (ticket nat) ] */ ; ASSERT_SOME } /* [ contract (ticket nat) : ticket nat ] */ ; SWAP /* [ ticket nat : contract (ticket nat) ] */ ; diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer.tz].out index 18d9f6cf3ee5..85bbab8acce3 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--ticketer.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[opcodes/ticketer.tz] Well typed -Gas remaining: 1039988.950 units remaining +Gas remaining: 1039986.744 units remaining { parameter address ; storage nat ; code { UNPAIR @@ -15,7 +15,8 @@ Gas remaining: 1039988.950 units remaining SWAP /* [ nat : nat : address : nat ] */ ; TICKET - /* [ ticket nat : address : nat ] */ ; + /* [ option (ticket nat) : address : nat ] */ ; + ASSERT_SOME ; DIP { CONTRACT (ticket nat) /* [ option (contract (ticket nat)) : nat ] */ ; ASSERT_SOME ; diff --git a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--utxor.tz].out b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--utxor.tz].out index 9a04b176993f..2c2adeed4c65 100644 --- a/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--utxor.tz].out +++ b/tests_python/tests_alpha/_regtest_outputs/test_contract.TestTypecheck::test_typecheck[opcodes--utxor.tz].out @@ -1,7 +1,7 @@ tests_alpha/test_contract.py::TestTypecheck::test_typecheck[opcodes/utxor.tz] Well typed -Gas remaining: 1039969.043 units remaining +Gas remaining: 1039966.804 units remaining { parameter (pair address address) ; storage nat ; code { UNPAIR @@ -15,7 +15,8 @@ Gas remaining: 1039969.043 units remaining SWAP /* [ nat : nat : pair address address : nat ] */ ; TICKET - /* [ ticket nat : pair address address : nat ] */ ; + /* [ option (ticket nat) : pair address address : nat ] */ ; + ASSERT_SOME ; PUSH nat 2 /* [ nat : ticket nat : pair address address : nat ] */ ; PUSH nat 3 diff --git a/tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz b/tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz index 4ac4fac5a465..ecea3a4f8c83 100644 --- a/tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz +++ b/tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz @@ -4,6 +4,7 @@ code { CAR; UNPAIR 4; TICKET; + ASSERT_SOME; PAIR; SWAP; CONTRACT %deposit (pair (ticket string) tx_rollup_l2_address); diff --git a/tezt/tests/contracts/proto_current_mainnet/tickets.tz b/tezt/tests/contracts/proto_current_mainnet/tickets.tz index 08adb63dc9d0..febaa100a6df 100644 --- a/tezt/tests/contracts/proto_current_mainnet/tickets.tz +++ b/tezt/tests/contracts/proto_current_mainnet/tickets.tz @@ -1,3 +1,3 @@ parameter unit; storage (list (ticket string)); -code { CDR ; PUSH nat 1 ; PUSH string "Red" ; TICKET ; CONS ; NIL operation; PAIR } +code { CDR ; PUSH nat 1 ; PUSH string "Red" ; TICKET ; ASSERT_SOME ; CONS ; NIL operation; PAIR } diff --git a/tezt/tests/contracts/proto_current_mainnet/tx_rollup_deposit.tz b/tezt/tests/contracts/proto_current_mainnet/tx_rollup_deposit.tz new file mode 100644 index 000000000000..04ad6f727541 --- /dev/null +++ b/tezt/tests/contracts/proto_current_mainnet/tx_rollup_deposit.tz @@ -0,0 +1,20 @@ +parameter (pair string nat tx_rollup_l2_address address); +storage unit; +code { + CAR; + UNPAIR 4; + TICKET; + PAIR; + SWAP; + CONTRACT %deposit (pair (ticket string) tx_rollup_l2_address); + ASSERT_SOME; + SWAP; + PUSH mutez 0; + SWAP; + TRANSFER_TOKENS; + UNIT; + NIL operation; + DIG 2; + CONS; + PAIR; + } diff --git a/tezt/tests/iticket_migration.ml b/tezt/tests/iticket_migration.ml new file mode 100644 index 000000000000..da69814577a7 --- /dev/null +++ b/tezt/tests/iticket_migration.ml @@ -0,0 +1,565 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Marigold *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +(* Testing + ------- + Component: Protocol + Invocation: dune exec tezt/tests/main.exe -- --file iticket_migration.ml + Subject: Checks the migration of ITicket in protocol Alpha, to make sure + that the old TICKET instruction is mapped to TICKET_DEPRECATED, + and the old contracts continue to function provided that they + avoid creating zero tickets. +*) + +(* This test originates a contract that creates a zero ticket with the old TICKET + instruction, performs a protocol upgrade and inspect the script to make sure + TICKET is mapped to TICKET_DEPRECATED. It also calls this contract which does + not mitigate creation of zero tickets and this call should fail. +*) +let test_ticket_migration ~blocks_per_cycle ~migration_level ~migrate_from + ~migrate_to = + Test.register + ~__FILE__ + ~title: + (Printf.sprintf + "ITicket migration at level %d from %s to %s" + migration_level + (Protocol.name migrate_from) + (Protocol.name migrate_to)) + ~tags:["protocol"; "migration"; "sandbox"] + @@ fun () -> + assert (migration_level >= blocks_per_cycle) ; + Log.info "Node starting" ; + let* node = + Node.init + ~patch_config: + (Node.Config_file.set_sandbox_network_with_user_activated_upgrades + [(migration_level, migrate_to)]) + [Synchronisation_threshold 0; Connections 0] + in + Log.info "Node initialized" ; + let* client = Client.(init ~endpoint:(Node node) ()) in + let* () = Client.activate_protocol ~protocol:migrate_from client in + Log.info "Protocol activated" ; + let* contract_id = + Client.( + originate_contract + ~init:"Unit" + ~burn_cap:Tez.one + ~alias:"ticket" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~prg: + {| + storage unit; + parameter unit; + code + { + DROP; + PUSH nat 0; + PUSH string "hello"; + TICKET; + DROP; + UNIT; + NIL operation; + PAIR + } + |} + client) + in + Log.info "Contract %s originated" contract_id ; + (* Bake until migration *) + let* () = repeat 2 (fun () -> Client.bake_for_and_wait client) in + let* code_before = + Client.(contract_code ~unparsing_mode:Optimized) contract_id client + in + Log.info "code: %s" code_before ; + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~arg:"Unit" + client + in + (* Ensure that we did migrate *) + let* migration_block = + RPC.Client.call client @@ RPC.get_chain_block_metadata ~block:"2" () + in + Log.info "Checking migration block consistency" ; + Check.( + (migration_block.protocol = Protocol.hash migrate_from) + string + ~error_msg:"expected protocol = %R, got %L") ; + Check.( + (migration_block.next_protocol = Protocol.hash migrate_from) + string + ~error_msg:"expected next_protocol = %R, got %L") ; + (* Test that we can still bake after migration *) + let rec wait_for_migration_block () = + let* () = Client.bake_for_and_wait client in + let* migration_block = + RPC.(Client.call client @@ get_chain_block_header ()) + in + let level = JSON.(migration_block |-> "level" |> as_int) in + if level >= migration_level then + RPC.( + Client.call client + @@ get_chain_block_metadata ~block:(string_of_int level) ()) + else wait_for_migration_block () + in + let* migration_block = wait_for_migration_block () in + Log.info + "protocol: %s, next_protocol: %s" + migration_block.protocol + migration_block.next_protocol ; + (* Bake one more time to complete the protocol upgrade *) + let* () = Client.bake_for_and_wait client in + let* code_after = + Client.(contract_code ~unparsing_mode:Optimized) contract_id client + in + Log.info "code: %s" code_after ; + Check.( + (code_after =~ rex "\\bTICKET_DEPRECATED\\s*;") + ~error_msg:"expecting TICKET_DEPRECATED instruction, got code %L") ; + (* This transfer is now expected to fail because the contract produces a zero + amount ticket. *) + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~arg:"Unit" + ~expect_failure:true + client + in + unit + +(* This test originates a contract that creates, extracts and splits tickets in storage. + It then performs a protocol upgrade and calls the contract again to ensure it is + still functioning. +*) +let test_ticket_migration_in_storage_with_zero_tickets ~blocks_per_cycle + ~migration_level ~migrate_from ~migrate_to = + Test.register + ~__FILE__ + ~title: + (Printf.sprintf + "ITicket migration at level %d with zero ticket in storage" + migration_level) + ~tags:["protocol"; "migration"; "sandbox"] + @@ fun () -> + assert (migration_level >= blocks_per_cycle) ; + Log.info "Node starting" ; + let* node = + Node.init + ~patch_config: + (Node.Config_file.set_sandbox_network_with_user_activated_upgrades + [(migration_level, migrate_to)]) + [Synchronisation_threshold 0; Connections 0] + in + Log.info "Node initialized" ; + let* client = Client.(init ~endpoint:(Node node) ()) in + let* () = Client.activate_protocol ~protocol:migrate_from client in + Log.info "Protocol activated" ; + let* contract_id = + Client.( + originate_contract + ~init:"{}" + ~burn_cap:Tez.one + ~alias:"ticket" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~prg: + {| + storage (list (ticket string)); + parameter (or (unit %push) (unit %pop)); + code + { + UNPAIR; + IF_LEFT + { + DROP; + # forge a ticket of amount 4 + PUSH nat 0; + PUSH string "hello"; + TICKET; + CONS; + } + { + DROP; + # decrement the ticket at the stack top by 1 + IF_CONS + { DROP } + { PUSH string "empty stack"; FAILWITH } + }; + NIL operation; + PAIR + } + |} + client) + in + Log.info "Contract %s originated" contract_id ; + (* Bake until migration *) + let* () = repeat 2 (fun () -> Client.bake_for_and_wait client) in + let* code_before = + Client.(contract_code ~unparsing_mode:Optimized) contract_id client + in + Log.info "code: %s" code_before ; + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~entrypoint:"push" + ~arg:"Unit" + client + in + (* Ensure that we did migrate *) + let* migration_block = + RPC.Client.call client @@ RPC.get_chain_block_metadata ~block:"2" () + in + Log.info "Checking migration block consistency" ; + Check.( + (migration_block.protocol = Protocol.hash migrate_from) + string + ~error_msg:"expected protocol = %R, got %L") ; + Check.( + (migration_block.next_protocol = Protocol.hash migrate_from) + string + ~error_msg:"expected next_protocol = %R, got %L") ; + (* Test that we can still bake after migration *) + let rec wait_for_migration_block () = + let* () = Client.bake_for_and_wait client in + let* migration_block = + RPC.(Client.call client @@ get_chain_block_header ()) + in + let level = JSON.(migration_block |-> "level" |> as_int) in + if level >= migration_level then + RPC.( + Client.call client + @@ get_chain_block_metadata ~block:(string_of_int level) ()) + else wait_for_migration_block () + in + let* migration_block = wait_for_migration_block () in + Log.info + "protocol: %s, next_protocol: %s" + migration_block.protocol + migration_block.next_protocol ; + (* Bake one more time to complete the protocol upgrade *) + let* () = Client.bake_for_and_wait client in + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~entrypoint:"pop" + ~expect_failure:true + ~arg:"Unit" + client + in + unit + +(* This test originates a contract that creates, extracts and splits tickets in storage. + It then performs a protocol upgrade and calls the contract again to ensure it is + still functioning. +*) +let test_ticket_migration_in_storage ~blocks_per_cycle ~migration_level + ~migrate_from ~migrate_to = + Test.register + ~__FILE__ + ~title:(Printf.sprintf "ITicket migration at level %d" migration_level) + ~tags:["protocol"; "migration"; "sandbox"] + @@ fun () -> + assert (migration_level >= blocks_per_cycle) ; + Log.info "Node starting" ; + let* node = + Node.init + ~patch_config: + (Node.Config_file.set_sandbox_network_with_user_activated_upgrades + [(migration_level, migrate_to)]) + [Synchronisation_threshold 0; Connections 0] + in + Log.info "Node initialized" ; + let* client = Client.(init ~endpoint:(Node node) ()) in + let* () = Client.activate_protocol ~protocol:migrate_from client in + Log.info "Protocol activated" ; + let* contract_id = + Client.( + originate_contract + ~init:"{}" + ~burn_cap:Tez.one + ~alias:"ticket" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~prg: + {| + storage (list (ticket string)); + parameter (or (unit %forge) (unit %split)); + code + { + UNPAIR; + IF_LEFT + { + DROP; + # forge a ticket of amount 4 + PUSH nat 4; + PUSH string "hello"; + TICKET; + CONS; + } + { + DROP; + # decrement the ticket at the stack top by 1 + IF_CONS + { + READ_TICKET; + GET 4; + PUSH nat 1; + SWAP; + SUB; + DUP; + # drop the ticket if it will go down to 0 + EQ; + IF + { DROP 2 } + { + ISNAT; + ASSERT_SOME; + PUSH nat 1; + PAIR; + SWAP; + SPLIT_TICKET; + ASSERT_SOME; + CDR; + CONS + } + } + { PUSH string "empty stack"; FAILWITH } + }; + NIL operation; + PAIR + } + |} + client) + in + Log.info "Contract %s originated" contract_id ; + (* Bake until migration *) + let* () = repeat 2 (fun () -> Client.bake_for_and_wait client) in + let* code_before = + Client.(contract_code ~unparsing_mode:Optimized) contract_id client + in + Log.info "code: %s" code_before ; + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~entrypoint:"forge" + ~arg:"Unit" + client + in + (* Ensure that we did migrate *) + let* migration_block = + RPC.Client.call client @@ RPC.get_chain_block_metadata ~block:"2" () + in + Log.info "Checking migration block consistency" ; + Check.( + (migration_block.protocol = Protocol.hash migrate_from) + string + ~error_msg:"expected protocol = %R, got %L") ; + Check.( + (migration_block.next_protocol = Protocol.hash migrate_from) + string + ~error_msg:"expected next_protocol = %R, got %L") ; + (* Test that we can still bake after migration *) + let rec wait_for_migration_block () = + let* () = Client.bake_for_and_wait client in + let* migration_block = + RPC.(Client.call client @@ get_chain_block_header ()) + in + let level = JSON.(migration_block |-> "level" |> as_int) in + if level >= migration_level then + RPC.( + Client.call client + @@ get_chain_block_metadata ~block:(string_of_int level) ()) + else wait_for_migration_block () + in + let* migration_block = wait_for_migration_block () in + Log.info + "protocol: %s, next_protocol: %s" + migration_block.protocol + migration_block.next_protocol ; + (* Bake one more time to complete the protocol upgrade *) + let* () = Client.bake_for_and_wait client in + let* code_after = + Client.(contract_code ~unparsing_mode:Optimized) contract_id client + in + Log.info "code: %s" code_after ; + Check.( + (code_after =~ rex "\\bTICKET_DEPRECATED\\s*;") + ~error_msg:"expecting TICKET_DEPRECATED instruction, got code %L") ; + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~entrypoint:"forge" + ~arg:"Unit" + client + in + let* () = Client.bake_for_and_wait client in + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~entrypoint:"split" + ~arg:"Unit" + client + in + unit + +(* This test activates Alpha protocol and asserts that it is impossible to + originate contracts containing the deprecated TICKET instruction. +*) +let test_iticket_deprecation ~protocol = + Test.register + ~__FILE__ + ~title:(Printf.sprintf "ITicket deprecation") + ~tags:["protocol"; "migration"; "sandbox"] + @@ fun () -> + let* _, client = Client.init_with_protocol `Client ~protocol () in + let* _ = Client.gen_and_show_keys client in + let process = + Client.( + spawn_originate_contract + ~init:"Unit" + ~burn_cap:Tez.one + ~alias:"ticket" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~log_output:true + ~prg: + {| + storage unit; + parameter unit; + code + { + DROP; + PUSH nat 0; + PUSH string "hello"; + TICKET_DEPRECATED; + DROP; + UNIT; + NIL operation; + PAIR + } + |} + client) + in + Process.check_error + ~msg:(rex "Use of deprecated instruction: TICKET_DEPRECATED") + process + +(* This test checks that after migration, the new ITicket instruction pushes + an option, and it correctly pushes some ticket if the ticket is well-formed.*) +let test_iticket_after_migration ~protocol = + Test.register + ~__FILE__ + ~title:(Printf.sprintf "ITicket semantics after migration") + ~tags:["protocol"; "migration"; "sandbox"] + @@ fun () -> + let* _, client = Client.init_with_protocol `Client ~protocol () in + let* _ = Client.gen_and_show_keys client in + let* contract_id = + Client.( + originate_contract + ~init:"{}" + ~burn_cap:Tez.one + ~alias:"ticket" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~prg: + {| + storage (list (ticket string)); + parameter unit; + code + { + CDR; + PUSH nat 1; + PUSH string "hello"; + TICKET; + ASSERT_SOME; + CONS; + NIL operation; + PAIR + } + |} + client) + in + let* () = Client.bake_for_and_wait client in + let* () = + Client.transfer + ~burn_cap:Tez.one + ~amount:Tez.zero + ~giver:Constant.bootstrap1.alias + ~receiver:contract_id + ~arg:"Unit" + client + in + unit + +let register ~migrate_from ~migrate_to = + let parameters = JSON.parse_file (Protocol.parameter_file migrate_to) in + let blocks_per_cycle = JSON.(get "blocks_per_cycle" parameters |> as_int) in + match migrate_to with + | Protocol.Alpha -> + (* test_ticket_migration + ~blocks_per_cycle + ~migration_level:(2 * blocks_per_cycle) + ~migrate_from + ~migrate_to ; + test_iticket_deprecation ~protocol:Protocol.Alpha ; + test_ticket_migration_in_storage + ~blocks_per_cycle + ~migration_level:(2 * blocks_per_cycle) + ~migrate_from + ~migrate_to ; *) + test_ticket_migration_in_storage_with_zero_tickets + ~blocks_per_cycle + ~migration_level:(2 * blocks_per_cycle) + ~migrate_from + ~migrate_to + (* ; + test_iticket_after_migration ~protocol:Protocol.Alpha *) + | _ -> () diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index e1368643c4de..05e79ecf4db9 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -79,7 +79,8 @@ let register_protocol_migration_tests () = Voting.register ~from_protocol:migrate_to ~to_protocol:Demo - ~loser_protocols:[migrate_from] + ~loser_protocols:[migrate_from] ; + Iticket_migration.register ~migrate_from ~migrate_to let register_protocol_agnostic_tests () = (* Tests that are relatively protocol-agnostic. diff --git a/tezt/tests/tx_rollup.ml b/tezt/tests/tx_rollup.ml index 034cdfd4a6d1..938547c0cf6a 100644 --- a/tezt/tests/tx_rollup.ml +++ b/tezt/tests/tx_rollup.ml @@ -1542,7 +1542,12 @@ let test_deposit_withdraw_max_big_tickets = ~alias:"deposit_contract" ~amount:Tez.zero ~src:account - ~prg:"file:./tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz" + ~prg: + (match protocol with + | Alpha -> + "file:./tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz" + | _ -> + "file:./tezt/tests/contracts/proto_current_mainnet/tx_rollup_deposit.tz") ~init:"Unit" ~burn_cap:Tez.one client diff --git a/tezt/tests/tx_rollup_l2_node.ml b/tezt/tests/tx_rollup_l2_node.ml index 8f974039fcb5..1c77a03d42c0 100644 --- a/tezt/tests/tx_rollup_l2_node.ml +++ b/tezt/tests/tx_rollup_l2_node.ml @@ -26,7 +26,7 @@ (* Testing ------- Component: Tx_rollup_node - Invocation: dune exec tezt/tests/main.exe -- --file tx_rollup_node.ml + Invocation: dune exec tezt/tests/main.exe -- --file tx_rollup_l2_node.ml Subject: Various test scenarios for the Tx rollup node *) @@ -846,6 +846,13 @@ let get_ticket_hash_from_deposit (d : Tx_rollup_node.Inbox.message) : string = let get_ticket_hash_from_deposit_json inbox = JSON.(inbox |=> 0 |-> "message" |-> "deposit" |-> "ticket_hash" |> as_string) +let choose_deposit_contract_by_protocol ~protocol = + match protocol with + | Protocol.Alpha -> + "file:./tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz" + | _ -> + "file:./tezt/tests/contracts/proto_current_mainnet/tx_rollup_deposit.tz" + (* Checks that the a ticket can be transfered from the L1 to the rollup. *) let test_ticket_deposit_from_l1_to_l2 = Protocol.register_test @@ -872,7 +879,7 @@ let test_ticket_deposit_from_l1_to_l2 = ~alias:"rollup_deposit" ~amount:Tez.zero ~src:"bootstrap1" - ~prg:"file:./tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz" + ~prg:(choose_deposit_contract_by_protocol ~protocol) ~init:"Unit" ~burn_cap:Tez.(of_int 1) client @@ -1039,7 +1046,7 @@ let test_l2_to_l2_transaction = ~alias:"rollup_deposit" ~amount:Tez.zero ~src:"bootstrap1" - ~prg:"file:./tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz" + ~prg:(choose_deposit_contract_by_protocol ~protocol) ~init:"Unit" ~burn_cap:Tez.(of_int 1) client @@ -1241,14 +1248,14 @@ let get_ticket_hash_from_op op = (** Originate a contract and make a deposit for [dest] and optionally for a list of destination in [dests]. *) -let make_deposit ~source ~tx_rollup_hash ~tx_node ~client ?(dests = []) - ~tickets_amount dest = +let make_deposit ~protocol ~source ~tx_rollup_hash ~tx_node ~client + ?(dests = []) ~tickets_amount dest = let* contract_id = Client.originate_contract ~alias:"rollup_deposit" ~amount:Tez.zero ~src:source - ~prg:"file:./tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz" + ~prg:(choose_deposit_contract_by_protocol ~protocol) ~init:"Unit" ~burn_cap:Tez.(of_int 1) client @@ -1332,6 +1339,7 @@ let test_batcher ~test_persistence = let bls_pkh_2 = bls_key_2.aggregate_public_key_hash in let* _level, _contract_id = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -1582,6 +1590,7 @@ let test_reorganization = let bls_pkh_2 = bls_key_2.aggregate_public_key_hash in let* _level, _contract_id = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -1701,6 +1710,7 @@ let test_l2_proof_rpc_position = let bls_pkh_2 = bls_key_2.aggregate_public_key_hash in let* _level, _contract_id = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -1905,6 +1915,7 @@ let test_reject_bad_commitment = let pkh1_str = bls_key1.aggregate_public_key_hash in let* _level, _contract_id = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2015,6 +2026,7 @@ let test_committer = let bls_pkh_2 = bls_key_2.aggregate_public_key_hash in let* tzlevel, _ = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2135,6 +2147,7 @@ let test_tickets_context = let bls_pkh_2 = bls_key_2.aggregate_public_key_hash in let* _level, contract_id = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2268,6 +2281,7 @@ let test_round_trip ~title ?before_init ~originator ~operator ~batch_signer let bls_pkh_2 = bls_key_2.aggregate_public_key_hash in let* _level, deposit_contract = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2482,6 +2496,7 @@ let test_accuser = let bls_pkh_1 = bls_key_1.aggregate_public_key_hash in let* _level, _deposit_contract = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2610,6 +2625,7 @@ let test_transfer_command = let* bls_key_2 = Client.bls_gen_and_show_keys client in let* _level, _contract_id = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2677,6 +2693,7 @@ let test_withdraw_command = let* bls_key_1 = Client.bls_gen_and_show_keys client in let* _level, _contract_id = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2753,6 +2770,7 @@ let test_catch_up = let bls_pkh_2 = bls_key_2.aggregate_public_key_hash in let* tzlevel, _deposit_contract = make_deposit + ~protocol ~source:Constant.bootstrap2.public_key_hash ~tx_rollup_hash ~tx_node @@ -2831,7 +2849,7 @@ let test_origination_deposit_same_block = ~alias:"rollup_deposit" ~amount:Tez.zero ~src:"bootstrap1" - ~prg:"file:./tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz" + ~prg:(choose_deposit_contract_by_protocol ~protocol) ~init:"Unit" ~burn_cap:Tez.(of_int 1) client -- GitLab From 61646fea8c8d5d4ce1934dea11991eb0150a2902 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Mon, 5 Sep 2022 14:39:40 +0800 Subject: [PATCH 5/8] Proto: adapt types to ensure zero tickets are impossible to parse --- .../lib_benchmark/michelson_samplers.ml | 7 +- .../interpreter_benchmarks.ml | 19 +- .../interpreter_workload.ml | 4 +- .../lib_benchmarks_proto/ticket_benchmarks.ml | 6 +- src/proto_alpha/lib_protocol/apply.ml | 26 ++- .../lib_protocol/michelson_v1_gas.ml | 4 +- .../lib_protocol/michelson_v1_gas.mli | 5 +- .../lib_protocol/sc_rollup_operations.ml | 5 +- .../lib_protocol/script_interpreter.ml | 45 ++-- .../lib_protocol/script_ir_translator.ml | 11 +- .../lib_protocol/script_ir_unparser.ml | 2 +- .../lib_protocol/script_tc_errors.ml | 2 + .../script_tc_errors_registration.ml | 9 + .../lib_protocol/script_typed_ir.ml | 22 +- .../lib_protocol/script_typed_ir.mli | 18 +- .../lib_protocol/script_typed_ir_size.ml | 4 +- .../michelson/test_ticket_accounting.ml | 5 +- .../michelson/test_ticket_manager.ml | 2 +- .../michelson/test_ticket_operations_diff.ml | 197 ++++++++++-------- .../michelson/test_ticket_scanner.ml | 39 ++-- .../integration/operations/test_sc_rollup.ml | 31 ++- .../test_sc_rollup_management_protocol.ml | 5 +- .../lib_protocol/ticket_accounting.ml | 10 +- .../lib_protocol/ticket_lazy_storage_diff.ml | 2 +- .../lib_protocol/ticket_operations_diff.ml | 26 ++- .../lib_protocol/ticket_operations_diff.mli | 2 +- .../lib_protocol/ticket_scanner.ml | 18 +- .../lib_protocol/ticket_scanner.mli | 2 - src/proto_alpha/lib_protocol/ticket_token.mli | 2 +- .../lib_protocol/tx_rollup_ticket.ml | 14 +- .../lib_protocol/tx_rollup_ticket.mli | 6 +- 31 files changed, 338 insertions(+), 212 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index f36ab8c661e0..2ce41a3d1add 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -803,7 +803,12 @@ end) let ticketer = Alpha_context.Contract.Implicit (Crypto_samplers.pkh rng_state) in - let amount = Michelson_base.nat rng_state in + let amount = + let open Script_typed_ir.Ticket_amount in + match of_n (Michelson_base.nat rng_state) with + | Some amount -> add amount one + | None -> one + in Script_typed_ir.{ticketer; contents; amount} let comparable ty = value ty diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index cb9c98c540df..e6b40fe3e3e7 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -2848,7 +2848,7 @@ module Registration_section = struct Alpha_context.Contract.Implicit Environment.Signature.Public_key_hash.zero; contents = (); - amount = zero; + amount = Script_typed_ir.Ticket_amount.one; } in benchmark_with_fixed_stack @@ -2869,6 +2869,13 @@ module Registration_section = struct fun () -> let half_amount = Samplers.Random_value.value nat rng_state in let amount = Script_int.add_n half_amount half_amount in + let amount = + let open Script_typed_ir.Ticket_amount in + let two = add one one in + match of_n amount with + | Some amount -> add two amount + | None -> add one one + in let ticket = Samplers.Random_value.value (ticket unit) rng_state in let ticket = {ticket with amount} in Ex_stack_and_kinstr @@ -2903,7 +2910,7 @@ module Registration_section = struct { ticket with contents = Script_string.empty; - amount = Script_int.zero_n; + amount = Script_typed_ir.Ticket_amount.one; } in Ex_stack_and_kinstr @@ -2925,7 +2932,13 @@ module Registration_section = struct let ticket = Samplers.Random_value.value (ticket string) rng_state in - let alt_amount = Samplers.Random_value.value nat rng_state in + let alt_amount = + let amount = Samplers.Random_value.value nat rng_state in + let open Script_typed_ir.Ticket_amount in + match of_n amount with + | Some amount -> add amount one + | None -> one + in let ticket' = {ticket with amount = alt_amount} in Ex_stack_and_kinstr { diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml index 0721772f1894..a2826fa847bf 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_workload.ml @@ -1425,8 +1425,8 @@ let extract_ir_sized_step : | IJoin_tickets (_, cmp_ty, _), ((ticket1, ticket2), _) -> let size1 = Size.size_of_comparable_value cmp_ty ticket1.contents in let size2 = Size.size_of_comparable_value cmp_ty ticket2.contents in - let tez1 = Size.integer ticket1.amount in - let tez2 = Size.integer ticket2.amount in + let tez1 = Size.integer (ticket1.amount :> Script_int.n Script_int.num) in + let tez2 = Size.integer (ticket2.amount :> Script_int.n Script_int.num) in Instructions.join_tickets size1 size2 tez1 tez2 | IHalt _, _ -> Instructions.halt | ILog _, _ -> Instructions.log diff --git a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml index 0796b2bb5b34..fb953f23f0b0 100644 --- a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml @@ -251,7 +251,11 @@ let ticket_sampler rng_state = let pkh, _, _ = Signature.generate_key ~algo:Signature.Ed25519 ~seed () in let ticketer = Alpha_context.Contract.Implicit pkh in Script_typed_ir. - {ticketer; contents = Script_int.zero; amount = Script_int.one_n} + { + ticketer; + contents = Script_int.zero; + amount = Script_typed_ir.Ticket_amount.one; + } (** A benchmark for {!Ticket_costs.Constants.cost_collect_tickets_step}. *) module Collect_tickets_benchmark : Benchmark.S = struct diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 44b611db0d48..416ae54cc999 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -470,11 +470,13 @@ let apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters ~payer Option.value_e ~error: (Error_monad.trace_of_error Tx_rollup_invalid_transaction_ticket_amount) - (Option.bind (Script_int.to_int64 ticket_amount) Tx_rollup_l2_qty.of_int64) + (Option.bind + (Script_int.to_int64 (ticket_amount :> Script_int.n Script_int.num)) + Tx_rollup_l2_qty.of_int64) >>?= fun ticket_amount -> error_when Tx_rollup_l2_qty.(ticket_amount <= zero) - Ticket_scanner.Forbidden_zero_ticket_quantity + Script_tc_errors.Forbidden_zero_ticket_quantity >>?= fun () -> let deposit, message_size = Tx_rollup_message.make_deposit @@ -820,7 +822,7 @@ let apply_manager_operation : Tx_rollup_reveal.{contents; ty; ticketer; amount; claimer} -> error_when Tx_rollup_l2_qty.(amount <= zero) - Ticket_scanner.Forbidden_zero_ticket_quantity + Script_tc_errors.Forbidden_zero_ticket_quantity >>?= fun () -> Tx_rollup_ticket.parse_ticket ~consume_deserialization_gas @@ -860,7 +862,13 @@ let apply_manager_operation : ( Tx_rollup_withdraw. {claimer; amount; ticket_hash = tx_rollup_ticket_hash}, ticket_token ) = - let amount = Tx_rollup_l2_qty.to_z amount in + Script_typed_ir.Ticket_amount.of_z + @@ Script_int.of_zint (Tx_rollup_l2_qty.to_z amount) + |> Option.value_e + ~error: + (Error_monad.trace_of_error + Script_tc_errors.Forbidden_zero_ticket_quantity) + >>?= fun amount -> Ticket_balance_key.of_ex_token ctxt ~owner:(Contract (Contract.Implicit claimer)) @@ -891,10 +899,12 @@ let apply_manager_operation : -> ( (* The encoding ensures that the amount is in a natural number. Here is mainly to check that it is non-zero.*) - error_when - Compare.Z.(amount <= Z.zero) - Ticket_scanner.Forbidden_zero_ticket_quantity - >>?= fun () -> + Option.value_e + ~error: + (Error_monad.trace_of_error + Script_tc_errors.Forbidden_zero_ticket_quantity) + @@ Script_typed_ir.Ticket_amount.of_z (Script_int.of_zint amount) + >>?= fun amount -> match destination with | Implicit _ -> fail Cannot_transfer_ticket_to_implicit | Originated destination_hash -> diff --git a/src/proto_alpha/lib_protocol/michelson_v1_gas.ml b/src/proto_alpha/lib_protocol/michelson_v1_gas.ml index 6a578209dcea..92f5b0bcb210 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_gas.ml +++ b/src/proto_alpha/lib_protocol/michelson_v1_gas.ml @@ -1509,7 +1509,9 @@ module Cost_of = struct in Gas.( contents_comparison +@ compare_address - +@ add_nat ticket_a.amount ticket_b.amount) + +@ add_nat + (ticket_a.amount :> Script_int.n Script_int.num) + (ticket_b.amount :> Script_int.n Script_int.num)) let emit = atomic_step_cost cost_N_IEmit diff --git a/src/proto_alpha/lib_protocol/michelson_v1_gas.mli b/src/proto_alpha/lib_protocol/michelson_v1_gas.mli index f799d7d55640..9a06aacfc629 100644 --- a/src/proto_alpha/lib_protocol/michelson_v1_gas.mli +++ b/src/proto_alpha/lib_protocol/michelson_v1_gas.mli @@ -351,7 +351,10 @@ module Cost_of : sig val read_ticket : Gas.cost val split_ticket : - 'a Script_int.num -> 'a Script_int.num -> 'a Script_int.num -> Gas.cost + Script_typed_ir.ticket_amount -> + 'a Script_int.num -> + 'a Script_int.num -> + Gas.cost val join_tickets : 'a Script_typed_ir.comparable_ty -> diff --git a/src/proto_alpha/lib_protocol/sc_rollup_operations.ml b/src/proto_alpha/lib_protocol/sc_rollup_operations.ml index e639c91c33d0..792969484142 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_operations.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_operations.ml @@ -339,13 +339,14 @@ let transfer_ticket_tokens ctxt ~source_destination ~acc_storage_diff {Ticket_operations_diff.ticket_token; total_amount = _; destinations} = let open Lwt_tzresult_syntax in List.fold_left_es - (fun (acc_storage_diff, ctxt) (target_destination, amount) -> + (fun (acc_storage_diff, ctxt) + (target_destination, (amount : Script_typed_ir.ticket_amount)) -> let* storage_diff, ctxt = transfer_ticket_token ctxt ~source_destination ~target_destination - ~amount:(Script_int.to_zint amount) + ~amount:Script_int.(to_zint (amount :> n num)) ticket_token in return (Z.(add acc_storage_diff storage_diff), ctxt)) diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 44ebf43376aa..149e559d844a 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1489,37 +1489,44 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let accu = aux witness stack in (step [@ocaml.tailcall]) g gas k ks accu stack (* Tickets *) - | ITicket_deprecated (loc, _, k) -> + | ITicket_deprecated (_, _, k) -> let contents = accu and amount, stack = stack in - if Compare.Int.(Script_int.(compare amount zero_n) = 0) then - fail (Ticket_amount_zero loc) - else - let ticketer = Contract.Originated sc.self in - let accu = {ticketer; contents; amount} in - (step [@ocaml.tailcall]) g gas k ks accu stack - | ITicket (_, _, k) -> + Option.value_e + ~error: + (Error_monad.trace_of_error + Script_tc_errors.Forbidden_zero_ticket_quantity) + @@ Script_typed_ir.Ticket_amount.of_n amount + >>?= fun amount -> + let ticketer = Contract.Originated sc.self in + let accu = {ticketer; contents; amount} in + (step [@ocaml.tailcall]) g gas k ks accu stack + | ITicket (_, _, k) -> ( let contents = accu and amount, stack = stack in - if Compare.Int.(Script_int.(compare amount zero_n) = 0) then - (step [@ocaml.tailcall]) g gas k ks None stack - else - let ticketer = Contract.Originated sc.self in - let accu = Some {ticketer; contents; amount} in - (step [@ocaml.tailcall]) g gas k ks accu stack + match Script_typed_ir.Ticket_amount.of_n amount with + | Some amount -> + let ticketer = Contract.Originated sc.self in + let accu = Some {ticketer; contents; amount} in + (step [@ocaml.tailcall]) g gas k ks accu stack + | None -> (step [@ocaml.tailcall]) g gas k ks None stack) | IRead_ticket (_, _, k) -> let {ticketer; contents; amount} = accu in let stack = (accu, stack) in let destination : Destination.t = Contract ticketer in let addr = {destination; entrypoint = Entrypoint.default} in - let accu = (addr, (contents, amount)) in + let accu = + (addr, (contents, (amount :> Script_int.n Script_int.num))) + in (step [@ocaml.tailcall]) g gas k ks accu stack | ISplit_ticket (_, k) -> let ticket = accu and (amount_a, amount_b), stack = stack in let result = + Option.bind (Ticket_amount.of_n amount_a) @@ fun amount_a -> + Option.bind (Ticket_amount.of_n amount_b) @@ fun amount_b -> + let amount = Ticket_amount.add amount_a amount_b in if Compare.Int.( - Script_int.(compare (add_n amount_a amount_b) ticket.amount) = 0) - && Compare.Int.(Script_int.(compare amount_a zero_n) > 0) - && Compare.Int.(Script_int.(compare amount_b zero_n) > 0) + Script_int.(compare (amount :> n num) (ticket.amount :> n num)) + = 0) then Some ( {ticket with amount = amount_a}, @@ -1543,7 +1550,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = { ticketer = ticket_a.ticketer; contents = ticket_a.contents; - amount = Script_int.add_n ticket_a.amount ticket_b.amount; + amount = Ticket_amount.add ticket_a.amount ticket_b.amount; } else None in diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 0b9166cd0bde..4f987a86ea9e 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -2109,10 +2109,13 @@ let rec parse_data : opened_ticket_type (location expr) t >>?= fun ty -> non_terminal_recursion ctxt ty expr >>=? fun (({destination; entrypoint = _}, (contents, amount)), ctxt) -> - match destination with - | Contract ticketer -> return ({ticketer; contents; amount}, ctxt) - | Tx_rollup _ | Sc_rollup _ -> - fail (Unexpected_ticket_owner destination) + match Ticket_amount.of_n amount with + | Some amount -> ( + match destination with + | Contract ticketer -> return ({ticketer; contents; amount}, ctxt) + | Tx_rollup _ | Sc_rollup _ -> + fail (Unexpected_ticket_owner destination)) + | None -> traced_fail Forbidden_zero_ticket_quantity else traced_fail (Unexpected_forged_value (location expr)) (* Sets *) | Set_t (t, _ty_name), (Seq (loc, vs) as expr) -> diff --git a/src/proto_alpha/lib_protocol/script_ir_unparser.ml b/src/proto_alpha/lib_protocol/script_ir_unparser.ml index ef40e260e1d7..37300a1c0195 100644 --- a/src/proto_alpha/lib_protocol/script_ir_unparser.ml +++ b/src/proto_alpha/lib_protocol/script_ir_unparser.ml @@ -544,7 +544,7 @@ module Data_unparser (P : MICHELSON_PARSER) = struct ~stack_depth mode t - (addr, (contents, amount)) + (addr, (contents, (amount :> Script_int.n Script_int.num))) | Set_t (t, _), set -> List.fold_left_es (fun (l, ctxt) item -> diff --git a/src/proto_alpha/lib_protocol/script_tc_errors.ml b/src/proto_alpha/lib_protocol/script_tc_errors.ml index 1f0c39d222b8..ba465e11c333 100644 --- a/src/proto_alpha/lib_protocol/script_tc_errors.ml +++ b/src/proto_alpha/lib_protocol/script_tc_errors.ml @@ -74,6 +74,8 @@ type error += Tx_rollup_bad_deposit_parameter of Script.location * Script.expr type error += Tx_rollup_invalid_ticket_amount of Z.t +type error += Forbidden_zero_ticket_quantity + type error += Tx_rollup_addresses_disabled of Script.location (* Smart-contract rollup errors *) diff --git a/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml b/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml index 70b586a528ed..3b873c9f6406 100644 --- a/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml +++ b/src/proto_alpha/lib_protocol/script_tc_errors_registration.ml @@ -254,6 +254,15 @@ let () = (obj1 (req "requested_value" Data_encoding.z)) (function Tx_rollup_invalid_ticket_amount z -> Some z | _ -> None) (fun z -> Tx_rollup_invalid_ticket_amount z) ; + register_error_kind + `Permanent + ~id:"michelson_v1.forbidden_zero_amount_ticket" + ~title:"Zero ticket amount is not allowed" + ~description: + "It is not allowed to use a zero amount ticket in this operation." + Data_encoding.empty + (function Forbidden_zero_ticket_quantity -> Some () | _ -> None) + (fun () -> Forbidden_zero_ticket_quantity) ; (* Tx rollup addresses disabled *) register_error_kind `Permanent diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 0d4af45f03ca..de99a3ecb9b5 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -217,7 +217,27 @@ module Script_timelock = struct let get_plaintext_size (Chest_tag x) = Timelock.get_plaintext_size x end -type 'a ticket = {ticketer : Contract.t; contents : 'a; amount : n num} +module Ticket_amount = struct + type t = n num + + let of_n n = + if Compare.Int.(Script_int.(compare n zero_n) > 0) then Some (n : t) + else None + + open Script_int + + let of_z z = Option.bind (is_nat z) of_n + + let add a b = add_n a b + + let sub a b = of_z @@ sub a b + + let one = one_n +end + +type ticket_amount = Ticket_amount.t + +type 'a ticket = {ticketer : Contract.t; contents : 'a; amount : ticket_amount} module type TYPE_SIZE = sig (* A type size represents the size of its type parameter. diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index cbaf6f5855a0..966659122b73 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -167,7 +167,23 @@ module Script_timelock : sig val get_plaintext_size : chest -> int end -type 'a ticket = {ticketer : Contract.t; contents : 'a; amount : n num} +module Ticket_amount : sig + type t = private n num + + val of_n : n num -> t option + + val of_z : z num -> t option + + val add : t -> t -> t + + val sub : t -> t -> t option + + val one : t +end + +type ticket_amount = Ticket_amount.t + +type 'a ticket = {ticketer : Contract.t; contents : 'a; amount : ticket_amount} type empty_cell = EmptyCell diff --git a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml index 6e72d57ee6a4..9f83611ff53b 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir_size.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir_size.ml @@ -214,7 +214,9 @@ let chain_id_size = !!16 (* by Obj.reachable_words. *) (* [contents] is handled by the recursion scheme in [value_size]. *) let ticket_size {ticketer; contents = _; amount} = - h3w +! Contract.in_memory_size ticketer +! script_nat_size amount + h3w + +! Contract.in_memory_size ticketer + +! script_nat_size (amount :> Script_int.n Script_int.num) let chest_size chest = (* diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml index ed6156801acc..d8857d475c72 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_accounting.ml @@ -445,7 +445,10 @@ let assert_ticket_diffs ctxt ~loc ~arg_type ~storage_type ~arg ~old_storage let assert_balance = Ticket_helpers.assert_balance let string_ticket ticketer contents amount = - let amount = Script_int.abs @@ Script_int.of_int amount in + let amount = + WithExceptions.Option.get ~loc:__LOC__ + @@ Ticket_amount.of_n @@ Script_int.abs @@ Script_int.of_int amount + in let ticketer = Result.value_f ~default:(fun _ -> assert false) @@ Contract.of_b58check ticketer diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml index 281b3aa47b40..f8984e995394 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_manager.ml @@ -57,7 +57,7 @@ let init_env () = let collect_token_amounts ctxt tickets = let accum (tokens, ctxt) ticket = let token, amount = Ticket_token.token_and_amount_of_ex_ticket ticket in - let tokens = (token, Script_int.to_zint amount) :: tokens in + let tokens = (token, Script_int.(to_zint (amount :> n num))) :: tokens in return (tokens, ctxt) in List.fold_left_es accum ([], ctxt) tickets diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml index 3b77f2deb1a9..25148e49afdc 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_operations_diff.ml @@ -41,7 +41,7 @@ open Script_typed_ir type ticket_token_diff = { ticket_token : Ticket_token.ex_token; total_amount : Script_int.n Script_int.num; - destinations : (Destination.t * Script_int.n Script_int.num) list; + destinations : (Destination.t * ticket_amount) list; } let to_local_ticket_token_diff @@ -55,22 +55,25 @@ let wrap m = m >|= Environment.wrap_tzresult let assert_fails ~loc ?error m = let open Lwt_result_syntax in let*! res = m in + let rec aux err_res = + match (err_res, error) with + | Environment.Ecoproto_error err' :: rest, Some err -> + (* Matched exact error. *) + if err' = err then return_unit else aux rest + | _ :: rest, Some _ -> aux rest + | [], Some _ -> + (* Expected a different error. *) + let msg = + Printf.sprintf "Expected a different error at location %s" loc + in + Stdlib.failwith msg + | _, None -> + (* Any error is ok. *) + return () + in match res with | Ok _ -> Stdlib.failwith "Expected failure" - | Error err_res -> ( - match (err_res, error) with - | Environment.Ecoproto_error err' :: _, Some err when err = err' -> - (* Matched exact error. *) - return_unit - | _, Some _ -> - (* Expected a different error. *) - let msg = - Printf.sprintf "Expected a different error at location %s" loc - in - Stdlib.failwith msg - | _, None -> - (* Any error is ok. *) - return ()) + | Error err_res -> aux err_res let big_map_updates_of_key_values ctxt key_values = List.fold_right_es @@ -141,13 +144,13 @@ let string_of_destination_and_amounts cas = "[%a]" (Format.pp_print_list ~pp_sep:(fun fmt () -> Format.fprintf fmt "; ") - (fun fmt (contract, amount) -> + (fun fmt (contract, (amount : ticket_amount)) -> Format.fprintf fmt {|("%a", %s)|} Destination.pp contract - (Script_int.to_string amount))) + Script_int.(to_string (amount :> n num)))) cas let string_of_ticket_operations_diff ctxt @@ -396,7 +399,13 @@ let list_ticket_string_ty = let make_ticket (ticketer, contents, amount) = Script_string.of_string contents >>?= fun contents -> - return {ticketer; contents; amount = nat amount} + let amount = nat amount in + Option.value_e + ~error: + (Environment.Error_monad.trace_of_error + Script_tc_errors.Forbidden_zero_ticket_quantity) + @@ Ticket_amount.of_n amount + >>?= fun amount -> return {ticketer; contents; amount} let make_tickets ts = let* elements = List.map_es make_ticket ts in @@ -458,6 +467,14 @@ let test_transfer_empty_ticket_list () = let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation] in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ ticket_diffs ~expected:[] +let one = Ticket_amount.one + +let two = Ticket_amount.add one one + +let three = Ticket_amount.add two one + +let five = Ticket_amount.add three two + (** Test transfer a list of one ticket. *) let test_transfer_one_ticket () = let* baker, src, block = init () in @@ -489,7 +506,7 @@ let test_transfer_one_ticket () = ticket_token = string_token ~ticketer "white"; total_amount = nat 1; destinations = - [(Destination.Contract (Originated orig_contract), nat 1)]; + [(Destination.Contract (Originated orig_contract), one)]; }; ] @@ -531,17 +548,17 @@ let test_transfer_multiple_tickets () = { ticket_token = string_token ~ticketer "red"; total_amount = nat 5; - destinations = [(Destination.Contract orig_contract, nat 5)]; + destinations = [(Destination.Contract orig_contract, five)]; }; { ticket_token = string_token ~ticketer "blue"; total_amount = nat 2; - destinations = [(Destination.Contract orig_contract, nat 2)]; + destinations = [(Destination.Contract orig_contract, two)]; }; { ticket_token = string_token ~ticketer "green"; total_amount = nat 3; - destinations = [(Destination.Contract orig_contract, nat 3)]; + destinations = [(Destination.Contract orig_contract, three)]; }; ] @@ -586,32 +603,32 @@ let test_transfer_different_tickets () = { ticket_token = string_token ~ticketer:ticketer1 "red"; total_amount = nat 2; - destinations = [(destination, nat 2)]; + destinations = [(destination, two)]; }; { ticket_token = string_token ~ticketer:ticketer1 "green"; total_amount = nat 2; - destinations = [(destination, nat 2)]; + destinations = [(destination, two)]; }; { ticket_token = string_token ~ticketer:ticketer1 "blue"; total_amount = nat 2; - destinations = [(destination, nat 2)]; + destinations = [(destination, two)]; }; { ticket_token = string_token ~ticketer:ticketer2 "red"; total_amount = nat 1; - destinations = [(destination, nat 1)]; + destinations = [(destination, one)]; }; { ticket_token = string_token ~ticketer:ticketer2 "green"; total_amount = nat 1; - destinations = [(destination, nat 1)]; + destinations = [(destination, one)]; }; { ticket_token = string_token ~ticketer:ticketer2 "blue"; total_amount = nat 1; - destinations = [(destination, nat 1)]; + destinations = [(destination, one)]; }; ] @@ -650,6 +667,7 @@ let test_transfer_to_two_contracts_with_different_tickets () = let* ticket_diffs, ctxt = ticket_diffs_of_operations incr [operation1; operation2] in + let one = Ticket_amount.one in assert_equal_ticket_token_diffs ctxt ~loc:__LOC__ @@ -661,8 +679,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract (Originated destination2), nat 1); - (Destination.Contract (Originated destination1), nat 1); + (Destination.Contract (Originated destination2), one); + (Destination.Contract (Originated destination1), one); ]; }; { @@ -670,8 +688,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract (Originated destination2), nat 1); - (Destination.Contract (Originated destination1), nat 1); + (Destination.Contract (Originated destination2), one); + (Destination.Contract (Originated destination1), one); ]; }; { @@ -679,8 +697,8 @@ let test_transfer_to_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract (Originated destination2), nat 1); - (Destination.Contract (Originated destination1), nat 1); + (Destination.Contract (Originated destination2), one); + (Destination.Contract (Originated destination1), one); ]; }; ] @@ -742,7 +760,7 @@ let test_originate_with_one_ticket () = { ticket_token = string_token ~ticketer "white"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(Destination.Contract orig_contract, one)]; }; ] @@ -783,17 +801,17 @@ let test_originate_with_multiple_tickets () = { ticket_token = string_token ~ticketer "red"; total_amount = nat 5; - destinations = [(Destination.Contract orig_contract, nat 5)]; + destinations = [(Destination.Contract orig_contract, five)]; }; { ticket_token = string_token ~ticketer "blue"; total_amount = nat 2; - destinations = [(Destination.Contract orig_contract, nat 2)]; + destinations = [(Destination.Contract orig_contract, two)]; }; { ticket_token = string_token ~ticketer "green"; total_amount = nat 3; - destinations = [(Destination.Contract orig_contract, nat 3)]; + destinations = [(Destination.Contract orig_contract, three)]; }; ] @@ -845,32 +863,32 @@ let test_originate_with_different_tickets () = { ticket_token = string_token ~ticketer:ticketer1 "red"; total_amount = nat 2; - destinations = [(Destination.Contract orig_contract, nat 2)]; + destinations = [(Destination.Contract orig_contract, two)]; }; { ticket_token = string_token ~ticketer:ticketer1 "green"; total_amount = nat 2; - destinations = [(Destination.Contract orig_contract, nat 2)]; + destinations = [(Destination.Contract orig_contract, two)]; }; { ticket_token = string_token ~ticketer:ticketer1 "blue"; total_amount = nat 2; - destinations = [(Destination.Contract orig_contract, nat 2)]; + destinations = [(Destination.Contract orig_contract, two)]; }; { ticket_token = string_token ~ticketer:ticketer2 "red"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(Destination.Contract orig_contract, one)]; }; { ticket_token = string_token ~ticketer:ticketer2 "green"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(Destination.Contract orig_contract, one)]; }; { ticket_token = string_token ~ticketer:ticketer2 "blue"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(Destination.Contract orig_contract, one)]; }; ] @@ -919,8 +937,8 @@ let test_originate_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract orig_contract2, nat 1); - (Destination.Contract orig_contract1, nat 1); + (Destination.Contract orig_contract2, one); + (Destination.Contract orig_contract1, one); ]; }; { @@ -928,8 +946,8 @@ let test_originate_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract orig_contract2, nat 1); - (Destination.Contract orig_contract1, nat 1); + (Destination.Contract orig_contract2, one); + (Destination.Contract orig_contract1, one); ]; }; { @@ -937,8 +955,8 @@ let test_originate_two_contracts_with_different_tickets () = total_amount = nat 2; destinations = [ - (Destination.Contract orig_contract2, nat 1); - (Destination.Contract orig_contract1, nat 1); + (Destination.Contract orig_contract2, one); + (Destination.Contract orig_contract1, one); ]; }; ] @@ -995,8 +1013,8 @@ let test_originate_and_transfer () = total_amount = nat 2; destinations = [ - (Destination.Contract (Originated destination2), nat 1); - (Destination.Contract orig_contract1, nat 1); + (Destination.Contract (Originated destination2), one); + (Destination.Contract orig_contract1, one); ]; }; { @@ -1004,8 +1022,8 @@ let test_originate_and_transfer () = total_amount = nat 2; destinations = [ - (Destination.Contract (Originated destination2), nat 1); - (Destination.Contract orig_contract1, nat 1); + (Destination.Contract (Originated destination2), one); + (Destination.Contract orig_contract1, one); ]; }; { @@ -1013,8 +1031,8 @@ let test_originate_and_transfer () = total_amount = nat 2; destinations = [ - (Destination.Contract (Originated destination2), nat 1); - (Destination.Contract orig_contract1, nat 1); + (Destination.Contract (Originated destination2), one); + (Destination.Contract orig_contract1, one); ]; }; ] @@ -1063,17 +1081,17 @@ let test_originate_big_map_with_tickets () = { ticket_token = string_token ~ticketer "red"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(Destination.Contract orig_contract, one)]; }; { ticket_token = string_token ~ticketer "green"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(Destination.Contract orig_contract, one)]; }; { ticket_token = string_token ~ticketer "blue"; total_amount = nat 1; - destinations = [(Destination.Contract orig_contract, nat 1)]; + destinations = [(Destination.Contract orig_contract, one)]; }; ] @@ -1144,17 +1162,17 @@ let test_transfer_big_map_with_tickets () = { ticket_token = string_token ~ticketer:ticketer_contract "red"; total_amount = nat 1; - destinations = [(destination, nat 1)]; + destinations = [(destination, one)]; }; { ticket_token = string_token ~ticketer:ticketer_contract "green"; total_amount = nat 1; - destinations = [(destination, nat 1)]; + destinations = [(destination, one)]; }; { ticket_token = string_token ~ticketer:ticketer_contract "blue"; total_amount = nat 1; - destinations = [(destination, nat 1)]; + destinations = [(destination, one)]; }; ] @@ -1178,9 +1196,7 @@ let test_tx_rollup_deposit_one_ticket () = pair_t Micheline.dummy_location ticket_ty tx_rollup_l2_address_t) |> Environment.wrap_tzresult in - let amount = - Script_int.(is_nat @@ of_int 1) |> WithExceptions.Option.get ~loc:__LOC__ - in + let amount = one in let*? contents = Script_string.of_string "white" |> Environment.wrap_tzresult in @@ -1211,7 +1227,7 @@ let test_tx_rollup_deposit_one_ticket () = { ticket_token = string_token ~ticketer "white"; total_amount = nat 1; - destinations = [(Destination.Tx_rollup tx_rollup, nat 1)]; + destinations = [(Destination.Tx_rollup tx_rollup, one)]; }; ] @@ -1229,21 +1245,21 @@ let test_transfer_fails_on_multiple_zero_tickets () = ~storage:"{}" ~forges_tickets:false in - let* operation, incr = - transfer_tickets_operation - ~incr - ~src - ~destination:orig_contract - [ - (ticketer, "red", 1); - (ticketer, "blue", 0); - (ticketer, "green", 2); - (ticketer, "red", 0); - (ticketer, "green", 3); - ] - in - assert_fails ~loc:__LOC__ ~error:Ticket_scanner.Forbidden_zero_ticket_quantity - @@ ticket_diffs_of_operations incr [operation] + assert_fails + ~loc:__LOC__ + ~error:Script_tc_errors.Forbidden_zero_ticket_quantity + @@ (* let* operation, incr = *) + transfer_tickets_operation + ~incr + ~src + ~destination:orig_contract + [ + (ticketer, "red", 1); + (ticketer, "blue", 0); + (ticketer, "green", 2); + (ticketer, "red", 0); + (ticketer, "green", 3); + ] (** Test that zero-amount tickets are detected and that an error is yielded. *) let test_fail_on_zero_amount_tickets () = @@ -1265,19 +1281,16 @@ let test_fail_on_zero_amount_tickets () = ticketer_addr ticketer_addr in - let* _orig_contract, operation, ctxt = - origination_operation - block - ~src - ~baker - ~script:ticket_list_script - ~storage - ~forges_tickets:true - in assert_fails ~loc:__LOC__ - ~error:Ticket_scanner.Forbidden_zero_ticket_quantity - (ticket_diffs_of_operations ctxt [operation]) + ~error:Script_tc_errors.Forbidden_zero_ticket_quantity + @@ origination_operation + block + ~src + ~baker + ~script:ticket_list_script + ~storage + ~forges_tickets:true let tests = [ diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml index 1e2b71eecb4a..91da29fff9fc 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml @@ -39,22 +39,23 @@ open Alpha_context let assert_fails ~loc ?error m = let open Lwt_result_syntax in let*! res = m in + let rec aux err_res = + match (err_res, error) with + | Environment.Ecoproto_error err' :: rest, Some err -> + if err = err' then return_unit else aux rest + | _, Some _ -> + (* Expected a different error. *) + let msg = + Printf.sprintf "Expected a different error at location %s" loc + in + Stdlib.failwith msg + | _, None -> + (* Any error is ok. *) + return () + in match res with | Ok _ -> Stdlib.failwith "Expected failure" - | Error err_res -> ( - match (err_res, error) with - | Environment.Ecoproto_error err' :: _, Some err when err = err' -> - (* Matched exact error. *) - return_unit - | _, Some _ -> - (* Expected a different error. *) - let msg = - Printf.sprintf "Expected a different error at location %s" loc - in - Stdlib.failwith msg - | _, None -> - (* Any error is ok. *) - return ()) + | Error err_res -> aux err_res let ( let* ) m f = m >>=? f @@ -95,7 +96,7 @@ let string_list_of_ex_tickets ctxt tickets = ticketer content Z.pp_print - (Script_int.to_zint amount) + Script_int.(to_zint (amount :> n num)) in return (str :: xs, ctxt) in @@ -113,6 +114,10 @@ let make_ex_ticket ctxt ~ticketer ~type_exp ~content_exp ~amount = wrap @@ Script_ir_translator.parse_comparable_data ctxt cty node in let amount = Script_int.(abs @@ of_int amount) in + let amount = + WithExceptions.Option.get ~loc:__LOC__ + @@ Script_typed_ir.Ticket_amount.of_n amount + in let ticket = Script_typed_ir.{ticketer; contents; amount} in return (Ticket_scanner.Ex_ticket (cty, ticket), ctxt) @@ -303,7 +308,7 @@ let test_tickets_in_unit_ticket () = let assert_string_tickets_fail_on_zero_amount ~loc ~include_lazy ~type_exp ~value_exp = let* ctxt = new_ctxt () in - assert_fails ~loc ~error:Ticket_scanner.Forbidden_zero_ticket_quantity + assert_fails ~loc ~error:Script_tc_errors.Forbidden_zero_ticket_quantity @@ tickets_of_value ctxt ~include_lazy ~type_exp ~value_exp let test_tickets_in_list_with_zero_amount () = @@ -437,7 +442,7 @@ let test_tickets_in_big_map_strict_only () = { Elt 1 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "red" 1); Elt 2 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "green" 2); - Elt 3 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 0); + Elt 3 (Pair "KT1ThEdxfUcWUwqsdergy3QnbCWGHSUHeHJq" "blue" 3); } |} ~expected:[] diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml index 61cb20be242c..b8e8024ba861 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_sc_rollup.ml @@ -1185,15 +1185,28 @@ let test_zero_amount_ticket () = ] in let output = make_output ~outbox_level:0 ~message_index:0 transactions in - assert_fails - ~loc:__LOC__ - ~error:Ticket_scanner.Forbidden_zero_ticket_quantity - (execute_outbox_message_without_proof_validation - incr - rollup - ~cemented_commitment - ~source - output) + let*! result = + execute_outbox_message_without_proof_validation + incr + rollup + ~cemented_commitment + ~source + output + in + match result with + | Error e -> + if + Option.is_some + @@ List.find + (function + | Environment.Ecoproto_error + Script_tc_errors.Forbidden_zero_ticket_quantity -> + true + | _ -> false) + e + then return_unit + else Stdlib.failwith "Expected failure" + | Ok _ -> Stdlib.failwith "Expected failure" (* Check that executing an outbox message fails when the inclusion proof in invalid. *) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml index 64341fdbd929..fda068fbaf97 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml @@ -72,7 +72,10 @@ let check_encode_decode_outbox_message ctxt message = let string_ticket ticketer contents amount = let open WithExceptions in - let amount = Script_int.abs @@ Script_int.of_int amount in + let amount = + Option.get ~loc:__LOC__ @@ Script_typed_ir.Ticket_amount.of_n + @@ Script_int.abs @@ Script_int.of_int amount + in let ticketer = Result.get_ok ~loc:__LOC__ (Contract.of_b58check ticketer) in let contents = Result.get_ok ~loc:__LOC__ (Script_string.of_string contents) diff --git a/src/proto_alpha/lib_protocol/ticket_accounting.ml b/src/proto_alpha/lib_protocol/ticket_accounting.ml index eff0753f365a..bbb04f408bfa 100644 --- a/src/proto_alpha/lib_protocol/ticket_accounting.ml +++ b/src/proto_alpha/lib_protocol/ticket_accounting.ml @@ -80,7 +80,10 @@ let ticket_balances_of_value ctxt ~include_lazy ty value = (fun (acc, ctxt) ticket -> let token, amount = Ticket_token.token_and_amount_of_ex_ticket ticket in Gas.consume ctxt Ticket_costs.Constants.cost_collect_tickets_step - >|? fun ctxt -> ((token, Script_int.to_zint amount) :: acc, ctxt)) + >|? fun ctxt -> + ( (token, Script_int.to_zint (amount :> Script_int.n Script_int.num)) + :: acc, + ctxt )) ([], ctxt) tickets >>?= fun (list, ctxt) -> Ticket_token_map.of_list ctxt list @@ -235,10 +238,11 @@ let update_ticket_balances ctxt ~self ~ticket_diffs operations = ~amount:(Script_int.to_zint total_amount)) >>?= fun () -> List.fold_left_e - (fun (acc, ctxt) (token, amount) -> + (fun (acc, ctxt) (token, (amount : Script_typed_ir.ticket_amount)) -> (* Consume some gas for for traversing the list. *) Gas.consume ctxt Ticket_costs.Constants.cost_collect_tickets_step - >|? fun ctxt -> ((token, Script_int.to_zint amount) :: acc, ctxt)) + >|? fun ctxt -> + ((token, Script_int.(to_zint (amount :> n num))) :: acc, ctxt)) ([], ctxt) destinations >>?= fun (destinations, ctxt) -> diff --git a/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml b/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml index 0d38e380f39a..abc4fb54e37f 100644 --- a/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_lazy_storage_diff.ml @@ -52,7 +52,7 @@ let token_and_amount ctxt ex_ticket = Gas.consume ctxt Ticket_costs.Constants.cost_collect_tickets_step >|? fun ctxt -> let token, amount = Ticket_token.token_and_amount_of_ex_ticket ex_ticket in - ((token, Script_int.to_zint amount), ctxt) + ((token, Script_int.(to_zint (amount :> n num))), ctxt) (** Extracts the ticket-token and amount from an ex_ticket value and returns the opposite of the amount. This is used to account for removal of tickets inside diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 41c3a74e4271..267a95211b9c 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -24,6 +24,9 @@ (*****************************************************************************) open Alpha_context +module Ticket_amount = Script_typed_ir.Ticket_amount + +type ticket_amount = Script_typed_ir.ticket_amount type ticket_transfer = { destination : Destination.t; @@ -33,7 +36,7 @@ type ticket_transfer = { type ticket_token_diff = { ticket_token : Ticket_token.ex_token; total_amount : Script_int.n Script_int.num; - destinations : (Destination.t * Script_int.n Script_int.num) list; + destinations : (Destination.t * ticket_amount) list; } type error += Failed_to_get_script of Contract.t | Contract_not_originated @@ -115,7 +118,7 @@ module Ticket_token_map = struct - The internal contract-indexed map cannot be empty. *) - let add ctxt ~ticket_token ~destination ~amount map = + let add ctxt ~ticket_token ~destination ~(amount : ticket_amount) map = Ticket_token_map.update ctxt ticket_token @@ -129,12 +132,15 @@ module Ticket_token_map = struct (* Update the inner contract map *) let update ctxt prev_amt_opt = match prev_amt_opt with - | Some prev_amount -> + | Some (prev_amount : ticket_amount) -> Gas.consume ctxt - (Ticket_costs.add_int_cost prev_amount amount) + Script_int.( + Ticket_costs.add_int_cost + (prev_amount :> n num) + (amount :> n num)) >|? fun ctxt -> - (Some (Script_int.add_n prev_amount amount), ctxt) + (Some (Ticket_amount.add prev_amount amount), ctxt) | None -> ok (Some amount, ctxt) in Destination_map.update ctxt destination update destination_map @@ -248,9 +254,13 @@ let ticket_diffs_of_operations ctxt operations = ticket-token. *) Destination_map.fold ctxt - (fun ctxt total_amount _destination amount -> - Gas.consume ctxt (Ticket_costs.add_int_cost total_amount amount) - >|? fun ctxt -> (Script_int.add_n total_amount amount, ctxt)) + (fun ctxt total_amount _destination (amount : ticket_amount) -> + Gas.consume + ctxt + Script_int.( + Ticket_costs.add_int_cost total_amount (amount :> n num)) + >|? fun ctxt -> + (Script_int.(add_n total_amount (amount :> n num)), ctxt)) Script_int.zero_n destination_map >>? fun (total_amount, ctxt) -> diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.mli b/src/proto_alpha/lib_protocol/ticket_operations_diff.mli index b2ca7987ee6e..d413a81da9e6 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.mli +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.mli @@ -36,7 +36,7 @@ type ticket_token_diff = private { ticket_token : Ticket_token.ex_token; total_amount : Script_int.n Script_int.num; destinations : - (Alpha_context.Destination.t * Script_int.n Script_int.num) list; + (Alpha_context.Destination.t * Script_typed_ir.ticket_amount) list; } (** [ticket_diffs_of_operations ctxt ops] returns a diff --git a/src/proto_alpha/lib_protocol/ticket_scanner.ml b/src/proto_alpha/lib_protocol/ticket_scanner.ml index fcd879b311c4..4993572e9fa7 100644 --- a/src/proto_alpha/lib_protocol/ticket_scanner.ml +++ b/src/proto_alpha/lib_protocol/ticket_scanner.ml @@ -29,7 +29,6 @@ open Alpha_context type error += | (* Permanent *) Unsupported_non_empty_overlay | (* Permanent *) Unsupported_type_operation - | (* Permanent *) Forbidden_zero_ticket_quantity let () = register_error_kind @@ -51,16 +50,7 @@ let () = Format.fprintf ppf "Types embedding operations are not supported") Data_encoding.empty (function Unsupported_type_operation -> Some () | _ -> None) - (fun () -> Unsupported_type_operation) ; - register_error_kind - `Permanent - ~id:"forbidden_zero_amount_ticket" - ~title:"Zero ticket amount is not allowed" - ~description: - "It is not allowed to use a zero amount ticket in this operation." - Data_encoding.empty - (function Forbidden_zero_ticket_quantity -> Some () | _ -> None) - (fun () -> Forbidden_zero_ticket_quantity) + (fun () -> Unsupported_type_operation) type ex_ticket = | Ex_ticket : @@ -415,11 +405,7 @@ module Ticket_collection = struct (tickets_of_big_map [@ocaml.tailcall]) ctxt val_hty key_ty x acc k else (k [@ocaml.tailcall]) ctxt acc | True_ht, Ticket_t (comp_ty, _) -> - let Script_typed_ir.{ticketer = _; contents = _; amount} = x in - fail_when - Compare.Int.(Script_int.compare amount Script_int.zero_n = 0) - Forbidden_zero_ticket_quantity - >>=? fun () -> (k [@ocaml.tailcall]) ctxt (Ex_ticket (comp_ty, x) :: acc) + (k [@ocaml.tailcall]) ctxt (Ex_ticket (comp_ty, x) :: acc) and tickets_of_list : type a ac ret. diff --git a/src/proto_alpha/lib_protocol/ticket_scanner.mli b/src/proto_alpha/lib_protocol/ticket_scanner.mli index 96947fec0325..209c633ab74a 100644 --- a/src/proto_alpha/lib_protocol/ticket_scanner.mli +++ b/src/proto_alpha/lib_protocol/ticket_scanner.mli @@ -26,8 +26,6 @@ (** This module provides an API for extracting tickets of arbitrary types from an OCaml values, given a type-witness. *) -type error += (* Permanent *) Forbidden_zero_ticket_quantity - (** A type for representing existentially quantified tickets (tickets with different types of payloads). An [ex_ticket] value consists of: - A type-witness representing the type of the content of the ticket. diff --git a/src/proto_alpha/lib_protocol/ticket_token.mli b/src/proto_alpha/lib_protocol/ticket_token.mli index ec048615d71a..164b51405756 100644 --- a/src/proto_alpha/lib_protocol/ticket_token.mli +++ b/src/proto_alpha/lib_protocol/ticket_token.mli @@ -41,4 +41,4 @@ type ex_token = (** [token_and_amount_of_ex_ticket ex_ticket] returns the token and amount of the given ticket [ex_ticket]. *) val token_and_amount_of_ex_ticket : - Ticket_scanner.ex_ticket -> ex_token * Script_int.n Script_int.num + Ticket_scanner.ex_ticket -> ex_token * Script_typed_ir.ticket_amount diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml index 368d6b904559..1d03467e2972 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml @@ -55,17 +55,9 @@ let parse_ticket_and_operation ~consume_deserialization_gas ~ticketer ~contents let ticket_token = Ticket_token.Ex_token {ticketer; contents_type; contents} in - Option.value_e - ~error: - (Error_monad.trace_of_error - @@ Tx_rollup_errors.Internal_error - "Ticket quantity is negative, this can't happen because it comes \ - from a qty.") - Script_int.(is_nat @@ of_zint amount) - >>?= fun amount_node -> Script_typed_ir.ticket_t Micheline.dummy_location contents_type >>?= fun ticket_ty -> - let ticket = Script_typed_ir.{ticketer; contents; amount = amount_node} in + let ticket = Script_typed_ir.{ticketer; contents; amount} in Script_ir_translator.unparse_data ctxt Optimized ticket_ty ticket >>=? fun (parameters_expr, ctxt) -> Gas.consume ctxt (Script.strip_locations_cost parameters_expr) @@ -100,7 +92,9 @@ let make_withdraw_order ctxt tx_rollup ex_ticket claimer amount = in return (ctxt, withdrawal) -let transfer_ticket_with_hashes ctxt ~src_hash ~dst_hash qty = +let transfer_ticket_with_hashes ctxt ~src_hash ~dst_hash + (qty : Script_typed_ir.ticket_amount) = + let qty = Script_int.(to_zint (qty :> n num)) in Ticket_balance.adjust_balance ctxt src_hash ~delta:(Z.neg qty) >>=? fun (src_storage_diff, ctxt) -> Ticket_balance.adjust_balance ctxt dst_hash ~delta:qty diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli index 77865d9e7dca..d900a644a817 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli @@ -50,7 +50,7 @@ val parse_ticket_and_operation : source:Contract.t -> destination:Contract_hash.t -> entrypoint:Entrypoint.t -> - amount:Z.t -> + amount:Script_typed_ir.ticket_amount -> context -> (context * Ticket_token.ex_token * Script_typed_ir.packed_internal_operation) tzresult @@ -85,7 +85,7 @@ val transfer_ticket_with_hashes : context -> src_hash:Ticket_hash.t -> dst_hash:Ticket_hash.t -> - Z.t -> + Script_typed_ir.ticket_amount -> (context * Z.t) tzresult Lwt.t (** [transfer_ticket ctxt ~src ~dst ex_token qty] updates the table of @@ -100,5 +100,5 @@ val transfer_ticket : src:Destination.t -> dst:Destination.t -> Ticket_token.ex_token -> - counter -> + Script_typed_ir.ticket_amount -> (context * counter, error trace) result Lwt.t -- GitLab From 681a0329c090da63f91d99173723f8d30881c2b3 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 8 Sep 2022 16:14:04 +0800 Subject: [PATCH 6/8] Proto: move Ticket_amount module out of Script_typed_ir --- .../lib_benchmark/michelson_samplers.ml | 2 +- .../interpreter_benchmarks.ml | 15 ++++--- .../lib_benchmarks_proto/ticket_benchmarks.ml | 6 +-- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 1 + src/proto_alpha/lib_protocol/apply.ml | 5 +-- src/proto_alpha/lib_protocol/dune | 4 ++ .../lib_protocol/script_interpreter.ml | 31 ++++---------- .../lib_protocol/script_typed_ir.ml | 18 -------- .../lib_protocol/script_typed_ir.mli | 14 ------- .../michelson/test_ticket_scanner.ml | 3 +- .../test_sc_rollup_management_protocol.ml | 4 +- src/proto_alpha/lib_protocol/ticket_amount.ml | 41 ++++++++++++++++++ .../lib_protocol/ticket_amount.mli | 42 +++++++++++++++++++ .../lib_protocol/ticket_operations_diff.ml | 11 ++--- 14 files changed, 115 insertions(+), 82 deletions(-) create mode 100644 src/proto_alpha/lib_protocol/ticket_amount.ml create mode 100644 src/proto_alpha/lib_protocol/ticket_amount.mli diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index 2ce41a3d1add..f57dc510d4ee 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -804,7 +804,7 @@ end) Alpha_context.Contract.Implicit (Crypto_samplers.pkh rng_state) in let amount = - let open Script_typed_ir.Ticket_amount in + let open Ticket_amount in match of_n (Michelson_base.nat rng_state) with | Some amount -> add amount one | None -> one diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index e6b40fe3e3e7..4dee5096896a 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -2848,7 +2848,7 @@ module Registration_section = struct Alpha_context.Contract.Implicit Environment.Signature.Public_key_hash.zero; contents = (); - amount = Script_typed_ir.Ticket_amount.one; + amount = Ticket_amount.one; } in benchmark_with_fixed_stack @@ -2868,13 +2868,12 @@ module Registration_section = struct in fun () -> let half_amount = Samplers.Random_value.value nat rng_state in + let half_amount = Script_int.add_n half_amount Script_int.one_n in let amount = Script_int.add_n half_amount half_amount in let amount = - let open Script_typed_ir.Ticket_amount in - let two = add one one in - match of_n amount with - | Some amount -> add two amount - | None -> add one one + (* this is safe because half_amount > 0 *) + WithExceptions.Option.get ~loc:__LOC__ + @@ Ticket_amount.of_n amount in let ticket = Samplers.Random_value.value (ticket unit) rng_state in let ticket = {ticket with amount} in @@ -2910,7 +2909,7 @@ module Registration_section = struct { ticket with contents = Script_string.empty; - amount = Script_typed_ir.Ticket_amount.one; + amount = Ticket_amount.one; } in Ex_stack_and_kinstr @@ -2934,7 +2933,7 @@ module Registration_section = struct in let alt_amount = let amount = Samplers.Random_value.value nat rng_state in - let open Script_typed_ir.Ticket_amount in + let open Ticket_amount in match of_n amount with | Some amount -> add amount one | None -> one diff --git a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml index fb953f23f0b0..3a472f44fca2 100644 --- a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml @@ -251,11 +251,7 @@ let ticket_sampler rng_state = let pkh, _, _ = Signature.generate_key ~algo:Signature.Ed25519 ~seed () in let ticketer = Alpha_context.Contract.Implicit pkh in Script_typed_ir. - { - ticketer; - contents = Script_int.zero; - amount = Script_typed_ir.Ticket_amount.one; - } + {ticketer; contents = Script_int.zero; amount = Ticket_amount.one} (** A benchmark for {!Ticket_costs.Constants.cost_collect_tickets_step}. *) module Collect_tickets_benchmark : Benchmark.S = struct diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 4505a81b5a49..675d17f88840 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -183,6 +183,7 @@ "Tx_rollup_l2_apply", "Tx_rollup_l2_verifier", + "Ticket_amount", "Local_gas_counter", "Script_tc_errors", "Gas_monad", diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 416ae54cc999..32eb8c178ed2 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -862,8 +862,7 @@ let apply_manager_operation : ( Tx_rollup_withdraw. {claimer; amount; ticket_hash = tx_rollup_ticket_hash}, ticket_token ) = - Script_typed_ir.Ticket_amount.of_z - @@ Script_int.of_zint (Tx_rollup_l2_qty.to_z amount) + Ticket_amount.of_z @@ Script_int.of_zint (Tx_rollup_l2_qty.to_z amount) |> Option.value_e ~error: (Error_monad.trace_of_error @@ -903,7 +902,7 @@ let apply_manager_operation : ~error: (Error_monad.trace_of_error Script_tc_errors.Forbidden_zero_ticket_quantity) - @@ Script_typed_ir.Ticket_amount.of_z (Script_int.of_zint amount) + @@ Ticket_amount.of_z (Script_int.of_zint amount) >>?= fun amount -> match destination with | Implicit _ -> fail Cannot_transfer_ticket_to_implicit diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index af80c03b5f2e..b4b6a01737b8 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -197,6 +197,7 @@ Tx_rollup_l2_batch Tx_rollup_l2_apply Tx_rollup_l2_verifier + Ticket_amount Local_gas_counter Script_tc_errors Gas_monad @@ -457,6 +458,7 @@ tx_rollup_l2_batch.ml tx_rollup_l2_batch.mli tx_rollup_l2_apply.ml tx_rollup_l2_apply.mli tx_rollup_l2_verifier.ml tx_rollup_l2_verifier.mli + ticket_amount.ml ticket_amount.mli local_gas_counter.ml local_gas_counter.mli script_tc_errors.ml gas_monad.ml gas_monad.mli @@ -697,6 +699,7 @@ tx_rollup_l2_batch.ml tx_rollup_l2_batch.mli tx_rollup_l2_apply.ml tx_rollup_l2_apply.mli tx_rollup_l2_verifier.ml tx_rollup_l2_verifier.mli + ticket_amount.ml ticket_amount.mli local_gas_counter.ml local_gas_counter.mli script_tc_errors.ml gas_monad.ml gas_monad.mli @@ -942,6 +945,7 @@ tx_rollup_l2_batch.ml tx_rollup_l2_batch.mli tx_rollup_l2_apply.ml tx_rollup_l2_apply.mli tx_rollup_l2_verifier.ml tx_rollup_l2_verifier.mli + ticket_amount.ml ticket_amount.mli local_gas_counter.ml local_gas_counter.mli script_tc_errors.ml gas_monad.ml gas_monad.mli diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 149e559d844a..49d87067fc5f 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -116,8 +116,6 @@ type error += Cannot_serialize_storage type error += Michelson_too_many_recursive_calls -type error += Ticket_amount_zero of Script.location - let () = let open Data_encoding in let trace_encoding = @@ -194,15 +192,7 @@ let () = "The returned storage was too big to be serialized with the provided gas" Data_encoding.empty (function Cannot_serialize_storage -> Some () | _ -> None) - (fun () -> Cannot_serialize_storage) ; - register_error_kind - `Temporary - ~id:"michelson_v1.ticket_amount_zero" - ~title:"Ticket amount is zero" - ~description:"A ticket of amount zero is not allowed" - (obj1 (req "location" Script.location_encoding)) - (function Ticket_amount_zero loc -> Some loc | _ -> None) - (fun loc -> Ticket_amount_zero loc) + (fun () -> Cannot_serialize_storage) (* @@ -1489,20 +1479,17 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let accu = aux witness stack in (step [@ocaml.tailcall]) g gas k ks accu stack (* Tickets *) - | ITicket_deprecated (_, _, k) -> + | ITicket_deprecated (_, _, k) -> ( let contents = accu and amount, stack = stack in - Option.value_e - ~error: - (Error_monad.trace_of_error - Script_tc_errors.Forbidden_zero_ticket_quantity) - @@ Script_typed_ir.Ticket_amount.of_n amount - >>?= fun amount -> - let ticketer = Contract.Originated sc.self in - let accu = {ticketer; contents; amount} in - (step [@ocaml.tailcall]) g gas k ks accu stack + match Ticket_amount.of_n amount with + | Some amount -> + let ticketer = Contract.Originated sc.self in + let accu = {ticketer; contents; amount} in + (step [@ocaml.tailcall]) g gas k ks accu stack + | None -> fail Script_tc_errors.Forbidden_zero_ticket_quantity) | ITicket (_, _, k) -> ( let contents = accu and amount, stack = stack in - match Script_typed_ir.Ticket_amount.of_n amount with + match Ticket_amount.of_n amount with | Some amount -> let ticketer = Contract.Originated sc.self in let accu = Some {ticketer; contents; amount} in diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index de99a3ecb9b5..84ea1d401e25 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -217,24 +217,6 @@ module Script_timelock = struct let get_plaintext_size (Chest_tag x) = Timelock.get_plaintext_size x end -module Ticket_amount = struct - type t = n num - - let of_n n = - if Compare.Int.(Script_int.(compare n zero_n) > 0) then Some (n : t) - else None - - open Script_int - - let of_z z = Option.bind (is_nat z) of_n - - let add a b = add_n a b - - let sub a b = of_z @@ sub a b - - let one = one_n -end - type ticket_amount = Ticket_amount.t type 'a ticket = {ticketer : Contract.t; contents : 'a; amount : ticket_amount} diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index 966659122b73..8f37c9788e50 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -167,20 +167,6 @@ module Script_timelock : sig val get_plaintext_size : chest -> int end -module Ticket_amount : sig - type t = private n num - - val of_n : n num -> t option - - val of_z : z num -> t option - - val add : t -> t -> t - - val sub : t -> t -> t option - - val one : t -end - type ticket_amount = Ticket_amount.t type 'a ticket = {ticketer : Contract.t; contents : 'a; amount : ticket_amount} diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml index 91da29fff9fc..c8dfe4b987ce 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_ticket_scanner.ml @@ -115,8 +115,7 @@ let make_ex_ticket ctxt ~ticketer ~type_exp ~content_exp ~amount = in let amount = Script_int.(abs @@ of_int amount) in let amount = - WithExceptions.Option.get ~loc:__LOC__ - @@ Script_typed_ir.Ticket_amount.of_n amount + WithExceptions.Option.get ~loc:__LOC__ @@ Ticket_amount.of_n amount in let ticket = Script_typed_ir.{ticketer; contents; amount} in return (Ticket_scanner.Ex_ticket (cty, ticket), ctxt) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml index fda068fbaf97..86ae64837a90 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_sc_rollup_management_protocol.ml @@ -73,8 +73,8 @@ let check_encode_decode_outbox_message ctxt message = let string_ticket ticketer contents amount = let open WithExceptions in let amount = - Option.get ~loc:__LOC__ @@ Script_typed_ir.Ticket_amount.of_n - @@ Script_int.abs @@ Script_int.of_int amount + Option.get ~loc:__LOC__ @@ Ticket_amount.of_n @@ Script_int.abs + @@ Script_int.of_int amount in let ticketer = Result.get_ok ~loc:__LOC__ (Contract.of_b58check ticketer) in let contents = diff --git a/src/proto_alpha/lib_protocol/ticket_amount.ml b/src/proto_alpha/lib_protocol/ticket_amount.ml new file mode 100644 index 000000000000..d1a800d00d5d --- /dev/null +++ b/src/proto_alpha/lib_protocol/ticket_amount.ml @@ -0,0 +1,41 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Marigold, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Script_int + +type t = n num + +let of_n n = + if Compare.Int.(Script_int.(compare n zero_n) > 0) then Some (n : t) else None + +open Script_int + +let of_z z = Option.bind (is_nat z) of_n + +let add = add_n + +let sub a b = of_z @@ sub a b + +let one = one_n diff --git a/src/proto_alpha/lib_protocol/ticket_amount.mli b/src/proto_alpha/lib_protocol/ticket_amount.mli new file mode 100644 index 000000000000..8b70e1fc37fd --- /dev/null +++ b/src/proto_alpha/lib_protocol/ticket_amount.mli @@ -0,0 +1,42 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2022 Marigold, *) +(* *) +(* 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. *) +(* *) +(*****************************************************************************) + +open Script_int + +(* A type for ticket amount values to ensure positivity *) +type t = private n num + +(* Converts a natural number to a ticket amount value unless the input is zero *) +val of_n : n num -> t option + +(* Converts a integral number to a ticket amount value unless the input is not positive *) +val of_z : z num -> t option + +val add : t -> t -> t + +(* Subtract among ticket amount values unless the resultant amount is not positive *) +val sub : t -> t -> t option + +val one : t diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 267a95211b9c..1f545ae4c9ae 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -24,9 +24,6 @@ (*****************************************************************************) open Alpha_context -module Ticket_amount = Script_typed_ir.Ticket_amount - -type ticket_amount = Script_typed_ir.ticket_amount type ticket_transfer = { destination : Destination.t; @@ -36,7 +33,7 @@ type ticket_transfer = { type ticket_token_diff = { ticket_token : Ticket_token.ex_token; total_amount : Script_int.n Script_int.num; - destinations : (Destination.t * ticket_amount) list; + destinations : (Destination.t * Ticket_amount.t) list; } type error += Failed_to_get_script of Contract.t | Contract_not_originated @@ -118,7 +115,7 @@ module Ticket_token_map = struct - The internal contract-indexed map cannot be empty. *) - let add ctxt ~ticket_token ~destination ~(amount : ticket_amount) map = + let add ctxt ~ticket_token ~destination ~(amount : Ticket_amount.t) map = Ticket_token_map.update ctxt ticket_token @@ -132,7 +129,7 @@ module Ticket_token_map = struct (* Update the inner contract map *) let update ctxt prev_amt_opt = match prev_amt_opt with - | Some (prev_amount : ticket_amount) -> + | Some (prev_amount : Ticket_amount.t) -> Gas.consume ctxt Script_int.( @@ -254,7 +251,7 @@ let ticket_diffs_of_operations ctxt operations = ticket-token. *) Destination_map.fold ctxt - (fun ctxt total_amount _destination (amount : ticket_amount) -> + (fun ctxt total_amount _destination (amount : Ticket_amount.t) -> Gas.consume ctxt Script_int.( -- GitLab From 9b9bbb6e07bd81e45525bb119fe63c1963771244 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Fri, 9 Sep 2022 15:56:56 +0800 Subject: [PATCH 7/8] Proto: retype ticket amount with Ticket_amount.t --- .../lib_client/client_proto_context.mli | 2 +- .../lib_client/operation_result.ml | 2 +- .../client_proto_context_commands.ml | 53 ++++++++++--------- src/proto_alpha/lib_protocol/TEZOS_PROTOCOL | 4 +- .../lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/apply.ml | 11 +--- src/proto_alpha/lib_protocol/dune | 16 +++--- .../lib_protocol/operation_repr.ml | 4 +- .../lib_protocol/operation_repr.mli | 2 +- .../lib_protocol/test/helpers/op.ml | 4 +- .../lib_protocol/test/helpers/op.mli | 4 +- .../test/helpers/operation_generator.ml | 10 +++- .../integration/operations/test_tx_rollup.ml | 37 ++++++++----- .../validate/manager_operation_helpers.ml | 4 +- src/proto_alpha/lib_protocol/ticket_amount.ml | 11 +++- .../lib_protocol/ticket_amount.mli | 4 ++ 16 files changed, 98 insertions(+), 72 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 7830269d141f..382300861838 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -792,7 +792,7 @@ val transfer_ticket : contents:string -> ty:string -> ticketer:Contract.t -> - amount:Z.t -> + amount:Ticket_amount.t -> destination:Contract.t -> entrypoint:Entrypoint.t -> unit -> diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 4c0173dff994..d178952cef64 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -305,7 +305,7 @@ let pp_manager_operation_content (type kind) source ppf Contract.pp ticketer Z.pp_print - amount + Script_int.(to_zint (amount :> n num)) Contract.pp destination (fun ppf entrypoint -> diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 39b34b34cc9b..7393c2ecee14 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -2876,31 +2876,34 @@ let commands_rw () = cctxt -> let open Lwt_result_syntax in let* _, src_pk, src_sk = Client_keys.get_key cctxt source in - let* _res = - transfer_ticket - cctxt - ~chain:cctxt#chain - ~block:cctxt#block - ~dry_run - ~verbose_signing - ?fee - ?storage_limit - ?counter - ?confirmations:cctxt#confirmations - ~simulation - ~source - ~src_pk - ~src_sk - ~fee_parameter - ~contents - ~ty - ~ticketer - ~amount - ~destination - ~entrypoint - () - in - return_unit); + match Ticket_amount.of_zint amount with + | Some amount -> + let* _res = + transfer_ticket + cctxt + ~chain:cctxt#chain + ~block:cctxt#block + ~dry_run + ~verbose_signing + ?fee + ?storage_limit + ?counter + ?confirmations:cctxt#confirmations + ~simulation + ~source + ~src_pk + ~src_sk + ~fee_parameter + ~contents + ~ty + ~ticketer + ~amount + ~destination + ~entrypoint + () + in + return_unit + | None -> cctxt#error "ticket quantity should not be zero or negative"); command ~group ~desc:"Originate a new smart-contract rollup." diff --git a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL index 675d17f88840..fc3f11c84905 100644 --- a/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL +++ b/src/proto_alpha/lib_protocol/TEZOS_PROTOCOL @@ -92,6 +92,8 @@ "Liquidity_baking_repr", "Block_header_repr", "Destination_repr", + "Script_int", + "Ticket_amount", "Operation_repr", "Manager_repr", "Commitment_repr", @@ -173,7 +175,6 @@ "Alpha_context", "Script_string", - "Script_int", "Script_timestamp", "Tx_rollup_l2_storage_sig", @@ -183,7 +184,6 @@ "Tx_rollup_l2_apply", "Tx_rollup_l2_verifier", - "Ticket_amount", "Local_gas_counter", "Script_tc_errors", "Gas_monad", diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 434e90807de9..a15e7045571c 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -4216,7 +4216,7 @@ and _ manager_operation = contents : Script.lazy_expr; ty : Script.lazy_expr; ticketer : Contract.t; - amount : Z.t; + amount : Ticket_amount.t; destination : Contract.t; entrypoint : Entrypoint.t; } diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 32eb8c178ed2..d7698bb66248 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -862,7 +862,8 @@ let apply_manager_operation : ( Tx_rollup_withdraw. {claimer; amount; ticket_hash = tx_rollup_ticket_hash}, ticket_token ) = - Ticket_amount.of_z @@ Script_int.of_zint (Tx_rollup_l2_qty.to_z amount) + Tx_rollup_l2_qty.to_z amount + |> Ticket_amount.of_zint |> Option.value_e ~error: (Error_monad.trace_of_error @@ -896,14 +897,6 @@ let apply_manager_operation : return (ctxt, result, []) | Transfer_ticket {contents; ty; ticketer; amount; destination; entrypoint} -> ( - (* The encoding ensures that the amount is in a natural number. Here is - mainly to check that it is non-zero.*) - Option.value_e - ~error: - (Error_monad.trace_of_error - Script_tc_errors.Forbidden_zero_ticket_quantity) - @@ Ticket_amount.of_z (Script_int.of_zint amount) - >>?= fun amount -> match destination with | Implicit _ -> fail Cannot_transfer_ticket_to_implicit | Originated destination_hash -> diff --git a/src/proto_alpha/lib_protocol/dune b/src/proto_alpha/lib_protocol/dune index b4b6a01737b8..aabf5f136dc6 100644 --- a/src/proto_alpha/lib_protocol/dune +++ b/src/proto_alpha/lib_protocol/dune @@ -118,6 +118,8 @@ Liquidity_baking_repr Block_header_repr Destination_repr + Script_int + Ticket_amount Operation_repr Manager_repr Commitment_repr @@ -189,7 +191,6 @@ Dal_slot_storage Alpha_context Script_string - Script_int Script_timestamp Tx_rollup_l2_storage_sig Tx_rollup_l2_context_sig @@ -197,7 +198,6 @@ Tx_rollup_l2_batch Tx_rollup_l2_apply Tx_rollup_l2_verifier - Ticket_amount Local_gas_counter Script_tc_errors Gas_monad @@ -378,6 +378,8 @@ liquidity_baking_repr.ml liquidity_baking_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli + script_int.ml script_int.mli + ticket_amount.ml ticket_amount.mli operation_repr.ml operation_repr.mli manager_repr.ml manager_repr.mli commitment_repr.ml commitment_repr.mli @@ -450,7 +452,6 @@ dal_slot_storage.ml dal_slot_storage.mli alpha_context.ml alpha_context.mli script_string.ml script_string.mli - script_int.ml script_int.mli script_timestamp.ml script_timestamp.mli tx_rollup_l2_storage_sig.ml tx_rollup_l2_context_sig.ml @@ -458,7 +459,6 @@ tx_rollup_l2_batch.ml tx_rollup_l2_batch.mli tx_rollup_l2_apply.ml tx_rollup_l2_apply.mli tx_rollup_l2_verifier.ml tx_rollup_l2_verifier.mli - ticket_amount.ml ticket_amount.mli local_gas_counter.ml local_gas_counter.mli script_tc_errors.ml gas_monad.ml gas_monad.mli @@ -619,6 +619,8 @@ liquidity_baking_repr.ml liquidity_baking_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli + script_int.ml script_int.mli + ticket_amount.ml ticket_amount.mli operation_repr.ml operation_repr.mli manager_repr.ml manager_repr.mli commitment_repr.ml commitment_repr.mli @@ -691,7 +693,6 @@ dal_slot_storage.ml dal_slot_storage.mli alpha_context.ml alpha_context.mli script_string.ml script_string.mli - script_int.ml script_int.mli script_timestamp.ml script_timestamp.mli tx_rollup_l2_storage_sig.ml tx_rollup_l2_context_sig.ml @@ -699,7 +700,6 @@ tx_rollup_l2_batch.ml tx_rollup_l2_batch.mli tx_rollup_l2_apply.ml tx_rollup_l2_apply.mli tx_rollup_l2_verifier.ml tx_rollup_l2_verifier.mli - ticket_amount.ml ticket_amount.mli local_gas_counter.ml local_gas_counter.mli script_tc_errors.ml gas_monad.ml gas_monad.mli @@ -865,6 +865,8 @@ liquidity_baking_repr.ml liquidity_baking_repr.mli block_header_repr.ml block_header_repr.mli destination_repr.ml destination_repr.mli + script_int.ml script_int.mli + ticket_amount.ml ticket_amount.mli operation_repr.ml operation_repr.mli manager_repr.ml manager_repr.mli commitment_repr.ml commitment_repr.mli @@ -937,7 +939,6 @@ dal_slot_storage.ml dal_slot_storage.mli alpha_context.ml alpha_context.mli script_string.ml script_string.mli - script_int.ml script_int.mli script_timestamp.ml script_timestamp.mli tx_rollup_l2_storage_sig.ml tx_rollup_l2_context_sig.ml @@ -945,7 +946,6 @@ tx_rollup_l2_batch.ml tx_rollup_l2_batch.mli tx_rollup_l2_apply.ml tx_rollup_l2_apply.mli tx_rollup_l2_verifier.ml tx_rollup_l2_verifier.mli - ticket_amount.ml ticket_amount.mli local_gas_counter.ml local_gas_counter.mli script_tc_errors.ml gas_monad.ml gas_monad.mli diff --git a/src/proto_alpha/lib_protocol/operation_repr.ml b/src/proto_alpha/lib_protocol/operation_repr.ml index 386003470779..020ffe01b888 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.ml +++ b/src/proto_alpha/lib_protocol/operation_repr.ml @@ -417,7 +417,7 @@ and _ manager_operation = contents : Script_repr.lazy_expr; ty : Script_repr.lazy_expr; ticketer : Contract_repr.t; - amount : Z.t; + amount : Ticket_amount.t; destination : Contract_repr.t; entrypoint : Entrypoint_repr.t; } @@ -1035,7 +1035,7 @@ module Encoding = struct (req "ticket_contents" Script_repr.lazy_expr_encoding) (req "ticket_ty" Script_repr.lazy_expr_encoding) (req "ticket_ticketer" Contract_repr.encoding) - (req "ticket_amount" n) + (req "ticket_amount" Ticket_amount.encoding) (req "destination" Contract_repr.encoding) (req "entrypoint" Entrypoint_repr.simple_encoding); select = diff --git a/src/proto_alpha/lib_protocol/operation_repr.mli b/src/proto_alpha/lib_protocol/operation_repr.mli index ce9e4cf2089e..168184395c05 100644 --- a/src/proto_alpha/lib_protocol/operation_repr.mli +++ b/src/proto_alpha/lib_protocol/operation_repr.mli @@ -481,7 +481,7 @@ and _ manager_operation = ty : Script_repr.lazy_expr; (** Type of the withdrawn ticket's contents *) ticketer : Contract_repr.t; (** Ticketer of the withdrawn ticket *) - amount : Z.t; + amount : Ticket_amount.t; (** Quantity of the withdrawn ticket. Must match the amount that was enabled. *) destination : Contract_repr.t; diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index 7eab0f71f8d2..5415b242697f 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -756,8 +756,8 @@ let tx_rollup_dispatch_tickets ?force_reveal ?counter ?fee ?gas_limit sign account.sk ctxt to_sign_op let transfer_ticket ?force_reveal ?counter ?fee ?gas_limit ?storage_limit ctxt - ~(source : Contract.t) ~contents ~ty ~ticketer amount ~destination - entrypoint = + ~(source : Contract.t) ~contents ~ty ~ticketer ~amount ~destination + ~entrypoint = manager_operation ?force_reveal ?counter diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.mli b/src/proto_alpha/lib_protocol/test/helpers/op.mli index 43be79111161..a52e005b9df4 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.mli +++ b/src/proto_alpha/lib_protocol/test/helpers/op.mli @@ -528,9 +528,9 @@ val transfer_ticket : contents:Script.lazy_expr -> ty:Script.lazy_expr -> ticketer:Contract.t -> - Z.t -> + amount:Ticket_amount.t -> destination:Contract.t -> - Entrypoint_repr.t -> + entrypoint:Entrypoint_repr.t -> (packed_operation, tztrace) result Lwt.t (** [tx_rollup_reject ctxt source tx_rollup tx_rollup level message diff --git a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml index d645e1bdb48c..58b381a5be0a 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/operation_generator.ml @@ -643,7 +643,15 @@ let generate_transfer_ticket random_state : let ty = Script.lazy_expr (Expr.from_string "nat") in let ticketer = random_contract random_state in let destination = random_contract random_state in - let amount = random_counter random_state in + let amount = + WithExceptions.Option.get ~loc:__LOC__ + @@ Ticket_amount.of_n + @@ Script_int.( + add_n one_n + @@ Option.value ~default:zero_n + @@ is_nat @@ of_zint + @@ random_counter random_state) + in let entrypoint = Entrypoint.default in Transfer_ticket {contents; ty; ticketer; amount; destination; entrypoint} in diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml index 5ab504d79889..e572e2980095 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_tx_rollup.ml @@ -4360,9 +4360,12 @@ module Withdraw = struct ~contents:(Script.lazy_expr Nat_ticket.contents) ~ty:(Script.lazy_expr Nat_ticket.ty) ~ticketer:deposit_contract - (Tx_rollup_l2_qty.to_z half_amount) + ~amount: + (WithExceptions.Option.get ~loc:__LOC__ + @@ Ticket_amount.of_z + @@ Script_int.of_int64 int64_half_amount) ~destination:withdraw_contract - entrypoint + ~entrypoint >>=? fun operation -> Block.bake ~operation block >>=? fun block -> (* 4.1 We assert that [withdraw_contract] has received the ticket as @@ -4432,9 +4435,12 @@ module Withdraw = struct ~contents:(Script.lazy_expr Nat_ticket.contents) ~ty:(Script.lazy_expr Nat_ticket.ty) ~ticketer:deposit_contract - (Tx_rollup_l2_qty.to_z half_amount) + ~amount: + (WithExceptions.Option.get ~loc:__LOC__ + @@ Ticket_amount.of_z + @@ Script_int.of_int64 int64_half_amount) ~destination:withdraw_dropping_contract - entrypoint + ~entrypoint >>=? fun operation -> Block.bake ~operation block >>=? fun block -> (* 4. Finally, we assert that [withdraw_contract] has received the ticket as @@ -4844,18 +4850,18 @@ module Withdraw = struct ~contents:(Script.lazy_expr Nat_ticket.contents) ~ty:(Script.lazy_expr Nat_ticket.ty) ~ticketer:deposit_contract - qty + ~amount:qty ~destination:withdraw_contract - Entrypoint.default + ~entrypoint:Entrypoint.default in (* Execute withdraw with half amount *) - withdraw_op account1 block Z.one >>=? fun operation -> + withdraw_op account1 block Ticket_amount.one >>=? fun operation -> Block.bake ~operation block >>=? fun block -> (* Execute withdraw with the rest amount *) - withdraw_op account1 block Z.one >>=? fun operation -> + withdraw_op account1 block Ticket_amount.one >>=? fun operation -> Block.bake ~operation block >>=? fun block -> (* Execute again, now should fail with a ticket table error *) - withdraw_op account1 block Z.one >>=? fun operation -> + withdraw_op account1 block Ticket_amount.one >>=? fun operation -> Incremental.begin_construction block >>=? fun incr -> Incremental.add_operation ~expect_apply_failure:(function @@ -4882,8 +4888,10 @@ module Withdraw = struct [ticket_info3; ticket_info4] >>=? fun operation -> Block.bake ~operation block >>=? fun block -> - withdraw_op account1 block (Z.of_int 2) >>=? fun operation1 -> - withdraw_op account2 block (Z.of_int 2) >>=? fun operation2 -> + withdraw_op account1 block Ticket_amount.(add one one) + >>=? fun operation1 -> + withdraw_op account2 block Ticket_amount.(add one one) + >>=? fun operation2 -> Block.bake ~operations:[operation1; operation2] block >>=? fun _block -> return_unit @@ -5462,9 +5470,12 @@ module Withdraw = struct ~contents:(Script.lazy_expr Nat_ticket.contents) ~ty:(Script.lazy_expr Nat_ticket.ty) ~ticketer:forge_withdraw_deposit_contract - (Tx_rollup_l2_qty.to_z Nat_ticket.amount) + ~amount: + (WithExceptions.Option.get ~loc:__LOC__ + @@ Ticket_amount.of_zint + @@ Tx_rollup_l2_qty.to_z Nat_ticket.amount) ~destination:forge_withdraw_deposit_contract - (Entrypoint.of_string_strict_exn "withdraw") + ~entrypoint:(Entrypoint.of_string_strict_exn "withdraw") >>=? fun operation -> Block.bake ~operation block in let token_one = diff --git a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml index c1bd639da1e3..c6e0d8fa4ad8 100644 --- a/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/integration/validate/manager_operation_helpers.ml @@ -842,13 +842,13 @@ let mk_transfer_ticket (oinfos : operation_req) (infos : infos) = (match infos.accounts.tx with | None -> infos.accounts.source | Some tx -> tx)) - Z.zero + ~amount:Ticket_amount.one ~destination: (contract_of (match infos.accounts.dest with | None -> infos.accounts.source | Some dest -> dest)) - Entrypoint.default + ~entrypoint:Entrypoint.default let mk_tx_rollup_dispacth_ticket (oinfos : operation_req) (infos : infos) = let open Lwt_result_syntax in diff --git a/src/proto_alpha/lib_protocol/ticket_amount.ml b/src/proto_alpha/lib_protocol/ticket_amount.ml index d1a800d00d5d..9bc9cbbfebf6 100644 --- a/src/proto_alpha/lib_protocol/ticket_amount.ml +++ b/src/proto_alpha/lib_protocol/ticket_amount.ml @@ -30,12 +30,19 @@ type t = n num let of_n n = if Compare.Int.(Script_int.(compare n zero_n) > 0) then Some (n : t) else None -open Script_int - let of_z z = Option.bind (is_nat z) of_n +let of_zint z = of_z @@ of_zint z + let add = add_n let sub a b = of_z @@ sub a b let one = one_n + +let encoding = + let open Data_encoding in + conv_with_guard + to_zint + (fun n -> Option.value_e ~error:"expecting positive number" @@ of_zint n) + n diff --git a/src/proto_alpha/lib_protocol/ticket_amount.mli b/src/proto_alpha/lib_protocol/ticket_amount.mli index 8b70e1fc37fd..191e0949cc70 100644 --- a/src/proto_alpha/lib_protocol/ticket_amount.mli +++ b/src/proto_alpha/lib_protocol/ticket_amount.mli @@ -28,12 +28,16 @@ open Script_int (* A type for ticket amount values to ensure positivity *) type t = private n num +val encoding : t Data_encoding.t + (* Converts a natural number to a ticket amount value unless the input is zero *) val of_n : n num -> t option (* Converts a integral number to a ticket amount value unless the input is not positive *) val of_z : z num -> t option +val of_zint : Z.t -> t option + val add : t -> t -> t (* Subtract among ticket amount values unless the resultant amount is not positive *) -- GitLab From 5f6c4dd0f30d14857e814050fb37dc228b1980e0 Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Mon, 12 Sep 2022 23:50:10 +0800 Subject: [PATCH 8/8] Test: remove environment variable and reinstate tests --- tests_python/.python-version | 1 - tezt/tests/iticket_migration.ml | 27 +++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 tests_python/.python-version diff --git a/tests_python/.python-version b/tests_python/.python-version deleted file mode 100644 index 29c9b940b643..000000000000 --- a/tests_python/.python-version +++ /dev/null @@ -1 +0,0 @@ -tezos diff --git a/tezt/tests/iticket_migration.ml b/tezt/tests/iticket_migration.ml index da69814577a7..0bddb3a7f69b 100644 --- a/tezt/tests/iticket_migration.ml +++ b/tezt/tests/iticket_migration.ml @@ -544,22 +544,21 @@ let register ~migrate_from ~migrate_to = let blocks_per_cycle = JSON.(get "blocks_per_cycle" parameters |> as_int) in match migrate_to with | Protocol.Alpha -> - (* test_ticket_migration - ~blocks_per_cycle - ~migration_level:(2 * blocks_per_cycle) - ~migrate_from - ~migrate_to ; - test_iticket_deprecation ~protocol:Protocol.Alpha ; - test_ticket_migration_in_storage - ~blocks_per_cycle - ~migration_level:(2 * blocks_per_cycle) - ~migrate_from - ~migrate_to ; *) + test_ticket_migration + ~blocks_per_cycle + ~migration_level:(2 * blocks_per_cycle) + ~migrate_from + ~migrate_to ; + test_iticket_deprecation ~protocol:Protocol.Alpha ; + test_ticket_migration_in_storage + ~blocks_per_cycle + ~migration_level:(2 * blocks_per_cycle) + ~migrate_from + ~migrate_to ; test_ticket_migration_in_storage_with_zero_tickets ~blocks_per_cycle ~migration_level:(2 * blocks_per_cycle) ~migrate_from - ~migrate_to - (* ; - test_iticket_after_migration ~protocol:Protocol.Alpha *) + ~migrate_to ; + test_iticket_after_migration ~protocol:Protocol.Alpha | _ -> () -- GitLab