Skip to content

Commit

Permalink
evmc: Add Istanbul support
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Nov 8, 2019
1 parent b36c49e commit 769e062
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions core/vm/evmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// EVMC represents the reference to a common EVMC-based VM instance and
// the current execution context as required by go-ethereum design.
type EVMC struct {
instance *evmc.VM // The reference to the EVMC VM instance.
instance *evmc.VM // The reference to the EVMC VM instance.
env *EVM // The execution context.
cap evmc.Capability // The supported EVMC capability (EVM or Ewasm)
readOnly bool // The readOnly flag (TODO: Try to get rid of it).
Expand Down Expand Up @@ -120,8 +120,10 @@ func (host *hostContext) SetStorage(addr common.Address, key common.Hash, value

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

hasNetStorageCostEIP := host.env.ChainConfig().IsConstantinople(host.env.BlockNumber) &&
!host.env.ChainConfig().IsPetersburg(host.env.BlockNumber)
hasEIP2200 := host.env.ChainConfig().IsIstanbul(host.env.BlockNumber)
hasNetStorageCostEIP := hasEIP2200 ||
(host.env.ChainConfig().IsConstantinople(host.env.BlockNumber) &&
!host.env.ChainConfig().IsPetersburg(host.env.BlockNumber))
if !hasNetStorageCostEIP {

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

resetClearRefund := params.NetSstoreResetClearRefund
cleanRefund := params.NetSstoreResetRefund

if hasEIP2200 {
resetClearRefund = params.SstoreInitRefundEIP2200
cleanRefund = params.SstoreCleanRefundEIP2200
}

if original == current {
if original == (common.Hash{}) { // create slot (2.1.1)
return evmc.StorageAdded
Expand All @@ -154,9 +164,9 @@ func (host *hostContext) SetStorage(addr common.Address, key common.Hash, value
}
if original == value {
if original == (common.Hash{}) { // reset to original inexistent slot (2.2.2.1)
host.env.StateDB.AddRefund(params.NetSstoreResetClearRefund)
host.env.StateDB.AddRefund(resetClearRefund)
} else { // reset to original existing slot (2.2.2.2)
host.env.StateDB.AddRefund(params.NetSstoreResetRefund)
host.env.StateDB.AddRefund(cleanRefund)
}
}
return evmc.StorageModifiedAgain
Expand Down Expand Up @@ -198,7 +208,8 @@ func (host *hostContext) GetTxContext() evmc.TxContext {
Number: host.env.BlockNumber.Int64(),
Timestamp: host.env.Time.Int64(),
GasLimit: int64(host.env.GasLimit),
Difficulty: common.BigToHash(host.env.Difficulty)}
Difficulty: common.BigToHash(host.env.Difficulty),
ChainID: common.BigToHash(host.env.chainConfig.ChainID)}
}

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

0 comments on commit 769e062

Please sign in to comment.