@@ -140,6 +140,16 @@ def eat_gas(compustate, amount):
140
140
return True
141
141
142
142
143
+ def all_but_1_nth (gas , n ):
144
+ return gas - (gas // n )
145
+
146
+
147
+ def max_call_gas (gas ):
148
+ """Since EIP150 CALLs will send only all but 1/64th of the available gas.
149
+ """
150
+ return all_but_1_nth (gas , n = opcodes .CALL_CHILD_LIMIT_DENOM )
151
+
152
+
143
153
def vm_exception (error , ** kargs ):
144
154
log_vm_exit .trace ('EXCEPTION' , cause = error , ** kargs )
145
155
return 0 , 0 , []
@@ -513,14 +523,20 @@ def vm_execute(ext, msg, code):
513
523
return vm_exception ('OOG EXTENDING MEMORY' )
514
524
if ext .get_balance (msg .to ) >= value and msg .depth < 1024 :
515
525
cd = CallData (mem , mstart , msz )
516
- create_msg = Message (msg .to , b'' , value , compustate .gas , cd , msg .depth + 1 )
526
+ ingas = compustate .gas
527
+ # EIP150(1b) CREATE only provides all but one 64th of the
528
+ # parent gas to the child call
529
+ if ext .post_anti_dos_hardfork ():
530
+ ingas = max_call_gas (ingas )
531
+
532
+ create_msg = Message (msg .to , b'' , value , ingas , cd , msg .depth + 1 )
517
533
o , gas , addr = ext .create (create_msg )
518
534
if o :
519
535
stk .append (utils .coerce_to_int (addr ))
520
- compustate .gas = gas
536
+ compustate .gas -= ( ingas - gas )
521
537
else :
522
538
stk .append (0 )
523
- compustate .gas = 0
539
+ compustate .gas -= ingas
524
540
else :
525
541
stk .append (0 )
526
542
elif op == 'CALL' :
@@ -535,9 +551,19 @@ def vm_execute(ext, msg, code):
535
551
(value > 0 ) * opcodes .GCALLVALUETRANSFER + \
536
552
ext .post_anti_dos_hardfork () * opcodes .CALL_SUPPLEMENTAL_GAS
537
553
# ^ EIP150 Increase the gas cost of CALL to 700
554
+
555
+ if ext .post_anti_dos_hardfork ():
556
+ # EIP150(1b) if a call asks for more gas than all but one 64th of
557
+ # the maximum allowed amount, call with all but one 64th of the
558
+ # maximum allowed amount of gas
559
+ if compustate .gas < extra_gas :
560
+ return vm_exception ('OUT OF GAS' , needed = extra_gas )
561
+ gas = min (gas , max_call_gas (compustate .gas - extra_gas ))
562
+ else :
563
+ if compustate .gas < gas + extra_gas :
564
+ return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
565
+
538
566
submsg_gas = gas + opcodes .GSTIPEND * (value > 0 )
539
- if compustate .gas < gas + extra_gas :
540
- return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
541
567
if ext .get_balance (msg .to ) >= value and msg .depth < 1024 :
542
568
compustate .gas -= (gas + extra_gas )
543
569
cd = CallData (mem , meminstart , meminsz )
@@ -568,9 +594,19 @@ def vm_execute(ext, msg, code):
568
594
extra_gas = (value > 0 ) * opcodes .GCALLVALUETRANSFER + \
569
595
ext .post_anti_dos_hardfork () * opcodes .CALL_SUPPLEMENTAL_GAS
570
596
# ^ EIP150 Increase the gas cost of CALLCODE, DELEGATECALL to 700
597
+
598
+ if ext .post_anti_dos_hardfork ():
599
+ # EIP150(1b) if a call asks for more gas than all but one 64th of
600
+ # the maximum allowed amount, call with all but one 64th of the
601
+ # maximum allowed amount of gas
602
+ if compustate .gas < extra_gas :
603
+ return vm_exception ('OUT OF GAS' , needed = extra_gas )
604
+ gas = min (gas , max_call_gas (compustate .gas - extra_gas ))
605
+ else :
606
+ if compustate .gas < gas + extra_gas :
607
+ return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
608
+
571
609
submsg_gas = gas + opcodes .GSTIPEND * (value > 0 )
572
- if compustate .gas < gas + extra_gas :
573
- return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
574
610
if ext .get_balance (msg .to ) >= value and msg .depth < 1024 :
575
611
compustate .gas -= (gas + extra_gas )
576
612
to = utils .encode_int (to )
0 commit comments