@@ -92,7 +92,7 @@ module.exports = {
92
92
} else {
93
93
var bytes = 1 + logTable ( exponent )
94
94
const gasAmount = new BN ( bytes ) . muln ( eei . _runState . _common . param ( 'gasPrices' , 'expByte' ) )
95
- eei . subGas ( gasAmount )
95
+ eei . useGas ( gasAmount )
96
96
97
97
var m = BN . red ( utils . TWO_POW256 )
98
98
base = base . toRed ( m )
@@ -199,7 +199,7 @@ module.exports = {
199
199
SHA3 : function ( offset , length , eei ) {
200
200
var data = eei . memLoad ( offset , length )
201
201
// copy fee
202
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'sha3Word' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
202
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'sha3Word' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
203
203
return new BN ( utils . keccak256 ( data ) )
204
204
} ,
205
205
// 0x30 range - closure state
@@ -255,15 +255,15 @@ module.exports = {
255
255
CALLDATACOPY : function ( memOffset , dataOffset , dataLength , eei ) {
256
256
eei . memStore ( memOffset , eei . getCallData ( ) , dataOffset , dataLength )
257
257
// sub the COPY fee
258
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . imul ( dataLength . divCeil ( new BN ( 32 ) ) ) )
258
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . imul ( dataLength . divCeil ( new BN ( 32 ) ) ) )
259
259
} ,
260
260
CODESIZE : function ( eei ) {
261
261
return new BN ( eei . getCodeSize ( ) )
262
262
} ,
263
263
CODECOPY : function ( memOffset , codeOffset , length , eei ) {
264
264
eei . memStore ( memOffset , eei . getCode ( ) , codeOffset , length )
265
265
// sub the COPY fee
266
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
266
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
267
267
} ,
268
268
EXTCODESIZE : function ( address , eei , cb ) {
269
269
var stateManager = eei . _runState . stateManager
@@ -277,10 +277,10 @@ module.exports = {
277
277
var stateManager = eei . _runState . stateManager
278
278
address = addressToBuffer ( address )
279
279
280
- // FIXME: for some reason this must come before subGas
280
+ // FIXME: for some reason this must come before useGas
281
281
eei . subMemUsage ( memOffset , length )
282
282
// copy fee
283
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
283
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
284
284
285
285
stateManager . getContractCode ( address , function ( err , code ) {
286
286
if ( err ) return cb ( err )
@@ -322,7 +322,7 @@ module.exports = {
322
322
323
323
eei . memStore ( memOffset , utils . toBuffer ( eei . getReturnDataSize ( ) ) , returnDataOffset , length , false )
324
324
// sub the COPY fee
325
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . mul ( length . divCeil ( new BN ( 32 ) ) ) )
325
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'copy' ) ) . mul ( length . divCeil ( new BN ( 32 ) ) ) )
326
326
} ,
327
327
GASPRICE : function ( eei ) {
328
328
return new BN ( eei . getTxGasPrice ( ) )
@@ -419,27 +419,27 @@ module.exports = {
419
419
} ,
420
420
JUMP : function ( dest , eei ) {
421
421
if ( dest . gtn ( eei . getCodeSize ( ) ) ) {
422
- eei . trap ( ERROR . INVALID_JUMP + ' at ' + eei . describeLocation ( ) )
422
+ eei . trap ( ERROR . INVALID_JUMP + ' at ' + describeLocation ( eei . getCode ( ) , eei . getAddress ( ) , eei . _runState . programCounter ) )
423
423
}
424
424
425
425
dest = dest . toNumber ( )
426
426
427
427
if ( ! eei . jumpIsValid ( dest ) ) {
428
- eei . trap ( ERROR . INVALID_JUMP + ' at ' + eei . describeLocation ( ) )
428
+ eei . trap ( ERROR . INVALID_JUMP + ' at ' + describeLocation ( eei . getCode ( ) , eei . getAddress ( ) , eei . _runState . programCounter ) )
429
429
}
430
430
431
431
eei . _runState . programCounter = dest
432
432
} ,
433
433
JUMPI : function ( dest , cond , eei ) {
434
434
if ( ! cond . isZero ( ) ) {
435
435
if ( dest . gtn ( eei . getCodeSize ( ) ) ) {
436
- eei . trap ( ERROR . INVALID_JUMP + ' at ' + eei . describeLocation ( ) )
436
+ eei . trap ( ERROR . INVALID_JUMP + ' at ' + describeLocation ( eei . getCode ( ) , eei . getAddress ( ) , eei . _runState . programCounter ) )
437
437
}
438
438
439
439
dest = dest . toNumber ( )
440
440
441
441
if ( ! eei . jumpIsValid ( dest ) ) {
442
- eei . trap ( ERROR . INVALID_JUMP + ' at ' + eei . describeLocation ( ) )
442
+ eei . trap ( ERROR . INVALID_JUMP + ' at ' + describeLocation ( eei . getCode ( ) , eei . getAddress ( ) , eei . _runState . programCounter ) )
443
443
}
444
444
445
445
eei . _runState . programCounter = dest
@@ -502,7 +502,7 @@ module.exports = {
502
502
503
503
const numOfTopics = eei . _runState . opCode - 0xa0
504
504
const mem = eei . memLoad ( memOffset , memLength )
505
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'logTopic' ) ) . imuln ( numOfTopics ) . iadd ( memLength . muln ( eei . _runState . _common . param ( 'gasPrices' , 'logData' ) ) ) )
505
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'logTopic' ) ) . imuln ( numOfTopics ) . iadd ( memLength . muln ( eei . _runState . _common . param ( 'gasPrices' , 'logData' ) ) ) )
506
506
507
507
// add address
508
508
var log = [ eei . getAddress ( ) ]
@@ -564,7 +564,7 @@ module.exports = {
564
564
}
565
565
566
566
// Deduct gas costs for hashing
567
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'sha3Word' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
567
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'sha3Word' ) ) . imul ( length . divCeil ( new BN ( 32 ) ) ) )
568
568
eei . checkCallMemCost ( options , localOpts )
569
569
eei . checkOutOfGas ( options )
570
570
eei . makeCall ( options , localOpts , done )
@@ -595,7 +595,7 @@ module.exports = {
595
595
}
596
596
597
597
if ( ! value . isZero ( ) ) {
598
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callValueTransfer' ) ) )
598
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callValueTransfer' ) ) )
599
599
}
600
600
601
601
stateManager . accountIsEmpty ( toAddress , function ( err , empty ) {
@@ -607,7 +607,7 @@ module.exports = {
607
607
if ( empty ) {
608
608
if ( ! value . isZero ( ) ) {
609
609
try {
610
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callNewAccount' ) ) )
610
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callNewAccount' ) ) )
611
611
} catch ( e ) {
612
612
done ( e . error )
613
613
return
@@ -653,7 +653,7 @@ module.exports = {
653
653
}
654
654
655
655
if ( ! value . isZero ( ) ) {
656
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callValueTransfer' ) ) )
656
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callValueTransfer' ) ) )
657
657
}
658
658
659
659
eei . checkCallMemCost ( options , localOpts )
@@ -790,7 +790,7 @@ module.exports = {
790
790
if ( ( new BN ( contract . balance ) ) . gtn ( 0 ) ) {
791
791
if ( empty ) {
792
792
try {
793
- eei . subGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callNewAccount' ) ) )
793
+ eei . useGas ( new BN ( eei . _runState . _common . param ( 'gasPrices' , 'callNewAccount' ) ) )
794
794
} catch ( e ) {
795
795
cb ( e . error )
796
796
return
@@ -825,3 +825,10 @@ module.exports = {
825
825
} )
826
826
}
827
827
}
828
+
829
+ function describeLocation ( code , address , pc ) {
830
+ const hash = utils . keccak256 ( code ) . toString ( 'hex' )
831
+ address = address . toString ( 'hex' )
832
+ pc = pc - 1
833
+ return hash + '/' + address + ':' + pc
834
+ }
0 commit comments