|
|
@ -75,20 +75,17 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { |
|
|
|
destinations = analyseJumpDests(context.Code) |
|
|
|
destinations = analyseJumpDests(context.Code) |
|
|
|
mem = NewMemory() |
|
|
|
mem = NewMemory() |
|
|
|
stack = newStack() |
|
|
|
stack = newStack() |
|
|
|
pc uint64 = 0 |
|
|
|
pc = new(big.Int) |
|
|
|
step = 0 |
|
|
|
|
|
|
|
statedb = self.env.State() |
|
|
|
statedb = self.env.State() |
|
|
|
|
|
|
|
|
|
|
|
jump = func(from uint64, to *big.Int) error { |
|
|
|
jump = func(from *big.Int, to *big.Int) error { |
|
|
|
p := to.Uint64() |
|
|
|
nop := context.GetOp(to) |
|
|
|
|
|
|
|
if !destinations.Has(to) { |
|
|
|
nop := context.GetOp(p) |
|
|
|
return fmt.Errorf("invalid jump destination (%v) %v", nop, to) |
|
|
|
if !destinations.Has(p) { |
|
|
|
|
|
|
|
return fmt.Errorf("invalid jump destination (%v) %v", nop, p) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self.Printf(" ~> %v", to) |
|
|
|
self.Printf(" ~> %v", to) |
|
|
|
pc = to.Uint64() |
|
|
|
pc = to |
|
|
|
|
|
|
|
|
|
|
|
self.Endl() |
|
|
|
self.Endl() |
|
|
|
|
|
|
|
|
|
|
@ -105,7 +102,6 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { |
|
|
|
// The base for all big integer arithmetic
|
|
|
|
// The base for all big integer arithmetic
|
|
|
|
base := new(big.Int) |
|
|
|
base := new(big.Int) |
|
|
|
|
|
|
|
|
|
|
|
step++ |
|
|
|
|
|
|
|
// Get the memory location of pc
|
|
|
|
// Get the memory location of pc
|
|
|
|
op = context.GetOp(pc) |
|
|
|
op = context.GetOp(pc) |
|
|
|
|
|
|
|
|
|
|
@ -428,22 +424,11 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { |
|
|
|
|
|
|
|
|
|
|
|
self.Printf(" => %v", value) |
|
|
|
self.Printf(" => %v", value) |
|
|
|
case CALLDATALOAD: |
|
|
|
case CALLDATALOAD: |
|
|
|
var ( |
|
|
|
data := getData(callData, stack.pop(), common.Big32) |
|
|
|
offset = stack.pop() |
|
|
|
|
|
|
|
data = make([]byte, 32) |
|
|
|
|
|
|
|
lenData = big.NewInt(int64(len(callData))) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if lenData.Cmp(offset) >= 0 { |
|
|
|
|
|
|
|
length := new(big.Int).Add(offset, common.Big32) |
|
|
|
|
|
|
|
length = common.BigMin(length, lenData) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
copy(data, callData[offset.Int64():length.Int64()]) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", data) |
|
|
|
self.Printf(" => 0x%x", data) |
|
|
|
|
|
|
|
|
|
|
|
stack.push(common.BigD(data)) |
|
|
|
stack.push(common.Bytes2Big(data)) |
|
|
|
case CALLDATASIZE: |
|
|
|
case CALLDATASIZE: |
|
|
|
l := int64(len(callData)) |
|
|
|
l := int64(len(callData)) |
|
|
|
stack.push(big.NewInt(l)) |
|
|
|
stack.push(big.NewInt(l)) |
|
|
@ -542,13 +527,11 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { |
|
|
|
|
|
|
|
|
|
|
|
// 0x50 range
|
|
|
|
// 0x50 range
|
|
|
|
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32: |
|
|
|
case PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16, PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32: |
|
|
|
a := uint64(op - PUSH1 + 1) |
|
|
|
a := big.NewInt(int64(op - PUSH1 + 1)) |
|
|
|
byts := context.GetRangeValue(pc+1, a) |
|
|
|
byts := getData(code, new(big.Int).Add(pc, big.NewInt(1)), a) |
|
|
|
// push value to stack
|
|
|
|
// push value to stack
|
|
|
|
stack.push(common.BigD(byts)) |
|
|
|
stack.push(common.Bytes2Big(byts)) |
|
|
|
pc += a |
|
|
|
pc.Add(pc, a) |
|
|
|
|
|
|
|
|
|
|
|
step += int(op) - int(PUSH1) + 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.Printf(" => 0x%x", byts) |
|
|
|
self.Printf(" => 0x%x", byts) |
|
|
|
case POP: |
|
|
|
case POP: |
|
|
@ -628,7 +611,8 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { |
|
|
|
|
|
|
|
|
|
|
|
case JUMPDEST: |
|
|
|
case JUMPDEST: |
|
|
|
case PC: |
|
|
|
case PC: |
|
|
|
stack.push(big.NewInt(int64(pc))) |
|
|
|
//stack.push(big.NewInt(int64(pc)))
|
|
|
|
|
|
|
|
stack.push(pc) |
|
|
|
case MSIZE: |
|
|
|
case MSIZE: |
|
|
|
stack.push(big.NewInt(int64(mem.Len()))) |
|
|
|
stack.push(big.NewInt(int64(mem.Len()))) |
|
|
|
case GAS: |
|
|
|
case GAS: |
|
|
@ -734,7 +718,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) { |
|
|
|
return nil, fmt.Errorf("Invalid opcode %x", op) |
|
|
|
return nil, fmt.Errorf("Invalid opcode %x", op) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pc++ |
|
|
|
pc.Add(pc, One) |
|
|
|
|
|
|
|
|
|
|
|
self.Endl() |
|
|
|
self.Endl() |
|
|
|
} |
|
|
|
} |
|
|
|