`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.
```javascript
uint256 id = festivalPass.createPerformance(block.timestamp + 3600, 2 hours, 10e18);
Performance memory wrongPerf = festivalPass.performances(id);
```
```diff
emit PerformanceCreated(performanceCount, startTime, startTime + duration);
- return performanceCount++;
+ uint256 newId = performanceCount;
+ performanceCount++;
+ return newId;
}
```