Last Man Standing

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

Informational: Dead Code and Unused Logic in claimThrone

Root + Impact

Description

  • The claimThrone function contains a block of dead code. A local variable previousKingPayout is initialized to 0 and is never updated. However, a subsequent if statement checks a condition involving this variable that can never logically be met, rendering the entire if block unreachable.

    While this does not pose a direct security threat, it reduces code clarity, can lead to confusion for future developers, and represents a minor gas inefficiency. It may also indicate a partially removed feature, which could have other unforeseen side effects.


// src/Game.sol
function claimThrone() external payable /* ... */ {
// ...
uint256 sentAmount = msg.value;
@> uint256 previousKingPayout = 0;
uint256 currentPlatformFee = 0;
// ...
currentPlatformFee = (sentAmount * platformFeePercentage) / 100;
@> // This entire 'if' block is unreachable because 'previousKingPayout' is always 0
@> if (currentPlatformFee > (sentAmount - previousKingPayout)) {
@> currentPlatformFee = sentAmount - previousKingPayout;
@> }
// ...
}

Recommended Mitigation

It is recommended to remove the unused previousKingPayout variable and the entire unreachable if block that depends on it. This change simplifies the code, improves readability, and provides minor gas savings.

function claimThrone() external payable /* ... */ {
// ...
uint256 sentAmount = msg.value;
- uint256 previousKingPayout = 0;
uint256 currentPlatformFee = 0;
// ...
currentPlatformFee = (sentAmount * platformFeePercentage) / 100;
- // Defensive check to ensure platformFee doesn't exceed available amount after previousKingPayout
- if (currentPlatformFee > (sentAmount - previousKingPayout)) {
- currentPlatformFee = sentAmount - previousKingPayout;
- }
// Remaining amount goes to the pot
// ...
}
Updates

Appeal created

inallhonesty Lead Judge about 1 month 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.