Skip to content
Business logic Audit finding Advanced

OverlayV1UniswapV3Market computes wrong market liquidity

The contract computed market liquidity using a token-ordering flag derived from the OVL price feed rather than the market feed the liquidity came from. If the two pools ordered ETH differently, the depth calculation was inverted, producing a wrong market depth and market cap.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The OverlayV1UniswapV3Market.fetchPricePoint tries to compute the market depth in OVL terms as marketLiquidity (in ETH) / ovlPrice (in ETH per OVL). To get the market liquidity in ETH (and not the other token pair), it uses the ethIs0 boolean.

_marketLiquidity = ethIs0
    ? ( uint256(_liquidity) << 96 ) / _sqrtPrice
    : FullMath.mulDiv(uint256(_liquidity), _sqrtPrice, X96);

However, ethIs0 boolean refers to the ovlFeed, whereas the _liquidity refers to the marketFeed, and therefore the ethIs0 boolean has nothing to do with the market feed where the liquidity is taken from:

// in constructor, if token0 is eth refers to ovlFeed
ethIs0 = IUniswapV3Pool(_ovlFeed).token0() == _eth;

// in fetchPricePoint, _liquidity comes from different market feed
( _ticks, _liqs ) = IUniswapV3Pool(marketFeed).observe(_secondsAgo);
_marketLiquidity = ethIs0
    ? ( uint256(_liquidity) << 96 ) / _sqrtPrice
    : FullMath.mulDiv(uint256(_liquidity), _sqrtPrice, X96);

Impact

If the ovlFeed and marketFeed do not have the same token position for the ETH pair (ETH is either token 0 or token 1 for both pairs), then the market liquidity & depth is computed wrong (inverted). For example, the OverlayV1Market.depth() function will return a wrong depth which is used in the market cap computation.

Recommended Mitigation Steps

It seems that marketFeed.token0() == WETH should be used in fetchPricePoint to compute the liquidity instead of ovlFeed.token0() == WETH.

realisation (Overlay) confirmed:

Yeah, was aware of this, just hadn’t finalized it in the code as of yet.

The original report as published on Code4rena, by cmichel. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 token-ordering flag was taken from the OVL feed's pool while the liquidity value came from a different market pool, so the two were mismatched.

Impact

If the OVL and market pools place ETH in different token positions, the market liquidity and depth are computed inverted, so depth() and the market cap derived from it are wrong.

What the attacker needed

OVL and market pools order ETH differently

The fix

The token-ordering check should be taken from the market feed's own pool when computing liquidity, and the project confirmed the issue was known and to be addressed.

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 liquidity pool holds two tokens, and the code needs to know which one is ETH to convert amounts correctly. This contract checked that ordering on the wrong pool, so when the two pools disagreed the maths came out backwards and the reported market depth was wrong.

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 cmichel

View all

196 more disclosed reports, best first.

More from Overlay Protocol contest

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.