forked from cerc-io/plugeth
Fixed issue where JUMPI would do an equally check with 1 instead of GT
This commit is contained in:
parent
a90ffe1af1
commit
34c8045d5b
@ -120,6 +120,8 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *State) NewStateObject(addr []byte) *StateObject {
|
func (self *State) NewStateObject(addr []byte) *StateObject {
|
||||||
|
ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "(+) %x\n", addr)
|
||||||
|
|
||||||
stateObject := NewStateObject(addr)
|
stateObject := NewStateObject(addr)
|
||||||
self.stateObjects[string(addr)] = stateObject
|
self.stateObjects[string(addr)] = stateObject
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ func (self *StateTransition) BuyGas() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
//self.state.UpdateStateObject(coinbase)
|
|
||||||
|
|
||||||
self.AddGas(self.tx.Gas)
|
self.AddGas(self.tx.Gas)
|
||||||
sender.SubAmount(self.tx.GasValue())
|
sender.SubAmount(self.tx.GasValue())
|
||||||
@ -115,7 +114,7 @@ func (self *StateTransition) RefundGas() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StateTransition) TransitionState() (err error) {
|
func (self *StateTransition) TransitionState() (err error) {
|
||||||
//snapshot := st.state.Snapshot()
|
ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "(~) %x\n", self.tx.Hash())
|
||||||
|
|
||||||
/*
|
/*
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -132,8 +131,6 @@ func (self *StateTransition) TransitionState() (err error) {
|
|||||||
receiver *StateObject
|
receiver *StateObject
|
||||||
)
|
)
|
||||||
|
|
||||||
ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "(~) %x\n", tx.Hash())
|
|
||||||
|
|
||||||
// Make sure this transaction's nonce is correct
|
// Make sure this transaction's nonce is correct
|
||||||
if sender.Nonce != tx.Nonce {
|
if sender.Nonce != tx.Nonce {
|
||||||
return NonceError(tx.Nonce, sender.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.
|
// XXX Transactions after this point are considered valid.
|
||||||
|
|
||||||
defer func() {
|
defer self.RefundGas()
|
||||||
self.RefundGas()
|
|
||||||
|
|
||||||
/*
|
|
||||||
if sender != nil {
|
|
||||||
self.state.UpdateStateObject(sender)
|
|
||||||
}
|
|
||||||
|
|
||||||
if receiver != nil {
|
|
||||||
self.state.UpdateStateObject(receiver)
|
|
||||||
}
|
|
||||||
|
|
||||||
self.state.UpdateStateObject(self.Coinbase())
|
|
||||||
*/
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Increment the nonce for the next transaction
|
// Increment the nonce for the next transaction
|
||||||
sender.Nonce += 1
|
sender.Nonce += 1
|
||||||
|
|
||||||
// Get the receiver (TODO fix this, if coinbase is the receiver we need to save/retrieve)
|
|
||||||
receiver = self.Receiver()
|
receiver = self.Receiver()
|
||||||
|
|
||||||
// Transaction gas
|
// Transaction gas
|
||||||
|
@ -65,7 +65,7 @@ func (tx *Transaction) CreatesContract() bool {
|
|||||||
return tx.contractCreation
|
return tx.contractCreation
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Depricated */
|
/* Deprecated */
|
||||||
func (tx *Transaction) IsContract() bool {
|
func (tx *Transaction) IsContract() bool {
|
||||||
return tx.CreatesContract()
|
return tx.CreatesContract()
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,9 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
|||||||
var newMemSize uint64 = 0
|
var newMemSize uint64 = 0
|
||||||
switch op {
|
switch op {
|
||||||
case STOP:
|
case STOP:
|
||||||
|
gas.Set(ethutil.Big0)
|
||||||
case SUICIDE:
|
case SUICIDE:
|
||||||
|
gas.Set(ethutil.Big0)
|
||||||
case SLOAD:
|
case SLOAD:
|
||||||
gas.Set(GasSLoad)
|
gas.Set(GasSLoad)
|
||||||
case SSTORE:
|
case SSTORE:
|
||||||
@ -296,6 +298,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
|||||||
case EQ:
|
case EQ:
|
||||||
require(2)
|
require(2)
|
||||||
x, y := stack.Popn()
|
x, y := stack.Popn()
|
||||||
|
fmt.Printf("%x == %x\n", x, y)
|
||||||
// x == y
|
// x == y
|
||||||
if x.Cmp(y) == 0 {
|
if x.Cmp(y) == 0 {
|
||||||
stack.Push(ethutil.BigTrue)
|
stack.Push(ethutil.BigTrue)
|
||||||
@ -365,12 +368,14 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
|||||||
offset := stack.Pop().Int64()
|
offset := stack.Pop().Int64()
|
||||||
|
|
||||||
var data []byte
|
var data []byte
|
||||||
if len(closure.Args) >= int(offset+32) {
|
if len(closure.Args) >= int(offset) {
|
||||||
data = closure.Args[offset : offset+32]
|
l := int64(math.Min(float64(offset+32), float64(len(closure.Args))))
|
||||||
|
data = closure.Args[offset : offset+l]
|
||||||
} else {
|
} else {
|
||||||
data = []byte{0}
|
data = []byte{0}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Println("CALLDATALOAD", string(data), len(data), "==", len(closure.Args))
|
||||||
stack.Push(ethutil.BigD(data))
|
stack.Push(ethutil.BigD(data))
|
||||||
case CALLDATASIZE:
|
case CALLDATASIZE:
|
||||||
stack.Push(big.NewInt(int64(len(closure.Args))))
|
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)
|
require(1)
|
||||||
loc := stack.Pop()
|
loc := stack.Pop()
|
||||||
val := closure.GetMem(loc)
|
val := closure.GetMem(loc)
|
||||||
//fmt.Println("get", val.BigInt(), "@", loc)
|
|
||||||
stack.Push(val.BigInt())
|
stack.Push(val.BigInt())
|
||||||
case SSTORE:
|
case SSTORE:
|
||||||
require(2)
|
require(2)
|
||||||
val, loc := stack.Popn()
|
val, loc := stack.Popn()
|
||||||
//fmt.Println("storing", val, "@", loc)
|
fmt.Println("storing", string(val.Bytes()), "@", string(loc.Bytes()))
|
||||||
closure.SetStorage(loc, ethutil.NewValue(val))
|
closure.SetStorage(loc, ethutil.NewValue(val))
|
||||||
|
|
||||||
// Add the change to manifest
|
// Add the change to manifest
|
||||||
@ -471,7 +475,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
|
|||||||
case JUMPI:
|
case JUMPI:
|
||||||
require(2)
|
require(2)
|
||||||
cond, pos := stack.Popn()
|
cond, pos := stack.Popn()
|
||||||
if cond.Cmp(ethutil.BigTrue) == 0 {
|
if cond.Cmp(ethutil.BigTrue) >= 0 {
|
||||||
pc = pos
|
pc = pos
|
||||||
//pc.Sub(pc, ethutil.Big1)
|
//pc.Sub(pc, ethutil.Big1)
|
||||||
continue
|
continue
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package ethutil
|
package ethutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -171,14 +176,34 @@ func TestTriePurge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrieIt(t *testing.T) {
|
type TestItem struct {
|
||||||
_, trie := New()
|
Name string
|
||||||
trie.Update("c", LONG_WORD)
|
Inputs [][]string
|
||||||
trie.Update("ca", LONG_WORD)
|
Expectations string
|
||||||
trie.Update("cat", LONG_WORD)
|
}
|
||||||
|
|
||||||
it := trie.NewIterator()
|
func TestTrieIt(t *testing.T) {
|
||||||
it.Each(func(key string, node *Value) {
|
//_, trie := New()
|
||||||
fmt.Println(key, ":", node.Str())
|
resp, err := http.Get("https://raw.githubusercontent.com/ethereum/tests/master/trietest.json")
|
||||||
})
|
if err != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user