Submitted by hickuphh3
ThecosomataETH.sol#L94-L110
The ThecosomataETH contract adds ETH and BTRFLY tokens as liquidity into the ETH-BTRFLY curve crypto pool. The calculateAmountRequiredForLP() function relies on the price_oracle value returned by the pool to calculate the ETH and BTRFLY amounts to be added as liquidity. It is therefore important to ensure that price_oracle is accurate.
At the time of writing, the pool has about $5M in liquidity, which is comparable to that of the liquidity provided on UniswapV3. Flash loan attacks are therefore possible, but ineffective (explained further later).
In the curve v2 whitepaper, the price oracle mechanism is explained briefly in the Algorithm for repegging section. It is reproduced below for convenience.
With oracles (curve pool now, to be switched to chainlink based oracle as per comment in L27), there is an inverse correlation between freshness and tamper-resistance.
We can expect price_oracle to be relatively fresh as trades will occur whenever arbitrage opportunities arise against the UniV3 pool which has comparable liquidity. Note that the ETH-BTRFLY pool has a half-time of 10 minutes (T1/2 = 600). This means that after exactly 10 mins, both pLast and p_old have equal weightage.
It is unclear how resistant the EMA oracle is against manipulation. Flash loan attacks, while possible, will be ineffective because t will be zero (pLast will be ignored in the update). However, a sophisticated attacker could possibly skew the price oracle by inflating the price of BTRFLY a couple of blocks before the performUpkeep() transaction to get the treasury to deposit more ETH / burn more BTRFLY than necessary.
In my opinion, both freshness and tamper-resistance can be better secured.
This can be done by:
drahrealm (Redacted Cartel) commented:
Alex the Entreprenerd (judge) commented:
