generated from huff-language/huff-project-template
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSimpleStore.huff
41 lines (34 loc) · 1.01 KB
/
SimpleStore.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
/* 接口 */
#define function setValue(uint256) nonpayable returns ()
#define function getValue() view returns (uint256)
/* 存储槽位 */
#define constant VALUE_LOCATION = FREE_STORAGE_POINTER()
/* 方法 */
#define macro SET_VALUE() = takes (0) returns (0) {
0x04 calldataload // [value]
[VALUE_LOCATION] // [ptr, value]
sstore // []
stop // []
}
#define macro GET_VALUE() = takes (0) returns (0) {
// 从存储中加载值
[VALUE_LOCATION] // [ptr]
sload // [value]
// 将值存入内存
0x00 mstore
// 返回值
0x20 0x00 return
}
// 合约的主入口,判断调用的是哪个函数
#define macro MAIN() = takes (0) returns (0) {
// 通过selector判断要调用哪个函数
0x00 calldataload 0xE0 shr
dup1 __FUNC_SIG(setValue) eq set jumpi
dup1 __FUNC_SIG(getValue) eq get jumpi
// 如果没有匹配的函数,就revert
0x00 0x00 revert
set:
SET_VALUE()
get:
GET_VALUE()
}