20,000 USDC
View results
Submission Details
Severity: gas

# [G-26] Sort Solidity operations using short-circuit mode

Summary

[G-26] Sort Solidity operations using short-circuit mode

Short-circuiting is a solidity contract development model that uses OR/AND logic to sequence different cost operations. It puts low gas cost operations in the front and high gas cost operations in the back, so that if the front is low If the cost operation is feasible, you can skip (short-circuit) the subsequent high-cost Ethereum virtual machine operation.

//f(x) is a low gas cost operation
//g(y) is a high gas cost operation
//Sort operations with different gas costs as follows
f(x) || g(y)
f(x) && g(y)
file: /src/Lender.sol
132 if (
p.lender != msg.sender ||
p.minLoanSize == 0 ||
p.maxLoanRatio == 0 ||
p.auctionLength == 0 ||
p.auctionLength > MAX_AUCTION_LENGTH ||
138 p.interestRate > MAX_INTEREST_RATE

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L132-L138

Support

FAQs

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