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

Checks can be used without or operator for gas save

Summary

If statements can be customized like down below to save gas

Recommendations

The order of the checks should be like this in case of revert it traverse from low gas used to high gas used checks and revert early

p.lender != msg.sender
16 gas

p.minLoanSize == 0
12 gas

p.maxLoanRatio == 0
12 gas

p.auctionLength == 0
20 gas

p.auctionLength > MAX_AUCTION_LENGTH
40 gas

p.interestRate > MAX_INTEREST_RATE
60 gas

LenderTest:test_createPool() (gas: 240654)

LenderTest:test_createPool() (gas: 240638)

changing validation into this layout to save gas

if (p.lender != msg.sender) revert PoolConfig();

if (p.minLoanSize == 0 ) revert PoolConfig();

if (p.maxLoanRatio == 0 ) revert PoolConfig();

if (p.auctionLength == 0 ) revert PoolConfig();

if (p.auctionLength > MAX_AUCTION_LENGTH) revert PoolConfig();

if (p.interestRate > MAX_INTEREST_RATE) revert PoolConfig();

Tools Used

Foundry test suit- snapshot

Support

FAQs

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