-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathChallengeHiddenKitty.sol
More file actions
53 lines (43 loc) · 1.39 KB
/
ChallengeHiddenKitty.sol
File metadata and controls
53 lines (43 loc) · 1.39 KB
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: MIT
pragma solidity ^0.8.0;
/// @title The Lost Kitty
/// @author https://twitter.com/Cryptonicle1
/// @notice Lucas is a scientist who has lost his cat in a big house that has 2^256 rooms, anon can you find it?
/// @custom:url https://www.ctfprotocol.com/tracks/eko2022/hidden-kittycat
contract HiddenKittyCat {
address private immutable _owner;
constructor() {
_owner = msg.sender;
bytes32 slot = keccak256(abi.encodePacked(block.timestamp, blockhash(block.number - 69)));
assembly {
sstore(slot, "KittyCat!")
}
}
function areYouHidingHere(bytes32 slot) external view returns (bool) {
require(msg.sender == _owner, "!owner");
bytes32 kittyPointer;
assembly {
kittyPointer := sload(slot)
}
return kittyPointer == "KittyCat!";
}
function destroyMe() external {
require(msg.sender == _owner, "!owner");
selfdestruct(payable(address(0)));
}
}
contract House {
bool public catFound;
function isKittyCatHere(bytes32 _slot) external {
if (catFound) {
return;
}
HiddenKittyCat hiddenKittyCat = new HiddenKittyCat();
bool found = hiddenKittyCat.areYouHidingHere(_slot);
if (!found) {
hiddenKittyCat.destroyMe();
} else {
catFound = true;
}
}
}