aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-24 22:15:17 +0800
committerobscuren <geffobscura@gmail.com>2015-03-24 22:15:17 +0800
commit23bccbbc587aa22057eb7ae29c5b87d44b7cac7d (patch)
tree70e03dcff049ebbca32dc34c53881cf6b9e20a7c
parentbbe795455a13c57dbba64c1082b618e791af46ce (diff)
downloadgo-tangerine-23bccbbc587aa22057eb7ae29c5b87d44b7cac7d.tar
go-tangerine-23bccbbc587aa22057eb7ae29c5b87d44b7cac7d.tar.gz
go-tangerine-23bccbbc587aa22057eb7ae29c5b87d44b7cac7d.tar.bz2
go-tangerine-23bccbbc587aa22057eb7ae29c5b87d44b7cac7d.tar.lz
go-tangerine-23bccbbc587aa22057eb7ae29c5b87d44b7cac7d.tar.xz
go-tangerine-23bccbbc587aa22057eb7ae29c5b87d44b7cac7d.tar.zst
go-tangerine-23bccbbc587aa22057eb7ae29c5b87d44b7cac7d.zip
Modified according to poc 9 changes
* Refund of value
-rw-r--r--core/execution.go10
-rw-r--r--core/state_transition.go2
-rw-r--r--core/vm/environment.go2
-rw-r--r--tests/helper/vm.go2
-rw-r--r--tests/vm/gh_test.go9
5 files changed, 16 insertions, 9 deletions
diff --git a/core/execution.go b/core/execution.go
index 893b79dc7..72eb22bd5 100644
--- a/core/execution.go
+++ b/core/execution.go
@@ -39,20 +39,22 @@ func (self *Execution) exec(contextAddr *common.Address, code []byte, caller vm.
return nil, vm.DepthError{}
}
- snapshot := env.State().Copy()
+ vsnapshot := env.State().Copy()
if self.address == nil {
// Generate a new address
nonce := env.State().GetNonce(caller.Address())
addr := crypto.CreateAddress(caller.Address(), nonce)
- self.address = &addr
env.State().SetNonce(caller.Address(), nonce+1)
+ self.address = &addr
}
+ snapshot := env.State().Copy()
from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(*self.address)
err = env.Transfer(from, to, self.value)
if err != nil {
- env.State().Set(snapshot)
- //caller.ReturnGas(self.Gas, self.price)
+ env.State().Set(vsnapshot)
+
+ caller.ReturnGas(self.Gas, self.price)
return nil, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance())
}
diff --git a/core/state_transition.go b/core/state_transition.go
index d46838d02..6312dee88 100644
--- a/core/state_transition.go
+++ b/core/state_transition.go
@@ -196,7 +196,6 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
}
// Increment the nonce for the next transaction
- self.state.SetNonce(sender.Address(), sender.Nonce()+1)
vmenv := self.env
var ref vm.ContextRef
@@ -214,6 +213,7 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
}
}
} else {
+ self.state.SetNonce(sender.Address(), sender.Nonce()+1)
ret, err = vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
}
diff --git a/core/vm/environment.go b/core/vm/environment.go
index a0a18a99b..6c5202185 100644
--- a/core/vm/environment.go
+++ b/core/vm/environment.go
@@ -7,8 +7,8 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/core/state"
+ "github.com/ethereum/go-ethereum/rlp"
)
type Environment interface {
diff --git a/tests/helper/vm.go b/tests/helper/vm.go
index 68ae8e97b..b4318d161 100644
--- a/tests/helper/vm.go
+++ b/tests/helper/vm.go
@@ -6,9 +6,9 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"
+ "github.com/ethereum/go-ethereum/crypto"
)
type Env struct {
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index 123e8ccb5..cd5684dd4 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -7,10 +7,10 @@ import (
"testing"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/tests/helper"
)
@@ -144,6 +144,11 @@ func RunVmTest(p string, t *testing.T) {
if obj.Balance().Cmp(common.Big(account.Balance)) != 0 {
t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address().Bytes()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(common.Big(account.Balance), obj.Balance()))
}
+
+ if obj.Nonce() != common.String2Big(account.Nonce).Uint64() {
+ t.Errorf("%s's : (%x) nonce failed. Expected %v, got %v\n", name, obj.Address().Bytes()[:4], account.Nonce, obj.Nonce())
+ }
+
}
for addr, value := range account.Storage {
@@ -194,7 +199,7 @@ func RunVmTest(p string, t *testing.T) {
}
}
}
- //statedb.Trie().PrintRoot()
+ //fmt.Println(string(statedb.Dump()))
}
logger.Flush()
}