|
@@ -108,13 +108,13 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|
|
}
|
|
}
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ vmlogger.Debugf("(%d) (%x) %x (code=%d) gas: %v (d) %x\n", self.env.Depth(), caller.Address()[:4], closure.Address(), len(code), closure.Gas, callData)
|
|
|
|
|
+
|
|
|
// Don't bother with the execution if there's no code.
|
|
// Don't bother with the execution if there's no code.
|
|
|
if len(code) == 0 {
|
|
if len(code) == 0 {
|
|
|
return closure.Return(nil), nil
|
|
return closure.Return(nil), nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- vmlogger.Debugf("(%d) (%x) %x gas: %v (d) %x\n", self.env.Depth(), caller.Address()[:4], closure.Address(), closure.Gas, callData)
|
|
|
|
|
-
|
|
|
|
|
for {
|
|
for {
|
|
|
prevStep = step
|
|
prevStep = step
|
|
|
// The base for all big integer arithmetic
|
|
// The base for all big integer arithmetic
|
|
@@ -134,6 +134,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|
|
addStepGasUsage(GasStep)
|
|
addStepGasUsage(GasStep)
|
|
|
|
|
|
|
|
var newMemSize *big.Int = ethutil.Big0
|
|
var newMemSize *big.Int = ethutil.Big0
|
|
|
|
|
+ var additionalGas *big.Int = new(big.Int)
|
|
|
// Stack Check, memory resize & gas phase
|
|
// Stack Check, memory resize & gas phase
|
|
|
switch op {
|
|
switch op {
|
|
|
// Stack checks only
|
|
// Stack checks only
|
|
@@ -213,22 +214,24 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2])
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2])
|
|
|
case SHA3:
|
|
case SHA3:
|
|
|
require(2)
|
|
require(2)
|
|
|
-
|
|
|
|
|
gas.Set(GasSha)
|
|
gas.Set(GasSha)
|
|
|
-
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2])
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-2])
|
|
|
|
|
+ additionalGas.Set(stack.data[stack.Len()-2])
|
|
|
case CALLDATACOPY:
|
|
case CALLDATACOPY:
|
|
|
require(2)
|
|
require(2)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3])
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3])
|
|
|
|
|
+ additionalGas.Set(stack.data[stack.Len()-3])
|
|
|
case CODECOPY:
|
|
case CODECOPY:
|
|
|
require(3)
|
|
require(3)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3])
|
|
newMemSize = calcMemSize(stack.Peek(), stack.data[stack.Len()-3])
|
|
|
|
|
+ additionalGas.Set(stack.data[stack.Len()-3])
|
|
|
case EXTCODECOPY:
|
|
case EXTCODECOPY:
|
|
|
require(4)
|
|
require(4)
|
|
|
|
|
|
|
|
newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-4])
|
|
newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-4])
|
|
|
|
|
+ additionalGas.Set(stack.data[stack.Len()-4])
|
|
|
case CALL, CALLCODE:
|
|
case CALL, CALLCODE:
|
|
|
require(7)
|
|
require(7)
|
|
|
gas.Set(GasCall)
|
|
gas.Set(GasCall)
|
|
@@ -245,20 +248,23 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|
|
newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-3])
|
|
newMemSize = calcMemSize(stack.data[stack.Len()-2], stack.data[stack.Len()-3])
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ switch op {
|
|
|
|
|
+ case CALLDATACOPY, CODECOPY, EXTCODECOPY:
|
|
|
|
|
+ additionalGas.Add(additionalGas, u256(31))
|
|
|
|
|
+ additionalGas.Div(additionalGas, u256(32))
|
|
|
|
|
+ addStepGasUsage(additionalGas)
|
|
|
|
|
+ case SHA3:
|
|
|
|
|
+ additionalGas.Add(additionalGas, u256(31))
|
|
|
|
|
+ additionalGas.Div(additionalGas, u256(32))
|
|
|
|
|
+ additionalGas.Mul(additionalGas, GasSha3Byte)
|
|
|
|
|
+ addStepGasUsage(additionalGas)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if newMemSize.Cmp(ethutil.Big0) > 0 {
|
|
if newMemSize.Cmp(ethutil.Big0) > 0 {
|
|
|
newMemSize.Add(newMemSize, u256(31))
|
|
newMemSize.Add(newMemSize, u256(31))
|
|
|
newMemSize.Div(newMemSize, u256(32))
|
|
newMemSize.Div(newMemSize, u256(32))
|
|
|
newMemSize.Mul(newMemSize, u256(32))
|
|
newMemSize.Mul(newMemSize, u256(32))
|
|
|
|
|
|
|
|
- switch op {
|
|
|
|
|
- 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 {
|
|
if newMemSize.Cmp(u256(int64(mem.Len()))) > 0 {
|
|
|
memGasUsage := new(big.Int).Sub(newMemSize, u256(int64(mem.Len())))
|
|
memGasUsage := new(big.Int).Sub(newMemSize, u256(int64(mem.Len())))
|
|
|
memGasUsage.Mul(GasMemory, memGasUsage)
|
|
memGasUsage.Mul(GasMemory, memGasUsage)
|
|
@@ -643,9 +649,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|
|
case CODECOPY, EXTCODECOPY:
|
|
case CODECOPY, EXTCODECOPY:
|
|
|
var code []byte
|
|
var code []byte
|
|
|
if op == EXTCODECOPY {
|
|
if op == EXTCODECOPY {
|
|
|
- addr := stack.Pop().Bytes()
|
|
|
|
|
-
|
|
|
|
|
- code = statedb.GetCode(addr)
|
|
|
|
|
|
|
+ code = statedb.GetCode(stack.Pop().Bytes())
|
|
|
} else {
|
|
} else {
|
|
|
code = closure.Code
|
|
code = closure.Code
|
|
|
}
|
|
}
|
|
@@ -663,12 +667,11 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|
|
} else if cOff+l > size {
|
|
} else if cOff+l > size {
|
|
|
l = uint64(math.Min(float64(cOff+l), float64(size)))
|
|
l = uint64(math.Min(float64(cOff+l), float64(size)))
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
codeCopy := code[cOff : cOff+l]
|
|
codeCopy := code[cOff : cOff+l]
|
|
|
|
|
|
|
|
mem.Set(mOff, l, codeCopy)
|
|
mem.Set(mOff, l, codeCopy)
|
|
|
|
|
|
|
|
- self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, code[cOff:cOff+l])
|
|
|
|
|
|
|
+ self.Printf(" => [%v, %v, %v] %x", mOff, cOff, l, codeCopy)
|
|
|
case GASPRICE:
|
|
case GASPRICE:
|
|
|
stack.Push(closure.Price)
|
|
stack.Push(closure.Price)
|
|
|
|
|
|
|
@@ -891,7 +894,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
|
|
|
size, offset := stack.Popn()
|
|
size, offset := stack.Popn()
|
|
|
ret := mem.Get(offset.Int64(), size.Int64())
|
|
ret := mem.Get(offset.Int64(), size.Int64())
|
|
|
|
|
|
|
|
- self.Printf(" => (%d) 0x%x", len(ret), ret).Endl()
|
|
|
|
|
|
|
+ self.Printf(" => [%v, %v] (%d) 0x%x", offset, size, len(ret), ret).Endl()
|
|
|
|
|
|
|
|
return closure.Return(ret), nil
|
|
return closure.Return(ret), nil
|
|
|
case SUICIDE:
|
|
case SUICIDE:
|