Mystery Box

First Flight #25
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: low
Invalid

Gas Optimization: Unchecked can be applied to the increment of boxesOwned

Summary
Since it is unlikely to cause overflows, buyBox can make use of unchecked and ++ operator to save on gas costs, since it is unlikely that enough boxes will be accumulated to cause an overflow and the implicit overflow check costs unnecessary gas.

Vulnerability Details

Unnecessary costs due to implicit overflow check of solidity

function buyBox() public payable {
require(msg.value == boxPrice, "Incorrect ETH sent");
boxesOwned[msg.sender] += 1; //-> unchecked {++boxesOwned[msg.sender]}
}

Impact
Gas waste

Tools Used

Manual Review

Recommendation
Add an unchecked block that covers boxesOvned and ++ operator for the incrementor to save gas costs

Updates

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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

Give us feedback!