Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

`VotingBooth::s_totalAllowedVoters` being set as a storage variable wastes gas

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

  • Foundry

Recommendations

- address private s_totalAllowedVoters;
+ address immutable private s_totalAllowedVoters;
Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Out of scope

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.