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

++i preincrement is cheaper

Summary

Preincrement costs less gas than Post Increment

Vulnerability Details

Links above have code parts where post increment i++ in the loop iterations. This is more expensive than the preincrement form ++i.

Impact

Gas Savings: Preincrement ++i saves 5 less gas compared to i++. Therefore each loop iteration saves 5 gas which multiples with number times loop called and number instances of for loops leading to significant gas savings. e.g 5 gas * 20 loop iterations * 7 instances of for loops = gas savings to project for these seemingly small change

Tools Used

Manual Analysis

Recommendations

It is recommended to change all the incremements in all loops to form of ++i vs i++ e. g Lender.sol line 233
for (uint256 i = 0; i < borrows.length; ++i) { // note that a further optimization is to place unchecked {++i}

Support

FAQs

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