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

using the modifier also in the getPassword function saves gas

Summary

Using the PasswordStore::isOwner modifier, created in the previous submission, we can save gas on the function calls.

Vulnerability Details

Replacing the if inside the PasswordStore::getPassword function with the modifier isOwner we can save gas in the function call.

@> function getPassword() external view returns (string memory) {
@> if (msg.sender != s_owner) {
@> revert PasswordStore__NotOwner();
@> }
return s_password;
}

Impact

If we use the modifier also in the PasswordStore::getPassword function, as well as in the PasswordStore::setPassword function, the average gas consumption of a PasswordStore::getPassword call goes from 2990 to 1842, the maximum consumption goes from 3320 to 2343.
It also reduces the amount of duplicate code inside the smart contract.

Tools Used

  • manual review

  • foundry

Recommendations

As shown previously, we have to create an internal function _checkOwner with the if to check if the caller user is the owner, create the modifier isOwner that uses the function created, and remove the if from the PasswordStore::getPassword function and add the modifier isOwner in the definition of the PasswordStore::getPassword function.

+ modifier isOwner() {
+ _checkOwner();
+ _;
+ }
+ function _checkOwner() internal view {
+ if (msg.sender != s_owner) {
+ revert PasswordStore__NotOwner();
+ }
+ }
- function getPassword() external view returns (string memory) {
+ function getPassword() external view isOwner returns (string memory) {
- if (msg.sender != s_owner) {
- revert PasswordStore__NotOwner();
- }
return s_password;
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
almost 2 years ago
inallhonesty Lead Judge almost 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.