Summary
The VotingBooth::s_voters
variable is unable to be changed, and therefore should be immutable to save gas.
Vulnerability Details
If a variable never changes, then reading from storage is less gas efficient, and instead should read from the bytecode. Using an immutable variable will enable the protocol to save gas on reading VotingBooth::s_voters
variable.
Impact
Saved 12287 gas.
| src/VotingBooth.sol:VotingBooth contract | | | | | |
|------------------------------------------|-----------------|-------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 474481 | 2744 | | | | |
| Function Name | min | avg | median | max | # calls |
| getCreator | 268 | 268 | 268 | 268 | 4 |
| getTotalAllowedVoters | 324 | 324 | 324 | 324 | 4 |
| isActive | 292 | 1434 | 2292 | 2292 | 7 |
| vote | 28703 | 66050 | 68373 | 152505 | 8 |
| src/VotingBooth.sol:VotingBooth contract | | | | | |
|------------------------------------------|-----------------|-------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 462194 | 2797 | | | | |
| Function Name | min | avg | median | max | # calls |
| getCreator | 162 | 162 | 162 | 162 | 4 |
| getTotalAllowedVoters | 324 | 324 | 324 | 324 | 4 |
| isActive | 292 | 1434 | 2292 | 2292 | 7 |
| vote | 28709 | 65791 | 67318 | 152511 | 8 |
Tools Used
Recommendations
- address private s_creator;
+ address immutable private s_creator;