aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-19 23:26:38 +0800
committerobscuren <geffobscura@gmail.com>2015-05-20 06:21:23 +0800
commitf5af1fdca8dc7d44b4c2025195c19819886729b6 (patch)
tree2e8749dd034b7b09655001894e6e9bd755d1b49e
parent648b352424e70f099f62cc18a768babb90434350 (diff)
downloaddexon-f5af1fdca8dc7d44b4c2025195c19819886729b6.tar
dexon-f5af1fdca8dc7d44b4c2025195c19819886729b6.tar.gz
dexon-f5af1fdca8dc7d44b4c2025195c19819886729b6.tar.bz2
dexon-f5af1fdca8dc7d44b4c2025195c19819886729b6.tar.lz
dexon-f5af1fdca8dc7d44b4c2025195c19819886729b6.tar.xz
dexon-f5af1fdca8dc7d44b4c2025195c19819886729b6.tar.zst
dexon-f5af1fdca8dc7d44b4c2025195c19819886729b6.zip
core/vm: RETURN op code returns pointer to memory rather than copy
-rw-r--r--core/vm/memory.go12
-rw-r--r--core/vm/vm.go2
-rw-r--r--tests/vm/gh_test.go8
3 files changed, 17 insertions, 5 deletions
diff --git a/core/vm/memory.go b/core/vm/memory.go
index b77d486eb..d20aa9591 100644
--- a/core/vm/memory.go
+++ b/core/vm/memory.go
@@ -49,6 +49,18 @@ func (self *Memory) Get(offset, size int64) (cpy []byte) {
return
}
+func (self *Memory) GetPtr(offset, size int64) []byte {
+ if size == 0 {
+ return nil
+ }
+
+ if len(self.store) > int(offset) {
+ return self.store[offset : offset+size]
+ }
+
+ return nil
+}
+
func (m *Memory) Len() int {
return len(m.store)
}
diff --git a/core/vm/vm.go b/core/vm/vm.go
index 927b67293..35fa19d03 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -695,7 +695,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
self.Printf("resume %x (%v)", context.Address(), context.Gas)
case RETURN:
offset, size := stack.pop(), stack.pop()
- ret := mem.Get(offset.Int64(), size.Int64())
+ ret := mem.GetPtr(offset.Int64(), size.Int64())
self.Printf(" => [%v, %v] (%d) 0x%x", offset, size, len(ret), ret).Endl()
diff --git a/tests/vm/gh_test.go b/tests/vm/gh_test.go
index b01448420..827d8ec8b 100644
--- a/tests/vm/gh_test.go
+++ b/tests/vm/gh_test.go
@@ -286,13 +286,13 @@ func TestInputLimitsLight(t *testing.T) {
RunVmTest(fn, t)
}
-func TestStateExample(t *testing.T) {
- const fn = "../files/StateTests/stExample.json"
+func TestStateSystemOperations(t *testing.T) {
+ const fn = "../files/StateTests/stSystemOperationsTest.json"
RunVmTest(fn, t)
}
-func TestStateSystemOperations(t *testing.T) {
- const fn = "../files/StateTests/stSystemOperationsTest.json"
+func TestStateExample(t *testing.T) {
+ const fn = "../files/StateTests/stExample.json"
RunVmTest(fn, t)
}