Skip to content
Business logic Audit finding Intermediate

treasuryShare is Overwritten in FeePoolV0._shareMochi()

The FeePoolV0 contract overwrites treasuryShare when distributeMochi() is called, allowing veCRV holders to repeatedly distribute mochi tokens and eventually receive all tokens intended for the treasury.

leastwood Follow

Originally disclosed on Code4rena

Submitted by leastwood

Impact

The FeePoolV0.sol contract accrues fees upon the liquidation of undercollaterised positions. These fees are split between treasury and vMochi contracts. However, when distributeMochi() is called to distribute mochi tokens to veCRV holders, both mochiShare and treasuryShare is flushed from the contract when there are still usdm tokens in the contract.

Proof of Concept

Consider the following scenario:

  • The FeePoolV0.sol contract contains 100 usdm tokens at an exchange rate of 1:1 with mochi tokens.
  • updateReserve() is called to set the split of usdm tokens such that treasuryShare has claim on 20 usdm tokens and mochiShare has claim on the other 80 tokens.
  • A veCRV holder seeks to increase their earnings by calling distributeMochi() before sendToTreasury() has been called.
  • As a result, 80 usdm tokens are converted to mochi tokens and locked in a curve rewards pool.
  • Consequently, mochiShare and treasuryShare is set to 0 (aka flushed).
  • The same user calls updateReserve() to split the leftover 20 usdm tokens between treasuryShare and mochiShare.
  • mochiShare is now set to 16 usdm tokens.
  • The above process is repeated to distribute mochi tokens to veCRV holders again and again.
  • The end result is that veCRV holders have been able to receive all tokens that were intended to be distributed to the treasury.

FeePoolV0.sol L94

Tools Used

  • Manual code review
  • Discussions with the Mochi team.

Recommended Mitigation Steps

Consider removing the line in FeePoolV0.sol (mentioned above), where treasuryShare is flushed.

ryuheimat (Mochi) confirmed

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

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

Impact

veCRV holders could receive all tokens that were intended to be distributed to the treasury.

What the attacker needed

Contract holds usdm tokens; attacker is a veCRV holder

The fix

The line that flushes treasuryShare should be removed.

How it was found

  1. The contract holds 100 usdm tokens at a 1:1 rate with mochi.
  2. updateReserve() sets treasuryShare to 20 usdm and mochiShare to 80 usdm.
  3. A veCRV holder calls distributeMochi() before sendToTreasury().
  4. 80 usdm are converted to mochi and locked in a curve rewards pool, and both shares are set to 0.
  5. The user calls updateReserve() to split the remaining 20 usdm, setting mochiShare to 16 usdm.
  6. The process is repeated to distribute all tokens to veCRV holders.

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.

A smart contract holds fees that should be split between the treasury and users who lock tokens. A function that distributes rewards accidentally resets the treasury's share to zero, so a user can call it repeatedly and take all the fees.

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 leastwood

View all

70 more disclosed reports, best first.

More from Mochi contest

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.