From d7ab716eea1d1892e3358b1dece6b0e2cd31fce8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 19 Mar 2015 10:57:02 +0100 Subject: Fixed mkdnode & added some tests --- vm/vm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'vm') diff --git a/vm/vm.go b/vm/vm.go index 4d9e88e1a..c1b365c5c 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -4,8 +4,8 @@ import ( "fmt" "math/big" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/state" ) -- cgit v1.2.3 From cf45b939a098c9421092226d5c76dbce34eb2dda Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 19 Mar 2015 14:31:14 +0100 Subject: fixed tests --- vm/common.go | 8 ++++---- vm/context.go | 2 +- vm/vm.go | 17 ++++------------- 3 files changed, 9 insertions(+), 18 deletions(-) (limited to 'vm') diff --git a/vm/common.go b/vm/common.go index 1f07ec8a2..90c3361de 100644 --- a/vm/common.go +++ b/vm/common.go @@ -119,9 +119,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 6edde0824..1c2f665a4 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 c1b365c5c..a47818a44 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -443,24 +443,15 @@ 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() ) + data := getData(callData, cOff, l) - if cOff > size { - cOff = 0 - l = 0 - } else if cOff+l > size { - l = 0 - } - - code := callData[cOff : cOff+l] - - mem.Set(mOff, l, code) + mem.Set(mOff, l, 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 { @@ -487,7 +478,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { cOff = stack.pop().Uint64() l = stack.pop().Uint64() ) - codeCopy := getCode(code, cOff, l) + codeCopy := getData(code, cOff, l) mem.Set(mOff, l, codeCopy) -- cgit v1.2.3 From a756dbeb7b1027eb91130ecf8d5440dca8e738d8 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 19 Mar 2015 15:06:56 +0100 Subject: Removed uint casts --- vm/vm.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'vm') diff --git a/vm/vm.go b/vm/vm.go index a47818a44..089047a95 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -443,13 +443,16 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { self.Printf(" => %d", l) case CALLDATACOPY: var ( - mOff = stack.pop().Uint64() - cOff = stack.pop().Uint64() - l = stack.pop().Uint64() + mOff = stack.pop() + cOff = stack.pop() + l = stack.pop() ) - data := getData(callData, cOff, l) + var data []byte + if cOff.Cmp(big.NewInt(int64(len(callData)))) <= 0 { + data = getData(callData, cOff.Uint64(), l.Uint64()) + } - mem.Set(mOff, l, data) + mem.Set(mOff.Uint64(), l.Uint64(), data) self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, data) case CODESIZE, EXTCODESIZE: @@ -473,14 +476,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 := getData(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: -- cgit v1.2.3