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

Multiple accesses of a mapping/array should use a local variable cache

The instances below point to the second+ access of a value inside a mapping/array, within a function. Caching a mapping’s value in a local storage or calldata variable when the value is accessed multiple times, saves ~42 gas per access due to not having to recalculate the key’s keccak256 hash (Gkeccak256 - 30 gas) and that calculation’s associated stack operations. Caching an array’s struct avoids recalculating the array offsets into memory/calldata.

Recommendations

firest cache the pools[poolId]

Support

FAQs

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