-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmeta-token.challenge.js
64 lines (50 loc) · 1.78 KB
/
meta-token.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
57
58
59
60
61
62
63
64
const { expect } = require('chai')
const { ethers } = require('hardhat')
function generateMessageHash(sender, receiver, amount, nonce) {
const message = new ethers.utils.AbiCoder().encode(
['address', 'address', 'uint256', 'uint256'],
[sender, receiver, amount, nonce]
)
return ethers.utils.keccak256(message)
}
describe('[META TOKEN EXPLOIT]', async function () {
let deployer, attacker
const INITIAL_BALANCE = ethers.utils.parseEther('100')
const TRANSFER_AMOUNT = ethers.utils.parseEther('10')
before(async function () {
// SET UP
;[deployer, attacker, alice] = await ethers.getSigners()
this.token = await (
await ethers.getContractFactory('MetaToken', deployer)
).deploy("Meta Token", "Meta", INITIAL_BALANCE)
await this.token.transfer(alice.address, INITIAL_BALANCE)
const nonce = await this.token.nonce()
const messageHash = generateMessageHash(
alice.address,
attacker.address,
TRANSFER_AMOUNT,
nonce.toString()
)
this.signature = ethers.utils.splitSignature(
await alice.signMessage(ethers.utils.arrayify(messageHash))
)
await this.token.metaTransfer(
alice.address,
attacker.address,
TRANSFER_AMOUNT,
this.signature.v,
this.signature.r,
this.signature.s
)
expect(
await this.token.balanceOf(alice.address)
).to.be.equal(INITIAL_BALANCE.sub(TRANSFER_AMOUNT))
})
it('Exploit', async function () {
// YOUR EXPLOIT HERE
})
after(async function () {
// SUCCESS CONDITIONS
expect(await this.token.balanceOf(alice.address)).to.be.equal('0')
})
})