@@ -21,6 +21,7 @@ package protocol
2121
2222import (
2323 "cmp"
24+ "errors"
2425 "fmt"
2526 "slices"
2627 "time"
@@ -35,6 +36,7 @@ import (
3536 "github.com/erigontech/erigon/common/u256"
3637 "github.com/erigontech/erigon/diagnostics/metrics"
3738 "github.com/erigontech/erigon/execution/chain"
39+ "github.com/erigontech/erigon/execution/protocol/fixedgas"
3840 "github.com/erigontech/erigon/execution/protocol/params"
3941 "github.com/erigontech/erigon/execution/protocol/rules"
4042 "github.com/erigontech/erigon/execution/rlp"
@@ -273,10 +275,24 @@ func SysCallContractWithBlockContext(contract accounts.Address, data []byte, cha
273275 txContext = NewEVMTxContext (msg )
274276 }
275277 evm := vm .NewEVM (blockContext , txContext , ibs , chainConfig , vmConfig )
276- mdGas := evmtypes.MdGas {
277- Regular : msg .Gas (),
278- State : math .MaxUint64 ,
278+ rules := evm .ChainRules ()
279+ igasCalcRes , overflow := fixedgas .IntrinsicGas (fixedgas.IntrinsicGasCalcArgs {
280+ Data : data ,
281+ IsContractCreation : msg .To ().IsNil (),
282+ IsEIP2 : rules .IsHomestead ,
283+ IsEIP2028 : rules .IsIstanbul ,
284+ IsEIP3860 : vmConfig .HasEip3860 (rules ),
285+ IsEIP7623 : rules .IsPrague ,
286+ IsEIP8037 : rules .IsAmsterdam ,
287+ })
288+ if overflow {
289+ return nil , errors .New ("intrinsic gas calculation overflow in sys call" )
279290 }
291+ igas := evmtypes.MdGas {
292+ Regular : igasCalcRes .RegularGas ,
293+ State : igasCalcRes .StateGas ,
294+ }
295+ mdGas := SplitIntoMdGas (msg .Gas (), SysCallGasLimit , igas , rules )
280296 ret , _ , err := evm .Call (
281297 msg .From (),
282298 msg .To (),
@@ -314,10 +330,24 @@ func SysCreate(contract accounts.Address, data []byte, chainConfig *chain.Config
314330 txContext := NewEVMTxContext (msg )
315331 blockContext := NewEVMBlockContext (header , GetHashFn (header , nil ), nil , author , chainConfig )
316332 evm := vm .NewEVM (blockContext , txContext , ibs , chainConfig , vmConfig )
317- mdGas := evmtypes.MdGas {
318- Regular : msg .Gas (),
319- State : math .MaxUint64 ,
333+ rules := evm .ChainRules ()
334+ igasCalcRes , overflow := fixedgas .IntrinsicGas (fixedgas.IntrinsicGasCalcArgs {
335+ Data : data ,
336+ IsContractCreation : msg .To ().IsNil (),
337+ IsEIP2 : rules .IsHomestead ,
338+ IsEIP2028 : rules .IsIstanbul ,
339+ IsEIP3860 : vmConfig .HasEip3860 (rules ),
340+ IsEIP7623 : rules .IsPrague ,
341+ IsEIP8037 : rules .IsAmsterdam ,
342+ })
343+ if overflow {
344+ return nil , errors .New ("intrinsic gas calculation overflow in sys create" )
345+ }
346+ igas := evmtypes.MdGas {
347+ Regular : igasCalcRes .RegularGas ,
348+ State : igasCalcRes .StateGas ,
320349 }
350+ mdGas := SplitIntoMdGas (msg .Gas (), SysCallGasLimit , igas , rules )
321351 ret , _ , err := evm .SysCreate (
322352 msg .From (),
323353 msg .Data (),
0 commit comments