Rock Paper Scissors

First Flight #38
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

[G-1] Use of require statement to perform checks is not gas efficient

Summary

Use of require(condition, "error string") pattern is gas inefficient because the "error string" parameter, which is a descriptive error message, requires additional gas to encode and store on the blockchain. Specifically, the compiler converts this string into a 32-byte string, adding to the overall gas cost, even if the string is shorter.

Vulnerability Details

The require statement with an inline string message causes increased gas consumption due to the need to store the string data in the contract bytecode and during execution

Impact

The gas cost of failed transactions is unnecessarily increased, especially in functions where there are more require-statements. This can discourage user interaction with the contract and increase the operational cost of using the protocol. In large-scale deployments, the cumulative gas overhead from descriptive string errors can become significant.

Tools Used

Manual Review

Recommendations

  1. Declare all errors e.g. error BetAmountTooSmall()

  2. Use if/revert notation:-

if (msg.value < minBet) {
revert BetAmountTooSmall();
}
Updates

Appeal created

m3dython Lead Judge 2 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

Gas Optimization

Support

FAQs

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