Last Man Standing

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

Function claimThrone - Require Message Sender is Current King is Invalid - Should require that msg.sender is not current king

Root + Impact

Description

  • Ideal situation: In normal game play, the claimThrone function should ensure that the current king is not calling the claimThrone function.

  • Issue: In the current code, the require (msg.sender == currentKing ... causes the function to fail when its called by any different game player to the current king. For example, initially the currentKing is 0x0, and the message sender is some other address, so requiring msg.sender == currentKing will fail, this means that the rest of the code in claimThrone won't be reached, and currentKing cannot be set to the msg.sender later.

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.");

Risk

Likelihood:

  • The first time the claimThrone function is called by a valid player, or any time after (with the current code) it is called by a king that is not the current king, msg.sender will not be equal to the current king, so the require statement will fail.

Impact:

  • claimThrone function can never set the claimThrone function caller (msg.sender) to the new king .

  • Game play is not possible until this is fixed.


Proof of Concept

To fix this issue, we must correct the require statement as indicated in the Recommended Mitigation.

In other words we should require that msg.sender != currentKing in line 3 below.

See the existing code below and compare to Reccommended Mitigation which follows after it:

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.");

Recommended Mitigation

Update the require statement to check that player calling the claimThrone function is not the current king as indicated below (require that msg.sender != currentKing).

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.");
+ require(msg.sender != currentKing, "Game: You are already the king. No need to re-claim.");
Updates

Appeal created

inallhonesty Lead Judge 10 days 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.