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.
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.
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
);
}
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
- Call `distributeMochi()` to reset `treasuryShare` to zero.
- Call `updateReserve()` to allocate part of the reset `treasuryShare` to `mochiShare`.
- Call `distributeMochi()` again to distribute the newly allocated `mochiShare`.
- 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.