Summary
Prerequisite condition checks shall be done first before exection of transactional or state change functions to avoid wastage of gas and adhere to general best practices
Vulnerability Details
Prerequisite condtion check require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr())
found in KittyPool:whiskdrawMeowllateral
and KittyPool:meowintKittyCoin
shall be brought forward prior to other transactional or state change execution to ensure core condition is met to avoid unnecessary of gas wastage due to precondition requirement fails.
function whiskdrawMeowllateral(address _token, uint256 _ameownt) external tokenExists(_token) {
IKittyVault(tokenToVault[_token]).executeWhiskdrawal(msg.sender, _ameownt);
<@@> ! require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
}
function meowintKittyCoin(uint256 _ameownt) external {
kittyCoinMeownted[msg.sender] += _ameownt;
i_kittyCoin.mint(msg.sender, _ameownt);
<@@> ! require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
}
Impact
Waste of gas with function call reverts due to prerequisite condition is not met after running processes that could have been avoided beforehand
Tools Used
Manual review
Recommendations
Bring forward condition check prior to transactional or state change execution
function whiskdrawMeowllateral(address _token, uint256 _ameownt) external tokenExists(_token) {
+ require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
IKittyVault(tokenToVault[_token]).executeWhiskdrawal(msg.sender, _ameownt);
- require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
}
function meowintKittyCoin(uint256 _ameownt) external {
+ require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
kittyCoinMeownted[msg.sender] += _ameownt;
i_kittyCoin.mint(msg.sender, _ameownt);
- require(_hasEnoughMeowllateral(msg.sender), KittyPool__NotEnoughMeowllateralPurrrr());
}