The fees are incorrectly updated in the `_deposit` and `_withdraw` functions, which allows the attacker to break the protocol fees
The fee accounting in the Multipool contract's deposit and withdraw functions incorrectly calculates protocol fees by subtracting the position's previously accrued fees, so an attacker can mint tiny amounts to accrue fees beforehand and cause the protocol to lose most of its fees.
In _deposit and _withdraw function of Multipool contract, fee0 and fee1 are calculated from the accrued fee amounts to update feeGrowth of contract and send the protocol fee to the owner. However, these calculations are incorrect and do not align with the collected fees from the positions. It allows attacker break the protocol fees.
Vulnerability Detail
In function withdraw, all accrued fees from Uniswap V3 pool will be collected (tokensOwed0After and tokensOwed1After). However, fee0 and fee1 are updated by tokensOwed0After - tokensOwed0Before and tokensOwed1After - tokensOwed1Before.
It is incorrect because in cases where tokensOwed0Before > 0 or tokensOwed1Before > 0, fee0 and fee1 end up being smaller than the collected fees. Consequently, when _upFeesGrowth is executed, it will send smaller protocol fees than expected.
Therefore, an attacker can exploit this vulnerability and undermine the protocol fees by minting minuscule amounts to all positions within the Multipool contract. This is possible since anyone can mint for any positions in UniSwapV3 pools (the owner of position is recipient). This causes the fees of each position to be accrued beforehand, resulting in tokensOwed0Before and tokensOwed1Before becoming close to tokensOwed0After and tokensOwed1After. Then the majority of protocol fees will be lost (solvent in the reserve).
Scenario:
Attacker mints minuscule amounts to all positions within the Multipool contract to accrue fees for these positions.
The attacker then calls the earn() function to collect and update fees. In this scenario, tokensOwed0Before and tokensOwed1Before become equal to tokensOwed0After and tokensOwed1After (withdrawing 0 liquidity). As a result, fee0 and fee1 become 0, leading to the loss of these protocol fees.
fee0 and fee1 in _deposit and _withdraw function should be equal to the collected fee amounts (tokensOwed0After and tokensOwed1After)
Discussion
huuducsc
Escalate
This issue pertains to the incorrect updating of fees, resulting in a significant loss of the protocol fee. The explanation is clear enough if you have knowledge about UniswapV3.
Here are my detailed explanations:
The fee from the UniswapV3 pool is accumulated into the data of a position when that position is updated (by adding liquidity or removing liquidity ...). This allows anyone to mint minuscule amounts for the positions of Multipool to accrue the fee for them into position data.
Therefore, (tokensOwed0After - amount0) - tokensOwed0Before is only equal to the fee from the burn call (which is very small) and doesn't include the accrued fee mentioned above. However, the contract has collected all the collectible amounts of each position, which means the accrued fee has been collected but is not accumulated in fee0 and fee1.
```solidity=
(, , , uint128 tokensOwed0Before, uint128 tokensOwed1Before) = IUniswapV3Pool(
position.poolAddress
).positions(position.positionKey);
The _withdraw function will trigger _upFeesGrowth function with incorrect fee0 and fee1. They don't include the accrued fee of this position before. This will result in the protocol losing a significant protocol fee.
sherlock-admin
Escalate
This issue pertains to the incorrect updating of fees, resulting in a significant loss of the protocol fee. The explanation is clear enough if you have knowledge about UniswapV3.
Here are my detailed explanations:
In the function _withdraw of the Multipool contract, tokensOwed0Before and tokensOwed1Before are the current collectible amounts of this position (the current accrued fee). amount0 and amount1 are the amount from burning liquidity.
Therefore, (tokensOwed0After - amount0) - tokensOwed0Before is only equal to the fee from the burn call (which is very small) and doesn't include the accrued fee mentioned above. However, the contract has collected all the collectible amounts of each position, which means the accrued fee has been collected but is not accumulated in fee0 and fee1.
The _withdraw function will trigger _upFeesGrowth function with incorrect fee0 and fee1. They don't include the accrued fee of this position before. This will result in the protocol losing a significant protocol fee.
You've created a valid escalation!
To remove the escalation from consideration: Delete your comment.
You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.
ctf-sec
This seems like a medium, recommend bring sponsor for review
hrishibhat
@huuducsc
Sponsor comment:
It doesn't make sense and does not matter what small position the user will mint. The Uniswap positions are common for all users. The Uniswap positions are owned by the multipool and fees will be collected on the entire liquidity of the multitool for each withdrawal or deposit.
huuducsc
@huuducsc Sponsor comment:
It doesn't make sense and does not matter what small position the user will mint. The Uniswap positions are common for all users. The Uniswap positions are owned by the multipool and fees will be collected on the entire liquidity of the multitool for each withdrawal or deposit.
I agree that fees will be collected on the entire liquidity of the multitool for each withdrawal or deposit, but it is not related to this issue. This issue is about the protocol fee, which is derived from the total fees collected from Multipool's positions, and it may be compromised. The protocol fee is only charged in the _deposit and _withdraw functions. If the fees from Multipool's positions were to be collected without using _deposit and _withdraw (for example, by adding a small amount of liquidity directly), the protocol fee would not increase during the next _deposit or _withdraw action. As a result, an attacker would be able to manipulate the protocol fee by front-running these functions.
Fixed by deleting the subtraction of tokensOwed0Before and accounting for the collected fee amounts
The original report as published on Sherlock, by duc. 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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely, the fee calculation subtracts the position's previously accrued fees (tokensOwedBefore) from the total collected, so any fees accrued before the deposit or withdraw are not counted as protocol fees.
Impact
The protocol loses a significant portion of its fees, which remain in the reserve.
What the attacker needed
Attacker can mint to any Uniswap V3 position
The fix
The fee calculation should use the collected fee amounts directly, without subtracting the previously accrued fees.
How it was found
Attacker mints minuscule amounts to all positions within the Multipool contract to accrue fees for these positions.
The attacker then calls the earn() function to collect and update fees.
In this scenario, tokensOwed0Before and tokensOwed1Before become equal to tokensOwed0After and tokensOwed1After (withdrawing 0 liquidity).
As a result, fee0 and fee1 become 0, leading to the loss of these protocol fees.
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
The contract collects trading fees from Uniswap and is supposed to take a cut for the protocol. But it calculates the cut incorrectly, ignoring fees that had already built up. An attacker can make those fees build up in advance, so when the contract later collects them, it thinks there are no new fees and takes nothing.
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.