State variables should be cached in stack variables rather than re-reading them from storage
The instances below point to the second+ access of a state variable within a function.
Caching of a state variable replaces each Gwarmaccess (100 gas) with a much cheaper stack read.
Other less obvious fixes/optimizations include having local memory caches of state variable structs,
or having local caches of state variable contracts/addresses.
Saves 100 gas per instance
Link to code - https://github.com/Cyfrin/2023-07-beedle/tree/main/src/Lender.sol
Link to code - https://github.com/Cyfrin/2023-07-beedle/tree/main/src/Staking.sol
Code Review
Cache state variables if they need to be accessed more than once
NeoCrao
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.