@@ -108,13 +108,13 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
108
108
}
109
109
)
110
110
111
+ 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 )
112
+
111
113
// Don't bother with the execution if there's no code.
112
114
if len (code ) == 0 {
113
115
return closure .Return (nil ), nil
114
116
}
115
117
116
- vmlogger .Debugf ("(%d) (%x) %x gas: %v (d) %x\n " , self .env .Depth (), caller .Address ()[:4 ], closure .Address (), closure .Gas , callData )
117
-
118
118
for {
119
119
prevStep = step
120
120
// The base for all big integer arithmetic
@@ -134,6 +134,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
134
134
addStepGasUsage (GasStep )
135
135
136
136
var newMemSize * big.Int = ethutil .Big0
137
+ var additionalGas * big.Int = new (big.Int )
137
138
// Stack Check, memory resize & gas phase
138
139
switch op {
139
140
// Stack checks only
@@ -213,22 +214,24 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
213
214
newMemSize = calcMemSize (stack .Peek (), stack .data [stack .Len ()- 2 ])
214
215
case SHA3 :
215
216
require (2 )
216
-
217
217
gas .Set (GasSha )
218
-
219
218
newMemSize = calcMemSize (stack .Peek (), stack .data [stack .Len ()- 2 ])
219
+ additionalGas .Set (stack .data [stack .Len ()- 2 ])
220
220
case CALLDATACOPY :
221
221
require (2 )
222
222
223
223
newMemSize = calcMemSize (stack .Peek (), stack .data [stack .Len ()- 3 ])
224
+ additionalGas .Set (stack .data [stack .Len ()- 3 ])
224
225
case CODECOPY :
225
226
require (3 )
226
227
227
228
newMemSize = calcMemSize (stack .Peek (), stack .data [stack .Len ()- 3 ])
229
+ additionalGas .Set (stack .data [stack .Len ()- 3 ])
228
230
case EXTCODECOPY :
229
231
require (4 )
230
232
231
233
newMemSize = calcMemSize (stack .data [stack .Len ()- 2 ], stack .data [stack .Len ()- 4 ])
234
+ additionalGas .Set (stack .data [stack .Len ()- 4 ])
232
235
case CALL , CALLCODE :
233
236
require (7 )
234
237
gas .Set (GasCall )
@@ -245,20 +248,23 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
245
248
newMemSize = calcMemSize (stack .data [stack .Len ()- 2 ], stack .data [stack .Len ()- 3 ])
246
249
}
247
250
251
+ switch op {
252
+ case CALLDATACOPY , CODECOPY , EXTCODECOPY :
253
+ additionalGas .Add (additionalGas , u256 (31 ))
254
+ additionalGas .Div (additionalGas , u256 (32 ))
255
+ addStepGasUsage (additionalGas )
256
+ case SHA3 :
257
+ additionalGas .Add (additionalGas , u256 (31 ))
258
+ additionalGas .Div (additionalGas , u256 (32 ))
259
+ additionalGas .Mul (additionalGas , GasSha3Byte )
260
+ addStepGasUsage (additionalGas )
261
+ }
262
+
248
263
if newMemSize .Cmp (ethutil .Big0 ) > 0 {
249
264
newMemSize .Add (newMemSize , u256 (31 ))
250
265
newMemSize .Div (newMemSize , u256 (32 ))
251
266
newMemSize .Mul (newMemSize , u256 (32 ))
252
267
253
- switch op {
254
- case CALLDATACOPY , CODECOPY , EXTCODECOPY :
255
- addStepGasUsage (new (big.Int ).Div (newMemSize , u256 (32 )))
256
- case SHA3 :
257
- g := new (big.Int ).Div (newMemSize , u256 (32 ))
258
- g .Mul (g , GasSha3Byte )
259
- addStepGasUsage (g )
260
- }
261
-
262
268
if newMemSize .Cmp (u256 (int64 (mem .Len ()))) > 0 {
263
269
memGasUsage := new (big.Int ).Sub (newMemSize , u256 (int64 (mem .Len ())))
264
270
memGasUsage .Mul (GasMemory , memGasUsage )
@@ -643,9 +649,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
643
649
case CODECOPY , EXTCODECOPY :
644
650
var code []byte
645
651
if op == EXTCODECOPY {
646
- addr := stack .Pop ().Bytes ()
647
-
648
- code = statedb .GetCode (addr )
652
+ code = statedb .GetCode (stack .Pop ().Bytes ())
649
653
} else {
650
654
code = closure .Code
651
655
}
@@ -663,12 +667,11 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
663
667
} else if cOff + l > size {
664
668
l = uint64 (math .Min (float64 (cOff + l ), float64 (size )))
665
669
}
666
-
667
670
codeCopy := code [cOff : cOff + l ]
668
671
669
672
mem .Set (mOff , l , codeCopy )
670
673
671
- self .Printf (" => [%v, %v, %v] %x" , mOff , cOff , l , code [ cOff : cOff + l ] )
674
+ self .Printf (" => [%v, %v, %v] %x" , mOff , cOff , l , codeCopy )
672
675
case GASPRICE :
673
676
stack .Push (closure .Price )
674
677
@@ -891,7 +894,7 @@ func (self *DebugVm) Run(me, caller ClosureRef, code []byte, value, gas, price *
891
894
size , offset := stack .Popn ()
892
895
ret := mem .Get (offset .Int64 (), size .Int64 ())
893
896
894
- self .Printf (" => (%d) 0x%x" , len (ret ), ret ).Endl ()
897
+ self .Printf (" => [%v, %v] (%d) 0x%x" , offset , size , len (ret ), ret ).Endl ()
895
898
896
899
return closure .Return (ret ), nil
897
900
case SUICIDE :
0 commit comments