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

The setPassword function in the code can be made more gas-efficient by emitting the event before updating the password

Summary

The setPassword function in the code can be made more gas-efficient by emitting the event before updating the password. This change ensures that the event is emitted even if the password update fails, which is a good practice to provide complete information to users and auditors.

Vulnerability Details

In the code, the setPassword function emits the SetNetPassword event after updating the password as follows:

function setPassword(string memory newPassword) external {
s_password = newPassword;
emit SetNetPassword();
}

This order of operations means that if an error occurs during the password update (e.g., an out-of-gas error or a failed require condition), the event will not be emitted, potentially leaving users and auditors unaware of the attempted password change.

Impact

The impact of the current order of operations in the setPassword function is relatively minor, as it mainly affects the completeness of the event log. However, it's a good practice to ensure that events are always emitted, even in the case of a failed transaction, to provide accurate and transparent information.

Tools Used

No specific tools are used for this analysis. It's a manual code review based on the provided code snippet.

Recommendations

To enhance gas efficiency and provide complete information to users and auditors, it's recommended to emit the event before updating the password in the setPassword function. Here's an example of the modified code:

function setPassword(string memory newPassword) external {
emit SetNetPassword();
s_password = newPassword;
}
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.