aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-20 05:45:03 +0800
committerobscuren <geffobscura@gmail.com>2015-03-20 05:45:03 +0800
commitdf5901fdc58565448629a9bfd5ccecc1c5a5b349 (patch)
treef4365a7c84c098867cb97b684589ee17cd4b9309 /vm
parent013427bde27579d50010e728d9b59be91a7fb285 (diff)
downloadgo-tangerine-df5901fdc58565448629a9bfd5ccecc1c5a5b349.tar
go-tangerine-df5901fdc58565448629a9bfd5ccecc1c5a5b349.tar.gz
go-tangerine-df5901fdc58565448629a9bfd5ccecc1c5a5b349.tar.bz2
go-tangerine-df5901fdc58565448629a9bfd5ccecc1c5a5b349.tar.lz
go-tangerine-df5901fdc58565448629a9bfd5ccecc1c5a5b349.tar.xz
go-tangerine-df5901fdc58565448629a9bfd5ccecc1c5a5b349.tar.zst
go-tangerine-df5901fdc58565448629a9bfd5ccecc1c5a5b349.zip
Removed more casts
Diffstat (limited to 'vm')
-rw-r--r--vm/common.go9
-rw-r--r--vm/context.go4
-rw-r--r--vm/vm.go18
3 files changed, 11 insertions, 20 deletions
diff --git a/vm/common.go b/vm/common.go
index 5441a4ac5..8d8f4253f 100644
--- a/vm/common.go
+++ b/vm/common.go
@@ -73,9 +73,10 @@ func toValue(val *big.Int) interface{} {
return val
}
-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))))
+func getData(data []byte, start, size *big.Int) []byte {
+ dlen := big.NewInt(int64(len(data)))
- return common.RightPadBytes(data[x:y], int(size))
+ s := common.BigMin(start, dlen)
+ e := common.BigMin(new(big.Int).Add(s, size), dlen)
+ return common.RightPadBytes(data[s.Uint64():e.Uint64()], int(size.Uint64()))
}
diff --git a/vm/context.go b/vm/context.go
index ea70f2376..e73199b77 100644
--- a/vm/context.go
+++ b/vm/context.go
@@ -64,10 +64,6 @@ func (c *Context) GetRangeValue(x, size uint64) []byte {
return common.RightPadBytes(c.Code[x:y], int(size))
}
-func (c *Context) GetCode(x, size uint64) []byte {
- return getData(c.Code, x, size)
-}
-
func (c *Context) Return(ret []byte) []byte {
// Return the remaining gas to the caller
c.caller.ReturnGas(c.Gas, c.Price)
diff --git a/vm/vm.go b/vm/vm.go
index 123da6b03..7400a48c4 100644
--- a/vm/vm.go
+++ b/vm/vm.go
@@ -445,14 +445,11 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
cOff = stack.pop()
l = stack.pop()
)
- var data []byte
- if cOff.Cmp(big.NewInt(int64(len(callData)))) <= 0 {
- data = getData(callData, cOff.Uint64(), l.Uint64())
- }
+ data := getData(callData, cOff, l)
mem.Set(mOff.Uint64(), l.Uint64(), data)
- self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, data)
+ self.Printf(" => [%v, %v, %v]", mOff, cOff, l)
case CODESIZE, EXTCODESIZE:
var code []byte
if op == EXTCODESIZE {
@@ -482,10 +479,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
l = stack.pop()
)
- var codeCopy []byte
- if cOff.Cmp(big.NewInt(int64(len(code)))) <= 0 {
- codeCopy = getData(code, cOff.Uint64(), l.Uint64())
- }
+ codeCopy := getData(code, cOff, l)
mem.Set(mOff.Uint64(), l.Uint64(), codeCopy)
@@ -585,11 +579,11 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
self.Printf(" => 0x%x", val)
case MSTORE8:
- off, val := stack.pop(), stack.pop()
+ off, val := stack.pop().Int64(), stack.pop().Int64()
- mem.store[off.Int64()] = byte(val.Int64() & 0xff)
+ mem.store[off] = byte(val & 0xff)
- self.Printf(" => [%v] 0x%x", off, val)
+ self.Printf(" => [%v] 0x%x", off, mem.store[off])
case SLOAD:
loc := common.BigToHash(stack.pop())
val := common.Bytes2Big(statedb.GetState(context.Address(), loc))