From 7a057aeb50d02429da043dec32d5142b2328352e Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 17 Jun 2022 10:43:41 +0200 Subject: [PATCH 1/2] Proto/Michelson: generalize Tx_rollup_invalid_transaction_amount to use it for sc rollups too --- .../lib_protocol/script_interpreter_defs.ml | 22 +++++++++---------- .../integration/operations/test_tx_rollup.ml | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index d94e9eb22171..2d0de7109a46 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -38,24 +38,22 @@ open Script_typed_ir open Script_ir_translator open Local_gas_counter -type error += Tx_rollup_invalid_transaction_amount +type error += 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" + ~id:"operation.rollup_invalid_transaction_amount" + ~title:"Transaction amount to a 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." + "Because rollups are outside of the delegation mechanism of Tezos, they \ + cannot own Tez, and therefore transactions targeting a 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.") + Format.pp_print_string ppf "Transaction amount to a rollup must be zero.") Data_encoding.unit - (function Tx_rollup_invalid_transaction_amount -> Some () | _ -> None) - (fun () -> Tx_rollup_invalid_transaction_amount) + (function Rollup_invalid_transaction_amount -> Some () | _ -> None) + (fun () -> Rollup_invalid_transaction_amount) (* @@ -498,7 +496,7 @@ let make_transaction_to_tx_rollup (type t tc) ctxt ~destination ~amount 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 + error_unless Tez.(amount = zero) Rollup_invalid_transaction_amount >>?= fun () -> error_unless Entrypoint.(entrypoint = Tx_rollup.deposit_entrypoint) 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 dda98827132d..6f9a91110df6 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 @@ -1423,7 +1423,7 @@ let test_valid_deposit_invalid_amount () = op ~expect_apply_failure: (check_runtime_error - Script_interpreter_defs.Tx_rollup_invalid_transaction_amount) + Script_interpreter_defs.Rollup_invalid_transaction_amount) >>=? fun _ -> return_unit (** [test_deposit_too_many_tickets] checks that a deposit of -- GitLab From cdb6a7b749200944d505a189db1d3e017b4a3f91 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 10 Jun 2022 17:11:33 +0200 Subject: [PATCH 2/2] Proto/Michelson: implement TRANSFER_TOKENS to sc rollups Fix #2801 --- .../lib_protocol/script_interpreter_defs.ml | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index 2d0de7109a46..3b51e990b1d3 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -529,6 +529,26 @@ let make_transaction_to_tx_rollup (type t tc) ctxt ~destination ~amount refactoring away to reach it. *) assert false +let make_transaction_to_sc_rollup ctxt ~destination ~amount ~entrypoint + ~parameters_ty ~parameters = + error_unless Tez.(amount = zero) Rollup_invalid_transaction_amount + >>?= fun () -> + 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_sc_rollup + { + destination; + entrypoint; + parameters_ty; + parameters; + unparsed_parameters; + }, + ctxt ) ) + (* [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 @@ -566,10 +586,14 @@ let transfer (ctxt, sc) gas amount location parameters_ty parameters ~entrypoint ~parameters_ty ~parameters - | Sc_rollup _ -> - (* TODO #2801 - Implement transfers to sc rollups. *) - failwith "Transferring to smart-contract rollups is not yet supported") + | Sc_rollup destination -> + make_transaction_to_sc_rollup + ctxt + ~destination + ~amount + ~entrypoint + ~parameters_ty + ~parameters) >>=? fun (operation, ctxt) -> fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> let iop = {source = Contract.Originated sc.self; operation; nonce} in -- GitLab