[Paper Review] Attacking the DeFi Ecosystem with Flash Loans for Fun and Profit
The paper analyzes how flash loans and transaction atomicity enable high-revenue DeFi attacks, dissects two real attacks, and proposes a parametrized optimization framework to maximize attack profits.
Credit allows a lender to loan out surplus capital to a borrower. In the traditional economy, credit bears the risk that the borrower may default on its debt, the lender hence requires upfront collateral from the borrower, plus interest fee payments. Due to the atomicity of blockchain transactions, lenders can offer flash loans, i.e., loans that are only valid within one transaction and must be repaid by the end of that transaction. This concept has lead to a number of interesting attack possibilities, some of which were exploited in February 2020. This paper is the first to explore the implication of transaction atomicity and flash loans for the nascent decentralized finance (DeFi) ecosystem. We show quantitatively how transaction atomicity increases the arbitrage revenue. We moreover analyze two existing attacks with ROIs beyond 500k%. We formulate finding the attack parameters as an optimization problem over the state of the underlying Ethereum blockchain and the state of the DeFi ecosystem. We show how malicious adversaries can efficiently maximize an attack profit and hence damage the DeFi ecosystem further. Specifically, we present how two previously executed attacks can be "boosted" to result in a profit of 829.5k USD and 1.1M USD, respectively, which is a boost of 2.37x and 1.73x, respectively.
Motivation & Objective
- Explain how flash loans remove default risk and collateral needs in DeFi within atomic transactions.
- Quantify how transaction atomicity increases arbitrage revenue and analyze ROI of real attacks.
- Develop a constrained optimization framework to maximize attack profits given on-chain state and DeFi primitives.
- Evaluate the framework on two documented attacks and estimate potential missed profits (opportunity loss).
- Discuss broader implications for DeFi security and oracle/price manipulation risks.
Proposed method
- Describe flash loans and the three novel properties they enable: no default risk, no collateral, and pool-based loan size.
- Model DeFi actions as state transition functions with parameters, enabling an optimization problem over attack parameters.
- Formalize an attack vector as a sequence of transitions with constraints, and define an objective to maximize adversarial profit.
- Use a parametrized optimizer (SLSQP) to solve for optimal attack parameters given a blockchain state and DeFi models.
- Validate the optimization results by forking blockchains (Ganache) and implementing optimized attacks in Solidity for partial replication.
- Analyze the impact of atomicity on arbitrage by comparing atomic vs non-atomic execution scenarios.
Experimental results
Research questions
- RQ1How does blockchain transaction atomicity affect the profitability and risk of flash-loan-enabled attacks in DeFi?
- RQ2What attack parameters (e.g., loan sizes, collateral, leverage) maximize revenue for given DeFi states and platforms?
- RQ3How much additional profit could attackers realize if they used optimal parameters versus historically observed parameters?
- RQ4What is the bound on opportunity loss due to non-optimal parameter choices in real-world attacks?
- RQ5What are the broader security implications for DeFi ecosystems when flash loans and atomic transactions are used?
Key findings
- Two flash-loan-driven attacks yielded ROI beyond 500k% (pump attack with arbitrage and oracle manipulation).
- Optimized parameters could boost PA&A profits to 2,778.94 ETH (about 829.5k USD gain over the original 1,193.69 ETH), and oracle manipulation to 6,323.93 ETH (about 1.1M USD gain over the original 634.9k USD).
- In a local fork validating the PA&A, the optimized first-part revenue reached 1,958.01 ETH versus the original 1,193.69 ETH.
- Oracle manipulation shows the attacker could distort price oracles (Uniswap/Kyber) and borrow against inflated collateral to generate 2,381.41 ETH in the original attack, with optimization suggesting up to 4,167.01 ETH final revenue under constraints.
- Atomic transaction analysis demonstrates that arbitrage revenue decreases when intermediary transactions are inserted, illustrating the protective effect of atomicity against price volatility.
- The framework enables solving attack parameter optimization in under milliseconds on realistic blockchain states.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.