DFX Finance @Reentrancy@flashloan
KEY WORDS: flashloan, reentrancy
ATTACK TIME: 2022.11.11
LOSSES:4 million$
Event Background
DFX is an Ethereum-based decentralized exchange protocol with a dynamically tuned bonding curve optimized for fiat-backed stablecoins (like USDC, CADC, EURS, XSGD, etc) using real-world FX price feeds.
Tx Details
-
hacker contract: 0x6cfa86a352339e766ff1ca119c8c40824f41f22d
dfx-xidr-v2 contract: 0x46161158b1947d9149e066d6d31af1283b2d377c
- 0x27e843260c71443b4cc8cb6bf226c3f77b9695af: it is a multi wallet that receives fee with the
flashloan()
.
- fund flow
- [1] [2]: hacker borrowed a lot of USDC and XIDR from dfx
- [3] [4]: hacker paid back USDC and XIDR to dfx
- [5] :
token dfx-xidr-v2
was minted to hacker - [6] [7] : DFX multi wallet receives some USDC and XIDR as fee of
flashloan()
- [8] : hacker burned
token dfx-xidr-v2
Attack Process
The entire attack process
1.preparation
why hacker called viewDeposit()?
Hacker wanted to know how much token pair he should deposit to get 200,000*1e18
token dfx-xidr-v2
1 | /// @notice view deposits and curves minted a given deposit would return |
2.flashloan
in flash() we know it is similar to uniswapV2’s flashloan()
1 | function flash( |
3.pay back for flashloan
4.flashCallBack
deposit():
1 | /// @notice deposit into the pool with no slippage from the numeraire assets the pool supports |
Hacker deposited USDC and XIDR that he got in flashloan to mint token dfx-xidr-usdc
. Attention, hacker did deposit meaned that contract dfx-xidr-usdc would receive this USDC and XIDR, resulting at pass these checking:
1 | require(balance0Before.add(fee0) <= balance0After, 'Curve/insufficient-token0-returned'); |
5.withdraw&exploit
Vulnerability Analysis
attack logic is the same as Damn Vulnerable DeFi CTF’s Side Entrance.
Attack Recurrence
1 | // SPDX-License-Identifier: UNLICENSED |
Remediation
fixed flashloan() checking logic