Skip to content
Business logic Audit finding Intermediate

FeePoolV0.sol#distributeMochi() will unexpectedly flush treasuryShare , causing the protocol fee cannot be properly accounted for and collected

The `_shareMochi()` function resets `treasuryShare` to zero even though it only distributes `mochiShare`. An attacker can repeatedly call `distributeMochi()` and `updateReserve()` to consume the treasury share, causing the protocol to lose funds.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

distributeMochi() will call _buyMochi() to convert mochiShare to Mochi token and call _shareMochi() to send Mochi to vMochi Vault and veCRV Holders. It wont touch the treasuryShare.

However, in the current implementation, treasuryShare will be reset to 0. This is unexpected and will cause the protocol fee can not be properly accounted for and collected.

FeePoolV0.sol#L79 L95

function _shareMochi() internal {
    IMochi mochi = engine.mochi();
    uint256 mochiBalance = mochi.balanceOf(address(this));
    // send Mochi to vMochi Vault
    mochi.transfer(
        address(engine.vMochi()),
        (mochiBalance * vMochiRatio) / 1e18
    );
    // send Mochi to veCRV Holders
    mochi.transfer(
        crvVoterRewardPool,
        (mochiBalance * (1e18 - vMochiRatio)) / 1e18
    );
    // flush mochiShare
    mochiShare = 0;
    treasuryShare = 0;
}

Impact

Anyone can call distributeMochi() and reset treasuryShare to 0, and then call updateReserve() to allocate part of the wrongfuly resetted treasuryShare to mochiShare and call distributeMochi().

Repeat the steps above and the treasuryShare will be consumed to near zero, profits the vMochi Vault holders and veCRV Holders. The protocol suffers the loss of funds.

Recommendation

Change to:

function _buyMochi() internal {
    IUSDM usdm = engine.usdm();
    address[] memory path = new address[](2);
    path[0] = address(usdm);
    path[1] = address(engine.mochi());
    usdm.approve(address(uniswapRouter), mochiShare);
    uniswapRouter.swapExactTokensForTokens(
        mochiShare,
        1,
        path,
        address(this),
        type(uint256).max
    );
    // flush mochiShare
    mochiShare = 0;
}

function _shareMochi() internal {
    IMochi mochi = engine.mochi();
    uint256 mochiBalance = mochi.balanceOf(address(this));
    // send Mochi to vMochi Vault
    mochi.transfer(
        address(engine.vMochi()),
        (mochiBalance * vMochiRatio) / 1e18
    );
    // send Mochi to veCRV Holders
    mochi.transfer(
        crvVoterRewardPool,
        (mochiBalance * (1e18 - vMochiRatio)) / 1e18
    );
}

ryuheimat (Mochi) confirmed

The original report as published on Code4rena, by WatchPug. 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

Root cause

Likely, the `_shareMochi()` function incorrectly resets `treasuryShare` to zero even though it only handles `mochiShare`.

Impact

The protocol suffers the loss of funds, and the treasury share is consumed to near zero, profiting vMochi Vault holders and veCRV Holders.

What the attacker needed

None

How it was found

  1. Call `distributeMochi()` to reset `treasuryShare` to zero.
  2. Call `updateReserve()` to allocate part of the reset `treasuryShare` to `mochiShare`.
  3. Call `distributeMochi()` again to distribute the newly allocated `mochiShare`.
  4. Repeat the above steps to consume `treasuryShare` to near zero.

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.

The protocol keeps a separate pot of fees for the treasury, called `treasuryShare`. A function that is only supposed to pay out a different pot accidentally empties the treasury pot too. Because anyone can call that function, an attacker can keep triggering it to drain the treasury.

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 WatchPug

View all

197 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.