Flash Loan: A new way to play DeFi projects, how to attack MakerDao to obtain 700 million US dollars
Editor's Note: This article comes fromFirst class warehouse blockchain research institute (ID: first_vip1)Editor's Note: This article comes from
First class warehouse blockchain research institute (ID: first_vip1)
First class warehouse blockchain research institute (ID: first_vip1)
, Author: Dominik Harz, Compiler: First Class Warehouse-Mark, reprinted with authorization by Odaily.
If Maker doesn’t introduce a delay before the flash loan pool’s liquidity pool exceeds a threshold, there is little chance of stopping the attack (race condition).
introduce
Maker knew about the attack and held a vote on February 21 to prevent it.
secondary title
introduce
a16z:60000 MKR
0xfc7e22c6afa3ebb723bdde26d6ab3783aab9726b:51291 MKR
0x000be27f560fef0253cac4da8411611184356549:39645 MKR
[Maker governance contract: 192910 MKR]
Maker Foundation: 117993 MKR
Note: The Maker governance contract contains MKR tokens for multiple parties.
secondary title
governance attack
To reduce the number of MKR tokens required, he proposes to perform the attack when voting on new governance contracts. Currently, 192,910 MKR tokens are locked in the governance contract. However, if two or three contracts are voted in parallel with similar token distributions, the attacker will need fewer tokens.
This used to happen a lot in the past as shown in the image below:
The obvious attack strategy is to crowdfund the required MKR tokens via smart contracts and pay each attacker a share of the bounty. However, an attacker would likely need to accumulate around 50,000 MKR tokens to have a chance of attacking the system without Maker noticing these movements.
secondary title
New Attack Strategy: Flash Loans
However, if we consider flash loans, the requirement for a large amount of MKR tokens can be completely removed. Flash loans are a fairly new concept, so a brief explanation is given here. Typically, borrowers must provide collateral to obtain loans in DeFi projects. For example, in Maker, A can borrow Dai by depositing ETH. This is required, and this operates under the model of weak identities and economically sound agents.
Flash loans do away with this requirement, as it only happens in a single transaction:
1. A draws a loan from a flash loan liquidity provider (such as Aave or dYdX).
A repaid the flash loan with interest. If at any point during that transaction, the Flash Loan fails, the entire transaction will be reverted. Therefore, A can take the risk of the loan for free, and if he cannot repay the loan, it will be as if he had never taken it. Liquidity providers also win: they only lend funds if A is able to repay the loan.Flash loans work because of the way the Ethereum Virtual Machine is designed:
secondary title
On February 14th and February 18th, two incidents involving flash loans occurred, causing bZx to stop the platform. In the first transaction, a single flash loan earned 1,193 ETH (approximately $298,250) in profit. The trade was executed using a smart contract that opened a short position on Fulcrum on wBTC. In the same transaction, which took out a wBTC loan from Compound and traded wBTC on Kyber’s Uniswap reserve, causing slippage that ultimately also lowered the price of Fulcrum, can be found in bZx’s postmortem full details.
(First-class warehouse note: Fulcrum is a product that provides simple and effective loan and margin trading methods, and claims that it is currently the first and only trust-free margin platform, free of authorization, free of handling fees, and no need to create an account.)
Likewise, the second incident took place on February 18, making a profit of 2,378 ETH (approximately $600,000) in one transaction. The transaction involved an initial borrow of 7500 ETH to take a long position on Synthetix’s sUSD.
secondary title
At current exchange rates, the attacker would need approximately 485,000 ETH to purchase that amount of MKR, and only one exchange, Kyber, has enough available capacity. However, the attacker could also use multiple exchanges to buy 38k MKR from Kyber, 11.5k MKR from Uniswap, and 500 MKR from Switcheo, for a total of 378,940 ETH. This number is still high, but has been reduced by almost 100,000 ETH!
get enough liquidity
secondary title
get enough liquidity
Even with oracle operations, a large amount of ETH is required to perform an attack on Maker. An attacker can increase its liquidity by drawing two flash loans in the same transaction. Aave and dYdX protect themselves against reentrancy and only allow one flash loan in a single transaction, but an attacker can borrow ETH from both protocols in the same transaction.
Combination plan
Obviously, crowdfunding and flash loans can be combined. Using ~107k ETH of available liquidity, it is possible to get ~10800 MKR from Kyber. This allows multiple attackers to reduce the required amount of a combined 50k MKR to approximately 39.2k MKR. As an informal Twitter poll shows, some people do seem to be interested in this kind of attack:
It should also be noted that the top four account holders (actually five, but not considering the current Maker governance contract) were able to carry out the attack without crowdfunding.
best time to attack
Once sufficient liquidity (with or without a combination of oracle operations) can be obtained through the flash loan pool, anyone can take over the Maker governance contract. When the liquidity pool reaches that threshold, once Makers start voting, Makers need to ensure that as few MKR tokens as possible are allocated. This vulnerability could be exploited if MKR were distributed at any point during this voting process, any collateral could be stripped away.
An attacker would be able to steal $700 million worth of ETH collateral and be able to create new Dai at will. Since Dai is used as backing collateral for other protocols, this type of attack would pervade DeFi projects as a whole. Additionally, the attacker was able to trade his Dai for around $230 million worth of other currencies.
secondary title
Countermeasures


