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

Use unchecked for collateral

Summary

Use unchecked when dividing can save gas.

Vulnerability Details

In lender.sol,the borrow() function has,

if (collateral == 0) revert ZeroCollateral();
// make sure the user isn't borrowing too much
uint256 loanRatio = (debt * 10 ** 18) / collateral;

We can use unchecked for loanRatio calculation since collateral will never be zero because of previous statement.

Impact

Higher runtime gas usage

Tools Used

Manual review

Recommendations

consider using

if (collateral == 0) revert ZeroCollateral();
// make sure the user isn't borrowing too much
unchecked{
uint256 loanRatio = (debt * 10 ** 18) / collateral;
}

Support

FAQs

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