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

Emitting cached values instead of storage variables saves gas

Summary

Caching of a state variable replaces each Gwarmaccess (100 gas) with a much cheaper stack read.

Total Instances: 4

Estimated Gas Saved: 4 * 100 = 400

Recommendations

use already calculated totalDebt and cached loan variables to save 2SLOAD

emit Borrowed(
loan.borrower,
pool.lender,
loanId,
- loans[loanId].debt, // use totalDebt here
- loans[loanId].collateral, // loan.collateral here
+ totalDebt,
+ loan.collateral,
pool.interestRate,
block.timestamp
);

Tools used

manual code review

Support

FAQs

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