Last Man Standing

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

previousKingPayout logic missing and platform fee overcharged

Root + Impact

Description

When a new player claims the throne, the contract intends to:

  1. Pay 10% of the previous claim fee to the previous king as an incentive.

  2. Charge a platform fee that doesn’t exceed the remaining balance after that payout.

However, in the original implementation:

  • The previousKingPayout is declared and set to 0.

  • As a result, the platform fee calculation is incorrect since it assumes previousKingPayout is 0.

  • This causes the bypassing the check of currentPlatformFee > (sentAmount - previousKingPayout).

// @ The value of previousKingPayout is never set or used
// @ missing payout
// uint256 previousKingPayout = (claimFee * 10) / 100;
// payout logic not implemented

Risk

Likelihood:

  • This occurs every time a new king claims the throne.

Impact:

  • Loss of Funds: The previous king never receives their intended 10% reward.

  • Excess Platform Fees: The platform takes more than the intended fee, breaking economic balance.

  • Trust Violation: Players will lose trust due to incorrect fund distribution.

Proof of Concept

Explanation:

In the broken contract, the previousKingPayout is not initialized or paid. So this line:

if (currentPlatformFee > sentAmount - previousKingPayout) {
currentPlatformFee = sentAmount - previousKingPayout;
}

is effectively:

if (currentPlatformFee > sentAmount) {
currentPlatformFee = sentAmount;
}

Which never triggers, because currentPlatformFee is a % of sentAmount. But in reality, sentAmount - previousKingPayout is meant to cap the fee after paying out the previous king.

Code:

// Current broken logic:
uint256 currentPlatformFee = (sentAmount * platformFeePercentage) / 100;
// This check always passes since previousKingPayout = 0
if (currentPlatformFee > sentAmount - previousKingPayout) {
currentPlatformFee = sentAmount - previousKingPayout;
}
// No transfer to previous king

Recommended Mitigation

Explanation:

  • Explicitly assign the previousKingPayout before platform fee logic.

  • Transfer the amount to currentKing (i.e., the previous king).

  • Adjust the fee cap to subtract that amount.

// ✅ Add correct payout logic
// Calculate previous king payout if there is a current king
+ uint256 previousKingPayoutPercentage = 10; // 10% of the claim fee goes to the previous king
+ previousKingPayout = (sentAmount * previousKingPayoutPercentage) / 100;
+ if (currentKing != address(0) && previousKingPayout > 0) {
+ (bool success, ) = payable(currentKing).call{value: previousKingPayout}("");
+ require(success, "Game: Failed to send payout to previous king.");
+ }
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!