Donation fees are sandwichable in one transaction
The donation of fees to a Uniswap V4 pool can be sandwiched within a single transaction because the maximum donation limit is per transaction, not per block. An attacker can add concentrated liquidity just before a fee donation and remove it immediately after, capturing a large portion of the donated fees.
0x37 Follow with BugPull, Ironsidesec and 3 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/615
Found by
0x37, BugPull, Ironsidesec, ZeroTrust, araj, zzykxx
Summary
Doesn't matters if MEV is openly possible in the chain, when eevr a user does actions like liquidateProtectedListing, cancelListing, modifyListings, fillListings, Reserve and Relist. They can sandwich the fees donation to make profit or recover the tax they paid. Or, the liquidaton is open access, so you can sandwich that in same tc itself.
Root casue : allowing more than max donation limit per transaction.
Even if you don't allow to donate more than max, the user will just loop the donation and still extract the $, so its better to have a max donation per block state that tracks this. So donateThresholdMax should be implemented in per block limit way.
Vulnerability Detail
Uniswap openly advises to design the donation mechanism to not allow MEV extraction
IPoolManager.sol
/// @notice Donate the given currency amounts to the in-range liquidity providers of a pool
/// @dev Calls to donate can be frontrun adding just-in-time liquidity, with the aim of receiving a portion donated funds.
/// Donors should keep this in mind when designing donation mechanisms.
/// @dev This function donates to in-range LPs at slot0.tick. In certain edge-cases of the swap algorithm, the `sqrtPrice` of
/// a pool can be at the lower boundary of tick `n`, but the `slot0.tick` of the pool is already `n - 1`. In this case a call to
/// `donate` would donate to tick `n - 1` (slot0.tick) not tick `n` (getTickAtSqrtPrice(slot0.sqrtPriceX96)).
Fees are donated to uniV4 pool in several listing actions
liquidateProtectedListing: Amount worth1 ether - listing.tokenTaken - KEEPER_REWARDis donated. This amount will be huge in cases where, someone listed a protected listing and took 0.5 ether as token taken, but didnot unlock the listing. So since utilization rate became high, the listing heath gone negative and was put to liquidation during this time an amount f (1 ether - 0.5 ether taker - 0.05 ether keeper reward) = 0.40 ether is donated to pool. Thats a 1000$ direct donation- Other 5 flows of Listings contract, such as
cancelListing,modifyListings,fillListings,ReserveandRelistdonate the tax fees to the pool. The likelihood is above medium to have huge amount when most users do multiple arrays of tokens of multiple collections done in one transaction.
Issue flow :
- Figure out the tick where the donated fee will go in according to the @notice comment above on
IPoolManager.donate. - And provide the in-range liquidity so heavy ( like 100x than available in the whole range of that pool).
- Then do the
liquidateProtectedListing,cancelListing,modifyListings,fillListings,ReserveandRelistactions that donate fees worth doing this sandwich - Then trigger a fee donation happening on
before swaphook and then remove the provided liquidity in the first step.
You don't need to frontrun other user's actions, Just do this sandwiching whenever a liquidation of someone's listing happens. And you can also recover the paid tax/fees of your listings by this MEV. Or eevn better if chain allows to have public mempool, then every user's action is sandwichable.
UniswapImplementation.sol
32: /// Prevents fee distribution to Uniswap V4 pools below a certain threshold:
33: /// - Saves wasted calls that would distribute less ETH than gas spent
34: /// - Prevents targetted distribution to sandwich rewards
35: uint public donateThresholdMin = 0.001 ether;
36: >> uint public donateThresholdMax = 0.1 ether;
336: function _distributeFees(PoolKey memory _poolKey) internal {
---- SNIP ----
365: if (poolFee > 0) {
366: // Determine whether the currency is flipped to determine which is the donation side
367: (uint amount0, uint amount1) = poolParams.currencyFlipped ? (uint(0), poolFee) : (poolFee, uint(0));
368: >>> BalanceDelta delta = poolManager.donate(_poolKey, amount0, amount1, '');
369:
370: // Check the native delta amounts that we need to transfer from the contract
371: if (delta.amount0() < 0) {
372: _pushTokens(_poolKey.currency0, uint128(-delta.amount0()));
373: }
374:
375: if (delta.amount1() < 0) {
376: _pushTokens(_poolKey.currency1, uint128(-delta.amount1()));
377: }
378:
379: emit PoolFeesDistributed(poolParams.collection, poolFee, 0);
380: }
---- SNIP ----
402: }
403:
Impact
Loss of funds to the LPs. The fees they about to get due to LP, can be sandwiched and extracted. So high severity, and above medium likelihood even in the chans that doesn't have mempool. So, high severity.
Code Snippet
Tool used
Manual Review
Recommendation
Introduce a new way to track how much is donated on this block and limit it on evrery _donate call. example, allow only 0.1 ether per block
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 donation limit is enforced per transaction rather than per block, allowing repeated or large donations to be sandwiched.
Impact
Liquidity providers could lose the fees they are about to receive, as an attacker can sandwich the donation and extract those funds.
What the attacker needed
Ability to add and remove liquidity in the pool; A fee-donating action occurs
The fix
The donation limit should be tracked per block, not per transaction, to prevent repeated or large donations from being sandwiched.
How it was found
- Figure out the tick where the donated fee will go according to the IPoolManager.donate notice.
- Provide in-range liquidity that is very large compared to the pool's total liquidity.
- Perform an action that donates fees, such as liquidateProtectedListing or cancelListing.
- Trigger the fee donation on the before swap hook and then remove the provided liquidity.
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.
When fees are donated to a liquidity pool, anyone can add liquidity just before the donation and remove it right after, taking most of the donated money. This is called a sandwich attack. The report says the code only limits how much can be donated in one transaction, so an attacker can still profit by doing this repeatedly or within a single transaction.
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.