Summary
The VotingBooth::s_totalAllowedVoters
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_totalAllowedVoters
variable.
Impact
Saved 10251 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 | | | | |
| 464230 | 2821 | | | | |
| Function Name | min | avg | median | max | # calls |
| getCreator | 268 | 268 | 268 | 268 | 4 |
| getTotalAllowedVoters | 221 | 221 | 221 | 221 | 4 |
| isActive | 292 | 1434 | 2292 | 2292 | 7 |
| vote | 28606 | 65203 | 67276 | 152408 | 8 |
Tools Used
Recommendations
- address private s_totalAllowedVoters;
+ address immutable private s_totalAllowedVoters;