aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
Diffstat (limited to 'vm')
-rw-r--r--vm/common.go8
-rw-r--r--vm/context.go2
-rw-r--r--vm/vm.go37
3 files changed, 23 insertions, 24 deletions
diff --git a/vm/common.go b/vm/common.go
index cedc0f309..5441a4ac5 100644
--- a/vm/common.go
+++ b/vm/common.go
@@ -73,9 +73,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 c846aad89..ea70f2376 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 49e8cca98..123da6b03 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -441,24 +441,18 @@ 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()
+ mOff = stack.pop()
+ cOff = stack.pop()
+ l = stack.pop()
)
-
- if cOff > size {
- cOff = 0
- l = 0
- } else if cOff+l > size {
- l = 0
+ var data []byte
+ if cOff.Cmp(big.NewInt(int64(len(callData)))) <= 0 {
+ data = getData(callData, cOff.Uint64(), l.Uint64())
}
- code := callData[cOff : cOff+l]
-
- mem.Set(mOff, l, code)
+ mem.Set(mOff.Uint64(), l.Uint64(), 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 {
@@ -481,14 +475,19 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
} else {
code = context.Code
}
+
var (
- mOff = stack.pop().Uint64()
- cOff = stack.pop().Uint64()
- l = stack.pop().Uint64()
+ mOff = stack.pop()
+ cOff = stack.pop()
+ l = stack.pop()
)
- codeCopy := getCode(code, cOff, l)
- mem.Set(mOff, l, codeCopy)
+ var codeCopy []byte
+ if cOff.Cmp(big.NewInt(int64(len(code)))) <= 0 {
+ codeCopy = getData(code, cOff.Uint64(), l.Uint64())
+ }
+
+ mem.Set(mOff.Uint64(), l.Uint64(), codeCopy)
self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, codeCopy)
case GASPRICE: