Last Man Standing

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

## Precision loss ## [ claimThrone() ]

Root + Impact

Description

In the claimThrone() function, the platform fee is calculated using integer-based division with a percentage denominator:

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.");
uint256 sentAmount = msg.value;
uint256 previousKingPayout = 0;
uint256 currentPlatformFee = 0;
uint256 amountToPot = 0;
// Calculate platform fee
currentPlatformFee = (sentAmount * platformFeePercentage) / 100; @<

When the result of (sentAmount * platformFeePercentage) is not exactly divisible by 100, the remainder is silently discarded, leading to small but systematic rounding errors over time. This could slightly under-allocate platform fees or misrepresent the value added to the pot.



Risk

Likelihood: High

  • It becomes more noticeable at lower transaction values, where small wei amounts represent a larger proportion of the total fee

  • This will occur on every invocation of claimThrone() where sentAmount * platformFeePercentage is not divisible by 100

Impact:

  • The platform will under-collect fees over time

  • Accumulated over many players, this could lead to significant financial drift between expected vs actual fee distributions

  • The pot may receive more than intended, potential affecting the game's economic balance

Proof of Concept

Scenario:

  • msg.value = 101 wei

  • platformFeePercentage = 3

  • currentPlatformFee = (101 * 3) / 100

currentPlatformFee = (101 * 3) / 100 = 3 (should be 3.03)

A 0.03 wei rounding error occurs and is discarded.

This may seem small, but:

  • If over 1 million plays: 0.03 * 1,000,000 = 30,000 wei (~0.00003 ETH)

  • Larger sentAmount values (e.g. gwei/ether) can amplify this depending on the rate of growth



Recommended Mitigation

Increase precision to 10,000 or 1,000,000:

+ 10,000 or 1,000,000
Updates

Appeal created

inallhonesty Lead Judge about 1 month ago
Submission Judgement Published
Validated
Assigned finding tags:

Precision loss in fee calc

Support

FAQs

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