15,000 USDC
View results
Submission Details
Severity: gas
Valid

collateral and debt to cover not validated

Summary

In DSCEngine.sol, collateral and debtToCover are not checked if valid in liquidate() function.

Vulnerability Details

The liquidate function does not revert early if collateral and debtToCover are not valid

Impact

Gas can be wasted during runtime

Tools Used

Manual review

Recommendations

Use the following

function liquidate(address collateral, address user, uint256 debtToCover)
external
moreThanZero(debtToCover)
nonReentrant
{
// need to check health factor of the user
uint256 startingUserHealthFactor = _healthFactor(user);
if (startingUserHealthFactor >= MIN_HEALTH_FACTOR) {
revert DSCEngine__HealthFactorOk();
}
if(debtToCover > getCollateralBalanceOfUser(user,collateral)){
revert DSCEngine__ExcessDebtToCover();
}
//......
}

Support

FAQs

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