what is a Flash loan in DeFi terminology? aim of this post is to provide simple explanation of Flash loan, for everyone who is using DeFi, since this is one of the main parameters for successful hacks in DeFi history, if they are hacks after all, since all these are just using underlying technology, that is not easy to understand to most users
DEFINITION
Flash Loan, as defined by AAVE, that introduced them to main crypto world, enable you to borrow funds instantly and easily, without any collateral needed, in case that you return the funds to the pool within one transaction block, if you are not able to return the funds to the pool within transaction block, the transaction is reversed, so that effectively there is no action at all. In well funded Liquidity pools, these would not create meltdown, but in a poorly staked Liquidity pools this can cause many troubles
for the purpose, liquidity pools are charging small interest, that is close to zero ( 0,001-0,1 % range)
what that mean, is that developers (who are the prime users of Flash Loans) can exploit liquidity with small interest for the liquidity provider, and have main advantage over other participants on the market - and that is why
"Ethereum is a Dark Forest"main use-cases include Arbitrage, Collateral swapping, Self-liquidation, and here is an explanation for each of these:
- Arbitrage - it is as simple as purchase an asset on one market, and sell it on another market, where the current price is better (if you do this within one transaction block, you can use Flash Loan), and there is a lot of arbitrage bots that are made to do just this, although it is not too easy to exploit the market in this way, and profit is not guaranteed
- Collateral swapping - it is a practical way to swap your collateral when the price of underlying asset is moving fast, and you can be liquidated, then you swap your collateral for stable coin to secure your position
image from AAVE website
- Self-liquidation - practically, this is an opportunity to generate cash for a profitable action, and self-liquidate it within the same transaction block, so one can make money without initial investment
EXAMPLES
First example
1.
https://www.coindesk.com/exploit-during-ethdenver-reveals-experimental-nature-of-decentralized-finance - first exploit for bZx protocol, with 350k USD taken from the protocol
November 2020
2.
https://www.coindesk.com/value-defi-suffers-6m-flash-loan-attack - Value DeFi exploited for 6 million USD
3.
https://peckshield.medium.com/cheese-bank-incident-root-cause-analysis-d076bf87a1e7 - Cheese Bank exploited for 3.3 million USD
4.
https://www.coindesk.com/defi-project-akropolis-token-pool-drained - Akropolis hacked for 2 million USD
5.
https://www.coindesk.com/origin-protocol-loses-3-25m-in-latest-flash-loan-attack-reports - Origin protocol sustained attack for 7 million USD
6.
https://www.coindesk.com/harvest-finance-24m-attack-triggers-570m-bank-run-in-latest-defi-exploit - Harvest Finance was exploit for 24 million USD
bZx EXAMPLE AND STEPS EXPLAINEDwhat actually happened in bZx exploit is following:
- Flash Loan attack (all actions within one transaction block):
1. borrowing ETH from dYdX and using parts of the loan for simultaneous actions 2,3,4
2.1. minting cETH on Compound, using borrowed ETH (with part of the sum borrowed)
2.2. borrowing cWBTC on Compound using minted cETH
3.1. Margin trade ETH against WBTC on bZx with leverage (with part of the sum borrowed)
3.2. Use of arbitrage opportunity to buy WBTC for ETH gain on bZx
2.3. Convert cWBTC on Uniswap for ETH, that is now cheaper
4. paying back the ETH to dYdX, with a profit
so, practically, attacker used part of funds to create leverage on bZx to influence ETH/BTC price on Uniswap, and used another part of funds to mint BTC on Compound and buy that "cheap" ETH on Uniswap
CONCLUSIONMost of these opportunities for Flash Loan exploits is ceased with good oracles, like ChainLink, and use of several oracles within same DeFi project, so this should be your first stop to prove, when starting with new DeFi project. Nevertheless, the opportunity is always there and one should be aware of risk when investing in DeFi Liquidity Pools.
for more interest, one can look on following links:
https://aave.com/flash-loans/https://www.investopedia.com/terms/s/self-liquidating-loan.asphttps://hackingdistributed.com/2020/03/11/flash-loans/