Skip to content
Business logic Audit finding Intermediate

VaderPoolV2.mintFungible exposes users to unlimited slippage

The mintFungible function lets users add liquidity in any ratio but offers no way to set a minimum number of liquidity units to receive. A frontrunner could manipulate the pool reserves so the liquidity provider gets fewer units than expected and pocket part of the value.

TomFrenchBlockchain Follow

Originally disclosed on Code4rena

Submitted by TomFrenchBlockchain

Impact

Frontrunners can extract up to 100% of the value provided by LPs to VaderPoolV2.

Proof of Concept

Users can provide liquidity to VaderPoolV2 through the mintFungible function.

https://github.com/code-423n4/2021-11-vader/blob/429970427b4dc65e37808d7116b9de27e395ce0c/contracts/dex-v2/pool/VaderPoolV2.sol#L271-L335

This allows users to provide tokens in any ratio and the pool will calculate what fraction of the value in the pool this makes up and mint the corresponding amount of liquidity units as an ERC20.

However there’s no way for users to specify the minimum number of liquidity units they will accept. As the number of liquidity units minted is calculated from the current reserves, this allows frontrunners to manipulate the pool’s reserves in such a way that the LP receives fewer liquidity units than they should. e.g. LP provides a lot of nativeAsset but very little foreignAsset, the frontrunner can then sell a lot of nativeAsset to the pool to devalue it.

Once this is done the attacker returns the pool’s reserves back to normal and pockets a fraction of the value which the LP meant to provide as liqudity.

Recommended Mitigation Steps

Add a user-specified minimum amount of LP tokens to mint.

SamSteinGG (Vader) confirmed

Given that the codebase attempts to implement the Thorchain rust code in a one-to-one fashion, findings that relate to the mathematical accuracy of the codebase will only be accepted in one of the following cases:

  • The code deviates from the Thorchain implementation
  • A test case is created that illustrates the problem

While intuition is a valid ground for novel implementations, we have re-implemented a battle-tested implementation in another language and as such it is considered secure by design unless proven otherwise.

An additional note on this point is that any behaviour that the Thorchain model applies is expected to be the intended design in our protocol as well.

An important example is the slippage a user incurs on joining a particular LP pool for which there is no check as there can’t be any. Enforcing an LP unit based check here is meaningless given that LP units represent a share that greatly fluctuates (1 unit of LP out of 100 units is different than 1 out of 1000, however, a slippage check for 100 units of DAI for example is valid).

The original report as published on Code4rena, by TomFrenchBlockchain. 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 mintFungible function calculates minted liquidity units from current reserves without accepting a user-supplied minimum, so reserve manipulation before the transaction changes the outcome.

Impact

Frontrunners could extract up to 100% of the value provided by liquidity providers, though the project argued this slippage is intended design.

What the attacker needed

Attacker can frontrun transactions; victim adds liquidity via mintFungible

The fix

The reporter recommended adding a user-specified minimum amount of LP tokens to mint, but the project disputed that such a check is meaningful.

How it was found

  1. The liquidity provider calls mintFungible with a chosen ratio of tokens.
  2. A frontrunner observes the pending transaction and changes the pool reserves, for example by selling a large amount of one asset.
  3. The provider's transaction executes against the manipulated reserves and mints fewer liquidity units.
  4. The attacker restores the reserves and keeps a fraction of the value the provider intended to add.

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 trading pool, you get pool shares in return. This report says the function that gives you those shares never lets you say 'I will not accept fewer than this many shares', so someone watching the transaction could shift the pool's balance first and make your payout smaller.

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 TomFrenchBlockchain

View all

28 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.