Skip to content
Business logic Audit finding Intermediate

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

The contract incorrectly records the total amount paid by a user, including fees, as market funds, while the fees have already been sent to the treasury and the market owner. This double-counting can cause withdrawals of graduated market funds to fail due to insufficient balance, or allow one market to drain funds from others.

0rpse Follow with 0x486776, 0xEkko and 47 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-ethos-network-ii-judging/issues/660

Found by

0rpse, 0x486776, 0xEkko, 0xPhantom2, 0xProf, 0xaxaxa, 0xgremlincat, 0xlucky, 0xmujahid002, 0xpiken, 4th05, Abhan1041, AestheticBhai, Al-Qa-qa, Artur, BengalCatBalu, Bozho, Ch_301, Cybrid, DenTonylifer, DharkArtz, HOM1T, John44, JohnTPark24, KingNFT, KlosMitSoss, Limbooo, Nave765, NickAuditor2, Pablo, Waydou, Weed0607, X0sauce, X12, ami, blutorque, bube, bughuntoor, cryptic, debugging3, dobrevaleri, farismaulana, future2_22, hals, iamnmt, ke1caM, kenzo123, mahdikarimi, nikhilx0111, novaman33, parzival, pashap9990, qandisa, rudhra1749, shui, smbv-1923, t.aksoy, tjonair, tmotfl, tobi0x18, udo, vatsal, volodya, wellbyt3, whitehair0330, y4y, ydlee, zxriptor

Summary

Funds withdrawal is blocked as fees are not deducted from fundsPaid when already being applied.

Root Cause

When votes are bought in ReputationMarket market, user has to pay fees to:

  • donation fees going to owner of the market
  • protocol fees going to treasury

This is seen in applyFees function below:

Solidity
  function applyFees(
    uint256 protocolFee,
    uint256 donation,
    uint256 marketOwnerProfileId
  ) private returns (uint256 fees) {
@>    donationEscrow[donationRecipient[marketOwnerProfileId]] += donation; // donation fees are updated for market owner
    if (protocolFee > 0) {
@>      (bool success, ) = protocolFeeAddress.call{ value: protocolFee }(""); // protocolFees paid to treasury
      if (!success) revert FeeTransferFailed("Protocol fee deposit failed");
    }
    fees = protocolFee + donation;
  }

Next, the total amount a user pays when votes are bought is managed by the fundsPaid variable. The amount consists of: cost of votes + protocol fees + donation fees

The vulnerability exists in the execution here:

  1. send protocol fees to the treasury
  2. add donations to market owner's escrow
  3. marketOwner is able to withdraw donations via withdrawDonations()

In the buyVotes function, protocolFee and donation are paid first as seen below:

Solidity
 applyFees(protocolFee, donation, profileId);

Then, when tallying the market funds, marketFunds is updated with fundsPaid. This fundsPaid still includes the protocolFee and donation and has not been deducted.

Solidity
 marketFunds[profileId] += fundsPaid; 

Hence, the protocolFee and donation has been counted twice.

When a market graduates, because of the incorrect counting of marketFunds, the contract may not have enough funds to be withdrawn via ReputationMarket.withdrawGraduatedMarketFunds and results in transaction reverting.

Proof of Concept

Assume this scenario:

A market exists with 2 trust votes and 2 distrust votes, each costing 0.03 ETH. Protocol and donation fees are both set at 5%. Alice buys 2 trust votes for 0.07 ETH:

Fees (5% each): Protocol: 0.0015 ETH per vote → 0.003 ETH total. Donations: 0.0015 ETH per vote → 0.003 ETH total. Vote Cost: 0.03 ETH × 2 = 0.06 ETH. Refund: 0.07 ETH - (0.06 ETH + 0.006 ETH fees) = 0.004 ETH. The contract incorrectly records 0.066 ETH (votes + fees) as market funds.

Market owner withdraws the 0.06 ETH correctly available.

After market graduation, the contract attempts to withdraw the recorded 0.066 ETH, but only 0.06 ETH exists.

Impact:

The withdrawal fails due to insufficient funds. Funds are stuck, or other markets' funds are misallocated. If a withdrawal succeeds, it might wrongly pull ETH allocated to other markets, leading to losses for other users.

Line(s) of Code

https://github.com/sherlock-audit/2024-11-ethos-network-ii/blob/main/ethos/packages/contracts/contracts/ReputationMarket.sol#L442

https://github.com/sherlock-audit/2024-11-ethos-network-ii/blob/main/ethos/packages/contracts/contracts/ReputationMarket.sol#L920

https://github.com/sherlock-audit/2024-11-ethos-network-ii/blob/main/ethos/packages/contracts/contracts/ReputationMarket.sol#L660

https://github.com/sherlock-audit/2024-11-ethos-network-ii/blob/main/ethos/packages/contracts/contracts/ReputationMarket.sol#L1116

Recommendations

Update logic to deduct protocol fees and donations before updating marketFunds.

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/trust-ethos/ethos/pull/2216

The original report as published on Sherlock, by 0rpse. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 contract adds the full amount paid (including fees) to marketFunds after the fees have already been transferred out, so the fees are counted twice.

Impact

The withdrawal of graduated market funds may fail due to insufficient balance, potentially locking funds or causing misallocation where one market's withdrawal wrongly uses ETH from other markets.

What the attacker needed

A market with votes; fees set above zero; market graduates

The fix

The logic should be updated to deduct protocol fees and donations before updating marketFunds.

How it was found

  1. A market exists with 2 trust votes and 2 distrust votes, each costing 0.03 ETH, and fees set at 5%.
  2. Alice buys 2 trust votes for 0.07 ETH, paying 0.06 ETH for votes and 0.006 ETH in fees.
  3. The contract records 0.066 ETH as market funds, which includes the fees.
  4. The market owner withdraws the 0.06 ETH that is actually available.
  5. After the market graduates, an attempt to withdraw the recorded 0.066 ETH fails because only 0.06 ETH exists.

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 someone buys votes in a market, they pay a price plus fees. The fees go to the protocol and the market owner, and the rest stays in the market. The bug is that the contract also counts the fees as part of the market's funds, so it thinks there is more money than actually exists. Later, when trying to withdraw those funds, the transaction fails because the contract doesn't have enough.

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.

More by 0rpse

View all

23 more disclosed reports, best first.

More from Ethos Network Financial Contracts

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.