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

s_owner is not set as immutable consuming more gas

Summary

The PasswordStore::s_owner variable is not changed after the initialization inside the constructor, so it is best to set it as immutable to save gas.

Vulnerability Details

contract PasswordStore {
error PasswordStore__NotOwner();
@> address private s_owner;
string private s_password;

If a variable is not changed during the life of the smart contract it is better to set it as immutable because reading it costs much less gas.

Impact

More gas is wasted.

Using the command forge test --gas-report, the deployment gas cost results of 225780 without immutable, and 209477 with immutable.
Also the getPassword function consumes max 3320 of gas without immutable, and 1217 with immutable.

Tools Used

  • manual check

  • foundry

Recommendations

Set s_owner to immutable.

- address private s_owner;
+ address private immutable s_owner;
Updates

Lead Judging Commences

inallhonesty Lead Judge
about 2 years ago
inallhonesty Lead Judge about 2 years ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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