Wrong design/implementation of addLiquidity() allows attacker to steal funds from the liquidity pool
The addLiquidity function allows users to deposit arbitrary amounts of the two pool assets rather than a fixed ratio, which lets an attacker manipulate the pool price and profit at the expense of other liquidity providers. The attacker can add liquidity in extreme amounts and then drain funds from the pool.
Submitted by WatchPug
The current design/implementation of Vader pool allows users to addLiquidity using arbitrary amounts instead of a fixed ratio of amounts in comparison to Uni v2.
We believe this design is flawed and it essentially allows anyone to manipulate the price of the pool easily and create an arbitrage opportunity at the cost of all other liquidity providers.
An attacker can exploit this by adding liquidity in extreme amounts and drain the funds from the pool.
function mintFungible(
IERC20 foreignAsset,
uint256 nativeDeposit,
uint256 foreignDeposit,
address from,
address to
) external override nonReentrant returns (uint256 liquidity) {
IERC20Extended lp = wrapper.tokens(foreignAsset);
require(
lp != IERC20Extended(_ZERO_ADDRESS),
"VaderPoolV2::mintFungible: Unsupported Token"
);
(uint112 reserveNative, uint112 reserveForeign, ) = getReserves(
foreignAsset
); // gas savings
nativeAsset.safeTransferFrom(from, address(this), nativeDeposit);
foreignAsset.safeTransferFrom(from, address(this), foreignDeposit);
PairInfo storage pair = pairInfo[foreignAsset];
uint256 totalLiquidityUnits = pair.totalSupply;
if (totalLiquidityUnits == 0) liquidity = nativeDeposit;
else
liquidity = VaderMath.calculateLiquidityUnits(
nativeDeposit,
reserveNative,
foreignDeposit,
reserveForeign,
totalLiquidityUnits
);
require(
liquidity > 0,
"VaderPoolV2::mintFungible: Insufficient Liquidity Provided"
);
pair.totalSupply = totalLiquidityUnits + liquidity;
_update(
foreignAsset,
reserveNative + nativeDeposit,
reserveForeign + foreignDeposit,
reserveNative,
reserveForeign
);
lp.mint(to, liquidity);
emit Mint(from, to, nativeDeposit, foreignDeposit);
}
Proof of Concept
Given:
- A Vader pool with
100,000 USDVand1 BTC; - The
totalPoolUnitsis100.
The attacker can do the following in one transaction:
- Add liquidity with
100,000 USDVand 0 BTC, get50 liquidityUnits, representing 1/3 shares of the pool; - Swap
0.1 BTCto USDV, repeat for 5 times; spent0.5 BTCand got62163.36 USDV; - Remove liquidity, get back
45945.54 USDVand0.5 BTC; profit for: 62163.36 + 45945.54 - 100000 = 8108.9 USDV.
This is the intended design of the Thorchain CLP model. Can the warden provide a tangible attack vector in the form of a test?
Sponsor is acknowledging the issue.
@alcueca We do not acknowledge the issue. This is the intended design of the CLP model and the amount supplied for a trade is meant to be safeguarded off-chain. It is an inherent trait of the model.
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 mintFungible function calculates liquidity units based on the deposited amounts without enforcing that the deposit ratio matches the current reserve ratio, allowing arbitrary deposits that distort the pool's balance.
What the attacker needed
Access to the Vader pool; ability to add liquidity; ability to swap tokens
How it was found
- Add liquidity with 100,000 USDV and 0 BTC, receiving 50 liquidity units (one third of the pool).
- Swap 0.1 BTC to USDV, repeating five times, spending 0.5 BTC and receiving 62,163.36 USDV.
- Remove liquidity, getting back 45,945.54 USDV and 0.5 BTC, for a profit of 8,108.9 USDV.
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 is a shared pot of two cryptocurrencies that people trade against. Normally, when you add money to the pool, you must add both coins in the same proportion as the pool already holds. Here, the code lets you add any amounts you like, so an attacker can add a lot of one coin and none of the other, then trade to shift the price and take more than they put in.
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.