Separate calculation of fees in applyFees results in inflated total fee percentage
The applyFees function calculates each fee (protocol, donation, vouchers pool) independently using calcFee, causing the total effective fee to exceed the sum of the intended basis points. This leads to users being overcharged when multiple fees are applied.
Source: https://github.com/sherlock-audit/2024-11-ethos-network-ii-judging/issues/637
Found by
0xMosh, 0xProf, 0xaxaxa, 0xpiken, DigiSafe, HOM1T, JohnTPark24, ami, copperscrewer, debugging3, dobrevaleri, eLSeR17, future2_22, newspacexyz, pashap9990, tobi0x18, whitehair0330, zhenyazhd
Summary
The separate calculation of fees in applyFees using multiple calls to calcFee causes a higher total fee percentage than expected. This leads to users being overcharged because each fee is calculated independently, rather than as a proportion of the total deposit. As a result, the total effective fee exceeds the intended basis points when multiple fees are applied.
Root Cause
In thosVouch.sol:936 : https://github.com/sherlock-audit/2024-11-ethos-network-ii/blob/main/ethos/packages/contracts/contracts/EthosVouch.sol#L936
In the applyFees function of the EthosVouch contract, the protocol fee, donation fee, and vouchers pool fee are calculated independently using the calcFee function. This results in compounding effects where the combined fees are higher than intended.
Internal pre-conditions
- applyFees is called with amount and configured basis points for protocol, donation, and vouchers pool fees.
- Each fee (protocol, donation, and vouchers pool) is calculated using calcFee, which computes the fee based on the provided basis points independently of other fees.
External pre-conditions
- A user initiates an operation that triggers applyFees, such as buying or selling votes, where multiple fees are involved.
- The basis points for each fee (entryProtocolFeeBasisPoints, entryDonationFeeBasisPoints, entryVouchersPoolFeeBasisPoints) are configured with non-zero values.
Attack Path
- The user makes a transaction that triggers applyFees (e.g., buying votes).
- The protocol calculates multiple fees (protocol, donation, vouchers pool) using calcFee independently.
- Due to separate fee calculations, the total effective fee percentage exceeds the sum of the intended basis points, leading to user overcharging.
Impact
Affected users are overcharged due to inflated fees. For example: • If entryProtocolFeeBasisPoints = 2000 (20%) and entryDonationFeeBasisPoints = 2500 (25%), the total fee is expected to be 4500 basis points (45%). However, due to independent calculations, the effective fee becomes approximately 5789 basis points (57.89%), as shown in the testFee example.
The protocol’s reputation and user trust may suffer due to higher-than-expected charges.
PoC
function testFee() external {
uint256 feeBasisPoints = 2000; // 20%
uint256 feeBasisPoints2 = 2500; // 25%
uint256 total = 300000000000000; // 0.3 ETH
// Separate fee calculation
uint256 fee1 = total -
(total.mulDiv(10000, (10000 + feeBasisPoints), Math.Rounding.Floor));
uint256 fee2 = total -
(total.mulDiv(10000, (10000 + feeBasisPoints2), Math.Rounding.Floor));
console.log(fee1 + fee2, total - fee1 - fee2); // Inflated fee: 5789 basis points (~57.89%)
// Combined fee calculation
uint256 fee3 = total -
(total.mulDiv(10000, (10000 + feeBasisPoints2 + feeBasisPoints), Math.Rounding.Floor));
console.log(fee3, total - fee3); // Correct fee: 4500 basis points (45%)
}
Mitigation
- Calculate the total fee for all basis points in one step.
- Distribute the total fee proportionally to the respective components.
- Update applyFees to use the combined fee calculation logic, ensuring the total effective fee matches the expected sum of basis points.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/trust-ethos/ethos/pull/2243
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The applyFees function calculates each fee independently using calcFee, rather than calculating the total fee based on the sum of all basis points and then distributing it.
Impact
Users are overcharged due to inflated fees; for example, with 20% and 25% fees, the effective fee becomes about 57.89% instead of 45%.
What the attacker needed
ApplyFees is called with multiple non-zero fees
The fix
The protocol team fixed this issue in the following PRs/commits: https://github.com/trust-ethos/ethos/pull/2243
How it was found
- A user initiates an operation that triggers applyFees, such as buying or selling votes.
- The protocol calculates multiple fees (protocol, donation, vouchers pool) using calcFee independently.
- Due to separate fee calculations, the total effective fee percentage exceeds the sum of the intended basis points, leading to user overcharging.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you pay a fee, it's usually a percentage of the amount. If there are several fees, you'd expect the total percentage to be the sum of each. But here, each fee is calculated on the original amount separately, so the combined effect is larger than intended, meaning users pay more than they should.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.