generated from huff-language/huff-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SaltMiner.huff
69 lines (55 loc) · 3.13 KB
/
SaltMiner.huff
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
/*
███████╗ █████╗ ██╗ ████████╗███╗ ███╗██╗███╗ ██╗███████╗██████╗
██╔════╝██╔══██╗██║ ╚══██╔══╝████╗ ████║██║████╗ ██║██╔════╝██╔══██╗
███████╗███████║██║ ██║ ██╔████╔██║██║██╔██╗ ██║█████╗ ██████╔╝
╚════██║██╔══██║██║ ██║ ██║╚██╔╝██║██║██║╚██╗██║██╔══╝ ██╔══██╗
███████║██║ ██║███████╗██║ ██║ ╚═╝ ██║██║██║ ╚████║███████╗██║ ██║
╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝
*/
/// @notice A utility for finding the salt for a CREATE2 address for a UniV4 Hook
/// @author devtooligan
/* Interface */
#define function mineSalt(address,uint256,bytes32) view returns (uint256,address)
/* Constants */
#define constant CREATE2_MARKER = 0xff
#define constant PREFIX_MASK = 0x00ff00000000000000000000000000000000000000
#define constant ADDRESS_MASK = 0x000000000000000000000000FFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF
#define macro MINE_SALT() = takes (0) returns (0) {
0x60 0x04 0x00 calldatacopy
0x20 mload // [prefix]
[CREATE2_MARKER] // [0xff, prefix]
0x0b mstore8 // [prefix]
// Memory layout
// Hashing : 0xff(1) . deployerAddress(20) . salt(32) . initCodeHash(32)
// Hash size: 1 + 20 + 32 + 32 == 85 == 0x55
// Begins here at 0x0b with the CREATE2_MARKER, 0xff
// \/
// 0x00: 00 00 00 00 00 00 00 00 00 00 00 ff |-- address(this) -------------- |
// 0x20: |------------------------ salt ------------------------------------- |
// 0x40: |----------------- keccak256(initCode) ----------------------------- |
timestamp
begin_loop: // [salt, prefix]
0x20 mstore // [prefix]
0x55 0x0b sha3 // [hash, prefix]
dup1 // [hash, hash, prefix]
[PREFIX_MASK] and // [maskedHash, hash, prefix]
dup3 // [prefix, maskedHash, hash, prefix]
sub // [matchesPrefix, hash, prefix]
begin_loop
jumpi
dup1 // [hash, hash, prefix]
extcodesize // [codeSize, hash, prefix]
begin_loop
jumpi
[ADDRESS_MASK] and // [newAddress, prefix]
0x40 mstore // [prefix]
pop
0x40 0x20 return
}
#define macro MAIN() = takes (0) returns (0) {
0x00 calldataload 0xE0 shr
dup1 __FUNC_SIG(mineSalt) eq mineSalt jumpi
0x00 0x00 revert
mineSalt:
MINE_SALT()
}