@@ -135,6 +135,15 @@ def data_copy(compustate, size):
135
135
return True
136
136
137
137
138
+ def eat_gas (compustate , amount ):
139
+ if compustate .gas < amount :
140
+ compustate .gas = 0
141
+ return False
142
+ else :
143
+ compustate .gas -= amount
144
+ return True
145
+
146
+
138
147
def vm_exception (error , ** kargs ):
139
148
log_vm_exit .trace ('EXCEPTION' , cause = error , ** kargs )
140
149
return 0 , 0 , []
@@ -331,7 +340,11 @@ def vm_execute(ext, msg, code):
331
340
elif op == 'ADDRESS' :
332
341
stk .append (utils .coerce_to_int (msg .to ))
333
342
elif op == 'BALANCE' :
334
- addr = utils .coerce_addr_to_hex (stk .pop () % 2 ** 160 )
343
+ # EIP150: Increase the gas cost of BALANCE to 400
344
+ if ext .post_anti_dos_hardfork ():
345
+ if not eat_gas (compustate , opcodes .BALANCE_SUPPLEMENTAL_GAS ):
346
+ return vm_exception ("OUT OF GAS" )
347
+ addr = utils .coerce_addr_to_hex (stk .pop () % 2 ** 160 )
335
348
stk .append (ext .get_balance (addr ))
336
349
elif op == 'ORIGIN' :
337
350
stk .append (utils .coerce_to_int (ext .tx_origin ))
@@ -366,10 +379,18 @@ def vm_execute(ext, msg, code):
366
379
elif op == 'GASPRICE' :
367
380
stk .append (ext .tx_gasprice )
368
381
elif op == 'EXTCODESIZE' :
369
- addr = utils .coerce_addr_to_hex (stk .pop () % 2 ** 160 )
382
+ # EIP150: Increase the gas cost of EXTCODESIZE to 700
383
+ if ext .post_anti_dos_hardfork ():
384
+ if not eat_gas (compustate , opcodes .EXTCODELOAD_SUPPLEMENTAL_GAS ):
385
+ return vm_exception ("OUT OF GAS" )
386
+ addr = utils .coerce_addr_to_hex (stk .pop () % 2 ** 160 )
370
387
stk .append (len (ext .get_code (addr ) or b'' ))
371
388
elif op == 'EXTCODECOPY' :
372
- addr = utils .coerce_addr_to_hex (stk .pop () % 2 ** 160 )
389
+ # EIP150: Increase the base gas cost of EXTCODECOPY to 700
390
+ if ext .post_anti_dos_hardfork ():
391
+ if not eat_gas (compustate , opcodes .EXTCODELOAD_SUPPLEMENTAL_GAS ):
392
+ return vm_exception ("OUT OF GAS" )
393
+ addr = utils .coerce_addr_to_hex (stk .pop () % 2 ** 160 )
373
394
start , s2 , size = stk .pop (), stk .pop (), stk .pop ()
374
395
extcode = ext .get_code (addr ) or b''
375
396
assert utils .is_string (extcode )
@@ -418,6 +439,10 @@ def vm_execute(ext, msg, code):
418
439
return vm_exception ('OOG EXTENDING MEMORY' )
419
440
mem [s0 ] = s1 % 256
420
441
elif op == 'SLOAD' :
442
+ # EIP150: Increase the gas cost of SLOAD to 200
443
+ if ext .post_anti_dos_hardfork ():
444
+ if not eat_gas (compustate , opcodes .SLOAD_SUPPLEMENTAL_GAS ):
445
+ return vm_exception ("OUT OF GAS" )
421
446
stk .append (ext .get_storage_data (msg .to , stk .pop ()))
422
447
elif op == 'SSTORE' :
423
448
s0 , s1 = stk .pop (), stk .pop ()
@@ -514,10 +539,12 @@ def vm_execute(ext, msg, code):
514
539
to = utils .encode_int (to )
515
540
to = ((b'\x00 ' * (32 - len (to ))) + to )[12 :]
516
541
extra_gas = (not ext .account_exists (to )) * opcodes .GCALLNEWACCOUNT + \
517
- (value > 0 ) * opcodes .GCALLVALUETRANSFER
542
+ (value > 0 ) * opcodes .GCALLVALUETRANSFER + \
543
+ ext .post_anti_dos_hardfork () * opcodes .CALL_SUPPLEMENTAL_GAS
544
+ # ^ EIP150 Increase the gas cost of CALL to 700
518
545
submsg_gas = gas + opcodes .GSTIPEND * (value > 0 )
519
546
if compustate .gas < gas + extra_gas :
520
- return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
547
+ return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
521
548
if ext .get_balance (msg .to ) >= value and msg .depth < 1024 :
522
549
compustate .gas -= (gas + extra_gas )
523
550
cd = CallData (mem , meminstart , meminsz )
@@ -545,10 +572,12 @@ def vm_execute(ext, msg, code):
545
572
if not mem_extend (mem , compustate , op , meminstart , meminsz ) or \
546
573
not mem_extend (mem , compustate , op , memoutstart , memoutsz ):
547
574
return vm_exception ('OOG EXTENDING MEMORY' )
548
- extra_gas = (value > 0 ) * opcodes .GCALLVALUETRANSFER
575
+ extra_gas = (value > 0 ) * opcodes .GCALLVALUETRANSFER + \
576
+ ext .post_anti_dos_hardfork () * opcodes .CALL_SUPPLEMENTAL_GAS
577
+ # ^ EIP150 Increase the gas cost of CALLCODE, DELEGATECALL to 700
549
578
submsg_gas = gas + opcodes .GSTIPEND * (value > 0 )
550
579
if compustate .gas < gas + extra_gas :
551
- return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
580
+ return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
552
581
if ext .get_balance (msg .to ) >= value and msg .depth < 1024 :
553
582
compustate .gas -= (gas + extra_gas )
554
583
to = utils .encode_int (to )
@@ -581,6 +610,13 @@ def vm_execute(ext, msg, code):
581
610
elif op == 'SUICIDE' :
582
611
to = utils .encode_int (stk .pop ())
583
612
to = ((b'\x00 ' * (32 - len (to ))) + to )[12 :]
613
+
614
+ if ext .post_anti_dos_hardfork ():
615
+ # EIP150 Increase the gas cost of SUICIDE to 5000
616
+ extra_gas = opcodes .SUICIDE_SUPPLEMENTAL_GAS
617
+ if not eat_gas (compustate , extra_gas ):
618
+ return vm_exception ("OUT OF GAS" )
619
+
584
620
xfer = ext .get_balance (msg .to )
585
621
ext .set_balance (to , ext .get_balance (to ) + xfer )
586
622
ext .set_balance (msg .to , 0 )
0 commit comments