aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-22 02:38:43 +0800
committerobscuren <geffobscura@gmail.com>2014-07-22 02:38:43 +0800
commit20ee1ae65e57ef7d60404277162c84c572c6bb10 (patch)
treedbb43cc384068a98650b035d9f8a157e9de263f9 /ethchain
parenteab0b2a90a3e33d0be4d09cbb99d193ba2219844 (diff)
downloaddexon-20ee1ae65e57ef7d60404277162c84c572c6bb10.tar.gz
dexon-20ee1ae65e57ef7d60404277162c84c572c6bb10.tar.zst
dexon-20ee1ae65e57ef7d60404277162c84c572c6bb10.zip
Refactored CALLDATALOAD to use big int
* Added BigMin
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/vm.go14
1 files changed, 9 insertions, 5 deletions
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 34ecd95b7..a9bed1eca 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -503,13 +503,17 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
vm.Printf(" => %v", vm.vars.Value)
case CALLDATALOAD:
require(1)
- offset := stack.Pop().Int64()
+ var (
+ offset = stack.Pop()
+ data = make([]byte, 32)
+ lenData = big.NewInt(int64(len(closure.Args)))
+ )
- data := make([]byte, 32)
- if big.NewInt(int64(len(closure.Args))).Cmp(big.NewInt(offset)) >= 0 {
- l := int64(math.Min(float64(offset+32), float64(len(closure.Args))))
+ if lenData.Cmp(offset) >= 0 {
+ length := new(big.Int).Add(offset, ethutil.Big32)
+ length = ethutil.BigMin(length, lenData)
- copy(data, closure.Args[offset:l])
+ copy(data, closure.Args[offset.Int64():length.Int64()])
}
vm.Printf(" => 0x%x", data)