aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-19 21:31:14 +0800
committerobscuren <geffobscura@gmail.com>2015-03-19 21:31:14 +0800
commitcf45b939a098c9421092226d5c76dbce34eb2dda (patch)
tree2a57c4880feff1f0ff98ec505998dbb1643db1b0
parentd7ab716eea1d1892e3358b1dece6b0e2cd31fce8 (diff)
downloaddexon-cf45b939a098c9421092226d5c76dbce34eb2dda.tar
dexon-cf45b939a098c9421092226d5c76dbce34eb2dda.tar.gz
dexon-cf45b939a098c9421092226d5c76dbce34eb2dda.tar.bz2
dexon-cf45b939a098c9421092226d5c76dbce34eb2dda.tar.lz
dexon-cf45b939a098c9421092226d5c76dbce34eb2dda.tar.xz
dexon-cf45b939a098c9421092226d5c76dbce34eb2dda.tar.zst
dexon-cf45b939a098c9421092226d5c76dbce34eb2dda.zip
fixed tests
-rw-r--r--trie/trie.go9
-rw-r--r--vm/common.go8
-rw-r--r--vm/context.go2
-rw-r--r--vm/vm.go17
4 files changed, 16 insertions, 20 deletions
diff --git a/trie/trie.go b/trie/trie.go
index 4f47151a4..d990338ee 100644
--- a/trie/trie.go
+++ b/trie/trie.go
@@ -302,12 +302,17 @@ func (self *Trie) mknode(value *common.Value) Node {
case 2:
// A value node may consists of 2 bytes.
if value.Get(0).Len() != 0 {
- return NewShortNode(self, CompactDecode(string(value.Get(0).Bytes())), self.mknode(value.Get(1)))
+ key := CompactDecode(string(value.Get(0).Bytes()))
+ if key[len(key)-1] == 16 {
+ return NewShortNode(self, key, &ValueNode{self, value.Get(1).Bytes()})
+ } else {
+ return NewShortNode(self, key, self.mknode(value.Get(1)))
+ }
}
case 17:
if len(value.Bytes()) != 17 {
fnode := NewFullNode(self)
- for i := 0; i < l; i++ {
+ for i := 0; i < 16; i++ {
fnode.set(byte(i), self.mknode(value.Get(i)))
}
return fnode
diff --git a/vm/common.go b/vm/common.go
index 1f07ec8a2..90c3361de 100644
--- a/vm/common.go
+++ b/vm/common.go
@@ -119,9 +119,9 @@ func toValue(val *big.Int) interface{} {
return val
}
-func getCode(code []byte, start, size uint64) []byte {
- x := uint64(math.Min(float64(start), float64(len(code))))
- y := uint64(math.Min(float64(x+size), float64(len(code))))
+func getData(data []byte, start, size uint64) []byte {
+ x := uint64(math.Min(float64(start), float64(len(data))))
+ y := uint64(math.Min(float64(x+size), float64(len(data))))
- return common.RightPadBytes(code[x:y], int(size))
+ return common.RightPadBytes(data[x:y], int(size))
}
diff --git a/vm/context.go b/vm/context.go
index 6edde0824..1c2f665a4 100644
--- a/vm/context.go
+++ b/vm/context.go
@@ -65,7 +65,7 @@ func (c *Context) GetRangeValue(x, size uint64) []byte {
}
func (c *Context) GetCode(x, size uint64) []byte {
- return getCode(c.Code, x, size)
+ return getData(c.Code, x, size)
}
func (c *Context) Return(ret []byte) []byte {
diff --git a/vm/vm.go b/vm/vm.go
index c1b365c5c..a47818a44 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -443,24 +443,15 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
self.Printf(" => %d", l)
case CALLDATACOPY:
var (
- size = uint64(len(callData))
mOff = stack.pop().Uint64()
cOff = stack.pop().Uint64()
l = stack.pop().Uint64()
)
+ data := getData(callData, cOff, l)
- if cOff > size {
- cOff = 0
- l = 0
- } else if cOff+l > size {
- l = 0
- }
-
- code := callData[cOff : cOff+l]
-
- mem.Set(mOff, l, code)
+ mem.Set(mOff, l, data)
- self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, callData[cOff:cOff+l])
+ self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, data)
case CODESIZE, EXTCODESIZE:
var code []byte
if op == EXTCODESIZE {
@@ -487,7 +478,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
cOff = stack.pop().Uint64()
l = stack.pop().Uint64()
)
- codeCopy := getCode(code, cOff, l)
+ codeCopy := getData(code, cOff, l)
mem.Set(mOff, l, codeCopy)