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

# Storage variables can be cached to save gas

Low/Info · Three Sigma · Cross-chain bridge · 15th July, 2024

Finding 3S-OB-N03 of the Orange Bridge security review.

- Protocol: https://www.orangeweb3.com/
- Report: /reports/orange
- Source: https://cdn.sanity.io/files/qoqld077/production/686ad4e1d5035d69002f5f97e281e3c5a8b7ce00.pdf

---

### Description

Reading/writing from the same storage variable more than once should be avoided to save
gas.

### Recommendation

BRC20Factory::burn() can cache the [fee](https://github.com/orangecryptohq/orange-bridge-contract/blob/main/src/BRC20Factory.sol#L111) (read twice).
Vault::deposit() cache the [fee](https://github.com/orangecryptohq/orange-bridge-contract/blob/main/src/Vault.sol#L84-L89) (read thrice).
Vault::acceptAdmin() can cache the [pendingAdmin](https://github.com/orangecryptohq/orange-bridge-contract/blob/main/src/Vault.sol#L153-L156) (read 4 times).
Vault::withdraw() can cache [signers.length](https://github.com/orangecryptohq/orange-bridge-contract/blob/main/src/Vault.sol#L115) (read number of signers times).

### Status

Addressed in [#68ce26f](https://github.com/orangecryptohq/orange-bridge-contract/commit/68ce26ff8cacbbd39efae4662c2fdde12d16671c9).

---

Related findings:

- [Storage variables should be cached whenever possible to save gas](https://0xsimao.com/findings/glacier-storage-cached-whenever-gas): Glacier
- [Storage variables can be cached to save gas](https://0xsimao.com/findings/mitosis-storage-variables-cached-gas): Mitosis
- [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
