aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-18 00:05:46 +0800
committerobscuren <geffobscura@gmail.com>2014-06-18 00:05:46 +0800
commit34c8045d5be6488e9800c24e1e696e1b912f344c (patch)
tree322b1500e7e02b5fa5b2fab094605e433fdb6796
parenta90ffe1af1b28935fc77a2c5cf37972bac03f062 (diff)
downloadgo-tangerine-34c8045d5be6488e9800c24e1e696e1b912f344c.tar
go-tangerine-34c8045d5be6488e9800c24e1e696e1b912f344c.tar.gz
go-tangerine-34c8045d5be6488e9800c24e1e696e1b912f344c.tar.bz2
go-tangerine-34c8045d5be6488e9800c24e1e696e1b912f344c.tar.lz
go-tangerine-34c8045d5be6488e9800c24e1e696e1b912f344c.tar.xz
go-tangerine-34c8045d5be6488e9800c24e1e696e1b912f344c.tar.zst
go-tangerine-34c8045d5be6488e9800c24e1e696e1b912f344c.zip
Fixed issue where JUMPI would do an equally check with 1 instead of GT
-rw-r--r--ethchain/state.go2
-rw-r--r--ethchain/state_transition.go22
-rw-r--r--ethchain/transaction.go2
-rw-r--r--ethchain/vm.go14
-rw-r--r--ethutil/trie_test.go41
5 files changed, 47 insertions, 34 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index 993f1fb08..616ab77e0 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -120,6 +120,8 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
}
func (self *State) NewStateObject(addr []byte) *StateObject {
+ ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "(+) %x\n", addr)
+
stateObject := NewStateObject(addr)
self.stateObjects[string(addr)] = stateObject
diff --git a/ethchain/state_transition.go b/ethchain/state_transition.go
index 23175b0f3..dc465bbbd 100644
--- a/ethchain/state_transition.go
+++ b/ethchain/state_transition.go
@@ -97,7 +97,6 @@ func (self *StateTransition) BuyGas() error {
if err != nil {
return err
}
- //self.state.UpdateStateObject(coinbase)
self.AddGas(self.tx.Gas)
sender.SubAmount(self.tx.GasValue())
@@ -115,7 +114,7 @@ func (self *StateTransition) RefundGas() {
}
func (self *StateTransition) TransitionState() (err error) {
- //snapshot := st.state.Snapshot()
+ ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "(~) %x\n", self.tx.Hash())
/*
defer func() {
@@ -132,8 +131,6 @@ func (self *StateTransition) TransitionState() (err error) {
receiver *StateObject
)
- ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "(~) %x\n", tx.Hash())
-
// Make sure this transaction's nonce is correct
if sender.Nonce != tx.Nonce {
return NonceError(tx.Nonce, sender.Nonce)
@@ -146,26 +143,11 @@ func (self *StateTransition) TransitionState() (err error) {
// XXX Transactions after this point are considered valid.
- defer func() {
- self.RefundGas()
-
- /*
- if sender != nil {
- self.state.UpdateStateObject(sender)
- }
-
- if receiver != nil {
- self.state.UpdateStateObject(receiver)
- }
-
- self.state.UpdateStateObject(self.Coinbase())
- */
- }()
+ defer self.RefundGas()
// Increment the nonce for the next transaction
sender.Nonce += 1
- // Get the receiver (TODO fix this, if coinbase is the receiver we need to save/retrieve)
receiver = self.Receiver()
// Transaction gas
diff --git a/ethchain/transaction.go b/ethchain/transaction.go
index 3d52e4f73..9044f586e 100644
--- a/ethchain/transaction.go
+++ b/ethchain/transaction.go
@@ -65,7 +65,7 @@ func (tx *Transaction) CreatesContract() bool {
return tx.contractCreation
}
-/* Depricated */
+/* Deprecated */
func (tx *Transaction) IsContract() bool {
return tx.CreatesContract()
}
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 77a08faa6..690433180 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -120,7 +120,9 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
var newMemSize uint64 = 0
switch op {
case STOP:
+ gas.Set(ethutil.Big0)
case SUICIDE:
+ gas.Set(ethutil.Big0)
case SLOAD:
gas.Set(GasSLoad)
case SSTORE:
@@ -296,6 +298,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case EQ:
require(2)
x, y := stack.Popn()
+ fmt.Printf("%x == %x\n", x, y)
// x == y
if x.Cmp(y) == 0 {
stack.Push(ethutil.BigTrue)
@@ -365,12 +368,14 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
offset := stack.Pop().Int64()
var data []byte
- if len(closure.Args) >= int(offset+32) {
- data = closure.Args[offset : offset+32]
+ if len(closure.Args) >= int(offset) {
+ l := int64(math.Min(float64(offset+32), float64(len(closure.Args))))
+ data = closure.Args[offset : offset+l]
} else {
data = []byte{0}
}
+ fmt.Println("CALLDATALOAD", string(data), len(data), "==", len(closure.Args))
stack.Push(ethutil.BigD(data))
case CALLDATASIZE:
stack.Push(big.NewInt(int64(len(closure.Args))))
@@ -452,12 +457,11 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
require(1)
loc := stack.Pop()
val := closure.GetMem(loc)
- //fmt.Println("get", val.BigInt(), "@", loc)
stack.Push(val.BigInt())
case SSTORE:
require(2)
val, loc := stack.Popn()
- //fmt.Println("storing", val, "@", loc)
+ fmt.Println("storing", string(val.Bytes()), "@", string(loc.Bytes()))
closure.SetStorage(loc, ethutil.NewValue(val))
// Add the change to manifest
@@ -471,7 +475,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case JUMPI:
require(2)
cond, pos := stack.Popn()
- if cond.Cmp(ethutil.BigTrue) == 0 {
+ if cond.Cmp(ethutil.BigTrue) >= 0 {
pc = pos
//pc.Sub(pc, ethutil.Big1)
continue
diff --git a/ethutil/trie_test.go b/ethutil/trie_test.go
index c89f2fbb7..15dbc5567 100644
--- a/ethutil/trie_test.go
+++ b/ethutil/trie_test.go
@@ -1,7 +1,12 @@
package ethutil
import (
+ "bytes"
+ "encoding/json"
"fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
"reflect"
"testing"
)
@@ -171,14 +176,34 @@ func TestTriePurge(t *testing.T) {
}
}
+type TestItem struct {
+ Name string
+ Inputs [][]string
+ Expectations string
+}
+
func TestTrieIt(t *testing.T) {
- _, trie := New()
- trie.Update("c", LONG_WORD)
- trie.Update("ca", LONG_WORD)
- trie.Update("cat", LONG_WORD)
+ //_, trie := New()
+ resp, err := http.Get("https://raw.githubusercontent.com/ethereum/tests/master/trietest.json")
+ if err != nil {
+ t.Fail()
+ }
- it := trie.NewIterator()
- it.Each(func(key string, node *Value) {
- fmt.Println(key, ":", node.Str())
- })
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ t.Fail()
+ }
+
+ dec := json.NewDecoder(bytes.NewReader(body))
+ for {
+ var test TestItem
+ if err := dec.Decode(&test); err == io.EOF {
+ break
+ } else if err != nil {
+ t.Error("Fail something", err)
+ break
+ }
+ fmt.Println(test)
+ }
}