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

Minimize Storage Reads/Writes

Summary

Avoid redundant storage reads and writes. If there is value in memory, it is no need to read from storage.

Vulnerability Details

In function borrow() and refinance(), we can use pool.poolBalance instead of pools[poolId].poolBalance to get the value.

Impact

cost more gas

Tools Used

Recommendations

For borrow function:

// update the pool balance
_updatePoolBalance(poolId, pool.poolBalance - debt);
pools[poolId].outstandingLoans = pool.poolBalance + debt;

For refinance function:

// now lets deduct our tokens from the new pool
_updatePoolBalance(poolId, pool.poolBalance - debt);
pools[poolId].outstandingLoans = pool.outstandingLoans + debt;
// update pool balance
pools[poolId].poolBalance = pool.poolBalance - debt;

Support

FAQs

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