# Market funds cannot be withdrawn because of incorrect calculation of `fundsPaid`

ReputationMarket counts protocol and donation fees inside marketFunds after already paying them out, so graduated market withdrawals revert from insufficient balance.

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

**Target:** ReputationMarket.sol buyVotes/applyFees/withdrawGraduatedMarketFunds
**Root cause:** applyFees pays protocol fee to treasury and credits donation to owner escrow, but buyVotes then adds the full fundsPaid (including those fees) to marketFunds, double-counting them.
**Steps:**
1. Call `buyVotes` on a market with protocolFee and donation each 5%, paying cost+fees.
2. Observe `applyFees` sends protocolFee to treasury and adds donation to donationEscrow.
3. Observe `marketFunds[profileId] += fundsPaid` still includes those fees.
4. Market owner withdraws donations; market graduates.
5. Call `withdrawGraduatedMarketFunds`; it reverts because recorded marketFunds exceeds actual ETH balance.
**How found:** Code reading of buyVotes flow: noticed applyFees already disburses fees before marketFunds is incremented with the un-deducted fundsPaid.
**Exploitation:** No attacker profit; accounting error causes graduated market fund withdrawal to revert (funds stuck) or, if it succeeds, pulls ETH allocated to other markets.
**Insight:** When a purchase function both disburses fees and tracks a per-market balance, verify the tracked balance is net of fees already paid out; double-counting surfaces only at withdrawal/graduation time.

