From e315dd0d5d70e5112a88275bc44127e0adebb98c Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 7 Jul 2022 13:20:21 +0200 Subject: [PATCH 1/2] Proto/Apply: check parameter is unit for external operations only --- src/proto_alpha/lib_protocol/apply.ml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 58b03e065f7f..bc17951e45d5 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -786,7 +786,7 @@ type 'loc execution_arg = | Typed_arg : 'loc * ('a, _) Script_typed_ir.ty * 'a -> 'loc execution_arg | Untyped_arg : Script.expr -> _ execution_arg -let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh ~untyped_parameter +let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh ~external_entrypoint ~before_operation = let contract = Contract.Implicit pkh in (* Transfers of zero to implicit accounts are forbidden. *) @@ -796,14 +796,6 @@ let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh ~untyped_parameter Contract.allocated ctxt contract >>= fun already_allocated -> Token.transfer ctxt (`Contract source) (`Contract contract) amount >>=? fun (ctxt, balance_updates) -> - (* Only allow [Unit] parameter to implicit accounts. *) - (match untyped_parameter with - | None -> Result.return_unit - | Some parameter -> ( - match Micheline.root parameter with - | Prim (_, Michelson_v1_primitives.D_Unit, [], _) -> Result.return_unit - | _ -> error (Script_interpreter.Bad_contract_parameter contract))) - >>?= fun () -> (match external_entrypoint with | None -> Result.return_unit | Some entrypoint -> @@ -1100,7 +1092,6 @@ let apply_internal_operation_contents : ~source ~amount ~pkh - ~untyped_parameter:None ~external_entrypoint:None ~before_operation:ctxt_before_op >|=? fun (ctxt, res, ops) -> @@ -1267,12 +1258,16 @@ let apply_manager_operation : ctxt parameters >>?= fun (parameters, ctxt) -> + (* Only allow [Unit] parameter to implicit accounts. *) + (match Micheline.root parameters with + | Prim (_, Michelson_v1_primitives.D_Unit, [], _) -> Result.return_unit + | _ -> error (Script_interpreter.Bad_contract_parameter source_contract)) + >>?= fun () -> apply_transaction_to_implicit ~ctxt ~source:source_contract ~amount ~pkh - ~untyped_parameter:(Some parameters) ~external_entrypoint:(Some entrypoint) ~before_operation:ctxt_before_op >|=? fun (ctxt, res, ops) -> (ctxt, Transaction_result res, ops) -- GitLab From c5fd4766ef836dd536caa42f7542b29b991bd65e Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 7 Jul 2022 13:21:09 +0200 Subject: [PATCH 2/2] Proto/Apply: check entrypoint is default for external operations only --- src/proto_alpha/lib_protocol/apply.ml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index bc17951e45d5..89eb16234ab4 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -786,8 +786,7 @@ type 'loc execution_arg = | Typed_arg : 'loc * ('a, _) Script_typed_ir.ty * 'a -> 'loc execution_arg | Untyped_arg : Script.expr -> _ execution_arg -let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh - ~external_entrypoint ~before_operation = +let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh ~before_operation = let contract = Contract.Implicit pkh in (* Transfers of zero to implicit accounts are forbidden. *) error_when Tez.(amount = zero) (Empty_transaction contract) >>?= fun () -> @@ -796,12 +795,6 @@ let apply_transaction_to_implicit ~ctxt ~source ~amount ~pkh Contract.allocated ctxt contract >>= fun already_allocated -> Token.transfer ctxt (`Contract source) (`Contract contract) amount >>=? fun (ctxt, balance_updates) -> - (match external_entrypoint with - | None -> Result.return_unit - | Some entrypoint -> - if Entrypoint.is_default entrypoint then Result.return_unit - else error (Script_tc_errors.No_such_entrypoint entrypoint)) - >>?= fun () -> let result = Transaction_to_contract_result { @@ -1092,7 +1085,6 @@ let apply_internal_operation_contents : ~source ~amount ~pkh - ~external_entrypoint:None ~before_operation:ctxt_before_op >|=? fun (ctxt, res, ops) -> ( ctxt, @@ -1263,12 +1255,14 @@ let apply_manager_operation : | Prim (_, Michelson_v1_primitives.D_Unit, [], _) -> Result.return_unit | _ -> error (Script_interpreter.Bad_contract_parameter source_contract)) >>?= fun () -> + (if Entrypoint.is_default entrypoint then Result.return_unit + else error (Script_tc_errors.No_such_entrypoint entrypoint)) + >>?= fun () -> apply_transaction_to_implicit ~ctxt ~source:source_contract ~amount ~pkh - ~external_entrypoint:(Some entrypoint) ~before_operation:ctxt_before_op >|=? fun (ctxt, res, ops) -> (ctxt, Transaction_result res, ops) | Transaction -- GitLab