forked from huff-language/foundry-huff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constructor.huff
69 lines (57 loc) · 2.31 KB
/
Constructor.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
/* Interface */
#define function getArgOne() view returns (address)
#define function getArgTwo() view returns (uint256)
/* Storage Slots */
#define constant CONSTRUCTOR_ARG_ONE = FREE_STORAGE_POINTER()
#define constant CONSTRUCTOR_ARG_TWO = FREE_STORAGE_POINTER()
/* Events */
#define event ArgumentsUpdated(address indexed one, uint256 indexed two)
#define constant ARGUMENTS_TOPIC = 0xd0a6a6b9636b3b1e85120bfc8c36f7bc862769b48e0854deaf8780636a71ce7d
/* Constructor */
#define macro CONSTRUCTOR() = takes(0) returns (0) {
// Copy the first argument into memory
0x20 // [size] - byte size to copy
0x40 codesize sub // [offset, size] - offset in the code to copy from
0x00 // [mem, offset, size] - offset in memory to copy to
codecopy // []
// Store the first argument in storage
0x00 mload dup1 // [arg1, arg1]
[CONSTRUCTOR_ARG_ONE] // [CONSTRUCTOR_ARG_ONE, arg1, arg1]
sstore // [arg1]
// Copy the second argument into memory
0x20 // [size, arg1] - byte size to copy
0x20 codesize sub // [offset, size, arg1] - offset in the code to copy from
0x00 // [mem, offset, size, arg1] - offset in memory to copy to
codecopy // [arg1]
// Store the second argument in storage
0x00 mload dup1 // [arg2, arg2, arg1]
[CONSTRUCTOR_ARG_TWO] // [CONSTRUCTOR_ARG_TWO, arg2, arg2, arg1]
sstore // [arg2, arg1]
// Emit the owner updated event
swap1 // [arg1, arg2]
[ARGUMENTS_TOPIC] // [sig, arg1, arg2]
0x00 0x00 // [0, 0, sig, arg1, arg2]
log3 // []
}
/* First Argument Accessor */
#define macro GET_ARG_ONE() = takes (0) returns (0) {
[CONSTRUCTOR_ARG_ONE] sload
0x00 mstore
0x20 0x00 return
}
/* Second Argument Accessor */
#define macro GET_ARG_TWO() = takes (0) returns (0) {
[CONSTRUCTOR_ARG_TWO] sload
0x00 mstore
0x20 0x00 return
}
/* Main Macro */
#define macro MAIN() = takes (0) returns (0) {
0x00 calldataload 0xE0 shr
dup1 0xbb01e52d eq arg_one jumpi
dup1 0x98e45be4 eq arg_two jumpi
arg_one:
GET_ARG_ONE()
arg_two:
GET_ARG_TWO()
}