diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 101c62bf67fac56db53756cd3be6712c763cf9aa..8bef53c4780abb4c494f27735cbda291effbf423 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1496,9 +1496,9 @@ module View_helpers = struct Script_typed_ir.Internal_operation { operation = - Transaction + Transaction_to_contract { - destination = Contract destination; + destination; unparsed_parameters; entrypoint = _; amount = _; @@ -2576,11 +2576,11 @@ module RPC = struct ticket_diffs = _; }, _ctxt ) -> - View_helpers.extract_parameter_from_operations - entrypoint - operations - viewer_contract - >>?= fun parameter -> Lwt.return (Script_repr.force_decode parameter)) ; + Lwt.return + (View_helpers.extract_parameter_from_operations + entrypoint + operations + viewer_contract)) ; Registration.register0 ~chunked:true S.run_script_view diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 052f177cd8dae59bcc7d07b50cfbbea62e1379ec..115afe06eda16770562196e28066f0d042eeb486 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -95,7 +95,7 @@ type error += | Set_deposits_limit_too_high of {limit : Tez.t; max_limit : Tez.t} | Empty_transaction of Contract.t | Tx_rollup_feature_disabled - | Tx_rollup_invalid_transaction_amount + | Tx_rollup_invalid_transaction_ticket_amount | Tx_rollup_non_internal_transaction | Cannot_transfer_ticket_to_implicit | Sc_rollup_feature_disabled @@ -502,19 +502,17 @@ let () = register_error_kind `Permanent - ~id:"operation.tx_rollup_invalid_transaction_amount" - ~title:"Transaction amount to a transaction rollup must be zero" + ~id:"operation.tx_rollup_invalid_transaction_ticket_amount" + ~title:"Amount of transferred ticket is too high" ~description: - "Because transaction rollups are outside of the delegation mechanism of \ - Tezos, they cannot own Tez, and therefore transactions targeting a \ - transaction rollup must have its amount field set to zero." + "The ticket amount of a rollup transaction must fit in a signed 64-bit \ + integer." ~pp:(fun ppf () -> - Format.fprintf - ppf - "Transaction amount to a transaction rollup must be zero.") + Format.fprintf ppf "Amount of transferred ticket is too high.") Data_encoding.unit - (function Tx_rollup_invalid_transaction_amount -> Some () | _ -> None) - (fun () -> Tx_rollup_invalid_transaction_amount) ; + (function + | Tx_rollup_invalid_transaction_ticket_amount -> Some () | _ -> None) + (fun () -> Tx_rollup_invalid_transaction_ticket_amount) ; register_error_kind `Permanent @@ -1010,69 +1008,64 @@ let ex_ticket_size : (* gas *) return (ctxt, ty_size + val_size) -let apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters ~amount - ~entrypoint ~payer ~dst_rollup ~since = +let apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters ~payer + ~dst_rollup ~since = assert_tx_rollup_feature_enabled ctxt >>=? fun () -> - fail_unless Tez.(amount = zero) Tx_rollup_invalid_transaction_amount + (* If the ticket deposit fails on L2 for some reason + (e.g. [Balance_overflow] in the recipient), then it is + returned to [payer]. As [payer] is implicit, it cannot own + tickets directly. Therefore, erroneous deposits are + returned using the L2 withdrawal mechanism: a failing + deposit emits a withdrawal that can be executed by + [payer]. *) + Tx_rollup_parameters.get_deposit_parameters parameters_ty parameters + >>?= fun {ex_ticket; l2_destination} -> + ex_ticket_size ctxt ex_ticket >>=? fun (ctxt, ticket_size) -> + let limit = Constants.tx_rollup_max_ticket_payload_size ctxt in + fail_when + Compare.Int.(ticket_size > limit) + (Tx_rollup_errors_repr.Ticket_payload_size_limit_exceeded + {payload_size = ticket_size; limit}) >>=? fun () -> - if Entrypoint.(entrypoint = Tx_rollup.deposit_entrypoint) then - (* If the ticket deposit fails on L2 for some reason - (e.g. [Balance_overflow] in the recipient), then it is - returned to [payer]. As [payer] is implicit, it cannot own - tickets directly. Therefore, erroneous deposits are - returned using the L2 withdrawal mechanism: a failing - deposit emits a withdrawal that can be executed by - [payer]. *) - Tx_rollup_parameters.get_deposit_parameters parameters_ty parameters - >>?= fun {ex_ticket; l2_destination} -> - ex_ticket_size ctxt ex_ticket >>=? fun (ctxt, ticket_size) -> - let limit = Constants.tx_rollup_max_ticket_payload_size ctxt in - fail_when - Compare.Int.(ticket_size > limit) - (Tx_rollup_errors_repr.Ticket_payload_size_limit_exceeded - {payload_size = ticket_size; limit}) - >>=? fun () -> - let (ex_token, ticket_amount) = - Ticket_token.token_and_amount_of_ex_ticket ex_ticket - in - Ticket_balance_key.of_ex_token ctxt ~owner:(Tx_rollup dst_rollup) ex_token - >>=? fun (ticket_hash, ctxt) -> - Option.value_e - ~error:(Error_monad.trace_of_error Tx_rollup_invalid_transaction_amount) - (Option.bind - (Script_int.to_int64 ticket_amount) - Tx_rollup_l2_qty.of_int64) - >>?= fun ticket_amount -> - error_when - Tx_rollup_l2_qty.(ticket_amount <= zero) - Forbidden_zero_ticket_quantity - >>?= fun () -> - let (deposit, message_size) = - Tx_rollup_message.make_deposit - payer - l2_destination - ticket_hash - ticket_amount - in - Tx_rollup_state.get ctxt dst_rollup >>=? fun (ctxt, state) -> - Tx_rollup_state.burn_cost ~limit:None state message_size >>?= fun cost -> - Token.transfer ctxt (`Contract (Contract.Implicit payer)) `Burned cost - >>=? fun (ctxt, balance_updates) -> - Tx_rollup_inbox.append_message ctxt dst_rollup state deposit - >>=? fun (ctxt, state, paid_storage_size_diff) -> - Tx_rollup_state.update ctxt dst_rollup state >>=? fun ctxt -> - let result = - Transaction_result - (Transaction_to_tx_rollup_result - { - balance_updates; - consumed_gas = Gas.consumed ~since ~until:ctxt; - ticket_hash; - paid_storage_size_diff; - }) - in - return (ctxt, result, []) - else fail (Script_tc_errors.No_such_entrypoint entrypoint) + let (ex_token, ticket_amount) = + Ticket_token.token_and_amount_of_ex_ticket ex_ticket + in + Ticket_balance_key.of_ex_token ctxt ~owner:(Tx_rollup dst_rollup) ex_token + >>=? fun (ticket_hash, ctxt) -> + 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) + >>?= fun ticket_amount -> + error_when + Tx_rollup_l2_qty.(ticket_amount <= zero) + Forbidden_zero_ticket_quantity + >>?= fun () -> + let (deposit, message_size) = + Tx_rollup_message.make_deposit + payer + l2_destination + ticket_hash + ticket_amount + in + Tx_rollup_state.get ctxt dst_rollup >>=? fun (ctxt, state) -> + Tx_rollup_state.burn_cost ~limit:None state message_size >>?= fun cost -> + Token.transfer ctxt (`Contract (Contract.Implicit payer)) `Burned cost + >>=? fun (ctxt, balance_updates) -> + Tx_rollup_inbox.append_message ctxt dst_rollup state deposit + >>=? fun (ctxt, state, paid_storage_size_diff) -> + Tx_rollup_state.update ctxt dst_rollup state >>=? fun ctxt -> + let result = + Transaction_result + (Transaction_to_tx_rollup_result + { + balance_updates; + consumed_gas = Gas.consumed ~since ~until:ctxt; + ticket_hash; + paid_storage_size_diff; + }) + in + return (ctxt, result, []) let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract ~delegate ~source ~credit ~before_operation = @@ -1179,11 +1172,11 @@ let apply_internal_manager_operation_content : ~gas_consumed_in_precheck >>=? fun (ctxt, before_operation, consume_deserialization_gas) -> match operation with - | Transaction + | Transaction_to_contract { + destination; amount; unparsed_parameters = _; - destination = Contract contract; entrypoint; location; parameters_ty; @@ -1193,7 +1186,7 @@ let apply_internal_manager_operation_content : ~ctxt ~parameter:(Typed_arg (location, parameters_ty, typed_parameters)) ~source - ~contract + ~contract:destination ~amount ~entrypoint ~before_operation @@ -1205,24 +1198,14 @@ let apply_internal_manager_operation_content : ( ctxt, (manager_result : kind successful_manager_operation_result), operations ) - | Transaction - { - amount; - destination = Tx_rollup dst; - entrypoint; - unparsed_parameters = _; - location = _; - parameters_ty; - parameters; - } -> + | Transaction_to_tx_rollup + {destination; unparsed_parameters = _; parameters_ty; parameters} -> apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters - ~amount - ~entrypoint ~payer - ~dst_rollup:dst + ~dst_rollup:destination ~since:before_operation | Origination { @@ -1406,7 +1389,7 @@ let apply_external_manager_operation_content : ~contents ~ty ~source:source_contract - ~destination:(Contract destination) + ~destination ~entrypoint ~amount ctxt @@ -1786,8 +1769,8 @@ let apply_internal_manager_operations ctxt mode ~payer ~chain_id ops = | [] -> Lwt.return (Success ctxt, List.rev applied) | Script_typed_ir.Internal_operation ({source; operation; nonce} as op) :: rest -> ( - let op_res = Apply_results.contents_of_internal_operation op in (if internal_nonce_already_recorded ctxt nonce then + let op_res = Apply_results.contents_of_internal_operation op in fail (Internal_operation_replay (Internal_contents op_res)) else let ctxt = record_internal_nonce ctxt nonce in diff --git a/src/proto_alpha/lib_protocol/apply.mli b/src/proto_alpha/lib_protocol/apply.mli index cc6d8139ccf84bc02e4ae6689b974c1f717ac436..616e111969220d62ac7f6a11f9e37de13659397d 100644 --- a/src/proto_alpha/lib_protocol/apply.mli +++ b/src/proto_alpha/lib_protocol/apply.mli @@ -40,7 +40,7 @@ type error += | Internal_operation_replay of packed_internal_contents | Gas_quota_exceeded_init_deserialize | Tx_rollup_feature_disabled - | Tx_rollup_invalid_transaction_amount + | Tx_rollup_invalid_transaction_ticket_amount | Tx_rollup_non_internal_transaction | Sc_rollup_feature_disabled | Inconsistent_counters diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index a2146f53b400bad35ec55c564eb3b5bbd3246dcb..68a004b600145fe2018f0160224e36e29c1cc592 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -87,9 +87,24 @@ let contents_of_internal_operation (type kind) kind internal_contents = let operation : kind internal_manager_operation = match operation with - | Transaction {destination; amount; entrypoint; unparsed_parameters; _} -> + | Transaction_to_contract + {destination; amount; entrypoint; unparsed_parameters; _} -> Transaction - {destination; amount; entrypoint; parameters = unparsed_parameters} + { + destination = Contract destination; + amount; + entrypoint; + parameters = Script.lazy_expr unparsed_parameters; + } + | Transaction_to_tx_rollup {destination; unparsed_parameters; _} -> + Transaction + { + destination = Tx_rollup destination; + (* Dummy amount used for the external untyped view of internal transactions *) + amount = Tez.zero; + entrypoint = Tx_rollup.deposit_entrypoint; + parameters = Script.lazy_expr unparsed_parameters; + } | Origination {origination; _} -> Origination origination | Delegation delegate -> Delegation delegate in diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index d434ba18bfb019f330e73fce871ec6e9167746e3..1fe15e6e01cddbc8f8cc39ef8ef40f1620b1888c 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -38,6 +38,25 @@ open Script_typed_ir open Script_ir_translator open Local_gas_counter +type error += Tx_rollup_invalid_transaction_amount + +let () = + register_error_kind + `Permanent + ~id:"operation.tx_rollup_invalid_transaction_amount" + ~title:"Transaction amount to a transaction rollup must be zero" + ~description: + "Because transaction rollups are outside of the delegation mechanism of \ + Tezos, they cannot own Tez, and therefore transactions targeting a \ + transaction rollup must have its amount field set to zero." + ~pp:(fun ppf () -> + Format.pp_print_string + ppf + "Transaction amount to a transaction rollup must be zero.") + Data_encoding.unit + (function Tx_rollup_invalid_transaction_amount -> Some () | _ -> None) + (fun () -> Tx_rollup_invalid_transaction_amount) + (* Computing the cost of Michelson instructions @@ -498,51 +517,78 @@ let apply ctxt gas capture_ty capture lam = let (gas, ctxt) = local_gas_counter_and_outdated_context ctxt in return (lam', ctxt, gas) -(* [transfer (ctxt, sc) gas tez parameters_ty parameters destination entrypoint] - creates an operation that transfers an amount of [tez] to - a contract determined by [(destination, entrypoint)] - instantiated with argument [parameters] of type [parameters_ty]. *) -let transfer (ctxt, sc) gas amount location parameters_ty parameters destination - entrypoint = - (* [craft_transfer_parameters ctxt tp p] reorganizes, if need be, the - parameters submitted by the interpreter to prepare them for the - [Transaction] operation. *) - let craft_transfer_parameters : - type a ac. - context -> - (a, ac) ty -> - (location, prim) Micheline.node -> - Destination.t -> - ((location, prim) Micheline.node * context) tzresult = - fun ctxt tp p -> function - | Contract _ -> ok (p, ctxt) - (* The entrypoints of a transaction rollup are polymorphic wrt. the - tickets it can process. However, two Michelson values can have - the same Micheline representation, but different types. What - this means is that when we start the execution of a transaction - rollup, the type of its argument is lost if we just give it the - values provided by the Michelson script. - - To address this issue, we instrument a transfer to a transaction - rollup to inject the exact type of the entrypoint as used by - the smart contract. This allows the transaction rollup to extract - the type of the ticket. *) - | Tx_rollup _ -> ( - let open Micheline in - match tp with - | Pair_t (Ticket_t (tp, _), _, _, _) -> - Script_ir_translator.unparse_ty ~loc:dummy_location ctxt tp - >|? fun (ty, ctxt) -> (Seq (dummy_location, [p; ty]), ctxt) - | _ -> - (* TODO: https://gitlab.com/tezos/tezos/-/issues/2455 - Refute this branch thanks to the type system. - Thanks to the implementation of the [CONTRACT] - instruction, this branch is unreachable. But this is - not enforced by the type system, which means we are one - refactoring away to reach it. *) - assert false) - in +let make_transaction_to_contract ctxt ~destination ~amount ~entrypoint ~location + ~parameters_ty ~parameters = + unparse_data ctxt Optimized parameters_ty parameters + >>=? fun (unparsed_parameters, ctxt) -> + Lwt.return + ( Gas.consume ctxt (Script.strip_locations_cost unparsed_parameters) + >|? fun ctxt -> + let unparsed_parameters = Micheline.strip_locations unparsed_parameters in + ( Transaction_to_contract + { + destination; + amount; + entrypoint; + location; + parameters_ty; + parameters; + unparsed_parameters; + }, + ctxt ) ) + +let make_transaction_to_tx_rollup (type t tc) ctxt ~destination ~amount + ~entrypoint ~(parameters_ty : (t, tc) ty) ~parameters = + (* The entrypoints of a transaction rollup are polymorphic wrt. the + tickets it can process. However, two Michelson values can have + the same Micheline representation, but different types. What + this means is that when we start the execution of a transaction + rollup, the type of its argument is lost if we just give it the + values provided by the Michelson script. + + To address this issue, we instrument a transfer to a transaction + rollup to inject the exact type of the entrypoint as used by + the smart contract. This allows the transaction rollup to extract + the type of the ticket. *) + error_unless Tez.(amount = zero) Tx_rollup_invalid_transaction_amount + >>?= fun () -> + error_unless + Entrypoint.(entrypoint = Tx_rollup.deposit_entrypoint) + (Script_tc_errors.No_such_entrypoint entrypoint) + >>?= fun () -> + match parameters_ty with + | Pair_t (Ticket_t (tp, _), _, _, _) -> + unparse_data ctxt Optimized parameters_ty parameters + >>=? fun (unparsed_parameters, ctxt) -> + Lwt.return + ( Script_ir_translator.unparse_ty ~loc:Micheline.dummy_location ctxt tp + >>? fun (ty, ctxt) -> + let unparsed_parameters = + Micheline.Seq (Micheline.dummy_location, [unparsed_parameters; ty]) + in + Gas.consume ctxt (Script.strip_locations_cost unparsed_parameters) + >|? fun ctxt -> + let unparsed_parameters = + Micheline.strip_locations unparsed_parameters + in + ( Transaction_to_tx_rollup + {destination; parameters_ty; parameters; unparsed_parameters}, + ctxt ) ) + | _ -> + (* TODO: https://gitlab.com/tezos/tezos/-/issues/2455 + Refute this branch thanks to the type system. + Thanks to the implementation of the [CONTRACT] + instruction, this branch is unreachable. But this is + not enforced by the type system, which means we are one + refactoring away to reach it. *) + assert false +(* [transfer (ctxt, sc) gas tez parameters_ty parameters destination entrypoint] + creates an operation that transfers an amount of [tez] to a destination and + an entrypoint instantiated with argument [parameters] of type + [parameters_ty]. *) +let transfer (ctxt, sc) gas amount location parameters_ty parameters + (destination : Destination.t) entrypoint = let ctxt = update_context gas ctxt in collect_lazy_storage ctxt parameters_ty parameters >>?= fun (to_duplicate, ctxt) -> @@ -556,27 +602,25 @@ let transfer (ctxt, sc) gas amount location parameters_ty parameters destination ~to_update ~temporary:true >>=? fun (parameters, lazy_storage_diff, ctxt) -> - unparse_data ctxt Optimized parameters_ty parameters - >>=? fun (unparsed_parameters, ctxt) -> - craft_transfer_parameters ctxt parameters_ty unparsed_parameters destination - >>?= fun (unparsed_parameters, ctxt) -> - Gas.consume ctxt (Script.strip_locations_cost unparsed_parameters) - >>?= fun ctxt -> - let unparsed_parameters = - Script.lazy_expr (Micheline.strip_locations unparsed_parameters) - in - let operation = - Transaction - { - destination; - amount; - entrypoint; - location; - parameters_ty; - parameters; - unparsed_parameters; - } - in + (match destination with + | Contract destination -> + make_transaction_to_contract + ctxt + ~destination + ~amount + ~entrypoint + ~location + ~parameters_ty + ~parameters + | Tx_rollup destination -> + make_transaction_to_tx_rollup + ctxt + ~destination + ~amount + ~entrypoint + ~parameters_ty + ~parameters) + >>=? fun (operation, ctxt) -> fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let iop = {source = sc.self; operation; nonce} in let res = {piop = Internal_operation iop; lazy_storage_diff} in diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index b1d02fdaea88eb7f1301b1266a370ee9c6d54650..5e6b8a25d58fb186ef3c216eb0f42209a0667055 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -1367,14 +1367,21 @@ and ('input, 'output) view_signature = -> ('input, 'output) view_signature and 'kind manager_operation = - | Transaction : { - destination : Destination.t; + | Transaction_to_contract : { + destination : Contract.t; amount : Tez.tez; entrypoint : Entrypoint.t; location : Script.location; parameters_ty : ('a, _) ty; parameters : 'a; - unparsed_parameters : Script.lazy_expr; + unparsed_parameters : Script.expr; + } + -> Kind.transaction manager_operation + | Transaction_to_tx_rollup : { + destination : Tx_rollup.t; + parameters_ty : ('a, _) ty; + parameters : 'a; + unparsed_parameters : Script.expr; } -> Kind.transaction manager_operation | Origination : { @@ -1409,7 +1416,8 @@ type packed_manager_operation = let manager_kind : type kind. kind manager_operation -> kind Kind.manager = function - | Transaction _ -> Kind.Transaction_manager_kind + | Transaction_to_contract _ -> Kind.Transaction_manager_kind + | Transaction_to_tx_rollup _ -> Kind.Transaction_manager_kind | Origination _ -> Kind.Origination_manager_kind | Delegation _ -> Kind.Delegation_manager_kind diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index 547886e26bb647f46dd7ff7ebf7000899258d330..0a89fdab7d0ddb09e001e4a23f269bafddf9b3a4 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -1495,19 +1495,26 @@ and ('input, 'output) view_signature = -> ('input, 'output) view_signature and 'kind manager_operation = - | Transaction : { + | Transaction_to_contract : { (* The [unparsed_parameters] field may seem useless since we have access to a typed version of the field (with [parameters_ty] and [parameters]), but we keep it so that we do not have to unparse the typed version in order to produce the receipt ([Apply_results.internal_manager_operation]). *) - destination : Destination.t; + destination : Contract.t; amount : Tez.tez; entrypoint : Entrypoint.t; location : Script.location; parameters_ty : ('a, _) ty; parameters : 'a; - unparsed_parameters : Script.lazy_expr; + unparsed_parameters : Script.expr; + } + -> Kind.transaction manager_operation + | Transaction_to_tx_rollup : { + destination : Tx_rollup.t; + parameters_ty : ('a, _) ty; + parameters : 'a; + unparsed_parameters : Script.expr; } -> Kind.transaction manager_operation | Origination : { 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 88c72683af3b47ebdfb17a92faa31fd3971b9090..97b0db9465a8d328700f9fa2098d06ea416625f4 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 @@ -385,13 +385,12 @@ let transfer_operation ctxt ~src ~destination ~arg_type ~arg = { source = src; operation = - Transaction + Transaction_to_contract { amount = Tez.zero; - unparsed_parameters = - Script.lazy_expr @@ Micheline.strip_locations params_node; + unparsed_parameters = Micheline.strip_locations params_node; entrypoint = Entrypoint.default; - destination = Destination.Contract destination; + destination; location = Micheline.dummy_location; parameters_ty = arg_type; parameters = arg; 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 2d7a6be06fdcbbfb9960fb1254bfc43781ecb9cc..1c1cbc5f53994f1a18cf2b83a89fed0457dbed1e 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 @@ -292,13 +292,12 @@ let transfer_operation ~incr ~src ~destination ~parameters_ty ~parameters = { source = src; operation = - Transaction + Transaction_to_contract { amount = Tez.zero; - unparsed_parameters = - Script.lazy_expr @@ Micheline.strip_locations params_node; + unparsed_parameters = Micheline.strip_locations params_node; entrypoint = Entrypoint.default; - destination = Destination.Contract destination; + destination; location = Micheline.dummy_location; parameters_ty; parameters; @@ -325,14 +324,10 @@ let transfer_operation_to_tx_rollup ~incr ~src ~parameters_ty ~parameters { source = src; operation = - Transaction + Transaction_to_tx_rollup { - amount = Tez.zero; - unparsed_parameters = - Script.lazy_expr @@ Micheline.strip_locations params_node; - entrypoint = Tx_rollup.deposit_entrypoint; - destination = Destination.Tx_rollup tx_rollup; - location = Micheline.dummy_location; + unparsed_parameters = Micheline.strip_locations params_node; + destination = tx_rollup; parameters_ty; parameters; }; 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 f956197005105769d9b44a063334417f0f8647b7..e5b8eb330795262a1180c289630f20f79651b947 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 @@ -56,6 +56,16 @@ let check_proto_error_f f t = equals [e]. *) let check_proto_error e t = check_proto_error_f (( = ) e) t +(** [check_runtime_error e t] checks that the first error of [t] is the + Michelson runtime error and the second one equals [e]. *) +let check_runtime_error e = function + | Environment.Ecoproto_error (Script_interpreter.Runtime_contract_error _) + :: Environment.Ecoproto_error second :: _ + when second = e -> + Assert.test_error_encodings e ; + return_unit + | t -> failwith "Expected runtime error, got: %a" Error_monad.pp_print_trace t + (** [test_disable_feature_flag] try to originate a tx rollup with the feature flag is deactivated and check it fails *) let test_disable_feature_flag () = @@ -1398,7 +1408,8 @@ let test_valid_deposit_invalid_amount () = i op ~expect_failure: - (check_proto_error Apply.Tx_rollup_invalid_transaction_amount) + (check_runtime_error + Script_interpreter_defs.Tx_rollup_invalid_transaction_amount) >>=? fun _ -> return_unit (** [test_deposit_too_many_tickets] checks that a deposit of @@ -1420,7 +1431,7 @@ let test_deposit_too_many_tickets () = i operation ~expect_failure: - (check_proto_error Apply.Tx_rollup_invalid_transaction_amount) + (check_proto_error Apply.Tx_rollup_invalid_transaction_ticket_amount) >>=? fun i -> ignore i ; return_unit diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index 5d0038750cea0e4ae4485b0009c71c89ada9fb1b..b3584e951cb2ff893118984b8a961d3ab98ab11f 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -238,12 +238,12 @@ let tickets_of_origination ctxt ~preorigination ~storage_type ~storage = let tickets_of_operation ctxt (Script_typed_ir.Internal_operation {source = _; operation; nonce = _}) = match operation with - | Transaction + | Transaction_to_contract { amount = _; unparsed_parameters = _; entrypoint; - destination = Destination.Contract destination; + destination; location; parameters_ty; parameters; @@ -255,27 +255,17 @@ let tickets_of_operation ctxt ~location ~parameters_ty ~parameters - | Transaction - { - destination = Destination.Tx_rollup tx_rollup_dest; - unparsed_parameters = _; - entrypoint; - amount = _; - location = _; - parameters_ty; - parameters; - } -> - if Entrypoint.(entrypoint = Tx_rollup.deposit_entrypoint) then - Tx_rollup_parameters.get_deposit_parameters parameters_ty parameters - >>?= fun {ex_ticket; l2_destination = _} -> - return - ( Some - { - destination = Destination.Tx_rollup tx_rollup_dest; - tickets = [ex_ticket]; - }, - ctxt ) - else return (None, ctxt) + | Transaction_to_tx_rollup + {destination; unparsed_parameters = _; parameters_ty; parameters} -> + Tx_rollup_parameters.get_deposit_parameters parameters_ty parameters + >>?= fun {ex_ticket; l2_destination = _} -> + return + ( Some + { + destination = Destination.Tx_rollup destination; + tickets = [ex_ticket]; + }, + ctxt ) | Origination { origination = {delegate = _; script = _; credit = _}; diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml index 1813562a765a405d1de3396c3e60513d2318b70a..d4549894b9f79c6c76387d66f6a2e356d337998b 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.ml @@ -70,9 +70,7 @@ let parse_ticket_and_operation ~consume_deserialization_gas ~ticketer ~contents >>=? fun (parameters_expr, ctxt) -> Gas.consume ctxt (Script.strip_locations_cost parameters_expr) >>?= fun ctxt -> - let unparsed_parameters = - Script.lazy_expr (Micheline.strip_locations parameters_expr) - in + let unparsed_parameters = Micheline.strip_locations parameters_expr in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let op = Script_typed_ir.Internal_operation @@ -80,7 +78,7 @@ let parse_ticket_and_operation ~consume_deserialization_gas ~ticketer ~contents source; nonce; operation = - Transaction + Transaction_to_contract { amount = Tez.zero; unparsed_parameters; diff --git a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli index b8f6474347e604cec60670cdbe4271a4bbc1ee3c..281fb79289e6aafb4ecff8cce63738b9804ed100 100644 --- a/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli +++ b/src/proto_alpha/lib_protocol/tx_rollup_ticket.mli @@ -48,7 +48,7 @@ val parse_ticket_and_operation : contents:Script.lazy_expr -> ty:Script.lazy_expr -> source:Contract.t -> - destination:Destination.t -> + destination:Contract.t -> entrypoint:Entrypoint.t -> amount:Z.t -> context ->