-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabi-smuggling.challenge.js
56 lines (44 loc) · 2.29 KB
/
abi-smuggling.challenge.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
50
51
52
53
54
55
56
const { ethers } = require('hardhat');
const { expect } = require('chai');
describe('[Challenge] ABI smuggling', function () {
let deployer, player, recovery;
let token, vault;
const VAULT_TOKEN_BALANCE = 1000000n * 10n ** 18n;
before(async function () {
/** SETUP SCENARIO - NO NEED TO CHANGE ANYTHING HERE */
[ deployer, player, recovery ] = await ethers.getSigners();
// Deploy Damn Valuable Token contract
token = await (await ethers.getContractFactory('DamnValuableToken', deployer)).deploy();
// Deploy Vault
vault = await (await ethers.getContractFactory('SelfAuthorizedVault', deployer)).deploy();
expect(await vault.getLastWithdrawalTimestamp()).to.not.eq(0);
// Set permissions
const deployerPermission = await vault.getActionId('0x85fb709d', deployer.address, vault.address);
const playerPermission = await vault.getActionId('0xd9caed12', player.address, vault.address);
await vault.setPermissions([deployerPermission, playerPermission]);
expect(await vault.permissions(deployerPermission)).to.be.true;
expect(await vault.permissions(playerPermission)).to.be.true;
// Make sure Vault is initialized
expect(await vault.initialized()).to.be.true;
// Deposit tokens into the vault
await token.transfer(vault.address, VAULT_TOKEN_BALANCE);
expect(await token.balanceOf(vault.address)).to.eq(VAULT_TOKEN_BALANCE);
expect(await token.balanceOf(player.address)).to.eq(0);
// Cannot call Vault directly
await expect(
vault.sweepFunds(deployer.address, token.address)
).to.be.revertedWithCustomError(vault, 'CallerNotAllowed');
await expect(
vault.connect(player).withdraw(token.address, player.address, 10n ** 18n)
).to.be.revertedWithCustomError(vault, 'CallerNotAllowed');
});
it('Execution', async function () {
/** CODE YOUR SOLUTION HERE */
});
after(async function () {
/** SUCCESS CONDITIONS - NO NEED TO CHANGE ANYTHING HERE */
expect(await token.balanceOf(vault.address)).to.eq(0);
expect(await token.balanceOf(player.address)).to.eq(0);
expect(await token.balanceOf(recovery.address)).to.eq(VAULT_TOKEN_BALANCE);
});
});