Note — WEB3

Flash Loan Attacks, Explained in Under Five Minutes

Flash loan attacks are a common pattern in DeFi hacks because they give an attacker massive leverage to manipulate a protocol. For the space of a single transaction, an attacker can borrow hundreds of millions of dollars in tokens without putting down any collateral.

These flash loans are significant because they can affect protocol governance and token valuation. An attacker with a massive, temporary loan of tokens has outsized influence.

How Flash Loans Work

In traditional lending, a lender needs to be concerned about the borrower defaulting on their loan. To manage this risk, they often require the borrower to put up some collateral that can be used to recoup some of their losses.

In Web3, there's no need to do this. Transactions on smart contract platforms like Ethereum are all-or-nothing; if part of the transaction fails, the entire transaction is rolled back. As a result, the initial loan is only recorded on the distributed ledger if the borrower pays it back in full by the end of the transaction.

Eliminating the need for collateral enables Web3 users to take out much larger loans than they could otherwise, but they only last for a single transaction. These loans can be used for various purposes, such as arbitrage, governance manipulation, or price oracle manipulation.

Manipulating Decentralized Governance

Many Web3 projects attempt to implement decentralized governance in line with the original Web3 ethos. Often, this involves allowing users to create proposals, which are enacted via smart contracts if they win the vote.

To protect against attackers spinning up many accounts to skew the voting, governance is implemented using token ownership to determine the number of votes someone has. Flash loans complicate this since an attacker could take out a loan, place votes with their large number of tokens, then return the borrowed tokens at the end of the transaction. To stop this, protocols can use snapshots of token allocations for voting or weight votes based on how long someone has owned a token.

Managing the Flash Loan Threat

Flash loans aren't inherently bad. There are legitimate reasons why a user might need access to a large volume of tokens for the space of a single transaction, such as taking advantage of arbitrage opportunities.

However, flash loans can create problems for protocols that use token ownership to determine voting rights or that base token valuation on internal price calculations. Understanding the role of tokens in a project and implementing security best practices is critical to protect against these threats.