diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-15 15:31:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-15 15:31:29 +0800 |
commit | 9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2 (patch) | |
tree | c3dbd1b33acc3f57ecdc43acd707d511a6191104 /core/vm/evm.go | |
parent | 2403656373f1250e3668227bd9fc94e6e95412b9 (diff) | |
parent | f8d8b56b280dd921436fb046dbcaa010ef43122d (diff) | |
download | dexon-9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2.tar dexon-9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2.tar.gz dexon-9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2.tar.bz2 dexon-9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2.tar.lz dexon-9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2.tar.xz dexon-9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2.tar.zst dexon-9facf6423dbd38ebd7fbd9069cbcb98b0fd243c2.zip |
Merge pull request #14959 from karalabe/metropolis-precompiles
core/vm: metropolis precompiles
Diffstat (limited to 'core/vm/evm.go')
-rw-r--r-- | core/vm/evm.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/core/vm/evm.go b/core/vm/evm.go index 9296cc7ca..b8af9bd15 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -36,12 +36,14 @@ type ( // run runs the given contract and takes care of running precompiles with a fallback to the byte code interpreter. func run(evm *EVM, snapshot int, contract *Contract, input []byte) ([]byte, error) { if contract.CodeAddr != nil { - precompiledContracts := PrecompiledContracts - if p := precompiledContracts[*contract.CodeAddr]; p != nil { + precompiles := PrecompiledContractsHomestead + if evm.ChainConfig().IsMetropolis(evm.BlockNumber) { + precompiles = PrecompiledContractsMetropolis + } + if p := precompiles[*contract.CodeAddr]; p != nil { return RunPrecompiledContract(p, input, contract) } } - return evm.interpreter.Run(snapshot, contract, input) } @@ -100,8 +102,8 @@ type EVM struct { abort int32 } -// NewEVM retutrns a new EVM evmironment. The returned EVM is not thread safe -// and should only ever be used *once*. +// NewEVM retutrns a new EVM . The returned EVM is not thread safe and should +// only ever be used *once*. func NewEVM(ctx Context, statedb StateDB, chainConfig *params.ChainConfig, vmConfig Config) *EVM { evm := &EVM{ Context: ctx, @@ -143,10 +145,13 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas snapshot = evm.StateDB.Snapshot() ) if !evm.StateDB.Exist(addr) { - if PrecompiledContracts[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 { + precompiles := PrecompiledContractsHomestead + if evm.ChainConfig().IsMetropolis(evm.BlockNumber) { + precompiles = PrecompiledContractsMetropolis + } + if precompiles[addr] == nil && evm.ChainConfig().IsEIP158(evm.BlockNumber) && value.Sign() == 0 { return nil, gas, nil } - evm.StateDB.CreateAccount(addr) } evm.Transfer(evm.StateDB, caller.Address(), to.Address(), value) |