Platform: Code4rena
Start Date: 20/01/2022
Pot Size: $80,000 USDC
Total HM: 5
Participants: 37
Period: 7 days
Judge: Jack the Pug
Total Solo HM: 1
Id: 76
League: ETH
Rank: 31/37
Findings: 1
Award: $26.04
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: RamiRond
Also found by: Dravee, Ruhum, kirk-baird, p4st13r4
26.0437 USDC - $26.04
Ruhum
A state variable shouldn't be read multiple times within the same function. Instead, read it once and save it to memory. If the variable was modified, save it to storage at the end of the function.
That will use less gas than working with the state variable directly.
A good example is the following function: https://github.com/code-423n4/2022-01-sherlock/blob/main/contracts/managers/SherDistributionManager.sol#L90
Multiple state variables are read more than once. They are never modified. So simply saving them to memory and working with that will be way cheaper.
#0 - jack-the-pug
2022-03-26T07:12:14Z
Dup #77