Submitted by Trust
MagicLpAggregator is used to price LP tokens for closely-tied underlying tokens. It calculates the price below:
The code takes the minimal answer between the underlying oracles and considers all reserves to be worth that amount:
return int256(minAnswer * (baseReserve + quoteReserve) / pair.totalSupply());
The issue is that any difference in price between the assets represents an easy arbitrage opportunity. Suppose we have tokens (A,B), where real oracle shows:
The Pool has 1000000 LP tokens and contains:
The LP value would calculate as:
0.99 * 2000000 / 1000000 = $1.98
The actual value is:
(0.99 * 1000000 + 1 * 1000000) / 1000000 = $1.99
Suppose a platform trades LPs using the aggregator pricing. An attacker could:
The delta comes at the expense of LP holders whose position gets minimized.
Loss of value due to arbitrage of any platform using MagicLpAggregator pricing.
Always calculate the value based on the real underlying token value multiplied by amount.
Consider creating two separate oracles for lower-bound and upper-bound results. Then a lending protocol could indeed use the lower-bound for determining collateral value.
0xm3rlin (Abracadabra) disputed and commented:
141345 (Lookout) commented:
