generated from PaulRBerg/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathside-entrance.challenge.ts
39 lines (29 loc) · 1.54 KB
/
side-entrance.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
const { ethers } = require("hardhat");
const { expect } = require("chai");
describe("[Challenge] Side entrance", function () {
let deployer, attacker;
const ETHER_IN_POOL = ethers.utils.parseEther("1000");
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[deployer, attacker] = await ethers.getSigners();
const SideEntranceLenderPoolFactory = await ethers.getContractFactory("SideEntranceLenderPool", deployer);
this.pool = await SideEntranceLenderPoolFactory.deploy();
await this.pool.deposit({ value: ETHER_IN_POOL });
this.attackerInitialEthBalance = await ethers.provider.getBalance(attacker.address);
expect(await ethers.provider.getBalance(this.pool.address)).to.equal(ETHER_IN_POOL);
});
it("Exploit", async function () {
/** CODE YOUR EXPLOIT HERE */
const SideEntranceAttackerFactory = await ethers.getContractFactory("SideEntranceAttacker", attacker);
const attackerContract = await SideEntranceAttackerFactory.deploy(this.pool.address);
await attackerContract.attack();
});
after(async function () {
/** SUCCESS CONDITIONS */
expect(await ethers.provider.getBalance(this.pool.address)).to.be.equal("0");
// Not checking exactly how much is the final balance of the attacker,
// because it'll depend on how much gas the attacker spends in the attack
// If there were no gas costs, it would be balance before attack + ETHER_IN_POOL
expect(await ethers.provider.getBalance(attacker.address)).to.be.gt(this.attackerInitialEthBalance);
});
});