Last Man Standing

First Flight #45
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

getRemainingTime() Returns Incorrect Value When No King Exists

Root + Impact

Description

  • Normal behavior:
    getRemainingTime() should return 0 or a special value when no king exists, since there's no grace period to count down.

    Specific issue:
    The function calculates and returns a countdown based on lastClaimTime even when currentKing == address(0), misleading users about the actual game state.

function getRemainingTime() public view returns (uint256) {
if (gameEnded) {
return 0;
}
uint256 endTime = lastClaimTime + gracePeriod;
if (block.timestamp >= endTime) {
return 0;
}
return endTime - block.timestamp; // @> Returns countdown even with no king
}

Risk

Likelihood:

  • This occurs every time getRemainingTime() is called when no king exists.

Impact:

  • Front-end applications display incorrect countdown timers.

  • Users receive misleading information about game state.

  • Analytics and monitoring systems show wrong data.

Proof of Concept

The following test demonstrates that getRemainingTime() returns a countdown even when no king exists:

function testGetRemainingTimeWithNoKing() public {
// No one has claimed the throne yet (currentKing == address(0))
assertEq(game.currentKing(), address(0), "No king should exist");
// getRemainingTime() still returns a countdown, which is incorrect
uint256 remainingTime = game.getRemainingTime();
assertTrue(remainingTime > 0, "Should return 0 when no king exists, but returns countdown");
}

Recommended Mitigation

Add a check for when no king exists to return 0 instead of calculating a meaningless countdown:

function getRemainingTime() public view returns (uint256) {
- if (gameEnded) {
+ if (gameEnded || currentKing == address(0)) {
return 0;
}
uint256 endTime = lastClaimTime + gracePeriod;
if (block.timestamp >= endTime) {
return 0;
}
return endTime - block.timestamp;
}
Updates

Appeal created

inallhonesty Lead Judge 15 days ago
Submission Judgement Published
Invalidated
Reason: Design choice
r4y4n3 Submitter
14 days ago
inallhonesty Lead Judge
11 days ago
inallhonesty Lead Judge 10 days ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.