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

`buyLoan()` in `Lender.sol` can save gas by accessing existing memory variables instead of storage

Summary

buyLoan() in Lender.sol should access its instantiated memory variables instead of storage

Vulnerability Details

loans[loanId].debt and loans[loanId].collateral (lines 528 and 529) access storage when memory variables with their values have already been instantiated. 2 warm SLOADs (100 gas each) can be replaced with 2 MLOADS (3 gas each) for savings of 194 gas. Additionally, the gas cost of reading from an array is saved.

Impact

Greater than 194 gas is saved.

Tools Used

Recommendations

Change loans[loanId].debt to totalDebt and loans[loanId].collateral to loan.collateral (lines 528 and 529).

Support

FAQs

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