core/vm: RETURN op code returns pointer to memory rather than copy

pull/1043/head
obscuren 10 years ago
parent 648b352424
commit f5af1fdca8
  1. 12
      core/vm/memory.go
  2. 2
      core/vm/vm.go
  3. 8
      tests/vm/gh_test.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)
}

@ -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()

@ -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)
}

Loading…
Cancel
Save