From 1ff5056c44e3d885af15aa6fa8b250f0d3037136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Kuras?= Date: Mon, 26 Jul 2021 11:51:41 +0200 Subject: [PATCH] Permission bugs corrected in cw1-subkeys --- contracts/cw1-subkeys/src/contract.rs | 13 +++++++++++-- contracts/cw1-subkeys/src/error.rs | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/contracts/cw1-subkeys/src/contract.rs b/contracts/cw1-subkeys/src/contract.rs index 875184d20..d0b0d80eb 100644 --- a/contracts/cw1-subkeys/src/contract.rs +++ b/contracts/cw1-subkeys/src/contract.rs @@ -147,7 +147,7 @@ pub fn check_staking_permissions( return Err(ContractError::ReDelegatePerm {}); } } - s => panic!("Unsupported staking message: {:?}", s), + _ => return Err(ContractError::UnsupportedMessage {}), } Ok(true) } @@ -167,7 +167,7 @@ pub fn check_distribution_permissions( return Err(ContractError::WithdrawPerm {}); } } - s => panic!("Unsupported distribution message: {:?}", s), + _ => return Err(ContractError::UnsupportedMessage {}), } Ok(true) } @@ -362,6 +362,15 @@ fn can_execute(deps: Deps, sender: String, msg: CosmosMsg) -> StdResult { None => Ok(false), } } + CosmosMsg::Distribution(distribution_msg) => { + let perm_opt = PERMISSIONS.may_load(deps.storage, &sender)?; + match perm_opt { + Some(permission) => { + Ok(check_distribution_permissions(&distribution_msg, permission).is_ok()) + } + None => Ok(false), + } + } _ => Ok(false), } } diff --git a/contracts/cw1-subkeys/src/error.rs b/contracts/cw1-subkeys/src/error.rs index 7fc23ccac..d761821e6 100644 --- a/contracts/cw1-subkeys/src/error.rs +++ b/contracts/cw1-subkeys/src/error.rs @@ -35,6 +35,9 @@ pub enum ContractError { #[error("Set withdraw address is not allowed")] WithdrawAddrPerm {}, + + #[error("Unsupported message")] + UnsupportedMessage {}, } impl From for ContractError {