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

Lack of Granular Error Handling

Summary

The if statement that validates the pool from the Lender contract should be broken up into multiple smaller if statements, each with a revert + custom error.
Smaller if statements with clear conditions and custom errors make the code more readable and understandable.
Each condition becomes self-explanatory, making it easier for developers to follow the logic.
When an error occurs, it is easier to pinpoint the specific condition that caused the revert.
Smaller if statements can result in better gas optimization. If one condition fails early in the function, the rest of the conditions don't need to be checked, saving gas costs.

Tools Used

Manual review

Recommendations

Rewrite the if statement as follows:

function setPool(Pool calldata p) public returns (bytes32 poolId) {
// validate the pool
- if (
- p.lender != msg.sender || p.minLoanSize == 0 || p.maxLoanRatio == 0 || p.auctionLength == 0
- || p.auctionLength > MAX_AUCTION_LENGTH || p.interestRate > MAX_INTEREST_RATE
- ) revert PoolConfig();
+ if (p.lender != msg.sender) revert InvalidLender();
+ if (p.minLoanSize == 0) revert InvalidMinLoanSize();
+ if (p.maxLoanRatio == 0) revert InvalidMaxLoanRatio();
+ if (p.auctionLength == 0 || p.auctionLength > MAX_AUCTION_LENGTH) revert InvalidAuctionLength();
+ if (p.interestRate > MAX_INTEREST_RATE) revert InvalidInterestRate();

Define the new custom errors in Errors.sol

Support

FAQs

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

Give us feedback!