buyloan()
in Lender.sol
accesses storage variables multiple times; can save gas by caching in memory
buyloan()
accesses pools[poolId].poolBalance
and pools[poolId].interestRate
multiple times each. Specifically, pools[poolId].poolBalance
is accessed twice, and pools[poolId].interestRate
is accessed three times for a total of 2 cold SLOADs (2100 gas each) and 3 warm SLOADs (100 gas each), costing a total of 4500 gas. If these variables are cached instead, the cost will be 2 cold SLOADs (2100 gas each) to access the variables, 2 MSTOREs (3 gas each) to store the variables in memory, and 5 MLOADs (3 gas each) to access the variables, costing a total of 4221 gas. Therefore, 279 gas is saved. Additionally, the gas cost of reading from an array is avoided.
Greater than 279 gas is saved.
Use memory variables to cache the values ofpools[poolId].poolBalance
and pools[poolId].interestRate
.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.