-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13-Airdropper64.t.sol
69 lines (50 loc) · 1.83 KB
/
13-Airdropper64.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
69
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol";
import {Vault} from "../src/13-Airdropper64.sol";
contract Airdropper64Test is Test {
address owner;
address user;
address attacker;
bytes32 leftLeaf;
bytes32 rightLeaf;
Vault public vault;
function setUp() public {
owner = makeAddr("OWNER");
user = makeAddr("USER");
attacker = makeAddr("ATTACKER");
uint256 amount = 1 ether;
uint96 expiration = type(uint96).max;
leftLeaf = keccak256(abi.encodePacked(attacker, amount, expiration));
rightLeaf = keccak256(abi.encodePacked(user, amount, expiration));
// Calculate root
bytes32 root = keccak256(
abi.encode(leftLeaf, rightLeaf)
);
deal(owner, 2 ether);
vm.startPrank(owner);
vault = new Vault();
vault.setMerkleRoot(root);
vault.donate{value: 2 ether}();
vm.stopPrank();
}
function test_Airdropper64() public {
vm.startPrank(attacker);
// START OF SOLUTION
// (You can create any additional contract if needed)
// END OF SOLUTION
vm.stopPrank();
vm.startPrank(user);
bytes32[] memory userProof = new bytes32[](1);
userProof[0] = leftLeaf;
vault.claim(user, 1 ether, type(uint96).max, userProof);
vm.expectRevert();
vault.withdraw(user, 1 ether);
uint256 vaultBalance = address(vault).balance;
assertEq(vaultBalance, 0, "Vault still has balance");
uint256 userBalance = address(user).balance;
assertEq(userBalance, 0, "User has balance");
uint256 attackerBalance = address(attacker).balance;
assertEq(attackerBalance, 1 ether, "Attacker didn't get the assets");
}
}