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

Inefficient Gas Usage in Pool Loading

Summary

A gas optimization issue has been identified in the way the contract loads the pool data. The function loads the pool into memory and then redundantly accesses the same data from storage, leading to inefficient gas consumption.

Vulnerability Details

The function in question first loads the pool data into memory using the line Pool memory pool = pools[poolId];. However, later in the function, instead of using the already loaded pool variable from memory, it accesses the pool data again from storage with pools[poolId].poolBalance. This redundant storage access, especially when using the SLOAD opcode, is considerably more expensive in terms of gas than accessing data from memory using the MLOAD opcode.

Impact

Users interacting with this function will incur higher gas fees than necessary due to the redundant storage access.

Tools Used

Manual Review

Recommendations

Modify the function to utilize the pool variable loaded into memory instead of redundantly accessing the storage.

Support

FAQs

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