From 5721fcf668f8ab798b6602dc6ff88726bf0c8f86 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 17 Jun 2015 10:20:33 +0200 Subject: core/state, core/vm: cleanup refunds --- core/vm/vm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'core/vm') diff --git a/core/vm/vm.go b/core/vm/vm.go index c5ad761f6..0486fbbc7 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -690,7 +690,7 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo // 0 => non 0 g = params.SstoreSetGas } else if len(val) > 0 && len(y.Bytes()) == 0 { - statedb.Refund(self.env.Origin(), params.SstoreRefundGas) + statedb.Refund(params.SstoreRefundGas) g = params.SstoreClearGas } else { @@ -700,7 +700,7 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo gas.Set(g) case SUICIDE: if !statedb.IsDeleted(context.Address()) { - statedb.Refund(self.env.Origin(), params.SuicideRefundGas) + statedb.Refund(params.SuicideRefundGas) } case MLOAD: newMemSize = calcMemSize(stack.peek(), u256(32)) -- cgit v1.2.3 From 787a61bb27b9f51f4af67c69eb8f1c5869ae3144 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 17 Jun 2015 11:24:40 +0200 Subject: core/state, core/vm: reworked storage get / set to use common.Hash --- core/vm/vm.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'core/vm') diff --git a/core/vm/vm.go b/core/vm/vm.go index 0486fbbc7..336f6cf95 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -506,14 +506,14 @@ func (self *Vm) Run(context *Context, input []byte) (ret []byte, err error) { case SLOAD: loc := common.BigToHash(stack.pop()) - val := common.Bytes2Big(statedb.GetState(context.Address(), loc)) + val := statedb.GetState(context.Address(), loc).Big() stack.push(val) case SSTORE: loc := common.BigToHash(stack.pop()) val := stack.pop() - statedb.SetState(context.Address(), loc, val) + statedb.SetState(context.Address(), loc, common.BigToHash(val)) case JUMP: if err := jump(pc, stack.pop()); err != nil { @@ -686,10 +686,10 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo var g *big.Int y, x := stack.data[stack.len()-2], stack.data[stack.len()-1] val := statedb.GetState(context.Address(), common.BigToHash(x)) - if len(val) == 0 && len(y.Bytes()) > 0 { + if common.EmptyHash(val) && !common.EmptyHash(common.BigToHash(y)) { // 0 => non 0 g = params.SstoreSetGas - } else if len(val) > 0 && len(y.Bytes()) == 0 { + } else if !common.EmptyHash(val) && common.EmptyHash(common.BigToHash(y)) { statedb.Refund(params.SstoreRefundGas) g = params.SstoreClearGas @@ -697,6 +697,13 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo // non 0 => non 0 (or 0 => 0) g = params.SstoreClearGas } + + /* + if len(val) == 0 && len(y.Bytes()) > 0 { + } else if len(val) > 0 && len(y.Bytes()) == 0 { + } else { + } + */ gas.Set(g) case SUICIDE: if !statedb.IsDeleted(context.Address()) { -- cgit v1.2.3 From 753d62a4ddd974a1410b1ed3ee92a30115a1e0df Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 17 Jun 2015 14:14:17 +0200 Subject: core: TMP testing code --- core/vm/context.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'core/vm') diff --git a/core/vm/context.go b/core/vm/context.go index e33324b53..56e8f925a 100644 --- a/core/vm/context.go +++ b/core/vm/context.go @@ -26,16 +26,25 @@ type Context struct { Args []byte } +var dests destinations + +func init() { + dests = make(destinations) +} + // Create a new context for the given data items. func NewContext(caller ContextRef, object ContextRef, value, gas, price *big.Int) *Context { c := &Context{caller: caller, self: object, Args: nil} - if parent, ok := caller.(*Context); ok { - // Reuse JUMPDEST analysis from parent context if available. - c.jumpdests = parent.jumpdests - } else { - c.jumpdests = make(destinations) - } + /* + if parent, ok := caller.(*Context); ok { + // Reuse JUMPDEST analysis from parent context if available. + c.jumpdests = parent.jumpdests + } else { + c.jumpdests = make(destinations) + } + */ + c.jumpdests = dests // Gas should be a pointer so it can safely be reduced through the run // This pointer will be off the state transition -- cgit v1.2.3 From f5abc9f188fb684e3601314b8ae454ac5abbf0e9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 17 Jun 2015 17:09:39 +0200 Subject: core, core/vm: state improvements and tx pool speed up Removed full tx validation during state transitions --- core/vm/context.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'core/vm') diff --git a/core/vm/context.go b/core/vm/context.go index 56e8f925a..e33324b53 100644 --- a/core/vm/context.go +++ b/core/vm/context.go @@ -26,25 +26,16 @@ type Context struct { Args []byte } -var dests destinations - -func init() { - dests = make(destinations) -} - // Create a new context for the given data items. func NewContext(caller ContextRef, object ContextRef, value, gas, price *big.Int) *Context { c := &Context{caller: caller, self: object, Args: nil} - /* - if parent, ok := caller.(*Context); ok { - // Reuse JUMPDEST analysis from parent context if available. - c.jumpdests = parent.jumpdests - } else { - c.jumpdests = make(destinations) - } - */ - c.jumpdests = dests + if parent, ok := caller.(*Context); ok { + // Reuse JUMPDEST analysis from parent context if available. + c.jumpdests = parent.jumpdests + } else { + c.jumpdests = make(destinations) + } // Gas should be a pointer so it can safely be reduced through the run // This pointer will be off the state transition -- cgit v1.2.3 From 430bcdb21959e018fbc93bac0ccd8bbfa2fd5afb Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 18 Jun 2015 12:25:02 +0200 Subject: core/vm: clarified SSTORE --- core/vm/vm.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'core/vm') diff --git a/core/vm/vm.go b/core/vm/vm.go index 336f6cf95..9e092300d 100644 --- a/core/vm/vm.go +++ b/core/vm/vm.go @@ -686,6 +686,11 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo var g *big.Int y, x := stack.data[stack.len()-2], stack.data[stack.len()-1] val := statedb.GetState(context.Address(), common.BigToHash(x)) + + // This checks for 3 scenario's and calculates gas accordingly + // 1. From a zero-value address to a non-zero value (NEW VALUE) + // 2. From a non-zero value address to a zero-value address (DELETE) + // 3. From a nen-zero to a non-zero (CHANGE) if common.EmptyHash(val) && !common.EmptyHash(common.BigToHash(y)) { // 0 => non 0 g = params.SstoreSetGas @@ -697,13 +702,6 @@ func (self *Vm) calculateGasAndSize(context *Context, caller ContextRef, op OpCo // non 0 => non 0 (or 0 => 0) g = params.SstoreClearGas } - - /* - if len(val) == 0 && len(y.Bytes()) > 0 { - } else if len(val) > 0 && len(y.Bytes()) == 0 { - } else { - } - */ gas.Set(g) case SUICIDE: if !statedb.IsDeleted(context.Address()) { -- cgit v1.2.3