@@ -140,6 +140,11 @@ def eat_gas(compustate, amount):
140
140
return vm_exception ("OUT OF GAS" )
141
141
else :
142
142
compustate .gas -= amount
143
+ return True
144
+
145
+
146
+ def all_but_1n (x , n ):
147
+ return x - x / n
143
148
144
149
145
150
def vm_exception (error , ** kargs ):
@@ -550,15 +555,15 @@ def vm_execute(ext, msg, code):
550
555
cd = CallData (mem , mstart , msz )
551
556
ingas = compustate .gas
552
557
if ext .post_anti_dos_hardfork ():
553
- ingas = ingas * opcodes .CALL_CHILD_LIMIT_NUM / CALL_CHILD_LIMIT_DENOM
558
+ ingas = all_but_1n ( ingas , opcodes .CALL_CHILD_LIMIT_DENOM )
554
559
create_msg = Message (msg .to , b'' , value , ingas , cd , msg .depth + 1 )
555
560
o , gas , addr = ext .create (create_msg )
556
561
if o :
557
562
stk .append (utils .coerce_to_int (addr ))
558
- compustate .gas = gas
563
+ compustate .gas = compustate . gas - ingas + gas
559
564
else :
560
565
stk .append (0 )
561
- compustate .gas = 0
566
+ compustate .gas -= ingas
562
567
else :
563
568
stk .append (0 )
564
569
elif op == 'CALL' :
@@ -576,8 +581,7 @@ def vm_execute(ext, msg, code):
576
581
if ext .post_anti_dos_hardfork ():
577
582
if compustate .gas < extra_gas :
578
583
return vm_exception ('OUT OF GAS' , needed = extra_gas )
579
- elif gas > (compustate .gas - extra_gas ) * opcodes .CALL_CHILD_LIMIT_NUM / opcodes .CALL_CHILD_LIMIT_DENOM :
580
- gas = (compustate .gas - extra_gas ) * opcodes .CALL_CHILD_LIMIT_NUM / opcodes .CALL_CHILD_LIMIT_DENOM
584
+ gas = min (gas , all_but_1n (compustate .gas - extra_gas , opcodes .CALL_CHILD_LIMIT_DENOM ))
581
585
else :
582
586
if compustate .gas < gas + extra_gas :
583
587
return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
@@ -612,15 +616,14 @@ def vm_execute(ext, msg, code):
612
616
return vm_exception ('OOG EXTENDING MEMORY' )
613
617
extra_gas = (value > 0 ) * opcodes .GCALLVALUETRANSFER + \
614
618
ext .post_anti_dos_hardfork () * opcodes .CALL_SUPPLEMENTAL_GAS
615
- submsg_gas = gas + opcodes .GSTIPEND * (value > 0 )
616
619
if ext .post_anti_dos_hardfork ():
617
620
if compustate .gas < extra_gas :
618
621
return vm_exception ('OUT OF GAS' , needed = extra_gas )
619
- elif gas > (compustate .gas - extra_gas ) * opcodes .CALL_CHILD_LIMIT_NUM / opcodes .CALL_CHILD_LIMIT_DENOM :
620
- gas = (compustate .gas - extra_gas ) * opcodes .CALL_CHILD_LIMIT_NUM / opcodes .CALL_CHILD_LIMIT_DENOM
622
+ gas = min (gas , all_but_1n (compustate .gas - extra_gas , opcodes .CALL_CHILD_LIMIT_DENOM ))
621
623
else :
622
624
if compustate .gas < gas + extra_gas :
623
625
return vm_exception ('OUT OF GAS' , needed = gas + extra_gas )
626
+ submsg_gas = gas + opcodes .GSTIPEND * (value > 0 )
624
627
if ext .get_balance (msg .to ) >= value and msg .depth < 1024 :
625
628
compustate .gas -= (gas + extra_gas )
626
629
assert compustate .gas >= 0
@@ -655,8 +658,7 @@ def vm_execute(ext, msg, code):
655
658
not mem_extend (mem , compustate , op , codestart , codesz ):
656
659
return vm_exception ('OOG EXTENDING MEMORY' )
657
660
if ext .post_anti_dos_hardfork ():
658
- if gas > compustate .gas * opcodes .CALL_CHILD_LIMIT_NUM / opcodes .CALL_CHILD_LIMIT_DENOM :
659
- gas = compustate .gas * opcodes .CALL_CHILD_LIMIT_NUM / opcodes .CALL_CHILD_LIMIT_DENOM
661
+ gas = min (gas , all_but_1n (compustate .gas , opcodes .CALL_CHILD_LIMIT_DENOM ))
660
662
else :
661
663
if gas > compustate .gas :
662
664
return vm_exception ("OUT OF GAS" , needed = gas )
@@ -680,13 +682,13 @@ def vm_execute(ext, msg, code):
680
682
return vm_exception ('OOG EXTENDING MEMORY' )
681
683
return peaceful_exit ('RETURN' , compustate .gas , mem [s0 : s0 + s1 ])
682
684
elif op == 'SUICIDE' :
683
- if ext .post_anti_dos_hardfork ():
684
- if gas < opcodes .SUICIDE_SUPPLEMENTAL_GAS :
685
- return vm_exception ("OUT OF GAS" )
686
- else :
687
- gas -= opcodes .SUICIDE_SUPPLEMENTAL_GAS
688
685
to = utils .encode_int (stk .pop ())
689
686
to = ((b'\x00 ' * (32 - len (to ))) + to )[12 :]
687
+ if ext .post_anti_dos_hardfork ():
688
+ extra_gas = opcodes .SUICIDE_SUPPLEMENTAL_GAS + \
689
+ (not ext .account_exists (to )) * opcodes .GCALLNEWACCOUNT
690
+ if not eat_gas (compustate , extra_gas ):
691
+ return vm_exception ("OUT OF GAS" )
690
692
xfer = ext .get_balance (msg .to )
691
693
ext .set_balance (to , ext .get_balance (to ) + xfer )
692
694
ext .set_balance (msg .to , 0 )
0 commit comments