Beatland Festival

First Flight #44
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

Unnecessary checking for the first call of `attendPerformance`

Unnecessary checking for the first call of attendPerformance causing extra gas usage

Description

  • Normally user will buy festival pass and call attendPerformance to earn BEAT

  • The require condition in attendPerformance below checks if the current block timestamp is equal or bigger than the last time user checks in plus COOLDOWN, but it will still apply a COOLDOWN even though it's the user first time checking in for the first performance, thus causing extra gas used to users earning BEAT for the first time

require(block.timestamp >= lastCheckIn[msg.sender] + COOLDOWN, "Cooldown period not met");

Risk

Likelihood:

  • Basically happens for every first call on attendPerformance for any users so it's highly likely

Impact:

  • Causing unnecessary gas usage to users when they first call attendPerformance


Proof of Concept

forge test --mt test_AttendPerformance_Success
// gas usage BEFORE optimization
// first call - 109941
// subsequent call - 36215
// gas usage AFTER optimization
// first call - 109765
// subsequent call - 36249
// saved ~16% gas usage

Recommended Mitigation

- require(block.timestamp >= lastCheckIn[msg.sender] + COOLDOWN, "Cooldown period not met");
+ uint256 lastCheckInTime = lastCheckIn[msg.sender];
+ if (lastCheckInTime != 0) require(block.timestamp >= lastCheckInTime + COOLDOWN, "Cooldown period not met");
Updates

Lead Judging Commences

inallhonesty Lead Judge 26 days ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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