<!-- canonical: https://0xsimao.com/findings/glacier-storage-cached-whenever-gas -->

# Storage variables should be cached whenever possible to save gas

Low/Info · Three Sigma · Liquid staking · 12th July, 2023

Finding 3S-GLACIER-N11 of the Glacier security review.

- Protocol: https://www.glacier.io/
- Report: /reports/glacier
- Source: https://cdn.sanity.io/files/qoqld077/production/21bd3b6fa78c55968a6c9c7ea4fd49f34a8bd3d8.pdf

---

### Description

Storage reads should be avoided whenever possible to save gas, which can be achieved by
caching the variables in memory.

### Recommendation

For example, in [_withdrawRequest()](https://github.com/JackFrostDev/glacier-contracts/blob/main/contracts/protocol/GlacialAVAX/glAVAX.sol#L632), the variables totalWithdrawRequests and
userWithdrawRequestCount can be cached.

### Status

Currently being reviewed by the team.

---

Related findings:

- [Storage variables can be cached to save gas](https://0xsimao.com/findings/mitosis-storage-variables-cached-gas): Mitosis
- [Storage variables can be cached to save gas](https://0xsimao.com/findings/orange-storage-variables-cached-gas): Orange Bridge
- [Variables should be cached to memory to save gas](https://0xsimao.com/findings/metazero-ii-variables-cached-memory-gas): MetaZero Staking
- [genesisLimit can be placed as constant variables to save gas.](https://0xsimao.com/findings/metazero-i-genesis-placed-constant-gas): MetaZero Omnichain NFTs
