Improving redeemCollateral()
Function in DSCEngine.sol
The function redeemCollateral()
in DSCEngine.sol
has a potential overflow vulnerability. While it is intended behavior for the function to revert if the user passes an amount greater than their current deposited collateral, adding an additional check can provide a more user-friendly experience. By verifying that the amount they are attempting to withdraw is greater than or equal to their current deposited amount, the contract can throw a more informative error message if the condition is not met.
The code snippet in question can be found on line 282 of DSCEngine.sol.
Currently, the redeemCollateral()
function will revert if the user attempts to withdraw an amount greater than their deposited collateral, due to overflow.
The vulnerability was identified through manual code review.
To enhance the user experience and provide a clearer error message, it is recommended to add a validation check in the redeemCollateral()
function. Before proceeding with the redemption, the contract should check if the amount being passed is greater than or equal to the user's deposits for that specific token. If the condition is not met, the contract should revert with an informative error message, guiding the user to provide a valid withdrawal amount.
By implementing this recommendation, the contract will become more user-friendly and prevent potential confusion or unintended transactions due to overflow.
.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.