1/ Last week, there has been a number of flash loan-related scenarios (and potential scenarios): @harvest_finance, @MakerDAO, @iearnfinance.

So, here’s a short thread on flash loans. 👇
2/ Flash loan lets anyone borrow a very large amount of assets (as long as the amount + fee are paid back in the same transaction), which can be used to temporarily skew asset prices or balances.
3/ A typical flash loan attack pattern is a form of sandwich attack:
(1) Skew price/balance
(2) Main protocol uses the skewed price/balance (e.g. to open a position, deposit into AMM all at bad prices)
(3) Un-skew price/balance
4/ There are several solutions that can mitigate flash loan attacks.

🚨 DISCLAIMER: The solutions are not limited to what’s presented here. Feel free to suggest/add more.
5/ 1st sol: Allow calls from EOA only (user addresses).

Pros:
- Attack must be split in multiple transactions -> Safe from flash loans.

Cons:
- Breaks smart contract composability.
- Flash loan-like attack can still work (attacker being at more risk)
6/ 2nd sol: Price oracle for sanity-check.

Pros:
- The attacker can only skew prices up to a certain threshold.

Cons:
- Price update from off-chain can be front-runned.
- In some cases, attack can still be repeated to get the same profit.
7/ 3rd sol: Use Time-weighted Average Price (TWAP)

Pros:
- Flash loan doesn’t affect TWAP.

Cons:
- The longer the TWAP interval, the more the price delays from spot. The shorter the TWAP interval, the more prone it is to short-interval price manipulation.
8/ @AlphaFinanceLab's first mainnet product #AlphaHomora uses a combination of onlyEOA and price oracle.

This prevents any flash loan attempt, and the price can only deviate up to a certain threshold from the price oracle, limiting how much the attacker can skew the price.
9/ This capped price skewing guarantees that the attacker cannot steal funds from the ETH lenders.

A more detailed analysis on @AlphaFinanceLab blog: blog.alphafinance.io/alpha-homora-a…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Nipun | Alpha

Nipun | Alpha Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @nipun_pit

18 Dec
🚨 1/ The recent @warpfinance hack is the result of using vulnerable @UniswapProtocol 🦄 LP token prices.

The attacker was able to drain ~$7.8M worth of $DAI for smaller collateral.

#AlphaHomoraV2 uses a different LP pricing method that is safe against such attack vector. 👇
2/ The LP token pricing used is prone to the typical flash loan sandwich attack vector:

➡️ Flash loan and skew reserves
➡️ Fake LP price
➡️ Repay flash loan
➡️ Profit

So, how do we price an LP token in an unmanipulatable way?

Answer: **FAIR LP PRICING**
3/ What makes the **FAIR LP PRICE** safe from attacks?

There are two major components to the fair LP price that make the price safe:

① Fair Asset Prices
② Fair Asset Reserves
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!