@@ -19,6 +19,7 @@ type GasesByDimension struct {
19
19
StateGrowth uint64 `json:"gr,omitempty"`
20
20
HistoryGrowth uint64 `json:"h,omitempty"`
21
21
StateGrowthRefund int64 `json:"rf,omitempty"`
22
+ ChildExecutionCost uint64 `json:"exc,omitempty"`
22
23
}
23
24
24
25
// in the case of opcodes like CALL, STATICCALL, DELEGATECALL, etc,
@@ -202,6 +203,7 @@ func calcSimpleSingleDimensionGas(
202
203
StateGrowth : 0 ,
203
204
HistoryGrowth : 0 ,
204
205
StateGrowthRefund : 0 ,
206
+ ChildExecutionCost : 0 ,
205
207
}, nil , nil
206
208
}
207
209
@@ -237,6 +239,7 @@ func calcSimpleAddressAccessSetGas(
237
239
StateGrowth : 0 ,
238
240
HistoryGrowth : 0 ,
239
241
StateGrowthRefund : 0 ,
242
+ ChildExecutionCost : 0 ,
240
243
}
241
244
if err := checkGasDimensionsEqualOneDimensionalGas (pc , op , depth , gas , cost , ret ); err != nil {
242
245
return GasesByDimension {}, nil , err
@@ -270,6 +273,7 @@ func calcSLOADGas(
270
273
StateGrowth : 0 ,
271
274
HistoryGrowth : 0 ,
272
275
StateGrowthRefund : 0 ,
276
+ ChildExecutionCost : 0 ,
273
277
}
274
278
if err := checkGasDimensionsEqualOneDimensionalGas (pc , op , depth , gas , cost , ret ); err != nil {
275
279
return GasesByDimension {}, nil , err
@@ -324,6 +328,7 @@ func calcExtCodeCopyGas(
324
328
StateGrowth : 0 ,
325
329
HistoryGrowth : 0 ,
326
330
StateGrowthRefund : 0 ,
331
+ ChildExecutionCost : 0 ,
327
332
}
328
333
if err := checkGasDimensionsEqualOneDimensionalGas (pc , op , depth , gas , cost , ret ); err != nil {
329
334
return GasesByDimension {}, nil , err
@@ -405,6 +410,7 @@ func calcStateReadCallGas(
405
410
StateGrowth : 0 ,
406
411
HistoryGrowth : 0 ,
407
412
StateGrowthRefund : 0 ,
413
+ ChildExecutionCost : 0 ,
408
414
}, & CallGasDimensionInfo {
409
415
Pc : pc ,
410
416
Op : vm .OpCode (op ),
@@ -430,15 +436,17 @@ func finishCalcStateReadCallGas(
430
436
codeExecutionCost uint64 ,
431
437
callGasDimensionInfo CallGasDimensionInfo ,
432
438
) (GasesByDimension , error ) {
439
+ oneDimensionalGas := totalGasUsed - codeExecutionCost
433
440
computation := callGasDimensionInfo .AccessListComputationCost + callGasDimensionInfo .MemoryExpansionCost
434
441
stateAccess := callGasDimensionInfo .AccessListStateAccessCost
435
442
ret := GasesByDimension {
436
- OneDimensionalGasCost : totalGasUsed ,
443
+ OneDimensionalGasCost : oneDimensionalGas ,
437
444
Computation : computation ,
438
445
StateAccess : stateAccess ,
439
446
StateGrowth : 0 ,
440
447
HistoryGrowth : 0 ,
441
448
StateGrowthRefund : 0 ,
449
+ ChildExecutionCost : codeExecutionCost ,
442
450
}
443
451
err := checkGasDimensionsEqualCallGas (
444
452
callGasDimensionInfo .Pc ,
@@ -504,6 +512,7 @@ func calcLogGas(
504
512
StateGrowth : 0 ,
505
513
HistoryGrowth : historyGrowthCost ,
506
514
StateGrowthRefund : 0 ,
515
+ ChildExecutionCost : 0 ,
507
516
}, nil , nil
508
517
}
509
518
@@ -557,6 +566,7 @@ func calcCreateGas(
557
566
StateGrowth : 0 ,
558
567
HistoryGrowth : 0 ,
559
568
StateGrowthRefund : 0 ,
569
+ ChildExecutionCost : 0 ,
560
570
}, & CallGasDimensionInfo {
561
571
Pc : pc ,
562
572
Op : vm .OpCode (op ),
@@ -577,6 +587,7 @@ func finishCalcCreateGas(
577
587
codeExecutionCost uint64 ,
578
588
callGasDimensionInfo CallGasDimensionInfo ,
579
589
) (GasesByDimension , error ) {
590
+ oneDimensionalGas := totalGasUsed - codeExecutionCost
580
591
// totalGasUsed = init_code_cost + memory_expansion_cost + deployment_code_execution_cost + code_deposit_cost
581
592
codeDepositCost := totalGasUsed - params .CreateGas - callGasDimensionInfo .InitCodeCost -
582
593
callGasDimensionInfo .MemoryExpansionCost - callGasDimensionInfo .HashCost - codeExecutionCost
@@ -588,12 +599,13 @@ func finishCalcCreateGas(
588
599
computeNonNewAccountCost := staticNonNewAccountCost / 2
589
600
growthNonNewAccountCost := staticNonNewAccountCost - computeNonNewAccountCost
590
601
ret := GasesByDimension {
591
- OneDimensionalGasCost : totalGasUsed ,
602
+ OneDimensionalGasCost : oneDimensionalGas ,
592
603
Computation : callGasDimensionInfo .InitCodeCost + callGasDimensionInfo .MemoryExpansionCost + callGasDimensionInfo .HashCost + computeNonNewAccountCost ,
593
604
StateAccess : 0 ,
594
605
StateGrowth : growthNonNewAccountCost + params .CallNewAccountGas + codeDepositCost ,
595
606
HistoryGrowth : 0 ,
596
607
StateGrowthRefund : 0 ,
608
+ ChildExecutionCost : codeExecutionCost ,
597
609
}
598
610
err := checkGasDimensionsEqualCallGas (
599
611
callGasDimensionInfo .Pc ,
@@ -677,6 +689,7 @@ func calcReadAndStoreCallGas(
677
689
StateGrowth : 0 ,
678
690
HistoryGrowth : 0 ,
679
691
StateGrowthRefund : 0 ,
692
+ ChildExecutionCost : 0 ,
680
693
}, & CallGasDimensionInfo {
681
694
Pc : pc ,
682
695
Op : vm .OpCode (op ),
@@ -702,6 +715,8 @@ func finishCalcStateReadAndStoreCallGas(
702
715
codeExecutionCost uint64 ,
703
716
callGasDimensionInfo CallGasDimensionInfo ,
704
717
) (GasesByDimension , error ) {
718
+ oneDimensionalGas := totalGasUsed - codeExecutionCost
719
+ fmt .Println ("finishCalcStateReadAndStoreCallGas is called" )
705
720
// the stipend is 2300 and it is not charged to the call itself but used in the execution cost
706
721
var positiveValueCostLessStipend uint64 = 0
707
722
if callGasDimensionInfo .IsValueSentWithCall {
@@ -716,44 +731,53 @@ func finishCalcStateReadAndStoreCallGas(
716
731
// and whatever was left over after that was address_access_cost
717
732
// callcode is the same as call except does not have value_to_empty_account_cost,
718
733
// so this code properly handles it coincidentally, too
734
+ fmt .Println ("finishCalcStateReadAndStoreCallGas is continuing" )
719
735
ret := GasesByDimension {
720
- OneDimensionalGasCost : totalGasUsed ,
736
+ OneDimensionalGasCost : oneDimensionalGas ,
721
737
Computation : callGasDimensionInfo .MemoryExpansionCost + params .WarmStorageReadCostEIP2929 ,
722
738
StateAccess : positiveValueCostLessStipend ,
723
739
StateGrowth : 0 ,
724
740
HistoryGrowth : 0 ,
725
741
StateGrowthRefund : 0 ,
742
+ ChildExecutionCost : codeExecutionCost ,
726
743
}
727
744
if leftOver > params .ColdAccountAccessCostEIP2929 { // there is a value being sent to an empty account
745
+ fmt .Println ("leftOver > params.ColdAccountAccessCostEIP2929" )
728
746
var coldCost uint64 = 0
729
747
if leftOver - params .CallNewAccountGas == params .ColdAccountAccessCostEIP2929 {
730
748
coldCost = params .ColdAccountAccessCostEIP2929 - params .WarmStorageReadCostEIP2929
731
749
}
732
750
ret = GasesByDimension {
733
- OneDimensionalGasCost : totalGasUsed ,
751
+ OneDimensionalGasCost : oneDimensionalGas ,
734
752
Computation : callGasDimensionInfo .MemoryExpansionCost + params .WarmStorageReadCostEIP2929 ,
735
753
StateAccess : coldCost + positiveValueCostLessStipend ,
736
754
StateGrowth : params .CallNewAccountGas ,
737
755
HistoryGrowth : 0 ,
738
756
StateGrowthRefund : 0 ,
757
+ ChildExecutionCost : codeExecutionCost ,
739
758
}
740
759
} else if leftOver == params .ColdAccountAccessCostEIP2929 {
760
+ fmt .Println ("leftOver == params.ColdAccountAccessCostEIP2929" )
741
761
var coldCost uint64 = params .ColdAccountAccessCostEIP2929 - params .WarmStorageReadCostEIP2929
742
762
ret = GasesByDimension {
743
- OneDimensionalGasCost : totalGasUsed ,
763
+ OneDimensionalGasCost : oneDimensionalGas ,
744
764
Computation : callGasDimensionInfo .MemoryExpansionCost + params .WarmStorageReadCostEIP2929 ,
745
765
StateAccess : coldCost + positiveValueCostLessStipend ,
746
766
StateGrowth : 0 ,
747
767
HistoryGrowth : 0 ,
748
768
StateGrowthRefund : 0 ,
769
+ ChildExecutionCost : codeExecutionCost ,
749
770
}
750
771
}
772
+ fmt .Println ("finishCalcStateReadAndStoreCallGas is returning" )
751
773
err := checkGasDimensionsEqualCallGas (
752
774
callGasDimensionInfo .Pc ,
753
775
byte (callGasDimensionInfo .Op ),
754
776
codeExecutionCost ,
755
777
ret ,
756
778
)
779
+ fmt .Println ("End result: " , ret )
780
+ fmt .Println ("End error: " , err )
757
781
return ret , err
758
782
}
759
783
@@ -824,6 +848,7 @@ func calcSStoreGas(
824
848
StateGrowth : params .SstoreSetGas ,
825
849
HistoryGrowth : 0 ,
826
850
StateGrowthRefund : diff ,
851
+ ChildExecutionCost : 0 ,
827
852
}
828
853
} else if cost > 0 {
829
854
ret = GasesByDimension {
@@ -833,6 +858,7 @@ func calcSStoreGas(
833
858
StateGrowth : 0 ,
834
859
HistoryGrowth : 0 ,
835
860
StateGrowthRefund : diff ,
861
+ ChildExecutionCost : 0 ,
836
862
}
837
863
}
838
864
if err := checkGasDimensionsEqualOneDimensionalGas (pc , op , depth , gas , cost , ret ); err != nil {
@@ -881,6 +907,7 @@ func calcSelfDestructGas(
881
907
StateGrowth : params .CreateBySelfdestructGas ,
882
908
HistoryGrowth : 0 ,
883
909
StateGrowthRefund : 0 ,
910
+ ChildExecutionCost : 0 ,
884
911
}, nil , nil
885
912
} else if cost == params .CreateBySelfdestructGas + params .SelfdestructGasEIP150 + params .ColdAccountAccessCostEIP2929 {
886
913
// cold and funds target empty
@@ -895,6 +922,7 @@ func calcSelfDestructGas(
895
922
StateGrowth : params .CreateBySelfdestructGas ,
896
923
HistoryGrowth : 0 ,
897
924
StateGrowthRefund : 0 ,
925
+ ChildExecutionCost : 0 ,
898
926
}, nil , nil
899
927
} else if cost == params .SelfdestructGasEIP150 + params .ColdAccountAccessCostEIP2929 {
900
928
// address lookup was cold but funds target has money already. Cost is 7600
@@ -908,6 +936,7 @@ func calcSelfDestructGas(
908
936
StateGrowth : 0 ,
909
937
HistoryGrowth : 0 ,
910
938
StateGrowthRefund : 0 ,
939
+ ChildExecutionCost : 0 ,
911
940
}, nil , nil
912
941
}
913
942
// if you reach here, then the cost was 5000
@@ -920,6 +949,7 @@ func calcSelfDestructGas(
920
949
StateGrowth : 0 ,
921
950
HistoryGrowth : 0 ,
922
951
StateGrowthRefund : 0 ,
952
+ ChildExecutionCost : 0 ,
923
953
}, nil , nil
924
954
}
925
955
@@ -1086,12 +1116,13 @@ func checkGasDimensionsEqualCallGas(
1086
1116
codeExecutionCost uint64 ,
1087
1117
dim GasesByDimension ,
1088
1118
) error {
1089
- if dim .OneDimensionalGasCost != codeExecutionCost + dim .Computation + dim .StateAccess + dim .StateGrowth + dim .HistoryGrowth {
1119
+ if dim .OneDimensionalGasCost != dim .Computation + dim .StateAccess + dim .StateGrowth + dim .HistoryGrowth {
1090
1120
return fmt .Errorf (
1091
- "unexpected gas cost mismatch: pc %d, op %d, codeExecutionCost %d ! = %v" ,
1121
+ "unexpected gas cost mismatch: pc %d, op %d, with codeExecutionCost %d, expected %d = = %v" ,
1092
1122
pc ,
1093
1123
op ,
1094
1124
codeExecutionCost ,
1125
+ dim .OneDimensionalGasCost ,
1095
1126
dim ,
1096
1127
)
1097
1128
}
0 commit comments