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.
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.solcontract contains 100usdmtokens at an exchange rate of 1:1 withmochitokens. updateReserve()is called to set the split ofusdmtokens such thattreasurySharehas claim on 20usdmtokens andmochiSharehas claim on the other 80 tokens.- A
veCRVholder seeks to increase their earnings by callingdistributeMochi()beforesendToTreasury()has been called. - As a result, 80
usdmtokens are converted tomochitokens and locked in a curve rewards pool. - Consequently,
mochiShareandtreasuryShareis set to0(aka flushed). - The same user calls
updateReserve()to split the leftover 20usdmtokens betweentreasuryShareandmochiShare. mochiShareis now set to 16usdmtokens.- The above process is repeated to distribute
mochitokens toveCRVholders again and again. - The end result is that
veCRVholders have been able to receive all tokens that were intended to be distributed to the treasury.
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.
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
- The contract holds 100 usdm tokens at a 1:1 rate with mochi.
- updateReserve() sets treasuryShare to 20 usdm and mochiShare to 80 usdm.
- A veCRV holder calls distributeMochi() before sendToTreasury().
- 80 usdm are converted to mochi and locked in a curve rewards pool, and both shares are set to 0.
- The user calls updateReserve() to split the remaining 20 usdm, setting mochiShare to 16 usdm.
- 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.