aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/vm.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-10-20 19:36:29 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2016-11-13 17:44:04 +0800
commit445feaeef58bd89a113743dccf6fd5df55cde6fa (patch)
tree6c692a0989800f005a94bde2d372fcbe1f7630a1 /core/vm/vm.go
parent932d973e36ff0d41a6005b93d2d4ff1b4430fb04 (diff)
downloadgo-tangerine-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.gz
go-tangerine-445feaeef58bd89a113743dccf6fd5df55cde6fa.tar.zst
go-tangerine-445feaeef58bd89a113743dccf6fd5df55cde6fa.zip
core, core/state, trie: EIP158, reprice & skip empty account write
This commit implements EIP158 part 1, 2, 3 & 4 1. If an account is empty it's no longer written to the trie. An empty account is defined as (balance=0, nonce=0, storage=0, code=0). 2. Delete an empty account if it's touched 3. An empty account is redefined as either non-existent or empty. 4. Zero value calls and zero value suicides no longer consume the 25k reation costs. params: moved core/config to params Signed-off-by: Jeffrey Wilcke <jeffrey@ethereum.org>
Diffstat (limited to 'core/vm/vm.go')
-rw-r--r--core/vm/vm.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/core/vm/vm.go b/core/vm/vm.go
index 09cddc2f8..6e316acda 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -51,9 +51,9 @@ type EVM struct {
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,
- gasTable: env.RuleSet().GasTable(env.BlockNumber()),
+ gasTable: env.ChainConfig().GasTable(env.BlockNumber()),
}
}
@@ -172,6 +172,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 {
@@ -254,10 +255,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)
}
}
@@ -378,12 +389,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])