From a78a9ca4816372b9f7a55296c48fd428d76ad6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= Date: Thu, 8 Jun 2023 16:27:47 +0200 Subject: [PATCH] Proto: improve safety checks for set_delegate_parameters --- src/proto_alpha/lib_protocol/apply.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index baed815465d0..908409e22774 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -482,10 +482,17 @@ let apply_finalize_unstake ~ctxt ~sender ~amount ~destination ~before_operation in return (ctxt, result, []) -let apply_set_delegate_parameters ~ctxt ~delegate +let apply_set_delegate_parameters ~ctxt ~sender ~destination ~staking_over_baking_limit_millionth ~baking_over_staking_edge_billionth ~before_operation = let open Lwt_result_syntax in + let*? () = + error_unless + Signature.Public_key_hash.(sender = destination) + Invalid_self_transaction_destination + in + let* is_delegate = Contract.is_delegate ctxt sender in + let*? () = error_unless is_delegate Invalid_staking_parameters_sender in let staking_over_baking_limit_millionth = Z.to_int32 staking_over_baking_limit_millionth in @@ -497,9 +504,7 @@ let apply_set_delegate_parameters ~ctxt ~delegate ~staking_over_baking_limit_millionth ~baking_over_staking_edge_billionth in - let* is_delegate = Contract.is_delegate ctxt delegate in - let*? () = error_unless is_delegate Invalid_staking_parameters_sender in - let* ctxt = Delegate.Staking_parameters.register_update ctxt delegate t in + let* ctxt = Delegate.Staking_parameters.register_update ctxt sender t in let result = Transaction_to_contract_result { @@ -1034,7 +1039,8 @@ let apply_manager_operation : [] ) ) -> apply_set_delegate_parameters ~ctxt - ~delegate:source + ~sender:source + ~destination:pkh ~staking_over_baking_limit_millionth ~baking_over_staking_edge_billionth ~before_operation:ctxt_before_op -- GitLab