@@ -6,48 +6,56 @@ import (
6
6
"github.com/ethereum/go-ethereum/params"
7
7
)
8
8
9
+ // all custom precompiles have an address greater than or equal to this address
10
+ var CustomPrecompileStartingAddr = common .HexToAddress ("0x0000000000000000000000000000000000001001" )
11
+
9
12
// Forked from go-ethereum, except journaling logic which is unnecessary with cacheKV
10
13
11
14
type accessList struct {
12
15
Addresses map [common.Address ]int
13
16
Slots []map [common.Hash ]struct {}
14
17
}
15
18
16
- // deep copy so that changes to a new snapshot won't affect older ones
17
- func ( al * accessList ) Copy () * accessList {
18
- newAl := & accessList { Addresses : make ( map [common. Address ] int , len ( al .Addresses )), Slots : make ([] map [common. Hash ] struct {}, 0 , len ( al . Slots ))}
19
- for a , i := range al . Addresses {
20
- newAl . Addresses [ a ] = i
19
+ func ( s * DBImpl ) AddressInAccessList ( addr common. Address ) bool {
20
+ s . k . PrepareReplayedAddr ( s . ctx , addr )
21
+ _ , ok := s . getCurrentAccessList () .Addresses [ addr ]
22
+ if ok {
23
+ return true
21
24
}
22
- for i , slot := range al .Slots {
23
- newAl .Slots = append (newAl .Slots , make (map [common.Hash ]struct {}, len (slot )))
24
- for h := range slot {
25
- newAl.Slots [i ][h ] = struct {}{}
25
+ for _ , ts := range s .tempStatesHist {
26
+ if _ , ok := ts .transientAccessLists .Addresses [addr ]; ok {
27
+ return true
26
28
}
27
29
}
28
- return newAl
29
- }
30
-
31
- func (s * DBImpl ) AddressInAccessList (addr common.Address ) bool {
32
- s .k .PrepareReplayedAddr (s .ctx , addr )
33
- _ , ok := s .getAccessList ().Addresses [addr ]
34
- return ok
30
+ return false
35
31
}
36
32
37
33
func (s * DBImpl ) SlotInAccessList (addr common.Address , slot common.Hash ) (addressOk bool , slotOk bool ) {
38
34
s .k .PrepareReplayedAddr (s .ctx , addr )
39
- al := s .getAccessList ()
40
- idx , ok := al .Addresses [addr ]
41
- if ok && idx != - 1 {
35
+ al := s .getCurrentAccessList ()
36
+ idx , addrOk := al .Addresses [addr ]
37
+ if addrOk && idx != - 1 {
42
38
_ , slotOk := al.Slots [idx ][slot ]
43
- return ok , slotOk
39
+ if slotOk {
40
+ return true , true
41
+ }
44
42
}
45
- return ok , false
43
+ for _ , ts := range s .tempStatesHist {
44
+ idx , ok := ts .transientAccessLists .Addresses [addr ]
45
+ addrOk = addrOk || ok
46
+ if ok && idx != - 1 {
47
+ _ , slotOk := ts .transientAccessLists .Slots [idx ][slot ]
48
+ if slotOk {
49
+ return true , true
50
+ }
51
+ }
52
+ }
53
+ return addrOk , false
46
54
}
47
55
48
56
func (s * DBImpl ) AddAddressToAccessList (addr common.Address ) {
49
57
s .k .PrepareReplayedAddr (s .ctx , addr )
50
- al := s .getAccessList ()
58
+ al := s .getCurrentAccessList ()
51
59
defer s .saveAccessList (al )
52
60
if _ , present := al .Addresses [addr ]; present {
53
61
return
@@ -57,7 +65,7 @@ func (s *DBImpl) AddAddressToAccessList(addr common.Address) {
57
65
58
66
func (s * DBImpl ) AddSlotToAccessList (addr common.Address , slot common.Hash ) {
59
67
s .k .PrepareReplayedAddr (s .ctx , addr )
60
- al := s .getAccessList ()
68
+ al := s .getCurrentAccessList ()
61
69
defer s .saveAccessList (al )
62
70
idx , addrPresent := al .Addresses [addr ]
63
71
if ! addrPresent || idx == - 1 {
@@ -87,6 +95,10 @@ func (s *DBImpl) Prepare(_ params.Rules, sender, coinbase common.Address, dest *
87
95
// If it's a create-tx, the destination will be added inside evm.create
88
96
}
89
97
for _ , addr := range precompiles {
98
+ // skip any custom precompile
99
+ if addr .Cmp (CustomPrecompileStartingAddr ) >= 0 {
100
+ continue
101
+ }
90
102
s .AddAddressToAccessList (addr )
91
103
}
92
104
for _ , el := range txAccesses {
@@ -98,7 +110,7 @@ func (s *DBImpl) Prepare(_ params.Rules, sender, coinbase common.Address, dest *
98
110
s .AddAddressToAccessList (coinbase )
99
111
}
100
112
101
- func (s * DBImpl ) getAccessList () * accessList {
113
+ func (s * DBImpl ) getCurrentAccessList () * accessList {
102
114
return s .tempStateCurrent .transientAccessLists
103
115
}
104
116
0 commit comments