-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathembed.go
More file actions
114 lines (92 loc) · 2.09 KB
/
embed.go
File metadata and controls
114 lines (92 loc) · 2.09 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package enhanced_rpc
import (
"bytes"
_ "embed"
"encoding/csv"
"encoding/json"
"math/big"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)
//go:embed data/exploiter.json
var gasExploiter []byte
//go:embed data/whitelistContract.json
var gasWhitelist []byte
//go:embed data/sponsorship.json
var sponsorship []byte
//go:embed data/data.csv
var ofacAddresses []byte
func GasWhitelist() (addrs []common.Address) {
var _gasWhitelist map[common.Address]string
unmarshal(gasWhitelist, &_gasWhitelist)
for addr := range _gasWhitelist {
addrs = append(addrs, addr)
}
return
}
func GasExploiter() (res []common.Address) {
unmarshal(gasExploiter, &res)
return
}
func unmarshal(data []byte, a any) {
_ = json.Unmarshal(data, a)
}
type Sponsorship map[common.Address]*struct {
Allow map[string]int `json:"allow"`
CheckAmount bool `json:"checkAmount"`
}
func SponsorshipInit() {
if _sponsorship != nil {
return
}
unmarshal(sponsorship, &_sponsorship)
}
var (
_sponsorship Sponsorship
mu sync.Mutex
)
func IsSponsorable(a *common.Address, data []byte) (b bool) {
return false
SponsorshipInit()
if a == nil || len(data) <= 4 { // 格式不匹配
return
}
mu.Lock()
defer mu.Unlock()
info, ok := _sponsorship[*a]
if !ok { // 不在赞助列表中
return
}
length, ok := info.Allow[hexutil.Encode(data[:4])]
if !ok || length != len(data) { // 函数参数不匹配
return
}
if info.CheckAmount {
amount := new(big.Int).SetBytes(data[length-common.HashLength:])
if big.NewInt(48e16).Cmp(amount) > 0 { // 金额小于 0.48 ether, 不赞助
return
}
}
return true
}
func GetOfacAddresses() (res []common.Address) {
res = []common.Address{}
reader := csv.NewReader(bytes.NewReader(ofacAddresses))
_, err := reader.Read()
if err != nil {
panic(err)
}
records, err := reader.ReadAll()
if err != nil {
panic(err)
}
for _, record := range records {
if len(record) > 2 {
if addr := common.HexToAddress(record[1]); addr != (common.Address{}) {
res = append(res, addr)
}
}
}
return
}