aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/vm.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-11-15 20:46:47 +0800
committerGitHub <noreply@github.com>2016-11-15 20:46:47 +0800
commit81d9d7d38555a63602b9da3d07955ad4e5a62f02 (patch)
tree9ce0d55bfe182f6493867ea5497bf2c8cd9e8523 /core/vm/vm.go
parentef9265d0d7abf6614c1d2fb977989ab0d400a590 (diff)
parent822355f8a6e8826561433392fd94a8bde7e4dbf3 (diff)
downloadgo-tangerine-1.4.19.tar
go-tangerine-1.4.19.tar.gz
go-tangerine-1.4.19.tar.bz2
go-tangerine-1.4.19.tar.lz
go-tangerine-1.4.19.tar.xz
go-tangerine-1.4.19.tar.zst
go-tangerine-1.4.19.zip
Merge pull request #3252 from obscuren/release/1.4v1.4.19
1.4 HF
Diffstat (limited to 'core/vm/vm.go')
-rw-r--r--core/vm/vm.go35
1 files changed, 28 insertions, 7 deletions
diff --git a/core/vm/vm.go b/core/vm/vm.go
index a73dfc811..1c2229be5 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -57,10 +57,10 @@ func New(env Environment, cfg Config) *EVM {
return &EVM{
env: env,
- jumpTable: newJumpTable(env.RuleSet(), env.BlockNumber()),
+ jumpTable: newJumpTable(env.ChainConfig(), env.BlockNumber()),
cfg: cfg,
logger: logger,
- gasTable: env.RuleSet().GasTable(env.BlockNumber()),
+ gasTable: env.ChainConfig().GasTable(env.BlockNumber()),
}
}
@@ -177,6 +177,7 @@ func (evm *EVM) Run(contract *Contract, input []byte) (ret []byte, err error) {
// Get the memory location of pc
op = contract.GetOp(pc)
+ //fmt.Printf("OP %d %v\n", op, op)
// calculate the new memory size and gas price for the current executing opcode
newMemSize, cost, err = calculateGasAndSize(evm.gasTable, evm.env, contract, caller, op, statedb, mem, stack)
if err != nil {
@@ -256,10 +257,20 @@ func calculateGasAndSize(gasTable params.GasTable, env Environment, contract *Co
// stack Check, memory resize & gas phase
switch op {
case SUICIDE:
- // if suicide is not nil: homestead gas fork
+ // EIP150 homestead gas reprice fork:
if gasTable.CreateBySuicide != nil {
gas.Set(gasTable.Suicide)
- if !env.Db().Exist(common.BigToAddress(stack.data[len(stack.data)-1])) {
+ var (
+ address = common.BigToAddress(stack.data[len(stack.data)-1])
+ eip158 = env.ChainConfig().IsEIP158(env.BlockNumber())
+ )
+
+ if eip158 {
+ // if empty and transfers value
+ if env.Db().Empty(address) && statedb.GetBalance(contract.Address()).BitLen() > 0 {
+ gas.Add(gas, gasTable.CreateBySuicide)
+ }
+ } else if !env.Db().Exist(address) {
gas.Add(gas, gasTable.CreateBySuicide)
}
}
@@ -304,7 +315,8 @@ func calculateGasAndSize(gasTable params.GasTable, env Environment, contract *Co
quadMemGas(mem, newMemSize, gas)
case EXP:
- gas.Add(gas, new(big.Int).Mul(big.NewInt(int64(len(stack.data[stack.len()-2].Bytes()))), params.ExpByteGas))
+ expByteLen := int64((stack.data[stack.len()-2].BitLen() + 7) / 8)
+ gas.Add(gas, new(big.Int).Mul(big.NewInt(expByteLen), gasTable.ExpByte))
case SSTORE:
err := stack.require(2)
if err != nil {
@@ -380,12 +392,21 @@ func calculateGasAndSize(gasTable params.GasTable, env Environment, contract *Co
case CALL, CALLCODE:
gas.Set(gasTable.Calls)
+ transfersValue := stack.data[len(stack.data)-3].BitLen() > 0
if op == CALL {
- if !env.Db().Exist(common.BigToAddress(stack.data[stack.len()-2])) {
+ var (
+ address = common.BigToAddress(stack.data[len(stack.data)-2])
+ eip158 = env.ChainConfig().IsEIP158(env.BlockNumber())
+ )
+ if eip158 {
+ if env.Db().Empty(address) && transfersValue {
+ gas.Add(gas, params.CallNewAccountGas)
+ }
+ } else if !env.Db().Exist(address) {
gas.Add(gas, params.CallNewAccountGas)
}
}
- if len(stack.data[stack.len()-3].Bytes()) > 0 {
+ if transfersValue {
gas.Add(gas, params.CallValueTransferGas)
}
x := calcMemSize(stack.data[stack.len()-6], stack.data[stack.len()-7])