aboutsummaryrefslogtreecommitdiffstats
path: root/vm/vm_debug.go
diff options
context:
space:
mode:
Diffstat (limited to 'vm/vm_debug.go')
-rw-r--r--vm/vm_debug.go72
1 files changed, 34 insertions, 38 deletions
diff --git a/vm/vm_debug.go b/vm/vm_debug.go
index 0a541a769..8af1979b1 100644
--- a/vm/vm_debug.go
+++ b/vm/vm_debug.go
@@ -25,8 +25,6 @@ type DebugVm struct {
Fn string
Recoverable bool
-
- depth int
}
func NewDebugVm(env Environment) *DebugVm {
@@ -51,8 +49,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
closure := NewClosure(msg, caller, me, code, gas, price)
if self.env.Depth() == MaxCallDepth {
- closure.UseGas(gas)
-
+ //closure.UseGas(gas)
return closure.Return(nil), DepthError{}
}
@@ -98,7 +95,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
} else {
nop := OpCode(closure.GetOp(p))
if !(nop == JUMPDEST || destinations[from] != nil) {
- panic(fmt.Sprintf("JUMP missed JUMPDEST (%v) %v", nop, p))
+ panic(fmt.Sprintf("invalid jump destination (%v) %v", nop, p))
} else if nop == JUMP || nop == JUMPI {
panic(fmt.Sprintf("not allowed to JUMP(I) in to JUMP"))
}
@@ -116,7 +113,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
return closure.Return(nil), nil
}
- vmlogger.Debugf("(%d) %x gas: %v (d) %x\n", self.depth, closure.Address(), closure.Gas, callData)
+ vmlogger.Debugf("(%d) %x gas: %v (d) %x\n", self.env.Depth(), closure.Address(), closure.Gas, callData)
for {
prevStep = step
@@ -166,13 +163,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
case EXP:
require(2)
- exp := new(big.Int).Set(stack.data[stack.Len()-2])
- nbytes := 0
- for exp.Cmp(ethutil.Big0) > 0 {
- nbytes += 1
- exp.Rsh(exp, 8)
- }
- gas.Set(big.NewInt(int64(nbytes + 1)))
+ gas.Set(big.NewInt(int64(len(stack.data[stack.Len()-2].Bytes()) + 1)))
// Gas only
case STOP:
gas.Set(ethutil.Big0)
@@ -260,9 +251,12 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
newMemSize.Mul(newMemSize, u256(32))
switch op {
- // Additional gas usage on *CODPY
case CALLDATACOPY, CODECOPY, EXTCODECOPY:
addStepGasUsage(new(big.Int).Div(newMemSize, u256(32)))
+ case SHA3:
+ g := new(big.Int).Div(newMemSize, u256(32))
+ g.Mul(g, GasSha3Byte)
+ addStepGasUsage(g)
}
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
@@ -614,10 +608,10 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
self.Printf(" => %d", l)
case CALLDATACOPY:
var (
- size = int64(len(callData))
- mOff = stack.Pop().Int64()
- cOff = stack.Pop().Int64()
- l = stack.Pop().Int64()
+ size = uint64(len(callData))
+ mOff = stack.Pop().Uint64()
+ cOff = stack.Pop().Uint64()
+ l = stack.Pop().Uint64()
)
if cOff > size {
@@ -657,10 +651,10 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
}
var (
- size = int64(len(code))
- mOff = stack.Pop().Int64()
- cOff = stack.Pop().Int64()
- l = stack.Pop().Int64()
+ size = uint64(len(code))
+ mOff = stack.Pop().Uint64()
+ cOff = stack.Pop().Uint64()
+ l = stack.Pop().Uint64()
)
if cOff > size {
@@ -744,12 +738,12 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
case LOG0, LOG1, LOG2, LOG3, LOG4:
n := int(op - LOG0)
topics := make([][]byte, n)
- mSize, mStart := stack.Pop().Int64(), stack.Pop().Int64()
- data := mem.Geti(mStart, mSize)
+ mSize, mStart := stack.Popn()
for i := 0; i < n; i++ {
topics[i] = ethutil.LeftPadBytes(stack.Pop().Bytes(), 32)
}
+ data := mem.Geti(mStart.Int64(), mSize.Int64())
log := &Log{closure.Address(), topics, data}
self.env.AddLog(log)
@@ -763,7 +757,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
case MSTORE: // Store the value at stack top-1 in to memory at location stack top
// Pop value of the stack
val, mStart := stack.Popn()
- mem.Set(mStart.Int64(), 32, ethutil.BigToBytes(val, 256))
+ mem.Set(mStart.Uint64(), 32, ethutil.BigToBytes(val, 256))
self.Printf(" => 0x%x", val)
case MSTORE8:
@@ -839,8 +833,13 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
self.Printf("CREATE err %v", err)
} else {
- ref.SetCode(ret)
- msg.Output = ret
+ // gas < len(ret) * CreateDataGas == NO_CODE
+ dataGas := big.NewInt(int64(len(ret)))
+ dataGas.Mul(dataGas, GasCreateByte)
+ if closure.UseGas(dataGas) {
+ ref.SetCode(ret)
+ msg.Output = ret
+ }
stack.Push(ethutil.BigD(addr))
}
@@ -865,14 +864,16 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
// Get the arguments from the memory
args := mem.Get(inOffset.Int64(), inSize.Int64())
- var executeAddr []byte
+ var (
+ ret []byte
+ err error
+ )
if op == CALLCODE {
- executeAddr = closure.Address()
+ ret, err = self.env.CallCode(closure, addr.Bytes(), args, gas, price, value)
} else {
- executeAddr = addr.Bytes()
+ ret, err = self.env.Call(closure, addr.Bytes(), args, gas, price, value)
}
- ret, err := self.env.Call(closure, executeAddr, args, gas, price, value)
if err != nil {
stack.Push(ethutil.BigFalse)
@@ -881,9 +882,9 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
stack.Push(ethutil.BigTrue)
msg.Output = ret
- mem.Set(retOffset.Int64(), retSize.Int64(), ret)
+ mem.Set(retOffset.Uint64(), retSize.Uint64(), ret)
}
- self.Printf("resume %x", closure.Address())
+ self.Printf("resume %x (%v)", closure.Address(), closure.Gas)
// Debug hook
if self.Dbg != nil {
@@ -912,7 +913,6 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
default:
vmlogger.Debugf("(pc) %-3v Invalid opcode %x\n", pc, op)
- //panic(fmt.Sprintf("Invalid opcode %x", op))
closure.ReturnGas(big.NewInt(1), nil)
return closure.Return(nil), fmt.Errorf("Invalid opcode %x", op)
@@ -961,7 +961,3 @@ func (self *DebugVm) Endl() VirtualMachine {
func (self *DebugVm) Env() Environment {
return self.env
}
-
-func (self *DebugVm) Depth() int {
- return self.depth
-}