gas

collateral and debt to cover not validated

Reward

Total

24.49 USDC

Selected
24.49 USDC
Selected Submission

collateral and debt to cover not validated

Severity

Gas Optimization / Informational

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();
        }

        //......
  
    }