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) {
uint256 _userBalance = IERC20Metadata(_wToken).balanceOf(msg.sender);
uint256 _wTokenAmountToRedeem = _wTokenAmount;
if (_wTokenAmount == type(uint256).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) {
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;
}