Skip to content

Commit 769e062

Browse files
committed
evmc: Add Istanbul support
1 parent b36c49e commit 769e062

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

core/vm/evmc.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
// EVMC represents the reference to a common EVMC-based VM instance and
3636
// the current execution context as required by go-ethereum design.
3737
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.
3939
env *EVM // The execution context.
4040
cap evmc.Capability // The supported EVMC capability (EVM or Ewasm)
4141
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
120120

121121
host.env.StateDB.SetState(addr, key, value)
122122

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))
125127
if !hasNetStorageCostEIP {
126128

127129
zero := common.Hash{}
@@ -135,6 +137,14 @@ func (host *hostContext) SetStorage(addr common.Address, key common.Hash, value
135137
return evmc.StorageModified
136138
}
137139

140+
resetClearRefund := params.NetSstoreResetClearRefund
141+
cleanRefund := params.NetSstoreResetRefund
142+
143+
if hasEIP2200 {
144+
resetClearRefund = params.SstoreInitRefundEIP2200
145+
cleanRefund = params.SstoreCleanRefundEIP2200
146+
}
147+
138148
if original == current {
139149
if original == (common.Hash{}) { // create slot (2.1.1)
140150
return evmc.StorageAdded
@@ -154,9 +164,9 @@ func (host *hostContext) SetStorage(addr common.Address, key common.Hash, value
154164
}
155165
if original == value {
156166
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)
158168
} else { // reset to original existing slot (2.2.2.2)
159-
host.env.StateDB.AddRefund(params.NetSstoreResetRefund)
169+
host.env.StateDB.AddRefund(cleanRefund)
160170
}
161171
}
162172
return evmc.StorageModifiedAgain
@@ -198,7 +208,8 @@ func (host *hostContext) GetTxContext() evmc.TxContext {
198208
Number: host.env.BlockNumber.Int64(),
199209
Timestamp: host.env.Time.Int64(),
200210
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)}
202213
}
203214

204215
func (host *hostContext) GetBlockHash(number int64) common.Hash {

0 commit comments

Comments
 (0)