HardhatDeFi
15,000 USDC
View results
Submission Details
Severity: low
Invalid

Improper use of max

Summary

Improper use of uint256 max since it makes user to input the exact max amount so it can take the whole balance of the user.

Vulnerability Details

If use has 50 balance and he enter tokenAmount 30 no worries, everything works as it should. But if he writes 60 it will revert. Its not really proper to make user input the uint256 max so he can get his whole amount out (if he had inputed amount which is more than his actual balance). Instead it should be. Instead it should be if user inputs amount which is more than his actual balance it should do (inputed amount - actual balance).

function _redeemWToken(address _wToken, uint256 _wTokenAmount, address _recipient) internal returns (uint256) {
// Use the user's balance if `_wTokenAmount` equals `type(uint256).max`
uint256 _userBalance = IERC20Metadata(_wToken).balanceOf(msg.sender);
uint256 _wTokenAmountToRedeem = _wTokenAmount;
if (_wTokenAmount == type(uint256).max) {//@note improper use of max
_wTokenAmountToRedeem = _userBalance;
}
uint256 _amountReturned = _redeemWTokenPrivate(_wToken, _wTokenAmountToRedeem, _recipient, msg.sender);
return _amountReturned;
}

Impact

Low

Tools Used

Manual Review

Recommendations

function _redeemWToken(address _wToken, uint256 _wTokenAmount, address _recipient) internal returns (uint256) {
// Note: wTokens are not transferred to this contract. Instead, they are burnt from the caller's balance by this contract,
// which has the authority to do so as the owner of the wToken. Therefore, no prior approval from the caller is needed.
uint256 _userBalance = IERC20Metadata(_wToken).balanceOf(msg.sender);
uint256 _wTokenAmountToRedeem = _wTokenAmount;
if (_userBalance < _wTokenAmountToRedeem) { <- This is the proper way of using it
_wTokenAmountToRedeem = _userBalance;
}
uint256 _amountReturned = _redeemWTokenPrivate(_wToken, _wTokenAmountToRedeem, _recipient, msg.sender);
return _amountReturned;
}
Updates

Lead Judging Commences

bube Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.