diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-10 21:39:43 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-08-14 20:27:44 +0800 |
commit | 6131dd55c5cb6f964a1b8e8d51400f10d545a92e (patch) | |
tree | 3ac0b6667e5e2afbad8f7f5a528bc78f2517e78d /core/vm/evm.go | |
parent | 7bbdf3e2687ea293b68a7f73c039cbde411217fa (diff) | |
download | go-tangerine-6131dd55c5cb6f964a1b8e8d51400f10d545a92e.tar go-tangerine-6131dd55c5cb6f964a1b8e8d51400f10d545a92e.tar.gz go-tangerine-6131dd55c5cb6f964a1b8e8d51400f10d545a92e.tar.bz2 go-tangerine-6131dd55c5cb6f964a1b8e8d51400f10d545a92e.tar.lz go-tangerine-6131dd55c5cb6f964a1b8e8d51400f10d545a92e.tar.xz go-tangerine-6131dd55c5cb6f964a1b8e8d51400f10d545a92e.tar.zst go-tangerine-6131dd55c5cb6f964a1b8e8d51400f10d545a92e.zip |
core/vm: polish precompile contract code, add tests and benches
* Update modexp gas calculation to new version
* Fix modexp modulo 0 special case to return zero
Diffstat (limited to 'core/vm/evm.go')
-rw-r--r-- | core/vm/evm.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/core/vm/evm.go b/core/vm/evm.go index 20eaaccb4..b8af9bd15 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -36,16 +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 + precompiles := PrecompiledContractsHomestead if evm.ChainConfig().IsMetropolis(evm.BlockNumber) { - precompiledContracts = PrecompiledContractsMetropolis + precompiles = PrecompiledContractsMetropolis } - - if p := precompiledContracts[*contract.CodeAddr]; p != nil { + if p := precompiles[*contract.CodeAddr]; p != nil { return RunPrecompiledContract(p, input, contract) } } - return evm.interpreter.Run(snapshot, contract, input) } @@ -147,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) |