From a6f7a78c9569cea20fbd6763ed0d028119b16daf Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Thu, 16 Jun 2022 15:49:08 +0100 Subject: [PATCH 1/2] Proto: use contract-hash --- .../lib_protocol/alpha_context.mli | 4 +-- src/proto_alpha/lib_protocol/apply.ml | 30 +++++++++++++++++-- .../sc_rollup_inbox_message_repr.ml | 6 ++-- .../sc_rollup_inbox_message_repr.mli | 4 ++- .../lib_protocol/sc_rollup_inbox_storage.mli | 4 +-- .../sc_rollup_management_protocol.mli | 2 +- 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index c9f5abde2d40..9ae91306fc0a 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -2781,7 +2781,7 @@ module Sc_rollup : sig module Message : sig type internal_inbox_message = { payload : Script.expr; - sender : Contract.t; + sender : Contract_hash.t; source : Signature.public_key_hash; } @@ -2889,7 +2889,7 @@ module Sc_rollup : sig context -> rollup -> payload:Script.expr -> - sender:Contract.t -> + sender:Contract_hash.t -> source:Signature.public_key_hash -> (t * Z.t * context) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index aa4653d03a1a..4e310742fa33 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -127,6 +127,7 @@ type error += | Failing_noop_error | Zero_frozen_deposits of Signature.Public_key_hash.t | Incorrect_reveal_position + | Invalid_transfer_to_sc_rollup_from_implicit_account let () = register_error_kind @@ -792,7 +793,22 @@ let () = position") Data_encoding.empty (function Incorrect_reveal_position -> Some () | _ -> None) - (fun () -> Incorrect_reveal_position) + (fun () -> Incorrect_reveal_position) ; + register_error_kind + `Permanent + ~id:"operations.invalid_transfer_to_sc_rollup_from_implicit_account" + ~title:"Invalid transfer to sc rollup" + ~description:"Invalid transfer to sc rollup from implicit account" + ~pp:(fun ppf () -> + Format.fprintf + ppf + "Invalid source for transfer operation to smart-contract rollup. Only \ + originated accounts are allowed") + Data_encoding.empty + (function + | Invalid_transfer_to_sc_rollup_from_implicit_account -> Some () + | _ -> None) + (fun () -> Invalid_transfer_to_sc_rollup_from_implicit_account) open Apply_results @@ -1198,6 +1214,16 @@ let apply_internal_manager_operation_content : unparsed_parameters = payload; } -> assert_sc_rollup_feature_enabled ctxt >>=? fun () -> + (* TODO: #3242 + We could rather change the type of [source] in + {!Script_type_ir.internal_operation}. Only originated accounts should + be allowed anyway for internal operations. + *) + (match source with + | Contract.Implicit _ -> + error Invalid_transfer_to_sc_rollup_from_implicit_account + | Originated hash -> ok hash) + >>?= fun sender -> (* Adding the message to the inbox. Note that it is safe to ignore the size diff since only its hash and meta data are stored in the context. See #3232. *) @@ -1205,7 +1231,7 @@ let apply_internal_manager_operation_content : ctxt destination ~payload - ~sender:source + ~sender ~source:payer >|=? fun (inbox_after, _size, ctxt) -> let consumed_gas = Gas.consumed ~since:ctxt_before_op ~until:ctxt in diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml index 146856b63f91..938fc2d57b2f 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.ml @@ -56,10 +56,8 @@ let () = type internal_inbox_message = { payload : Script_repr.expr; - (** A Micheline value containing the parameters passed to the rollup. *) - sender : Contract_repr.t; (** The L1 caller contract. *) + sender : Contract_hash.t; source : Signature.public_key_hash; - (** The implicit account that originated the transaction. *) } type t = Internal of internal_inbox_message | External of string @@ -73,7 +71,7 @@ let encoding = ~title:"Internal" (obj3 (req "payload" Script_repr.expr_encoding) - (req "sender" Contract_repr.encoding) + (req "sender" Contract_hash.encoding) (req "source" Signature.Public_key_hash.encoding)) (function | Internal {payload; sender; source} -> Some (payload, sender, source) diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli index 0ccac6a06895..2b47747fc0a9 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_message_repr.mli @@ -49,7 +49,9 @@ type internal_inbox_message = { payload : Script_repr.expr; (** A Micheline value containing the parameters passed to the rollup. *) - sender : Contract_repr.t; (** The L1 caller contract. *) + sender : Contract_hash.t; + (** The contract hash of an Layer 1 originated contract sending a message + to the rollup. *) source : Signature.public_key_hash; (** The implicit account that originated the transaction. *) } diff --git a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli index fdc4e33a8dc6..c2a35f6a6eb2 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_inbox_storage.mli @@ -50,13 +50,13 @@ val add_external_messages : (** [add_internal_message context rollup ~payload ~sender ~source] adds the internal message of [payload], [sender], and [source] to [rollup]'s inbox. - See [add_external_messages] for returned values and failures. + See [add_external_messages] for returned values and failures. *) val add_internal_message : Raw_context.t -> Sc_rollup_repr.t -> payload:Script_repr.expr -> - sender:Contract_repr.t -> + sender:Contract_hash.t -> source:Signature.public_key_hash -> (Sc_rollup_inbox_repr.t * Z.t * Raw_context.t) tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli index f762731e98df..fd4be863605b 100644 --- a/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli +++ b/src/proto_alpha/lib_protocol/sc_rollup_management_protocol.mli @@ -67,7 +67,7 @@ val make_internal_inbox_message : context -> ('a, _) Script_typed_ir.ty -> payload:'a -> - sender:Contract.t -> + sender:Contract_hash.t -> source:public_key_hash -> (Sc_rollup.Inbox.Message.t * context) tzresult Lwt.t -- GitLab From 09db4ce2c24aa662c536c131b6fbca9f087022d9 Mon Sep 17 00:00:00 2001 From: Joel Bjornson Date: Thu, 16 Jun 2022 15:52:15 +0100 Subject: [PATCH 2/2] Test: amend tests --- .../test/unit/test_sc_rollup_management_protocol.ml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 8b5bbaef6d38..9d13f975705f 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 @@ -85,9 +85,8 @@ let test_encode_decode_internal_inbox_message () = let open WithExceptions in let open Lwt_result_syntax in let* ctxt = init_ctxt () in - let*? sender = - Environment.wrap_tzresult - (Contract.of_b58check "KT1BuEZtb68c1Q4yjtckcNjGELqWt56Xyesc") + let sender = + Contract_hash.of_b58check_exn "KT1BuEZtb68c1Q4yjtckcNjGELqWt56Xyesc" in let source = Result.get_ok -- GitLab