# Separate calculation of fees in applyFees results in inflated total fee percentage.

EthosVouch.applyFees calculates protocol, donation, and vouchers pool fees independently, inflating total fee from 45% to ~57.89% and overcharging users.

- Payout: Audit contest
- Severity: medium
- Program: Ethos Network
- Found by: 0xMosh
- Disclosed: 2024-11-20
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-11-ethos-network-ii-judging/issues/637
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-ethos-network-ii%3AM-3
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:sherlock sev:medium tech:solidity vuln:accounting-error vuln:business-logic

**Target:** EthosVouch smart contract applyFees function
**Root cause:** applyFees calls calcFee separately for each fee component, each computing fee as amount - amount*10000/(10000+bps), causing compounding instead of summing basis points first.
**Steps:**
1. Configure entryProtocolFeeBasisPoints=2000 and entryDonationFeeBasisPoints=2500.
2. Call a function that triggers applyFees with amount=0.3 ETH.
3. Observe fee1 = total - total.mulDiv(10000, 12000) and fee2 = total - total.mulDiv(10000, 12500).
4. Sum fee1+fee2 yields ~57.89% of total instead of expected 45%.
**How found:** Code review of applyFees revealed separate calcFee calls; testFee PoC demonstrated inflated effective fee.
**Exploitation:** Any user buying or selling votes with multiple non-zero fee basis points is overcharged; no attacker action needed beyond normal protocol use.
**Insight:** When multiple percentage fees are applied, sum basis points before calculating to avoid compounding; check for independent fee calculations in similar contracts.

## Proof of concept (copied exactly from the original report)

**testFee PoC showing inflated combined fee**

```
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%)
```

