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

Cache pools[poolId].poolBalance in 'buyLoan'

Summary

The state variable pools[poolId].poolBalance is read from storage 3 times in one function, caching it into memory will reduce gas usage of buyLoan function.

Vulnerability Details

486: if (pools[poolId].poolBalance < totalDebt) revert PoolTooSmall();
489: _updatePoolBalance(poolId, pools[poolId].poolBalance - totalDebt);
500: pools[oldPoolId].poolBalance + loan.debt + lenderInterest

Impact

Gas usage.

Tools Used

Manual review.

Recommendations

Cache pools[poolId].poolBalance in memory, before its first declaration in the buyLoans function.

Support

FAQs

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