Last Man Standing

First Flight #45
Beginner FriendlyFoundrySolidity
100 EXP
View results
Submission Details
Severity: medium
Valid

Check for msg.sender is currentKing in Game::claimThrone prevents anyone from joining the game at all

Bad require statement leads to no player able to join the game at the start.

Description

  • When the game starts, players are suppose to be able to claim the throne until another player claims it by paying a fee > previous claimants fee right?

  • The issue is that since the check only passes if msg.sender == currentKing and no currentKing should exist at the begining of the game then no one is able to call claimThrone.

    require(
    msg.sender == currentKing,
    "Game: You are already the king. No need to re-claim."
    );

Risk

Likelihood:

  • Very high because no player can join at the start so game does not even get past round 1


Impact:

  • No player can join the game.


Proof of Concept

// add the following to the test file 'Game.t.sol'
function testNoOneCanJoinTheGame() public {
vm.startPrank(address(player1));
vm.expectRevert();
game.claimThrone{value: INITIAL_CLAIM_FEE}();
vm.stopPrank();
}
// the test fails as expected and these are the traces:
`
Traces:
[46706] GameTest::testNoOneCanJoinTheGame()
├─ [0] VM::startPrank(player1: [0x7026B763CBE7d4E72049EA67E89326432a50ef84])
│ └─ ← [Return]
├─ [0] VM::expectRevert(custom error f4844814:)
│ └─ ← [Return]
├─ [28960] Game::claimThrone{value: 100000000000000000}()
│ └─ ← [Revert] revert: Game: You are already the king. No need to re-claim.
├─ [0] VM::stopPrank()
│ └─ ← [Return]
└─ ← [Stop]
`

Recommended Mitigation

require(
- msg.sender == currentKing,
+ msg.sender != currentKing,
"Game: You are already the king. No need to re-claim."
);
Updates

Appeal created

inallhonesty Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Game::claimThrone `msg.sender == currentKing` check is busted

Support

FAQs

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

Give us feedback!