@@ -35,7 +35,7 @@ import (
35
35
// EVMC represents the reference to a common EVMC-based VM instance and
36
36
// the current execution context as required by go-ethereum design.
37
37
type EVMC struct {
38
- instance * evmc.VM // The reference to the EVMC VM instance.
38
+ instance * evmc.VM // The reference to the EVMC VM instance.
39
39
env * EVM // The execution context.
40
40
cap evmc.Capability // The supported EVMC capability (EVM or Ewasm)
41
41
readOnly bool // The readOnly flag (TODO: Try to get rid of it).
@@ -120,8 +120,10 @@ func (host *hostContext) SetStorage(addr common.Address, key common.Hash, value
120
120
121
121
host .env .StateDB .SetState (addr , key , value )
122
122
123
- hasNetStorageCostEIP := host .env .ChainConfig ().IsConstantinople (host .env .BlockNumber ) &&
124
- ! host .env .ChainConfig ().IsPetersburg (host .env .BlockNumber )
123
+ hasEIP2200 := host .env .ChainConfig ().IsIstanbul (host .env .BlockNumber )
124
+ hasNetStorageCostEIP := hasEIP2200 ||
125
+ (host .env .ChainConfig ().IsConstantinople (host .env .BlockNumber ) &&
126
+ ! host .env .ChainConfig ().IsPetersburg (host .env .BlockNumber ))
125
127
if ! hasNetStorageCostEIP {
126
128
127
129
zero := common.Hash {}
@@ -135,6 +137,14 @@ func (host *hostContext) SetStorage(addr common.Address, key common.Hash, value
135
137
return evmc .StorageModified
136
138
}
137
139
140
+ resetClearRefund := params .NetSstoreResetClearRefund
141
+ cleanRefund := params .NetSstoreResetRefund
142
+
143
+ if hasEIP2200 {
144
+ resetClearRefund = params .SstoreInitRefundEIP2200
145
+ cleanRefund = params .SstoreCleanRefundEIP2200
146
+ }
147
+
138
148
if original == current {
139
149
if original == (common.Hash {}) { // create slot (2.1.1)
140
150
return evmc .StorageAdded
@@ -154,9 +164,9 @@ func (host *hostContext) SetStorage(addr common.Address, key common.Hash, value
154
164
}
155
165
if original == value {
156
166
if original == (common.Hash {}) { // reset to original inexistent slot (2.2.2.1)
157
- host .env .StateDB .AddRefund (params . NetSstoreResetClearRefund )
167
+ host .env .StateDB .AddRefund (resetClearRefund )
158
168
} else { // reset to original existing slot (2.2.2.2)
159
- host .env .StateDB .AddRefund (params . NetSstoreResetRefund )
169
+ host .env .StateDB .AddRefund (cleanRefund )
160
170
}
161
171
}
162
172
return evmc .StorageModifiedAgain
@@ -198,7 +208,8 @@ func (host *hostContext) GetTxContext() evmc.TxContext {
198
208
Number : host .env .BlockNumber .Int64 (),
199
209
Timestamp : host .env .Time .Int64 (),
200
210
GasLimit : int64 (host .env .GasLimit ),
201
- Difficulty : common .BigToHash (host .env .Difficulty )}
211
+ Difficulty : common .BigToHash (host .env .Difficulty ),
212
+ ChainID : common .BigToHash (host .env .chainConfig .ChainID )}
202
213
}
203
214
204
215
func (host * hostContext ) GetBlockHash (number int64 ) common.Hash {
0 commit comments