diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-06-24 01:19:33 +0800 |
commit | 72e2613a9fe3205fa5a67b72b832e03b2357ee88 (patch) | |
tree | bbc987510d279d9e174ff8f684158d668131661e /core/vm/vm.go | |
parent | 5daf8729be88eca87b302ebf7a46fc69cad0f6d0 (diff) | |
parent | 67e6f74e9af00ff011a6a02f18644804eb18cdaa (diff) | |
download | dexon-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar dexon-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.gz dexon-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.bz2 dexon-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.lz dexon-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.xz dexon-72e2613a9fe3205fa5a67b72b832e03b2357ee88.tar.zst dexon-72e2613a9fe3205fa5a67b72b832e03b2357ee88.zip |
Merge branch 'release/0.9.32'
Diffstat (limited to 'core/vm/vm.go')
-rw-r--r-- | core/vm/vm.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/core/vm/vm.go b/core/vm/vm.go index c5ad761f6..9e092300d 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,11 +686,16 @@ 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 { + + // 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 - } else if len(val) > 0 && len(y.Bytes()) == 0 { - statedb.Refund(self.env.Origin(), params.SstoreRefundGas) + } else if !common.EmptyHash(val) && common.EmptyHash(common.BigToHash(y)) { + statedb.Refund(params.SstoreRefundGas) g = params.SstoreClearGas } else { @@ -700,7 +705,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)) |