1

Let's assume that I'm writing a UniswapV2 LP token price oracle. Would it be a bad idea to rely on the LP token totalSupply for my calculation? Would it be possible to manipulate its value through a flash loan attack?

I'm mainly asking this question as I'm currently researching Alpha Finance's code for their LP token price oracle. They introduce the concept of fair reserves through the following formula:

enter image description here

Which could be simplified as follows:

enter image description here

p0 and p1 could be made flashloan-proof, as they could be pulled from Chainlink or Uniswap's TWAP price oracles. But I'm not sure if a flash loan attacker would be able to manipulate the total supply of the LP token (L), or even k for that matter. Or if it's simply the case that in case of a flash loan attack, both L and k would change and both changes would cancel out.

1 Answer 1

0

Let's consider the case where a flash loan attacker would try to manipulate the totalSupply by deposition tokens to the pool.

The new LP token totalSupply would be:

enter image description here

From equation (12) in the Uniswap V2 whitepaper, the change in the LP token supply is described by:

enter image description here

Which leads to:

enter image description here

The new constant product (k) would be:

enter image description here

By substituting in the fair reserve formula, we get:

enter image description here

Meaning, the price of the LP token does not change when new LP tokens are minted. A similar proof could be derived for when liquidity tokens are burned from the pool, but with the only difference being the term in nominator and denominator being eliminated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.