aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-01 02:03:31 +0800
committerobscuren <geffobscura@gmail.com>2014-07-01 02:03:31 +0800
commited276cd7c241749a9cf8add4e2fae3d3608a7ea4 (patch)
tree40416177aeac9874e0eecdb7194db9bc13e39174 /ethchain
parent82272ee08a7d72be1cc0947b6a0e8096a0353362 (diff)
downloadgo-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.gz
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.bz2
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.lz
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.xz
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.tar.zst
go-tangerine-ed276cd7c241749a9cf8add4e2fae3d3608a7ea4.zip
Added Paranoia check for VM execution
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/state.go81
-rw-r--r--ethchain/state_manager.go8
-rw-r--r--ethchain/state_test.go4
-rw-r--r--ethchain/state_transition.go33
-rw-r--r--ethchain/vm_test.go8
5 files changed, 26 insertions, 108 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index e28b91909..51d86fe2a 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -204,84 +204,3 @@ func (m *Manifest) AddStorageChange(stateObject *StateObject, storageAddr []byte
m.storageChanges[string(stateObject.Address())][string(storageAddr)] = storage
}
-
-/*
-
-// Resets the trie and all siblings
-func (s *State) Reset() {
- s.trie.Undo()
-
- // Reset all nested states
- for _, state := range s.states {
- state.Reset()
- }
-}
-
-// Syncs the trie and all siblings
-func (s *State) Sync() {
- // Sync all nested states
- for _, state := range s.states {
- state.Sync()
- }
-
- s.trie.Sync()
-}
-func (s *State) GetStateObject(addr []byte) *StateObject {
- data := s.trie.Get(string(addr))
- if data == "" {
- return nil
- }
-
- stateObject := NewStateObjectFromBytes(addr, []byte(data))
-
- // Check if there's a cached state for this contract
- cachedStateObject := s.states[string(addr)]
- if cachedStateObject != nil {
- //fmt.Printf("get cached #%d %x addr: %x\n", cachedStateObject.trie.Cache().Len(), cachedStateObject.Root(), addr[0:4])
- stateObject.state = cachedStateObject
- }
-
- return stateObject
-}
-
-// Updates any given state object
-func (s *State) UpdateStateObject(object *StateObject) {
- addr := object.Address()
-
- if object.state != nil && s.states[string(addr)] == nil {
- s.states[string(addr)] = object.state
- }
-
- ethutil.Config.Db.Put(ethutil.Sha3Bin(object.Script()), object.Script())
-
- s.trie.Update(string(addr), string(object.RlpEncode()))
-
- s.manifest.AddObjectChange(object)
-}
-
-func (s *State) GetAccount(addr []byte) (account *StateObject) {
- data := s.trie.Get(string(addr))
- if data == "" {
- account = NewAccount(addr, big.NewInt(0))
- } else {
- account = NewStateObjectFromBytes(addr, []byte(data))
- }
-
- // Check if there's a cached state for this contract
- cachedStateObject := s.states[string(addr)]
- if cachedStateObject != nil {
- account.state = cachedStateObject
- }
-
- return
-}
-
-func (s *State) Copy() *State {
- state := NewState(s.trie.Copy())
- for k, subState := range s.states {
- state.states[k] = subState.Copy()
- }
-
- return state
-}
-*/
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index 48c6401e3..363aa3da7 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -123,7 +123,8 @@ done:
break done
default:
- statelogger.Infoln(err)
+ //statelogger.Infoln(err)
+ return nil, nil, nil, err
}
}
@@ -236,7 +237,10 @@ func (sm *StateManager) ApplyDiff(state *State, parent, block *Block) (receipts
coinbase.SetGasPool(block.CalcGasLimit(parent))
// Process the transactions on to current block
- receipts, _, _, _ = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
+ receipts, _, _, err = sm.ProcessTransactions(coinbase, state, block, parent, block.Transactions())
+ if err != nil {
+ return nil, err
+ }
return receipts, nil
}
diff --git a/ethchain/state_test.go b/ethchain/state_test.go
index 503bdddb4..95be0f373 100644
--- a/ethchain/state_test.go
+++ b/ethchain/state_test.go
@@ -16,12 +16,12 @@ func TestSnapshot(t *testing.T) {
state.UpdateStateObject(stateObject)
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))
- snapshot := state.Snapshot()
+ snapshot := state.Copy()
stateObject = state.GetStateObject([]byte("aa"))
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))
- state.Revert(snapshot)
+ state.Set(snapshot)
stateObject = state.GetStateObject([]byte("aa"))
if !stateObject.GetStorage(ethutil.Big("0")).Cmp(ethutil.NewValue(42)) {
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go
index 4b4cbeb51..b18091691 100644
--- a/ethchain/state_transition.go
+++ b/ethchain/state_transition.go
@@ -226,20 +226,14 @@ func (self *StateTransition) transferValue(sender, receiver *StateObject) error
return fmt.Errorf("Insufficient funds to transfer value. Req %v, has %v", self.value, sender.Amount)
}
- //if self.value.Cmp(ethutil.Big0) > 0 {
// Subtract the amount from the senders account
sender.SubAmount(self.value)
// Add the amount to receivers account which should conclude this transaction
receiver.AddAmount(self.value)
- //statelogger.Debugf("%x => %x (%v)\n", sender.Address()[:4], receiver.Address()[:4], self.value)
- //}
-
return nil
}
-var testAddr = ethutil.FromHex("ec4f34c97e43fbb2816cfd95e388353c7181dab1")
-
func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []byte, err error, deepErr bool) {
var (
block = self.block
@@ -263,6 +257,7 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
deepErr = vm.err != nil
/*
+ var testAddr = ethutil.FromHex("ec4f34c97e43fbb2816cfd95e388353c7181dab1")
if bytes.Compare(testAddr, context.Address()) == 0 {
trie := context.state.trie
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
@@ -273,7 +268,7 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
}
*/
- Paranoia := true
+ Paranoia := true // TODO Create a flag for this
if Paranoia {
var (
trie = context.state.trie
@@ -287,17 +282,19 @@ func (self *StateTransition) Eval(script []byte, context *StateObject) (ret []by
a := ethutil.NewValue(trie2.Root).Bytes()
b := ethutil.NewValue(context.state.trie.Root).Bytes()
if bytes.Compare(a, b) != 0 {
- fmt.Printf("original: %x\n", trie.Root)
- trie.NewIterator().Each(func(key string, v *ethutil.Value) {
- v.Decode()
- fmt.Printf("%x : %x\n", key, v.Str())
- })
-
- fmt.Printf("new: %x\n", trie2.Root)
- trie2.NewIterator().Each(func(key string, v *ethutil.Value) {
- v.Decode()
- fmt.Printf("%x : %x\n", key, v.Str())
- })
+ /*
+ statelogger.Debugf("(o): %x\n", trie.Root)
+ trie.NewIterator().Each(func(key string, v *ethutil.Value) {
+ v.Decode()
+ statelogger.Debugf("%x : %x\n", key, v.Str())
+ })
+
+ statelogger.Debugf("(c): %x\n", trie2.Root)
+ trie2.NewIterator().Each(func(key string, v *ethutil.Value) {
+ v.Decode()
+ statelogger.Debugf("%x : %x\n", key, v.Str())
+ })
+ */
return nil, fmt.Errorf("PARANOIA: Different state object roots during copy"), false
}
diff --git a/ethchain/vm_test.go b/ethchain/vm_test.go
index c569d89ae..c8023cd79 100644
--- a/ethchain/vm_test.go
+++ b/ethchain/vm_test.go
@@ -5,9 +5,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
- "github.com/obscuren/mutan"
"math/big"
- "strings"
"testing"
)
@@ -17,7 +15,7 @@ func TestRun4(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
state := NewState(ethutil.NewTrie(db, ""))
- callerScript, err := mutan.Compile(strings.NewReader(`
+ callerScript, err := ethutil.Compile(`
this.store[this.origin()] = 10**20
hello := "world"
@@ -31,7 +29,7 @@ func TestRun4(t *testing.T) {
this.store[to] = this.store[to] + value
}
}
- `), false)
+ `)
if err != nil {
fmt.Println(err)
}
@@ -55,7 +53,7 @@ func TestRun4(t *testing.T) {
vm := NewVm(state, nil, RuntimeVars{
Origin: account.Address(),
- BlockNumber: 1,
+ BlockNumber: big.NewInt(1),
PrevHash: ethutil.FromHex("5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6"),
Coinbase: ethutil.FromHex("2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"),
Time: 1,