Beatland Festival

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

Incorrect Return Value in `FestivalPass::createPerformance`


Description

`FestivalPass::createPerformance` function is defined as:
```javascript
function createPerformance(
uint256 startTime,
uint256 duration,
uint256 reward
) external onlyOrganizer returns (uint256) {
require(startTime > block.timestamp, "Start time must be in the future");
require(duration > 0, "Duration must be greater than 0");
performances[performanceCount] = Performance({
startTime: startTime,
endTime: startTime + duration,
baseReward: reward
});
emit PerformanceCreated(performanceCount, startTime, startTime + duration);
return performanceCount++;
}
```
Here, performanceCount is returned after using the post-increment operator performanceCount++, which means the next ID is returned instead of the actual ID that was just created.
-> This results in an off-by-one logic bug:
- The function creates performance ID N, But returns N + 1.

Risk

Impact:

Off-by-one error can cause external contracts or frontends to reference the wrong performance

Proof of Concept

```javascript
uint256 id = festivalPass.createPerformance(block.timestamp + 3600, 2 hours, 10e18);
// This returns `1`
// But actual performance created is `performance[0]`
Performance memory wrongPerf = festivalPass.performances(id); // empty struct
```

Recommended Mitigation

```diff
emit PerformanceCreated(performanceCount, startTime, startTime + duration);
- return performanceCount++;
+ uint256 newId = performanceCount;
+ performanceCount++;
+ return newId;
}
```
Updates

Lead Judging Commences

inallhonesty Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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