Last Man Standing

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

# Precision Loss in Fee Calculations; Pot and Fee Distribution

# Precision Loss in Fee Calculations; Pot and Fee Distribution
​
## Description
​
- Normally, fee calculations should be as precise as possible to avoid loss of funds due to rounding errors.
- The current implementation uses integer division for percentage calculations, which can lead to precision loss, especially for small values.
​
```javascript
// Root cause in the codebase with @> marks to highlight the relevant section
function claimThrone() external payable gameNotEnded nonReentrant {
//...
@> currentPlatformFee = (sentAmount * platformFeePercentage) / 100;
//...
@> claimFee = claimFee + (claimFee * feeIncreasePercentage) / 100;
}
```
​
## Risk
​
**Likelihood**:
​
- This will occur on every claim, especially when claim fees are small or percentages are not multiples of 10.
- The effect is more pronounced as the game progresses and claim fees increase.
​
**Impact**:
​
- Small amounts of ETH may be lost due to rounding down, reducing the pot and platform fees over time.
- Players and the platform owner may receive less than expected.
​
## Proof of Concept
​
Here are some loss scenario's.
​
```javascript
// No loss scenario
sentAmount = 0.1 ETH = 100000000000000000 wei
platformFee = (100000000000000000 * 5) / 100 = 5000000000000000 wei
// Perfect division - no loss!
​
// Negligible Loss
sentAmount = 100000000000000001 wei (0.1 ETH + 1 wei)
platformFee = (100000000000000001 * 5) / 100 = 5000000000000000 wei
// Lost: 5 wei out of 0.1 ETH = negligible
​
// Loss scenario
sentAmount = 999 wei
platformFee = (999 * 5) / 100 = 49 wei // Lost: 4995 - 4900 = 95 wei
​
// Small amounts
sentAmount = 99 wei
platformFeePercentage = 5%
currentPlatformFee = (99 * 5) / 100 = 495 / 100 = 4 wei
// Lost: 495 - 400 = 95 wei (truncated)
​
// Fee increases
claimFee = 133 wei
feeIncreasePercentage = 10%
increase = (133 * 10) / 100 = 1330 / 100 = 13 wei
// Lost: 1330 - 1300 = 30 wei (truncated)
```
​
## Recommended Mitigation
​
Consider using a higher-precision base (e.g., basis points or 1e4) for percentages, or document the rounding behavior clearly.
​
```diff
- currentPlatformFee = (sentAmount * platformFeePercentage) / 100;
+ currentPlatformFee = (sentAmount * platformFeePercentage) / 10000; // if using basis points
```
​
---
Updates

Appeal created

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

Give us feedback!