Last Man Standing

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

Unused variable previousKingPayout present in claimThrone() function

Root + Impact

Description

  • The game is designed to distribute portions of the claim fee to different parties such as the platform and the pot, while potentially paying the previous king a portion of the claim fee.

  • The variable previousKingPayout is declared and initialized but never assigned or used to pay the previous king. This leaves dead code that may confuse developers or auditors and suggests unfinished or abandoned logic.

function claimThrone() external payable gameNotEnded nonReentrant {
// Previous code
@> uint256 previousKingPayout = 0; // @> Declared but never used or updated
@> if (currentPlatformFee > (sentAmount - previousKingPayout)) {
@> currentPlatformFee = sentAmount - previousKingPayout;
@> }
// rest of the code...
}

Risk

Likelihood:

  • This will be encountered every time a player claims the throne, as the variable is always initialized but unused.

  • This is persistent throughout the contract’s lifecycle unless the code is refactored.

Impact:

  • Causes confusion and reduces code clarity and maintainability.

  • May indicate incomplete or abandoned payout logic that could lead to misunderstanding of game mechanics.

Proof of Concept

This demonstrates that the variable is redundant and can mislead maintainers or auditors reviewing the contract.

// Dead code example:
// The variable previousKingPayout remains zero and does not affect balances or payouts,
// demonstrating it is unused in the claim distribution logic.

Recommended Mitigation

Removing unused variables prevents confusion and improves the maintainability of the smart contract codebase.

- uint256 previousKingPayout = 0;
- if (currentPlatformFee > (sentAmount - previousKingPayout)) {
- currentPlatformFee = sentAmount - previousKingPayout;
- }
+ // Remove previousKingPayout variable and simplify defensive check accordingly
+ if (currentPlatformFee > sentAmount) {
+ currentPlatformFee = sentAmount;
+ }
Updates

Appeal created

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

Missing Previous King Payout Functionality

Support

FAQs

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

Give us feedback!