Advanced
MEV and Its Effects on DeFi Users
Learn how Maximal Extractable Value (MEV) works, how it affects DeFi users through front-running and sandwich attacks, and strategies to protect your transactions.
Explore how flash loans work, their legitimate use cases in DeFi, and the security implications they introduce for lending protocols and liquidity pools.
Flash loans represent one of the most novel financial primitives to emerge from decentralized finance. Unlike any instrument in traditional finance, a flash loan allows a user to borrow an unlimited amount of capital with zero collateral — provided the entire amount plus fees is returned within the same blockchain transaction. If repayment fails, the transaction reverts atomically, as though the loan was never issued.
This mechanism is made possible by the deterministic execution environment of smart contracts. On Ethereum and other EVM-compatible chains, a transaction either fully succeeds or fully fails. There is no partial execution. Flash loan providers like Aave and dYdX exploit this property to offer risk-free lending from the protocol's perspective: the funds are never truly at risk because the repayment condition is enforced at the protocol level before the transaction finalizes.
A flash loan transaction typically follows a multi-step sequence within a single atomic operation:
All four steps happen within a single transaction, which means the blockchain state changes only if every step succeeds. This atomicity is the foundation of flash loan safety for lenders.
While flash loans have gained notoriety through high-profile exploits, they serve several critical functions that improve overall DeFi market efficiency.
The most common legitimate use of flash loans is arbitrage — exploiting price differences for the same asset across different decentralized exchanges. When ETH trades at $3,000 on Uniswap and $3,015 on SushiSwap, an arbitrageur can flash-borrow a large amount of ETH, sell on the more expensive venue, buy on the cheaper one, repay the loan, and pocket the difference — all without deploying personal capital.
This activity is not parasitic. Arbitrage corrects pricing inefficiencies and ensures that users across different DEXes receive consistent, fair pricing. Without arbitrageurs (many of whom rely on flash loans), price divergences between venues would persist longer, leading to worse execution for everyday traders.
Users with active lending positions can use flash loans to swap their collateral without first closing their position. For example, a borrower on Aave with an ETH-collateralized USDC loan could use a flash loan to repay the USDC debt, withdraw ETH, swap ETH for WBTC, deposit WBTC as new collateral, re-borrow USDC, and repay the flash loan. What would normally require significant spare capital and multiple transactions is accomplished atomically.
This is particularly relevant for Bitcoin-backed lending. A user leveraging platforms aggregated through Borrow could theoretically execute complex refinancing operations to move between protocols offering better rates — something that becomes increasingly practical as cross-chain flash loan infrastructure matures.
When a collateralized position approaches its liquidation threshold, the borrower faces a choice: add more collateral, repay debt, or accept a liquidation penalty (typically 5–15%). Flash loans offer a fourth option: self-liquidation. The user can flash-borrow enough to repay their debt, withdraw their collateral, sell enough collateral to repay the flash loan, and keep the remainder — avoiding the liquidation penalty entirely.
Advanced DeFi users employ flash loans for capital-efficient yield farming. By flash-borrowing assets to temporarily boost positions, users can claim higher reward tiers or rebalance yield-bearing positions across protocols. While these strategies require sophisticated smart contract programming, they demonstrate the composability that makes DeFi uniquely powerful.
Despite their legitimate utility, flash loans have been weaponized in numerous exploits that have cost DeFi protocols hundreds of millions of dollars. Understanding these attacks is essential for evaluating protocol security.
The most common flash loan attack vector exploits protocols that determine asset prices using on-chain spot data from a single liquidity pool. The attack pattern is:
The key insight is that the flash loan itself is not the vulnerability — it merely provides the capital. The actual vulnerability lies in the protocol's reliance on easily-manipulated price data.
Several high-profile incidents illustrate the pattern:
In each case, the root cause was not the flash loan mechanism but the protocol's oracle design — specifically, reliance on spot prices from a single pool rather than time-weighted or decentralized oracle solutions.
Flash loans democratize access to large amounts of capital. Before flash loans, manipulating on-chain prices required deploying millions in personal funds, which created a natural barrier. Flash loans remove this barrier entirely: an attacker needs only enough ETH to pay gas fees. This means any smart contract vulnerability that could previously be exploited only by well-capitalized actors is now accessible to anyone with programming skills.
This amplification effect has forced a fundamental rethinking of DeFi security assumptions. Protocols can no longer treat the cost of capital as a defense mechanism.
The DeFi ecosystem has developed multiple defense strategies in response to flash loan attacks.
Instead of reading spot prices that can be manipulated within a single block, protocols now commonly use TWAP oracles that calculate average prices over multiple blocks. Since a flash loan operates within a single transaction (and therefore a single block), it cannot influence a TWAP that considers historical data across many blocks.
Uniswap v3's built-in TWAP oracle, for example, accumulates price observations over time and allows protocols to query an average price over any desired window — making single-block manipulation economically impractical.
Services like Chainlink aggregate price data from multiple off-chain and on-chain sources, weighting and filtering outliers before posting on-chain. These feeds are resistant to flash loan manipulation because they do not rely on any single on-chain pool for pricing. Most serious lending protocols — including those aggregated by Borrow — use Chainlink or similar decentralized oracle infrastructure for their price feeds.
Modern protocols implement additional defenses:
Protocols increasingly invest in multiple independent smart contract audits that specifically test for flash loan attack vectors. Audit firms now include flash loan simulations as a standard part of their security review process, testing whether price oracle dependencies can be exploited through large single-transaction trades.
The Bitcoin DeFi ecosystem has a somewhat different relationship with flash loans due to Bitcoin's unique characteristics.
Native Bitcoin does not support the complex smart contract logic required for flash loans. However, Bitcoin Layer 2 solutions and sidechains with EVM compatibility — such as those building on wrapped BTC standards — do enable flash loan functionality. As Bitcoin DeFi matures, flash loan capabilities are expanding into the BTC ecosystem.
For users of Bitcoin-backed lending platforms, this creates both opportunities and considerations. The ability to flash-borrow wrapped Bitcoin could enable efficient collateral management and refinancing across protocols. At the same time, protocols accepting wrapped BTC as collateral must implement the same oracle security measures that have proven essential on Ethereum.
Users borrowing stablecoins against Bitcoin collateral through platforms aggregated by Borrow benefit from the security improvements that flash loan attacks have driven across the industry. The protocols available through Borrow's aggregation layer — including Aave, Morpho, and others — have all implemented robust oracle infrastructure and undergone extensive security audits that specifically address flash loan vectors.
Understanding flash loan dynamics helps borrowers evaluate protocol security more critically. When comparing lending venues, factors like oracle infrastructure, audit history, and flash loan resistance mechanisms should inform the decision alongside headline interest rates.
Flash loans have fundamentally influenced how DeFi protocols are designed and secured.
DeFi's composability — the ability for protocols to interact with each other seamlessly — is both its greatest strength and its primary attack surface. Flash loans exploit composability by chaining multiple protocol interactions within a single atomic transaction. This has led to a more nuanced understanding of composability risks and the development of isolated execution environments for sensitive operations.
On the positive side, flash loan-enabled arbitrage has significantly improved market efficiency across DeFi. Price discrepancies between venues are corrected faster, liquidity is distributed more efficiently, and users generally receive better execution on their trades. The MEV ecosystem — closely related to flash loans — has further driven these efficiency improvements, though not without its own set of challenges for everyday users.
The wave of flash loan exploits in 2020–2021 catalyzed a fundamental upgrade in DeFi security standards. Pre-flash-loan, many protocols launched with minimal auditing and simplistic oracle designs. Post-flash-loan, the industry standard now includes multiple independent audits, decentralized oracle infrastructure, bug bounty programs, and formal verification of critical contract logic. This security maturation benefits all DeFi users, including those in the Bitcoin lending space.
As DeFi infrastructure matures, flash loans continue to evolve. New use cases emerge as cross-chain bridges improve — including flash loan arbitrage across different blockchain networks. At the same time, improved security tooling, standardized oracle infrastructure, and more rigorous audit practices are reducing the attack surface.
For Bitcoin-backed lending specifically, the expansion of flash loan functionality to Bitcoin Layer 2 networks could enable more efficient capital allocation and position management. Users comparing lending options through aggregators like Borrow will benefit from understanding these mechanics as they become more relevant to the Bitcoin DeFi ecosystem.
The key takeaway is that flash loans are a powerful neutral tool. They improve market efficiency and enable novel financial strategies when used legitimately, while exposing vulnerabilities in poorly designed protocols when exploited. The appropriate response is not to eliminate flash loans but to build protocols robust enough to withstand them — a standard that the best lending platforms have already achieved.
Related Guides
Advanced
Learn how Maximal Extractable Value (MEV) works, how it affects DeFi users through front-running and sandwich attacks, and strategies to protect your transactions.
Intermediate
A comprehensive guide to the types of risks present in DeFi lending protocols, including smart contract risk, oracle risk, governance risk, and systemic risk, with practical mitigation strategies.
Common Questions
A flash loan is an uncollateralized loan that must be borrowed and repaid within a single blockchain transaction. Unlike traditional loans that require collateral, credit checks, and repayment schedules, flash loans leverage the atomic nature of blockchain transactions: if the borrower cannot repay the full amount plus fees by the end of the transaction, the entire operation reverts as if it never happened. This eliminates default risk for the lender while enabling capital-efficient strategies for the borrower.