Game::claimThrone
indefinitely extends the gracePeriod, preventing the game from ending
Description
The claimThrone()
function should allow players to claim the throne within a limited period.
However, lastClaimTime
is updated every time, causing the gracePeriod
to reset every time a player completes claimThrone()
.
function claimThrone() external payable gameNotEnded nonReentrant {
...
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;
...
}
Risk
Likelihood: High
Impact: High
Proof of Concept
This test shows that every time claimThrone()
is called, the gracePeriod is completely reset, preventing it from expiring. This can block the end of the game indefinitely.## Proof of Concept
function test_GracePeriodIsUpdatedOnClaimThrone() public {
uint256 graceBefore = game.getRemainingTime();
vm.warp(block.timestamp + 12 hours);
uint256 graceMid = game.getRemainingTime();
assertGt(graceBefore, graceMid);
vm.prank(player1);
game.claimThrone{value: INITIAL_CLAIM_FEE}();
uint256 graceAfter = game.getRemainingTime();
assertEq(graceAfter, graceBefore);
}
Ran 1 test for test/Game.t.sol:GameTest
[PASS] test_GracePeriodIsUpdatedOnClaimThrone() (gas: 160984)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 13.86ms (1.12ms CPU time)
Recommended Mitigation
Remove the line that resets lastClaimTime
.## Recommended Mitigation
function claimThrone() external payable gameNotEnded nonReentrant {
...ction claimThrone() external payable gameNotEnded nonReentrant {
amountToPot = sentAmount - currentPlatformFee; ...
pot = pot + amountToPot; amountToPot = sentAmount - currentPlatformFee;
// Update game state pot = pot + amountToPot;
currentKing = msg.sender;
- lastClaimTime = block.timestamp; // Update game state
playerClaimCount[msg.sender] = playerClaimCount[msg.sender] + 1;nder;
totalClaims = totalClaims + 1;estamp;
layerClaimCount[msg.sender] + 1;
// Increase the claim fee for the next player
claimFee = claimFee + (claimFee * feeIncreasePercentage) / 100;
// Increase the claim fee for the next player
...Percentage) / 100;
}