function attendPerformance(uint256 performanceId) external {
require(isPerformanceActive(performanceId), "Performance is not active");
require(hasPass(msg.sender), "Must own a pass");
require(!hasAttended[performanceId][msg.sender], "Already attended this performance");
require(block.timestamp >= lastCheckIn[msg.sender] + COOLDOWN, "Cooldown period not met");
hasAttended[performanceId][msg.sender] = true;
lastCheckIn[msg.sender] = block.timestamp;
uint256 multiplier = getMultiplier(msg.sender);
BeatToken(beatToken).mint(msg.sender, performances[performanceId].baseReward * multiplier);
emit Attended(msg.sender, performanceId, performances[performanceId].baseReward * multiplier);
}
function test_PassReuseVulnerability() public {
uint256 baseReward = 100e18;
vm.startPrank(organizer);
uint256 performanceId1 = festivalPass.createPerformance(
block.timestamp + 1 hours,
2 hours,
baseReward
);
uint256 performanceId2 = festivalPass.createPerformance(
block.timestamp + 4 hours,
2 hours,
baseReward
);
uint256 performanceId3 = festivalPass.createPerformance(
block.timestamp + 7 hours,
2 hours,
baseReward
);
vm.stopPrank();
vm.startPrank(user1);
festivalPass.buyPass{value: VIP_PRICE}(2);
vm.stopPrank();
vm.warp(block.timestamp + 1 hours + 30 minutes);
vm.startPrank(user1);
festivalPass.attendPerformance(performanceId1);
vm.stopPrank();
vm.warp(block.timestamp + COOLDOWN + 2 hours + 30 minutes);
vm.startPrank(user1);
festivalPass.attendPerformance(performanceId2);
vm.stopPrank();
vm.warp(block.timestamp + COOLDOWN + 2 hours + 30 minutes);
vm.startPrank(user1);
festivalPass.attendPerformance(performanceId3);
vm.stopPrank();
assertEq(
festivalPass.balanceOf(user1, 2),
1,
"VULNERABILITY: User still has their pass after attending 3 performances!"
);
uint256 vipMultiplier = 2;
uint256 totalRewardEarned = baseReward * vipMultiplier * 3;
uint256 totalWithBonus = VIP_WELCOME_BONUS + totalRewardEarned;
assertEq(beatToken.balanceOf(user1), totalWithBonus, "User earned rewards for all 3 performances");
uint256 fairReward = VIP_WELCOME_BONUS + (baseReward * vipMultiplier);
uint256 unfairAdvantage = totalWithBonus - fairReward;
assertGt(totalWithBonus, fairReward, "VULNERABILITY: User earned more than they should have!");
assertEq(unfairAdvantage, baseReward * vipMultiplier * 2, "User got 2 extra performance rewards");
vm.startPrank(organizer);
uint256 performanceId4 = festivalPass.createPerformance(
block.timestamp + 2 hours,
2 hours,
baseReward
);
vm.stopPrank();
vm.warp(block.timestamp + 2 hours + 30 minutes);
vm.startPrank(user1);
festivalPass.attendPerformance(performanceId4);
vm.stopPrank();
assertEq(
festivalPass.balanceOf(user1, 2), 1, "VULNERABILITY: User can attend unlimited performances with 1 pass!"
);
uint256 finalReward = VIP_WELCOME_BONUS + (baseReward * vipMultiplier * 4);
assertEq(beatToken.balanceOf(user1), finalReward, "User earned rewards for 4 performances with 1 pass");
console.log("VULNERABILITY DEMONSTRATED:");
console.log("User bought 1 VIP pass for", VIP_PRICE, "ETH");
console.log("User attended 4 performances and earned", finalReward, "BEAT tokens");
console.log("Fair reward should have been", VIP_WELCOME_BONUS + (baseReward * vipMultiplier), "BEAT tokens");
console.log(
"Unfair advantage:", finalReward - (VIP_WELCOME_BONUS + (baseReward * vipMultiplier)), "BEAT tokens"
);
}