Skip to content
Business logic Audit finding Advanced

Uniswap Aggregated Fees Can be Increased at Close to Zero Cost

An attacker can manipulate the recorded trading fees in a Uniswap v3 pool by concentrating liquidity in the active tick and wash trading, inflating the implied volatility (IV) used by the protocol. This can reduce the loan-to-value (LTV) ratio and unfairly liquidate existing borrowers.

Bandit Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-10-aloe-judging/issues/45

Found by

Bandit

The recorded fee collection in a Uniswap pool can be manipulated in the method described below while paying very little in "real" fees. This means that IV can be pushed upwards to unfairly liquidate pre-existing borrowers.

Vulnerability Detail

In a sufficiently liquid pool and high trading volume, the potential attack profits you may get from swapping a large amount of tokens back and forth is likely lower than the profit an attacker can make from manipulating IV. This is especially true due to the IV_CHANGE_PER_UPDATE which limits of the amount that IV can be manipulated per update.

However, its possible to boost the recorded trading fees via trading fees while paying a very small cost relative to the fee increase amount.

The attack rests on 2 facts:

  1. Aside from pools where the 2 pool assets are pegged to the same value, only a tiny portion of the total liquidity is in the "in-range" tickSpacing.
  2. In Uniswap, 100% of fees goes to the liquidity providers, in proportion to liquidity at the active tick, or ticks that gets passed through. This is different from other exchanges, where some portion of fees is distrubted to token holders, or the exchange operator.

Due to (1), a user with a large amount of capital can deposit all of it in the active tick and have >99% of the liquidity in the active tick. Due to (2), this also means that if they wash trade while keeping the price within that tick, they get >99% of the trading fees captured by their LP position. If $200K is deposited into that tick, then up to $200k can be traded, if the pool price starts exactly at the lower tick and ends at the upper tick, or vice versa.

The wash trading can performed in one flashbots bundle, and since the trades are basically against the oneself, the trading profits-and-loss and impermanant gain/loss approximately cancel out.

Manipulating fees higher drives the IV higher, which in turn reduces the LTV. Let's say a position is not liquidatable yet, but a reduction in LTV will make that position liquidatable. There is profit incentive for an attacker to use the wash trading manipulation to decrease the LTV and then liquidate that position.

Note that this efficiency in wash trading to inflate fees is only possible in Uniswap v3. In v2 style pools, liquidity cannot be concentrated and it is impractical to deposit enough liquidity to capture the overwhelming majority of an entire pool. Most CLOB such as dYdX, IDEX etc have some fees that go to the protocol or token stakers (Uniswap 100% of "taker" fees go to LP's or "makers"), which means that even though a maker and taker order can be matched by wash traders, there is still significant fee externalisation to the protocol.

Impact

  • IV is cheaply and easily manipulated upwards, and thus LTV can be decreased, which can unfairly liquidate users

Code Snippet

https://github.com/sherlock-audit/2023-10-aloe/blob/main/aloe-ii/core/src/libraries/Volatility.sol#L44-L81

Tool used

Manual Review

Recommendation

Using the MEDIAN fee of many short price intervals to calculate the Uniswap fees makes it more difficult to manipulate. The median, unlike mean (which is also implicitly used in the context a TWAP), is unaffected by large manipulations in a single block.

Discussion

sherlock-admin2

2 comment(s) were left on this issue during the judging contest.

panprog commented:

medium, because the volatility manipulation is still limited and not free, but possible to do to unfairly liquidate the accounts

MohammedRizwan commented:

valid

haydenshively

Manipulation is actually easier than that; an attacker can simply overpay in a flash swap and Uniswap will credit the overpayment directly to fee growth globals. The IV_CHANGE_PER_UPDATE constrains the impact of such an attack, making it quite expensive for limited payoff, especially considering the attacker doesn't know whether potential victims will respond to Warn or not. Medium for these reasons.

As for a fix, we could lower the constant to further constrain the attack. Since we're increasing the liquidation grace period in response to #73, borrowers should have more time to respond to unfair liquidations. And we could try to do the median feeGrowthGlobals thing as part of #91 improvements.

haydenshively

Fixed in https://github.com/aloelabs/aloe-ii/pull/219

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

How it worked

Root cause

Likely the protocol calculates implied volatility from Uniswap v3 fee growth without sufficient manipulation resistance, allowing an attacker to inflate fees cheaply by concentrating liquidity and wash trading.

Impact

IV can be cheaply manipulated upwards, reducing LTV and potentially leading to unfair liquidations, though the impact is limited by the IV_CHANGE_PER_UPDATE constant and the attacker's uncertainty about victim response.

What the attacker needed

Sufficiently liquid Uniswap v3 pool; large capital to concentrate liquidity; ability to execute flashbots bundle

The fix

The issue was fixed by lowering the IV_CHANGE_PER_UPDATE constant and considering a median-based fee calculation in a later improvement.

How it was found

  1. Deposit a large amount of capital into the active tick of a Uniswap v3 pool to control >99% of the liquidity in that tick.
  2. Wash trade within that tick to capture >99% of the trading fees, inflating the recorded fee growth.
  3. The inflated fees increase the implied volatility (IV), which reduces the LTV.
  4. Liquidate positions that become undercollateralized due to the reduced LTV.

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.

In a Uniswap v3 pool, fees go to liquidity providers based on where their liquidity is placed. An attacker can put almost all liquidity in the current price range and then trade back and forth with themselves, capturing most of the fees and making the pool appear to have high trading activity. The protocol uses these fees to estimate volatility; higher volatility lowers the allowed borrowing power, so the attacker can push a borrower into liquidation.

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 Bandit

View all

6 more disclosed reports, best first.

More from Aloe

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.