Root + Impact
Description
The owner in Game can front-run a player calling the claimThrone() function and update the platformFeePercentage value to 100.
function claimThrone() external payable gameNotEnded nonReentrant {
require(msg.value >= claimFee, "Game: Insufficient ETH sent to claim the throne.");
require(msg.sender != currentKing, "Game: You are already the king. No need to re-claim.");
uint256 sentAmount = msg.value;
uint256 previousKingPayout = 0;
uint256 currentPlatformFee = 0;
uint256 amountToPot = 0;
@> currentPlatformFee = (sentAmount * platformFeePercentage) / 100;
@> if (currentPlatformFee > (sentAmount - previousKingPayout)) {
currentPlatformFee = sentAmount - previousKingPayout;
}
platformFeesBalance = platformFeesBalance + currentPlatformFee;
@> amountToPot = sentAmount - currentPlatformFee;
pot = pot + amountToPot;
currentKing = msg.sender;
lastClaimTime = block.timestamp;
playerClaimCount[msg.sender] = playerClaimCount[msg.sender] + 1;
totalClaims = totalClaims + 1;
claimFee = claimFee + (claimFee * feeIncreasePercentage) / 100;
emit ThroneClaimed(
msg.sender,
sentAmount,
claimFee,
pot,
block.timestamp
);
}
Risk
Likelihood:
It is a fairly simple execution for the owner to do this. Thus, the likelihood is pretty high. Owner will receive more funds, so he is also incentivized to do so.
Impact:
Proof of Concept
Here's a test case proving the claim:
function test_OwnerTakesEverything() public {
vm.prank(player2);
game.claimThrone{value: 0.2 ether}();
vm.prank(player3);
game.claimThrone{value: 0.3 ether}();
uint256 potBefore = game.pot();
vm.prank(deployer);
game.updatePlatformFeePercentage(100);
vm.prank(player1);
game.claimThrone{value: 1 ether}();
uint256 potAfter = game.pot();
assert(potBefore == potAfter);
}
Recommended Mitigation
There should be a maximum threshold for the platform fee value