Skip to content
Business logic Audit finding Intermediate

Early user can break addLiquidity

The first liquidity provider can add a tiny amount of liquidity, causing the total liquidity units to be very small, which makes subsequent liquidity additions round down to zero and become impossible. An attacker could thus prevent other users from adding liquidity to the pool.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

https://github.com/code-423n4/2021-11-vader/blob/429970427b4dc65e37808d7116b9de27e395ce0c/contracts/dex/pool/BasePool.sol#L161-L163

uint256 totalLiquidityUnits = totalSupply;
if (totalLiquidityUnits == 0)
    liquidity = nativeDeposit; // TODO: Contact ThorChain on proper approach

In the current implementation, the first liquidity takes the nativeDeposit amount and uses it directly.

However, since this number (totalLiquidityUnits) will later be used for computing the liquidity issued for future addLiquidity using calculateLiquidityUnits.

A malicious user can add liquidity with only 1 wei USDV and making it nearly impossible for future users to add liquidity to the pool.

Recommendation

Uni v2 solved this problem by sending the first 1000 tokens to the zero address.

The same should work here, i.e., on first mint (totalLiquidityUnits == 0), lock some of the first minter’s tokens by minting ~1% of the initial amount to the zero address instead of to the first minter.

SamSteinGG (Vader) commented:

Duplicate of #24

alcueca (judge) commented:

Not a duplicate

The original report as published on Code4rena, by WatchPug. 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 first deposit sets the total liquidity units directly to the deposited amount without locking any minimum, allowing a tiny initial deposit to make future deposits round down to zero.

What the attacker needed

Attacker is first liquidity provider; attacker has a tiny amount of USDV

The fix

The first minter's tokens should be partially locked by minting about 1% of the initial amount to the zero address, similar to Uni v2's approach.

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 you add money to a liquidity pool, you get 'liquidity units' that represent your share. The first person to add money sets the initial exchange rate between units and the deposited amount. If they add a very small amount, the total units become tiny, so later deposits are rounded down to zero units, effectively blocking others from joining.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Vader 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.