-
Notifications
You must be signed in to change notification settings - Fork 0
/
reenter.js
49 lines (39 loc) · 1.36 KB
/
reenter.js
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
49
const { ethers } = require("hardhat");
const { expect } = require("chai");
describe("Reenter Challenge", function () {
let alice, bob;
const ETHER_IN_POOL = ethers.utils.parseEther("1000");
before(async function () {
/** SETUP SCENARIO - DON'T CHANGE ANYTHING HERE */
[alice, bob] = await ethers.getSigners();
const ReenterPoolFactory = await ethers.getContractFactory(
"ReenterPool",
alice
);
this.pool = await ReenterPoolFactory.deploy();
await this.pool.deposit({ value: ETHER_IN_POOL });
this.bobInitialEthBalance = await ethers.provider.getBalance(bob.address);
expect(await ethers.provider.getBalance(this.pool.address)).to.equal(
ETHER_IN_POOL
);
});
it("Exploit", async function () {
/** CODE YOUR EXPLOIT HERE */
});
after(async function () {
/** SUCCESS CONDITIONS */
if (
expect(await ethers.provider.getBalance(this.pool.address)).to.be.equal(
"0"
) &&
expect(await ethers.provider.getBalance(bob.address)).to.be.gt(
this.bobInitialEthBalance
)
) {
console.log("You have passed the Reenter Challenge");
}
// Not checking exactly how much is the final balance of bob,
// because it'll depend on how much gas bob spends in the attack
// If there were no gas costs, it would be balance before attack + ETHER_IN_POOL
});
});