aboutsummaryrefslogtreecommitdiffstats
path: root/vm
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-30 23:16:02 +0800
committerobscuren <geffobscura@gmail.com>2014-12-30 23:16:02 +0800
commit29c887ef2c39e91951e1ae14e7c4276334c434a4 (patch)
tree8659f74f018ee32ba8c278da19132a346045182e /vm
parent9d429180f995f61e3448f9e0ffce713434590055 (diff)
downloadgo-tangerine-29c887ef2c39e91951e1ae14e7c4276334c434a4.tar
go-tangerine-29c887ef2c39e91951e1ae14e7c4276334c434a4.tar.gz
go-tangerine-29c887ef2c39e91951e1ae14e7c4276334c434a4.tar.bz2
go-tangerine-29c887ef2c39e91951e1ae14e7c4276334c434a4.tar.lz
go-tangerine-29c887ef2c39e91951e1ae14e7c4276334c434a4.tar.xz
go-tangerine-29c887ef2c39e91951e1ae14e7c4276334c434a4.tar.zst
go-tangerine-29c887ef2c39e91951e1ae14e7c4276334c434a4.zip
Removed incorrect range check for push
Diffstat (limited to 'vm')
-rw-r--r--vm/closure.go17
-rw-r--r--vm/vm_debug.go5
2 files changed, 10 insertions, 12 deletions
diff --git a/vm/closure.go b/vm/closure.go
index 97b31ada0..df216f2ae 100644
--- a/vm/closure.go
+++ b/vm/closure.go
@@ -1,8 +1,10 @@
package vm
import (
+ "math"
"math/big"
+ "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/state"
)
@@ -51,19 +53,14 @@ func (c *Closure) GetByte(x uint64) byte {
}
func (c *Closure) GetBytes(x, y int) []byte {
- if x >= len(c.Code) || y >= len(c.Code) {
- return nil
- }
-
- return c.Code[x : x+y]
+ return c.GetRangeValue(uint64(x), uint64(y))
}
-func (c *Closure) GetRangeValue(x, y uint64) []byte {
- if x >= uint64(len(c.Code)) || y >= uint64(len(c.Code)) {
- return nil
- }
+func (c *Closure) GetRangeValue(x, size uint64) []byte {
+ x = uint64(math.Min(float64(x), float64(len(c.Code))))
+ y := uint64(math.Min(float64(x+size), float64(len(c.Code))))
- return c.Code[x : x+y]
+ return ethutil.LeftPadBytes(c.Code[x:y], int(size))
}
func (c *Closure) Return(ret []byte) []byte {
diff --git a/vm/vm_debug.go b/vm/vm_debug.go
index aa3291e66..2ee13c516 100644
--- a/vm/vm_debug.go
+++ b/vm/vm_debug.go
@@ -716,7 +716,8 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
//a := big.NewInt(int64(op) - int64(PUSH1) + 1)
a := uint64(op - PUSH1 + 1)
//pc.Add(pc, ethutil.Big1)
- val := ethutil.BigD(closure.GetRangeValue(pc+1, a))
+ byts := closure.GetRangeValue(pc+1, a)
+ val := ethutil.BigD(byts)
// Push value to stack
stack.Push(val)
pc += a
@@ -724,7 +725,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
step += int(op) - int(PUSH1) + 1
- self.Printf(" => 0x%x", val.Bytes())
+ self.Printf(" => 0x%x", byts)
case POP:
stack.Pop()
case DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16: