From 1cd18c2fd7016ea8ea5b8c95e57888f9928d8e76 Mon Sep 17 00:00:00 2001 From: Amp Date: Fri, 27 Nov 2026 03:26:18 +0000 Subject: [PATCH 1/2] Rebase the main patch onto current erigon The main patch stopped applying after erigon main moved precompile gas to MdGas, folded the CREATE gas functions into initCodeGas, returned MdGasCost from gas functions, dropped the chain config argument from Ethereum.Init and replaced AA transactions with EIP-8141 frames. - RunPrecompiledContract takes the gas schedule again, and the identity fast path in runPrecompile applies precompile overrides too. - memoryGasCost takes the EVM again; initCodeGas and the cached-slot SLOAD path read the schedule like the code they replaced. - Xatu is initialised from the chain config Ethereum keeps. - evmSizeClass moves to 512: GasSchedule and Config.CustomJumpTable add a pointer each, and EVM has no padding to hold them. - CalcCustomIntrinsicGas loses its isAATxn argument. Every caller passed false, and params.TxAAGas no longer exists on main. - The overlay builds the message and tx context itself, because transactions.ComputeTxContext lost two arguments on main but not in the v3.7 and v3.8 releases that share the main overlay. - The tracer test mock implements HasSelfdestructed, which main added to tracing.IntraBlockState. Co-authored-by: Sam Calder-Mason --- .../execution/vm/intrinsic_gas_override.go | 4 +- overlay/node/xatu/datasource_main.go | 14 +- overlay/node/xatu/intrinsic_gas_main.go | 2 +- overlay/node/xatu/intrinsic_gas_v3.go | 2 +- overlay/node/xatu/simulation_rpc_main.go | 2 +- overlay/node/xatu/tracer_main_test.go | 5 +- patches/erigontech/erigon/main/base.patch | 513 +++++++++--------- patches/erigontech/erigon/v3.3.10/base.patch | 2 +- patches/erigontech/erigon/v3.7.0/base.patch | 2 +- patches/erigontech/erigon/v3.7.1/base.patch | 2 +- patches/erigontech/erigon/v3.8.0/base.patch | 2 +- patches/erigontech/erigon/v3.8.1/base.patch | 2 +- 12 files changed, 286 insertions(+), 266 deletions(-) diff --git a/overlay/execution/vm/intrinsic_gas_override.go b/overlay/execution/vm/intrinsic_gas_override.go index 45e8c7c..af9cc10 100644 --- a/overlay/execution/vm/intrinsic_gas_override.go +++ b/overlay/execution/vm/intrinsic_gas_override.go @@ -80,14 +80,12 @@ func CalcCustomIntrinsicGas( data []byte, accessListLen, storageKeysLen uint64, isContractCreation bool, - isEIP2, isEIP2028, isEIP3860, isEIP7623, isAATxn bool, + isEIP2, isEIP2028, isEIP3860, isEIP7623 bool, authorizationsLen uint64, ) (gas uint64, floorGas7623 uint64) { // Set the starting gas for the raw transaction if isContractCreation && isEIP2 { gas = schedule.GetOr(GasKeyTxCreateBase, params.TxGasContractCreation) - } else if isAATxn { - gas = params.TxAAGas // AA base cost not overridable (niche, can add later) } else { gas = schedule.GetOr(GasKeyTxBase, params.TxGas) } diff --git a/overlay/node/xatu/datasource_main.go b/overlay/node/xatu/datasource_main.go index c2b9411..0b519b1 100644 --- a/overlay/node/xatu/datasource_main.go +++ b/overlay/node/xatu/datasource_main.go @@ -361,7 +361,7 @@ func (s *Service) DebugTraceTransaction( } // Compute tx context - msg, txCtx, err := transactions.ComputeTxContext(statedb, s.engine, chainRules, signer, block, execChainConfig, txIndex) + msg, txCtx, err := computeTxContext(statedb, chainRules, signer, block, txIndex) if err != nil { return nil, fmt.Errorf("failed to compute tx context: %w", err) } @@ -433,6 +433,18 @@ func (s *Service) IsSynced() bool { return s.synced.Load() } +// computeTxContext does what transactions.ComputeTxContext does. Its signature +// differs between erigon main and the v3.7 and v3.8 releases, which share this file. +func computeTxContext(statedb *erigonstate.IntraBlockState, chainRules *chain.Rules, signer *erigontypes.Signer, block *erigontypes.Block, txIndex int) (protocol.Message, evmtypes.TxContext, error) { + txn := block.Transactions()[txIndex] + statedb.SetTxContext(block.NumberU64(), txIndex) + msg, err := txn.AsMessage(*signer, block.BaseFee(), chainRules) + if err != nil { + return nil, evmtypes.TxContext{}, fmt.Errorf("convert transaction at index %d (%s) to message: %w", txIndex, txn.Hash(), err) + } + return msg, protocol.NewEVMTxContext(msg), nil +} + // executeWithTracer executes a transaction with the given tracer. func (s *Service) executeWithTracer( statedb *erigonstate.IntraBlockState, diff --git a/overlay/node/xatu/intrinsic_gas_main.go b/overlay/node/xatu/intrinsic_gas_main.go index f9b330c..7f907a6 100644 --- a/overlay/node/xatu/intrinsic_gas_main.go +++ b/overlay/node/xatu/intrinsic_gas_main.go @@ -37,7 +37,7 @@ func calcIntrinsicGasForTx(txn erigontypes.Transaction, chainRules *chain.Rules, intrinsicGas, _ = vm.CalcCustomIntrinsicGas( vmSchedule, txn.GetData(), accessListLen, storageKeysLen, txn.GetTo() == nil, chainRules.IsHomestead, chainRules.IsIstanbul, - chainRules.IsShanghai, chainRules.IsPrague, false, 0, + chainRules.IsShanghai, chainRules.IsPrague, 0, ) } } diff --git a/overlay/node/xatu/intrinsic_gas_v3.go b/overlay/node/xatu/intrinsic_gas_v3.go index b73b16c..4e806b1 100644 --- a/overlay/node/xatu/intrinsic_gas_v3.go +++ b/overlay/node/xatu/intrinsic_gas_v3.go @@ -31,7 +31,7 @@ func calcIntrinsicGasForTx(txn erigontypes.Transaction, chainRules *chain.Rules, intrinsicGas, _ = vm.CalcCustomIntrinsicGas( vmSchedule, txn.GetData(), accessListLen, storageKeysLen, txn.GetTo() == nil, chainRules.IsHomestead, chainRules.IsIstanbul, - chainRules.IsShanghai, chainRules.IsPrague, false, 0, + chainRules.IsShanghai, chainRules.IsPrague, 0, ) } } diff --git a/overlay/node/xatu/simulation_rpc_main.go b/overlay/node/xatu/simulation_rpc_main.go index e6bff83..39dd853 100644 --- a/overlay/node/xatu/simulation_rpc_main.go +++ b/overlay/node/xatu/simulation_rpc_main.go @@ -448,7 +448,7 @@ func (s *Service) executeSingleTransaction( } // Compute tx context - msg, txCtx, err := transactions.ComputeTxContext(statedb, s.engine, chainRules, signer, block, execChainConfig, txIndex) + msg, txCtx, err := computeTxContext(statedb, chainRules, signer, block, txIndex) if err != nil { return nil, fmt.Errorf("failed to compute tx context: %w", err) } diff --git a/overlay/node/xatu/tracer_main_test.go b/overlay/node/xatu/tracer_main_test.go index 86a44a7..44635f9 100644 --- a/overlay/node/xatu/tracer_main_test.go +++ b/overlay/node/xatu/tracer_main_test.go @@ -53,7 +53,10 @@ func (m *mockIntraBlockState) GetState(accounts.Address, accounts.StorageKey) (u return uint256.Int{}, nil } func (m *mockIntraBlockState) Exist(accounts.Address) (bool, error) { return false, nil } -func (m *mockIntraBlockState) GetRefund() uint64 { return m.refund } +func (m *mockIntraBlockState) HasSelfdestructed(accounts.Address) (bool, error) { + return false, nil +} +func (m *mockIntraBlockState) GetRefund() uint64 { return m.refund } // TestRefundCapture verifies that refund values are captured when OnTxStart // is called to initialize the tracer with a VMContext. diff --git a/patches/erigontech/erigon/main/base.patch b/patches/erigontech/erigon/main/base.patch index 60e9aa7..8367d4c 100644 --- a/patches/erigontech/erigon/main/base.patch +++ b/patches/erigontech/erigon/main/base.patch @@ -1,8 +1,8 @@ diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go -index 46dacca..a9f9b79 100644 +index 670ba36..0e1de24 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go -@@ -1236,6 +1236,12 @@ var ( +@@ -1292,6 +1292,12 @@ var ( Usage: "Suppress background state-aggregator (Domain/Hist/II) file build/merge and E2 block-snapshot retirement goroutines so execution is not perturbed by housekeeping work (legacy env var: NO_BACKGROUND_E3_BUILD=true). Diagnostic / focused-performance-testing use only — NOT an operational setting.", Value: false, } @@ -15,16 +15,16 @@ index 46dacca..a9f9b79 100644 ) var MetricFlags = []cli.Flag{&MetricsEnabledFlag, &MetricsHTTPFlag, &MetricsPortFlag} -@@ -2017,6 +2023,9 @@ func SetEthConfig(nodeCtx context.Context, ctx *cli.Command, nodeConfig *nodecfg - cfg.AllowAA = ctx.Bool(AAFlag.Name) +@@ -2113,6 +2119,9 @@ func SetEthConfig(nodeCtx context.Context, ctx *cli.Command, nodeConfig *nodecfg + cfg.Ethstats = ctx.String(EthStatsURLFlag.Name) + // Xatu: Set Xatu execution processor configuration + cfg.XatuConfig = ctx.String(XatuConfigFlag.Name) + - setParallelCommitment(ctx) + warnParallelCommitmentDeprecated(ctx, logger) + setCommitmentV3(ctx) - cfg.FcuTimeout = ctx.Duration(FcuTimeoutFlag.Name) diff --git a/common/math/integer.go b/common/math/integer.go index 95ca56f..7344d2a 100644 --- a/common/math/integer.go @@ -43,20 +43,18 @@ index 95ca56f..7344d2a 100644 + return x - y +} diff --git a/execution/protocol/txn_executor.go b/execution/protocol/txn_executor.go -index 282af0f..66e2e6d 100644 +index b1621ee..7133702 100644 --- a/execution/protocol/txn_executor.go +++ b/execution/protocol/txn_executor.go -@@ -607,6 +607,16 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. - auths := msg.Authorizations() - - intrinsicGasResult, overflow := st.calcIntrinsicGas(contractCreation, auths, accessTuples) +@@ -454,6 +454,14 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. + rules := st.evm.ChainRules() + vmConfig := st.evm.Config() + intrinsicGasResult, overflow := intrinsicGas(msg, rules, vmConfig.HasEip3860(rules)) + + // Xatu: Allow custom intrinsic gas schedule overrides for gas simulation + if st.evm.GasSchedule != nil && st.evm.GasSchedule.HasIntrinsicOverrides() { -+ rules := st.evm.ChainRules() -+ vmConfig := st.evm.Config() + isEIP3860 := vmConfig.HasEip3860(rules) -+ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, false, uint64(len(auths))) ++ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, uint64(len(auths))) + intrinsicGasResult = mdgas.IntrinsicGasCalcResult{ExecutionGas: gas, FloorGasCost: floorGas} + overflow = false + } @@ -64,185 +62,229 @@ index 282af0f..66e2e6d 100644 return nil, ErrGasUintOverflow } diff --git a/execution/vm/contracts.go b/execution/vm/contracts.go -index 30fed0f..d7be77d 100644 +index f055ba3..9198356 100644 --- a/execution/vm/contracts.go +++ b/execution/vm/contracts.go -@@ -260,9 +260,12 @@ func ActivePrecompiles(rules *chain.Rules) []accounts.Address { +@@ -264,8 +264,11 @@ func ActivePrecompiles(rules *chain.Rules) []accounts.Address { // - the returned bytes, // - the _remaining_ gas, // - any error that occurred --func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uint64, tracer *tracing.Hooks, -+func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uint64, tracer *tracing.Hooks, schedule *GasSchedule, - ) (ret []byte, remainingGas uint64, err error) { +-func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas mdgas.MdGas, tracer *tracing.Hooks) ([]byte, mdgas.MdGas, error) { ++func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas mdgas.MdGas, tracer *tracing.Hooks, schedule *GasSchedule) ([]byte, mdgas.MdGas, error) { gasCost := p.RequiredGas(input) + if schedule != nil { + gasCost = PrecompileGasWithOverrides(schedule, p.Name(), input, gasCost) + } - if suppliedGas < gasCost { - return nil, 0, ErrOutOfGas + if suppliedGas.Execution < gasCost { + return nil, suppliedGas, ErrOutOfGas } diff --git a/execution/vm/contracts_bench_test.go b/execution/vm/contracts_bench_test.go -index 88683f2..cd1295e 100644 +index c0b272a..ebcaa11 100644 --- a/execution/vm/contracts_bench_test.go +++ b/execution/vm/contracts_bench_test.go -@@ -164,7 +164,7 @@ func benchmarkPrecompiled(b *testing.B, addr string, test precompiledTest) { +@@ -167,7 +167,7 @@ func benchmarkPrecompiled(b *testing.B, addr string, test precompiledTest) { bench.ResetTimer() for i := 0; i < bench.N; i++ { copy(data, in) -- res, _, err = RunPrecompiledContract(p, data, reqGas, nil) -+ res, _, err = RunPrecompiledContract(p, data, reqGas, nil, nil) +- res, _, err = RunPrecompiledContract(p, data, mdgas.MdGas{Execution: reqGas}, nil) ++ res, _, err = RunPrecompiledContract(p, data, mdgas.MdGas{Execution: reqGas}, nil, nil) } bench.StopTimer() elapsed := max(uint64(time.Since(start)), 1) diff --git a/execution/vm/contracts_fuzz_test.go b/execution/vm/contracts_fuzz_test.go -index 2cdf7ed..c5911dd 100644 +index 03acd78..0dbc300 100644 --- a/execution/vm/contracts_fuzz_test.go +++ b/execution/vm/contracts_fuzz_test.go -@@ -38,7 +38,7 @@ func FuzzPrecompiledContracts(f *testing.F) { +@@ -40,7 +40,7 @@ func FuzzPrecompiledContracts(f *testing.F) { inWant := string(input) // Fuzzed input is expected to fail; the assertion below is about // the precompile not mutating the caller's buffer. -- _, _, _ = RunPrecompiledContract(p, input, gas, nil) -+ _, _, _ = RunPrecompiledContract(p, input, gas, nil, nil) +- _, _, _ = RunPrecompiledContract(p, input, mdgas.MdGas{Execution: gas}, nil) ++ _, _, _ = RunPrecompiledContract(p, input, mdgas.MdGas{Execution: gas}, nil, nil) if inHave := string(input); inWant != inHave { t.Errorf("Precompiled %v modified input data", a) } diff --git a/execution/vm/contracts_test.go b/execution/vm/contracts_test.go -index 9f8e227..eb441b3 100644 +index 8bdbb8e..301d6ab 100644 --- a/execution/vm/contracts_test.go +++ b/execution/vm/contracts_test.go -@@ -110,7 +110,7 @@ func testPrecompiled(t *testing.T, addr string, test precompiledTest) { +@@ -118,7 +118,7 @@ func testPrecompiled(t *testing.T, addr string, test precompiledTest) { gas := p.RequiredGas(in) t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) { t.Parallel() -- if res, _, err := RunPrecompiledContract(p, in, gas, nil); err != nil { -+ if res, _, err := RunPrecompiledContract(p, in, gas, nil, nil); err != nil { +- if res, _, err := RunPrecompiledContract(p, in, mdgas.MdGas{Execution: gas}, nil); err != nil { ++ if res, _, err := RunPrecompiledContract(p, in, mdgas.MdGas{Execution: gas}, nil, nil); err != nil { t.Error(err) } else if common.Bytes2Hex(res) != test.Expected { t.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res)) -@@ -133,7 +133,7 @@ func testPrecompiledOOG(t *testing.T, addr string, test precompiledTest) { - +@@ -142,7 +142,7 @@ func testPrecompiledOOG(t *testing.T, addr string, test precompiledTest) { t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) { t.Parallel() -- _, _, err := RunPrecompiledContract(p, in, gas, nil) -+ _, _, err := RunPrecompiledContract(p, in, gas, nil, nil) - if err.Error() != "out of gas" { - t.Errorf("Expected error [out of gas], got [%v]", err) - } -@@ -151,7 +151,7 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing + suppliedGas := mdgas.MdGas{Execution: gas, State: 50_000} +- _, remaining, err := RunPrecompiledContract(p, in, suppliedGas, nil) ++ _, remaining, err := RunPrecompiledContract(p, in, suppliedGas, nil, nil) + require.ErrorIs(t, err, ErrOutOfGas) + require.Equal(t, suppliedGas, remaining) + // Verify that the precompile did not touch the input buffer +@@ -159,7 +159,7 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing gas := p.RequiredGas(in) t.Run(test.Name, func(t *testing.T) { t.Parallel() -- _, _, err := RunPrecompiledContract(p, in, gas, nil) -+ _, _, err := RunPrecompiledContract(p, in, gas, nil, nil) +- _, _, err := RunPrecompiledContract(p, in, mdgas.MdGas{Execution: gas}, nil) ++ _, _, err := RunPrecompiledContract(p, in, mdgas.MdGas{Execution: gas}, nil, nil) if err == nil || err.Error() != test.ExpectedError { t.Errorf("Expected error [%v], got [%v]", test.ExpectedError, err) } -@@ -189,7 +189,7 @@ func TestPrecompiledModExpPotentialOutOfRange(t *testing.T) { +@@ -197,7 +197,7 @@ func TestPrecompiledModExpPotentialOutOfRange(t *testing.T) { hexString := "0x0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000ffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000ee" input := hexutil.MustDecode(hexString) maxGas := uint64(math.MaxUint64) -- _, _, err := RunPrecompiledContract(modExpContract, input, maxGas, nil) -+ _, _, err := RunPrecompiledContract(modExpContract, input, maxGas, nil, nil) +- _, _, err := RunPrecompiledContract(modExpContract, input, mdgas.MdGas{Execution: maxGas}, nil) ++ _, _, err := RunPrecompiledContract(modExpContract, input, mdgas.MdGas{Execution: maxGas}, nil, nil) require.NoError(t, err) } -@@ -200,52 +200,52 @@ func TestPrecompiledModExpInputEip7823(t *testing.T) { +@@ -208,52 +208,52 @@ func TestPrecompiledModExpInputEip7823(t *testing.T) { // length_of_EXPONENT = 1024; everything else is zero in := common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000") gas := pragueModExp.RequiredGas(in) -- res, _, err := RunPrecompiledContract(pragueModExp, in, gas, nil) -+ res, _, err := RunPrecompiledContract(pragueModExp, in, gas, nil, nil) +- res, _, err := RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ res, _, err := RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) require.NoError(t, err) assert.Equal(t, "", common.Bytes2Hex(res)) gas = osakaModExp.RequiredGas(in) -- _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil) -+ _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil, nil) +- _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) require.NoError(t, err) assert.Equal(t, "", common.Bytes2Hex(res)) // length_of_EXPONENT = 1025; everything else is zero in = common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004010000000000000000000000000000000000000000000000000000000000000000") gas = pragueModExp.RequiredGas(in) -- res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil) -+ res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil, nil) +- res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) require.NoError(t, err) assert.Equal(t, "", common.Bytes2Hex(res)) gas = osakaModExp.RequiredGas(in) -- _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil) -+ _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil, nil) +- _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) assert.ErrorIs(t, err, errModExpExponentLengthTooLarge) // length_of_EXPONENT = 2048; everything else is zero in = common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000") gas = pragueModExp.RequiredGas(in) -- res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil) -+ res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil, nil) +- res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) require.NoError(t, err) assert.Equal(t, "", common.Bytes2Hex(res)) gas = osakaModExp.RequiredGas(in) -- _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil) -+ _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil, nil) +- _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) assert.ErrorIs(t, err, errModExpExponentLengthTooLarge) // length_of_EXPONENT = 2^32; everything else is zero in = common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000") gas = pragueModExp.RequiredGas(in) -- res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil) -+ res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil, nil) +- res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) require.NoError(t, err) assert.Equal(t, "", common.Bytes2Hex(res)) gas = osakaModExp.RequiredGas(in) -- _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil) -+ _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil, nil) +- _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) assert.ErrorIs(t, err, errModExpExponentLengthTooLarge) // length_of_EXPONENT = 2^64; everything else is zero in = common.Hex2Bytes("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000") gas = pragueModExp.RequiredGas(in) -- res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil) -+ res, _, err = RunPrecompiledContract(pragueModExp, in, gas, nil, nil) +- res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ res, _, err = RunPrecompiledContract(pragueModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) require.NoError(t, err) assert.Equal(t, "", common.Bytes2Hex(res)) gas = osakaModExp.RequiredGas(in) -- _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil) -+ _, _, err = RunPrecompiledContract(osakaModExp, in, gas, nil, nil) +- _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil) ++ _, _, err = RunPrecompiledContract(osakaModExp, in, mdgas.MdGas{Execution: gas}, nil, nil) assert.ErrorIs(t, err, errModExpExponentLengthTooLarge) } +@@ -513,21 +513,21 @@ func TestCachedPrecompileOwnershipAndGas(t *testing.T) { + p := &countingPrecompile{output: []byte{1, 2, 3}} + c := newCachedPrecompile(p, wholeInputKey, [21]byte{201}) + input := fmt.Appendf(nil, "%s/%d", t.Name(), cacheTestID.Add(1)) +- out, gas, err := RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 3050}, nil) ++ out, gas, err := RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 3050}, nil, nil) + if err != nil || gas.Execution != 50 { + t.Fatalf("gas=%v err=%v", gas, err) + } + out[0] = 9 +- out, gas, err = RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 3050}, nil) ++ out, gas, err = RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 3050}, nil, nil) + if err != nil || gas.Execution != 50 || !bytes.Equal(out, []byte{1, 2, 3}) || p.calls != 1 { + t.Fatalf("output=%x gas=%v calls=%d err=%v", out, gas, p.calls, err) + } + out[1] = 9 +- out, _, err = RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 3000}, nil) ++ out, _, err = RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 3000}, nil, nil) + if err != nil || !bytes.Equal(out, []byte{1, 2, 3}) { + t.Fatal("cache output was mutated") + } +- _, _, err = RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 2999}, nil) ++ _, _, err = RunPrecompiledContract(c, input, mdgas.MdGas{Execution: 2999}, nil, nil) + if !errors.Is(err, ErrOutOfGas) || p.calls != 1 { + t.Fatal("cache hit bypassed gas check") + } diff --git a/execution/vm/evm.go b/execution/vm/evm.go -index 94ca2fa..1e1a2cb 100644 +index 9e89fd1..7578e32 100644 --- a/execution/vm/evm.go +++ b/execution/vm/evm.go -@@ -85,6 +85,10 @@ type EVM struct { - readOnly bool // Whether to throw on stateful modifications +@@ -46,13 +46,16 @@ func (evm *EVM) precompile(addr accounts.Address) (PrecompiledContract, bool) { + // runPrecompile puts the identity output into the buffer a RETURN of the callee frame would use. + func (evm *EVM) runPrecompile(p PrecompiledContract, input []byte, gas mdgas.MdGas, tracer *tracing.Hooks) ([]byte, mdgas.MdGas, error) { + if _, identity := p.(*dataCopy); !identity || len(input) == 0 { +- return RunPrecompiledContract(p, input, gas, tracer) ++ return RunPrecompiledContract(p, input, gas, tracer, evm.GasSchedule) + } + buf := evm.outputBuffer(evm.depth+1, uint64(len(input))) + if buf == nil { +- return RunPrecompiledContract(p, input, gas, tracer) ++ return RunPrecompiledContract(p, input, gas, tracer, evm.GasSchedule) + } + gasCost := p.RequiredGas(input) ++ if evm.GasSchedule != nil { ++ gasCost = PrecompileGasWithOverrides(evm.GasSchedule, p.Name(), input, gasCost) ++ } + if gas.Execution < gasCost { + return nil, gas, ErrOutOfGas + } +@@ -114,6 +117,10 @@ type EVM struct { returnData []byte // Last CALL's return data for subsequent reuse + spareFrame *CallContext // a finished nested frame's context, see putCallContext ++ + // GasSchedule allows overriding gas costs for simulation. + // When nil, standard params.X values are used. + GasSchedule *GasSchedule -+ - // Pointers before counters: interleaving them adds a word of padding. - internCache *storageKeyCache - addrCache *addressCache -@@ -446,7 +450,7 @@ func (evm *EVM) call(typ OpCode, caller accounts.Address, callerAddress accounts - // It is allowed to call precompiles, even via delegatecall - switch { - case isPrecompile: -- ret, gasRemaining.Execution, err = RunPrecompiledContract(p, input, gasRemaining.Execution, evm.Config().Tracer) -+ ret, gasRemaining.Execution, err = RunPrecompiledContract(p, input, gasRemaining.Execution, evm.Config().Tracer, evm.GasSchedule) - case len(code) == 0: - // If the account has no code, we can abort here - // The depth-check is already done, and precompiles handled above -@@ -750,7 +754,7 @@ func (evm *EVM) createWithPreparation(caller accounts.Address, codeAndHash *code - // HASH_COST(L) = 6*ceil(L/32); the state component (cpsb*L) is charged above. - executionGas = params.Keccak256WordGas * ToWordSize(uint64(len(ret))) - } else { -- executionGas = uint64(len(ret)) * params.CreateDataGas -+ executionGas = uint64(len(ret)) * evm.GasSchedule.GetOr(GasKeyCreateData, params.CreateDataGas) - } - gasRemaining, _, executionGasOk = useMdGas(gasRemaining, executionGas, mdgas.ExecutionGas, evm.Config().Tracer, tracing.GasChangeCallCodeStorage) + } + + // evmSizeClass is the Go allocation size class EVM fills. A field added here +@@ -122,7 +129,7 @@ type EVM struct { + // TestEVMFitsItsSizeClass is therefore a tripwire for the growth nobody meant, + // not a budget — a build-time assert would also fire in every package that + // grows an embedded type such as evmtypes.BlockContext. +-const evmSizeClass = 480 ++const evmSizeClass = 512 + + // ZeroUnpricedBaseFee returns blockCtx with the base fee dropped for a call that + // skips the fee checks and puts no price on gas, so that its fee cap is never +@@ -793,7 +800,7 @@ func (evm *EVM) createWithPreparation(caller accounts.Address, codeAndHash *code + if evm.chainRules.IsAmsterdam { + executionGas = params.Keccak256WordGas * ToWordSize(uint64(len(ret))) + } else { +- executionGas = uint64(len(ret)) * params.CreateDataGas ++ executionGas = uint64(len(ret)) * evm.GasSchedule.GetOr(GasKeyCreateData, params.CreateDataGas) } + var gasOK bool + gasRemaining, _, gasOK = useMdGas(gasRemaining, executionGas, mdgas.ExecutionGas, evm.Config().Tracer, tracing.GasChangeCallCodeStorage) diff --git a/execution/vm/export_test.go b/execution/vm/export_test.go index 97ff0ec..0636e08 100644 --- a/execution/vm/export_test.go @@ -255,10 +297,10 @@ index 97ff0ec..0636e08 100644 + return memoryGasCost(&EVM{}, callContext, newMemSize) } diff --git a/execution/vm/gas_table.go b/execution/vm/gas_table.go -index 8dd39ec..0e2d538 100644 +index 6fa98ff..ed12769 100644 --- a/execution/vm/gas_table.go +++ b/execution/vm/gas_table.go -@@ -54,7 +54,7 @@ func coldStorageAccessCost(rules *chain.Rules) uint64 { +@@ -57,7 +57,7 @@ func coldStorageAccessCost(rules *chain.Rules) uint64 { // memoryGasCost calculates the quadratic gas for memory expansion. It does so // only for the memory region that is expanded, not the total memory. @@ -267,7 +309,7 @@ index 8dd39ec..0e2d538 100644 if newMemSize == 0 { return 0, nil } -@@ -71,7 +71,7 @@ func memoryGasCost(callContext *CallContext, newMemSize uint64) (uint64, error) +@@ -74,7 +74,7 @@ func memoryGasCost(callContext *CallContext, newMemSize uint64) (uint64, error) if newMemSize > uint64(callContext.Memory.Len()) { square := newMemSizeWords * newMemSizeWords @@ -276,159 +318,122 @@ index 8dd39ec..0e2d538 100644 quadCoef := square / params.QuadCoeffDiv newTotalFee := linCoef + quadCoef -@@ -92,9 +92,9 @@ func memoryGasCost(callContext *CallContext, newMemSize uint64) (uint64, error) +@@ -95,9 +95,9 @@ func memoryGasCost(callContext *CallContext, newMemSize uint64) (uint64, error) // EXTCODECOPY (stack position 3) // RETURNDATACOPY (stack position 2) func memoryCopierGas(stackpos int) gasFunc { -- return func(_ *EVM, callContext *CallContext, scaopeGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { -+ return func(evm *EVM, callContext *CallContext, scaopeGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { +- return func(_ *EVM, callContext *CallContext, scaopeGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { ++ return func(evm *EVM, callContext *CallContext, scaopeGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { // Gas for expanding the memory - gas, err := memoryGasCost(callContext, memorySize) + gas, err := memoryGasCost(evm, callContext, memorySize) if err != nil { - return mdgas.MdGas{}, err + return mdgas.MdGasCost{}, err } -@@ -104,7 +104,7 @@ func memoryCopierGas(stackpos int) gasFunc { - return mdgas.MdGas{}, ErrGasUintOverflow +@@ -107,7 +107,7 @@ func memoryCopierGas(stackpos int) gasFunc { + return mdgas.MdGasCost{}, ErrGasUintOverflow } - if words, overflow = math.SafeMul(ToWordSize(words), params.CopyGas); overflow { + if words, overflow = math.SafeMul(ToWordSize(words), evm.GasSchedule.GetOr(GasKeyCopy, params.CopyGas)); overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } -@@ -256,26 +256,26 @@ func gasSStoreEIP2200(evm *EVM, callContext *CallContext, availableGas mdgas.MdG +@@ -259,26 +259,26 @@ func gasSStoreEIP2200(evm *EVM, callContext *CallContext, availableGas mdgas.MdG } func makeGasLog(n uint64) gasFunc { -- return func(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { -+ return func(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { +- return func(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { ++ return func(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { requestedSize, overflow := callContext.Stack.back(1).Uint64WithOverflow() if overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } - gas, err := memoryGasCost(callContext, memorySize) + gas, err := memoryGasCost(evm, callContext, memorySize) if err != nil { - return mdgas.MdGas{}, err + return mdgas.MdGasCost{}, err } - if gas, overflow = math.SafeAdd(gas, params.LogGas); overflow { + if gas, overflow = math.SafeAdd(gas, evm.GasSchedule.GetOr(GasKeyLog, params.LogGas)); overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } - if gas, overflow = math.SafeAdd(gas, n*params.LogTopicGas); overflow { + if gas, overflow = math.SafeAdd(gas, n*evm.GasSchedule.GetOr(GasKeyLogTopic, params.LogTopicGas)); overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } var memorySizeGas uint64 - if memorySizeGas, overflow = math.SafeMul(requestedSize, params.LogDataGas); overflow { + if memorySizeGas, overflow = math.SafeMul(requestedSize, evm.GasSchedule.GetOr(GasKeyLogData, params.LogDataGas)); overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } if gas, overflow = math.SafeAdd(gas, memorySizeGas); overflow { -@@ -285,8 +285,8 @@ func makeGasLog(n uint64) gasFunc { +@@ -288,8 +288,8 @@ func makeGasLog(n uint64) gasFunc { } } --func gasKeccak256(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { +-func gasKeccak256(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { - gas, err := memoryGasCost(callContext, memorySize) -+func gasKeccak256(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { ++func gasKeccak256(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { + gas, err := memoryGasCost(evm, callContext, memorySize) if err != nil { - return mdgas.MdGas{}, err + return mdgas.MdGasCost{}, err } -@@ -294,7 +294,7 @@ func gasKeccak256(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, me +@@ -297,7 +297,7 @@ func gasKeccak256(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, me if overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } - if wordGas, overflow = math.SafeMul(ToWordSize(wordGas), params.Keccak256WordGas); overflow { + if wordGas, overflow = math.SafeMul(ToWordSize(wordGas), evm.GasSchedule.GetOr(GasKeyKeccak256Word, params.Keccak256WordGas)); overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } if gas, overflow = math.SafeAdd(gas, wordGas); overflow { -@@ -306,8 +306,8 @@ func gasKeccak256(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, me +@@ -309,8 +309,8 @@ func gasKeccak256(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, me // pureMemoryGascost is used by several operations, which aside from their // static cost have a dynamic cost which is solely based on the memory // expansion --func pureMemoryGascost(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { +-func pureMemoryGascost(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { - g, err := memoryGasCost(callContext, memorySize) -+func pureMemoryGascost(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { ++func pureMemoryGascost(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { + g, err := memoryGasCost(evm, callContext, memorySize) - return mdgas.MdGas{Execution: g}, err + return mdgas.MdGasCost{Execution: g}, err } -@@ -323,7 +323,7 @@ func gasCreate(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, mem +@@ -326,7 +326,7 @@ func gasCreate(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, mem if evm.readOnly { - return mdgas.MdGas{}, ErrWriteProtection + return mdgas.MdGasCost{}, ErrWriteProtection } - g, err := memoryGasCost(callContext, memorySize) + g, err := memoryGasCost(evm, callContext, memorySize) - return mdgas.MdGas{Execution: g}, err + return mdgas.MdGasCost{Execution: g}, err } -@@ -331,7 +331,7 @@ func gasCreate2(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, me - if evm.readOnly { - return mdgas.MdGas{}, ErrWriteProtection +@@ -353,14 +353,14 @@ func initCodeGas(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, m } -- gas, err := memoryGasCost(callContext, memorySize) -+ gas, err := memoryGasCost(evm, callContext, memorySize) - if err != nil { - return mdgas.MdGas{}, err + var gasPerWord uint64 + if op == CREATE2 { +- gasPerWord = params.Keccak256WordGas ++ gasPerWord = evm.GasSchedule.GetOr(GasKeyKeccak256Word, params.Keccak256WordGas) } -@@ -340,7 +340,7 @@ func gasCreate2(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, me - return mdgas.MdGas{}, ErrGasUintOverflow - } - numWords := ToWordSize(size) -- wordGas, overflow := math.SafeMul(numWords, params.Keccak256WordGas) -+ wordGas, overflow := math.SafeMul(numWords, evm.GasSchedule.GetOr(GasKeyKeccak256Word, params.Keccak256WordGas)) - if overflow { - return mdgas.MdGas{}, ErrGasUintOverflow - } -@@ -355,7 +355,7 @@ func gasCreateEip3860(evm *EVM, callContext *CallContext, availableGas mdgas.MdG - if evm.readOnly { - return mdgas.MdGas{}, ErrWriteProtection - } -- gas.Execution, err = memoryGasCost(callContext, memorySize) -+ gas.Execution, err = memoryGasCost(evm, callContext, memorySize) - if err != nil { - return mdgas.MdGas{}, err - } -@@ -368,7 +368,7 @@ func gasCreateEip3860(evm *EVM, callContext *CallContext, availableGas mdgas.MdG - } - numWords := ToWordSize(size) - // Since size <= params.MaxInitCodeSize(Amsterdam), this multiplication cannot overflow -- wordGas := params.InitCodeWordGas * numWords -+ wordGas := evm.GasSchedule.GetOr(GasKeyInitCodeWord, params.InitCodeWordGas) * numWords - gas.Execution, overflow = math.SafeAdd(gas.Execution, wordGas) - if overflow { - return mdgas.MdGas{}, ErrGasUintOverflow -@@ -380,7 +380,7 @@ func gasCreate2Eip3860(evm *EVM, callContext *CallContext, availableGas mdgas.Md - if evm.readOnly { - return mdgas.MdGas{}, ErrWriteProtection - } -- gas.Execution, err = memoryGasCost(callContext, memorySize) -+ gas.Execution, err = memoryGasCost(evm, callContext, memorySize) - if err != nil { - return mdgas.MdGas{}, err - } -@@ -393,7 +393,7 @@ func gasCreate2Eip3860(evm *EVM, callContext *CallContext, availableGas mdgas.Md + // EnableEIP can install the EIP-3860 gas handler before Shanghai. + if eip3860 { + if err := CheckMaxInitCodeSize(size, true, evm.chainRules.IsAmsterdam); err != nil { + return mdgas.MdGasCost{}, err + } +- gasPerWord += params.InitCodeWordGas ++ gasPerWord += evm.GasSchedule.GetOr(GasKeyInitCodeWord, params.InitCodeWordGas) } - numWords := ToWordSize(size) - // Since size <= params.MaxInitCodeSize(Amsterdam), this multiplication cannot overflow -- wordGas := (params.InitCodeWordGas + params.Keccak256WordGas) * numWords -+ wordGas := (evm.GasSchedule.GetOr(GasKeyInitCodeWord, params.InitCodeWordGas) + evm.GasSchedule.GetOr(GasKeyKeccak256Word, params.Keccak256WordGas)) * numWords - gas.Execution, overflow = math.SafeAdd(gas.Execution, wordGas) - if overflow { - return mdgas.MdGas{}, ErrGasUintOverflow -@@ -401,11 +401,11 @@ func gasCreate2Eip3860(evm *EVM, callContext *CallContext, availableGas mdgas.Md + // A uint64 byte length rounds up to at most 2^59 words of 32 bytes. Even + // at 8 gas per word (CREATE2 with EIP-3860), the product fits in uint64. +@@ -498,11 +498,11 @@ func gasCreateAccount(evm *EVM, callContext *CallContext, availableGas mdgas.MdG return gas, nil } --func gasExpFrontier(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { -+func gasExpFrontier(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { +-func gasExpFrontier(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { ++func gasExpFrontier(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { expByteLen := uint64(common.BitLenToByteLen(callContext.Stack.data[callContext.Stack.len()-2].BitLen())) var ( @@ -437,12 +442,12 @@ index 8dd39ec..0e2d538 100644 overflow bool ) if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow { -@@ -414,11 +414,11 @@ func gasExpFrontier(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, - return mdgas.MdGas{Execution: gas}, nil +@@ -511,11 +511,11 @@ func gasExpFrontier(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, + return mdgas.MdGasCost{Execution: gas}, nil } --func gasExpEIP160(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { -+func gasExpEIP160(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGas, error) { +-func gasExpEIP160(_ *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { ++func gasExpEIP160(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64) (mdgas.MdGasCost, error) { expByteLen := uint64(common.BitLenToByteLen(callContext.Stack.data[callContext.Stack.len()-2].BitLen())) var ( @@ -451,7 +456,7 @@ index 8dd39ec..0e2d538 100644 overflow bool ) if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow { -@@ -437,9 +437,9 @@ func statelessGasCall(evm *EVM, callContext *CallContext, availableGas mdgas.MdG +@@ -534,9 +534,9 @@ func statelessGasCall(evm *EVM, callContext *CallContext, availableGas mdgas.MdG transfersValue := !callContext.Stack.back(2).IsZero() if transfersValue { @@ -461,10 +466,10 @@ index 8dd39ec..0e2d538 100644 - memoryGas, err := memoryGasCost(callContext, memorySize) + memoryGas, err := memoryGasCost(evm, callContext, memorySize) if err != nil { - return mdgas.MdGas{}, transfersValue, err + return mdgas.MdGasCost{}, transfersValue, err } -@@ -509,7 +509,7 @@ func statefulGasCall(evm *EVM, callContext *CallContext, gas mdgas.MdGas, availa - stateGas = params.StateGasNewAccount +@@ -607,7 +607,7 @@ func statefulGasCall(evm *EVM, callContext *CallContext, gas mdgas.MdGasCost, av + gas.State += params.StateGasNewAccount callContext.newAccountCharged = true } else { - accountGas = params.CallNewAccountGas @@ -472,7 +477,7 @@ index 8dd39ec..0e2d538 100644 } } } else { -@@ -522,7 +522,7 @@ func statefulGasCall(evm *EVM, callContext *CallContext, gas mdgas.MdGas, availa +@@ -620,7 +620,7 @@ func statefulGasCall(evm *EVM, callContext *CallContext, gas mdgas.MdGasCost, av if !exists { // note this doesn't need updating for amsterdam since // this branch is only for paths before spurious dragon @@ -481,16 +486,16 @@ index 8dd39ec..0e2d538 100644 } } -@@ -565,7 +565,7 @@ func statefulGasCallCode(evm *EVM, callContext *CallContext, gas mdgas.MdGas, av +@@ -656,7 +656,7 @@ func statefulGasCallCode(evm *EVM, callContext *CallContext, gas mdgas.MdGasCost } - func statelessGasCallCode(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64, withCallGasCalc bool) (mdgas.MdGas, bool, error) { + func statelessGasCallCode(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64, withCallGasCalc bool) (mdgas.MdGasCost, bool, error) { - memoryGas, err := memoryGasCost(callContext, memorySize) + memoryGas, err := memoryGasCost(evm, callContext, memorySize) if err != nil { - return mdgas.MdGas{}, false, err + return mdgas.MdGasCost{}, false, err } -@@ -574,7 +574,7 @@ func statelessGasCallCode(evm *EVM, callContext *CallContext, availableGas mdgas +@@ -665,7 +665,7 @@ func statelessGasCallCode(evm *EVM, callContext *CallContext, availableGas mdgas overflow bool ) if !callContext.Stack.back(2).IsZero() { @@ -499,26 +504,26 @@ index 8dd39ec..0e2d538 100644 } if gas.Execution, overflow = math.SafeAdd(gas.Execution, memoryGas); overflow { -@@ -618,7 +618,7 @@ func statefulGasDelegateCall(evm *EVM, callContext *CallContext, gas mdgas.MdGas +@@ -709,7 +709,7 @@ func statefulGasDelegateCall(evm *EVM, callContext *CallContext, gas mdgas.MdGas } - func statelessGasDelegateCall(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64, withCallGasCalc bool) (mdgas.MdGas, bool, error) { + func statelessGasDelegateCall(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64, withCallGasCalc bool) (mdgas.MdGasCost, bool, error) { - gas, err := memoryGasCost(callContext, memorySize) + gas, err := memoryGasCost(evm, callContext, memorySize) if err != nil { - return mdgas.MdGas{}, false, err + return mdgas.MdGasCost{}, false, err } -@@ -669,7 +669,7 @@ func statefulGasStaticCall(evm *EVM, callContext *CallContext, gas mdgas.MdGas, +@@ -760,7 +760,7 @@ func statefulGasStaticCall(evm *EVM, callContext *CallContext, gas mdgas.MdGasCo } - func statelessGasStaticCall(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64, withCallGasCalc bool) (mdgas.MdGas, bool, error) { + func statelessGasStaticCall(evm *EVM, callContext *CallContext, availableGas mdgas.MdGas, memorySize uint64, withCallGasCalc bool) (mdgas.MdGasCost, bool, error) { - gas, err := memoryGasCost(callContext, memorySize) + gas, err := memoryGasCost(evm, callContext, memorySize) if err != nil { - return mdgas.MdGas{}, false, err + return mdgas.MdGasCost{}, false, err } -@@ -726,7 +726,7 @@ func gasSelfdestruct(evm *EVM, callContext *CallContext, availableGas mdgas.MdGa - return mdgas.MdGas{}, err +@@ -817,7 +817,7 @@ func gasSelfdestruct(evm *EVM, callContext *CallContext, availableGas mdgas.MdGa + return mdgas.MdGasCost{}, err } if empty && !balance.IsZero() { - gas.Execution += params.CreateBySelfdestructGas @@ -526,7 +531,7 @@ index 8dd39ec..0e2d538 100644 } } else { exist, err := evm.IntraBlockState().Exist(address) -@@ -736,7 +736,7 @@ func gasSelfdestruct(evm *EVM, callContext *CallContext, availableGas mdgas.MdGa +@@ -827,7 +827,7 @@ func gasSelfdestruct(evm *EVM, callContext *CallContext, availableGas mdgas.MdGa // Exist() reads account state for gas calculation — record for BAL. evm.IntraBlockState().MarkAddressAccess(address, false) if !exist { @@ -536,13 +541,13 @@ index 8dd39ec..0e2d538 100644 } } diff --git a/execution/vm/interpreter.go b/execution/vm/interpreter.go -index 3f3046a..2d02719 100644 +index 0122234..824c376 100644 --- a/execution/vm/interpreter.go +++ b/execution/vm/interpreter.go -@@ -48,6 +48,10 @@ type Config struct { - RestoreState bool // Revert all changes made to the state (useful for constant system calls) - - ExtraEips []int // Additional EIPS that are to be enabled +@@ -62,6 +62,10 @@ type Config struct { + // OnInitCodeOverrideError reports gas or preparation errors that occur before a + // nested constructor frame opens. The receiver filters by deployment address. + OnInitCodeOverrideError func(address accounts.Address, err error) + + // CustomJumpTable allows injecting a modified JumpTable for gas repricing simulation. + // When set, this JumpTable is used instead of the fork-based default. @@ -550,7 +555,7 @@ index 3f3046a..2d02719 100644 } func (vmConfig *Config) HasEip3860(rules *chain.Rules) bool { -@@ -326,7 +330,18 @@ func LookupInstructionSet(rules *chain.Rules) JumpTable { +@@ -461,7 +465,18 @@ func LookupInstructionSet(rules *chain.Rules) JumpTable { return *jumpTable(rules, Config{}) } @@ -568,9 +573,9 @@ index 3f3046a..2d02719 100644 + } var jt *JumpTable switch { - case chainRules.IsAmsterdam: + case chainRules.IsBogota: diff --git a/execution/vm/jump_table.go b/execution/vm/jump_table.go -index 3c43de8..e13a417 100644 +index a5aff6a..bcf76d1 100644 --- a/execution/vm/jump_table.go +++ b/execution/vm/jump_table.go @@ -54,6 +54,17 @@ type operation struct { @@ -592,10 +597,10 @@ index 3c43de8..e13a417 100644 frontierInstructionSet = newFrontierInstructionSet() homesteadInstructionSet = newHomesteadInstructionSet() diff --git a/execution/vm/operations_acl.go b/execution/vm/operations_acl.go -index 3073c25..4d059e7 100644 +index 175c797..623b05f 100644 --- a/execution/vm/operations_acl.go +++ b/execution/vm/operations_acl.go -@@ -50,15 +50,16 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { +@@ -50,9 +50,10 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { clearRefund = params.SstoreClearsScheduleRefundEIP8038 stateCreate = params.StateGasPerStorageSet } else { @@ -609,49 +614,56 @@ index 3073c25..4d059e7 100644 clearRefund = clearingRefund stateCreate = 0 } - - slot := callContext.peekStorageKey(evm) +@@ -63,7 +64,7 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { + cached = callContext.lookupSlot(evm) + } + var slot accounts.StorageKey - access := params.WarmStorageReadCostEIP2929 + access := evm.GasSchedule.GetOr(GasKeySloadWarm, params.WarmStorageReadCostEIP2929) - slotPresent := evm.IntraBlockState().SlotKnownWarm(callContext.Address(), slot) - if !slotPresent { - _, slotPresent = evm.IntraBlockState().SlotInAccessList(callContext.Address(), slot) -@@ -122,12 +123,12 @@ func gasSLoadEIP2929(evm *EVM, callContext *CallContext, scopeGas mdgas.MdGas, m + slotPresent := cached >= 0 + if slotPresent { + slot = callContext.slots.key[cached] +@@ -149,16 +150,16 @@ func gasSLoadEIP2929(evm *EVM, callContext *CallContext, scopeGas mdgas.MdGas, m + // If the caller cannot afford the cost, this change will be rolled back // If he does afford it, we can skip checking the same thing later on, during execution + if callContext.slots.on && callContext.lookupSlot(evm) >= 0 { +- return mdgas.MdGasCost{Execution: params.WarmStorageReadCostEIP2929}, nil ++ return mdgas.MdGasCost{Execution: evm.GasSchedule.GetOr(GasKeySloadWarm, params.WarmStorageReadCostEIP2929)}, nil + } addr, slot := callContext.Address(), callContext.peekStorageKey(evm) if evm.IntraBlockState().SlotKnownWarm(addr, slot) { -- return mdgas.MdGas{Execution: params.WarmStorageReadCostEIP2929}, nil -+ return mdgas.MdGas{Execution: evm.GasSchedule.GetOr(GasKeySloadWarm, params.WarmStorageReadCostEIP2929)}, nil +- return mdgas.MdGasCost{Execution: params.WarmStorageReadCostEIP2929}, nil ++ return mdgas.MdGasCost{Execution: evm.GasSchedule.GetOr(GasKeySloadWarm, params.WarmStorageReadCostEIP2929)}, nil } if _, slotMod := evm.IntraBlockState().AddSlotToAccessList(addr, slot); slotMod { -- return mdgas.MdGas{Execution: coldStorageAccessCost(evm.chainRules)}, nil -+ return mdgas.MdGas{Execution: evm.GasSchedule.GetOr(GasKeySloadCold, coldStorageAccessCost(evm.chainRules))}, nil +- return mdgas.MdGasCost{Execution: coldStorageAccessCost(evm.chainRules)}, nil ++ return mdgas.MdGasCost{Execution: evm.GasSchedule.GetOr(GasKeySloadCold, coldStorageAccessCost(evm.chainRules))}, nil } -- return mdgas.MdGas{Execution: params.WarmStorageReadCostEIP2929}, nil -+ return mdgas.MdGas{Execution: evm.GasSchedule.GetOr(GasKeySloadWarm, params.WarmStorageReadCostEIP2929)}, nil +- return mdgas.MdGasCost{Execution: params.WarmStorageReadCostEIP2929}, nil ++ return mdgas.MdGasCost{Execution: evm.GasSchedule.GetOr(GasKeySloadWarm, params.WarmStorageReadCostEIP2929)}, nil } // gasExtCodeCopyEIP2929 implements extcodecopy according to EIP-2929 -@@ -146,7 +147,7 @@ func gasExtCodeCopyEIP2929(evm *EVM, callContext *CallContext, scopeGas mdgas.Md +@@ -177,7 +178,7 @@ func gasExtCodeCopyEIP2929(evm *EVM, callContext *CallContext, scopeGas mdgas.Md if evm.IntraBlockState().AddAddressToAccessList(addr) { var overflow bool // We charge (cold-warm), since 'warm' is already charged as constantGas - if gas.Execution, overflow = math.SafeAdd(gas.Execution, coldAccountAccessCost(evm.chainRules)-params.WarmStorageReadCostEIP2929); overflow { + if gas.Execution, overflow = math.SafeAdd(gas.Execution, evm.GasSchedule.GetOr(GasKeyCallCold, coldAccountAccessCost(evm.chainRules))-evm.GasSchedule.GetOr(GasKeyCallWarm, params.WarmStorageReadCostEIP2929)); overflow { - return mdgas.MdGas{}, ErrGasUintOverflow + return mdgas.MdGasCost{}, ErrGasUintOverflow } return gas, nil -@@ -166,7 +167,7 @@ func gasEip2929AccountCheck(evm *EVM, callContext *CallContext, scopeGas mdgas.M +@@ -197,7 +198,7 @@ func gasEip2929AccountCheck(evm *EVM, callContext *CallContext, scopeGas mdgas.M // If the caller cannot afford the cost, this change will be rolled back if evm.IntraBlockState().AddAddressToAccessList(addr) { // The warm storage read cost is already charged as constantGas -- return mdgas.MdGas{Execution: coldAccountAccessCost(evm.chainRules) - params.WarmStorageReadCostEIP2929}, nil -+ return mdgas.MdGas{Execution: evm.GasSchedule.GetOr(GasKeyCallCold, coldAccountAccessCost(evm.chainRules)) - evm.GasSchedule.GetOr(GasKeyCallWarm, params.WarmStorageReadCostEIP2929)}, nil +- return mdgas.MdGasCost{Execution: coldAccountAccessCost(evm.chainRules) - params.WarmStorageReadCostEIP2929}, nil ++ return mdgas.MdGasCost{Execution: evm.GasSchedule.GetOr(GasKeyCallCold, coldAccountAccessCost(evm.chainRules)) - evm.GasSchedule.GetOr(GasKeyCallWarm, params.WarmStorageReadCostEIP2929)}, nil } - return mdgas.MdGas{}, nil + return mdgas.MdGasCost{}, nil } -@@ -176,7 +177,7 @@ func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc { - addr := evm.internAddress(callContext.Stack.back(1)) +@@ -207,7 +208,7 @@ func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc { + addr := evm.intraBlockState.InternAddress(callContext.Stack.back(1)) // The WarmStorageReadCostEIP2929 (100) is already deducted in the form of a constant cost, so // the cost to charge for cold access, if any, is Cold - Warm - coldCost := params.ColdAccountAccessCostEIP2929 - params.WarmStorageReadCostEIP2929 @@ -659,16 +671,16 @@ index 3073c25..4d059e7 100644 warmAccess := evm.IntraBlockState().AddressInAccessList(addr) if !warmAccess { // Charge the remaining difference here already, to correctly calculate available -@@ -246,7 +247,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { +@@ -277,7 +278,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { } // If the caller cannot afford the cost, this change will be rolled back if !evm.IntraBlockState().AddressInAccessList(address) { - gas.Execution = coldAccountAccessCost(evm.chainRules) + gas.Execution = evm.GasSchedule.GetOr(GasKeyCallCold, coldAccountAccessCost(evm.chainRules)) - if _, ok := useGas(scopeGas.Execution, gas.Execution, evm.Config().Tracer, tracing.GasChangeCallStorageColdAccess); !ok { - return mdgas.MdGas{}, ErrOutOfGas + if scopeGas.Execution < gas.Execution { + return mdgas.MdGasCost{}, ErrOutOfGas } -@@ -270,7 +271,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { +@@ -301,7 +302,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { gas.Execution += params.AccountWriteCostEIP8038 gas.State = params.StateGasNewAccount } else { @@ -677,14 +689,13 @@ index 3073c25..4d059e7 100644 } } -@@ -306,14 +307,14 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu - return mdgas.MdGas{}, ErrWriteProtection +@@ -337,13 +338,13 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu + return mdgas.MdGasCost{}, ErrWriteProtection } - addr := evm.internAddress(callContext.Stack.back(1)) + addr := evm.intraBlockState.InternAddress(callContext.Stack.back(1)) - coldAccountAccess := coldAccountAccessCost(evm.ChainRules()) + coldAccountAccess := evm.GasSchedule.GetOr(GasKeyCallCold, coldAccountAccessCost(evm.ChainRules())) // Check slot presence in the access list - var gas mdgas.MdGas var accessGas uint64 if !evm.intraBlockState.AddressInAccessList(addr) { // The WarmStorageReadCostEIP2929 (100) is already deducted in the form of a constant cost, so @@ -694,7 +705,7 @@ index 3073c25..4d059e7 100644 // Charge the remaining difference here already, to correctly calculate available // gas for call if availableGas.Execution < accessGas { -@@ -374,7 +375,7 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu +@@ -403,7 +404,7 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu if !evm.intraBlockState.AddressInAccessList(dd) { delegationGas = coldAccountAccess } else { @@ -704,10 +715,10 @@ index 3073c25..4d059e7 100644 _, err := evm.intraBlockState.GetCode(addr) if err != nil { diff --git a/node/cli/default_flags.go b/node/cli/default_flags.go -index 99fdc46..31113de 100644 +index 8940a94..d3b8e19 100644 --- a/node/cli/default_flags.go +++ b/node/cli/default_flags.go -@@ -279,5 +279,7 @@ var DefaultFlags = []cli.Flag{ +@@ -291,5 +291,7 @@ var DefaultFlags = []cli.Flag{ &utils.MCPPortFlag, &utils.ErigondbDomainStepsInFrozenFileFlag, @@ -716,28 +727,24 @@ index 99fdc46..31113de 100644 &utils.CommitmentPlainValuesFlag, } diff --git a/node/eth/backend.go b/node/eth/backend.go -index 7c2361e..4728157 100644 +index bffceb5..082b5c1 100644 --- a/node/eth/backend.go +++ b/node/eth/backend.go -@@ -1108,12 +1108,27 @@ func (s *Ethereum) Init(stack *node.Node, config *ethconfig.Config, chainConfig - } - } +@@ -1057,8 +1057,23 @@ func (s *Ethereum) Init(stack *node.Node, config *ethconfig.Config) error { + s.logger.Info("[witness-cache] eager witness cache enabled", "blocks", jsonrpc.WitnessCacheCapacity(httpRpcCfg.WitnessCacheBlocks), "headCapture", headCaptureMode) } + + // Xatu: Initialize Xatu service if configured (requires -tags embedded) + var xatuAPIs []rpc.API + if config.XatuConfig != "" { + var xatuErr error -+ xatuAPIs, xatuErr = initXatu(stack, chainKv, s.blockReader, chainConfig, s.engine, config.XatuConfig, s.logger) ++ xatuAPIs, xatuErr = initXatu(stack, chainKv, s.blockReader, s.chainConfig, s.engine, config.XatuConfig, s.logger) + if xatuErr != nil { + return xatuErr + } + } + - // One APIList call even when MCP widens the namespace set, so the HTTP - // RPC server and MCP share the BaseApi block/receipt caches instead of - // each holding their own. - allAPIs := jsonrpc.APIList(chainKv, s.ethRpcClient, s.txPoolRpcClient, s.miningRpcClient, s.rpcFilters, s.rpcDaemonStateCache, blockReader, &apiCfg, s.engine, s.logger, testingEntry, witnessCache) - s.apiList = apisForNamespaces(allAPIs, append(slices.Clone(httpRpcCfg.API), "graphql")) + s.apiList = jsonrpc.APIList(chainKv, s.ethRpcClient, s.txPoolRpcClient, s.miningRpcClient, s.rpcFilters, s.rpcDaemonStateCache, blockReader, &httpRpcCfg, s.engine, s.logger, testingEntry, witnessCache) + // Add Xatu simulation APIs if service is available + if len(xatuAPIs) > 0 { @@ -745,10 +752,10 @@ index 7c2361e..4728157 100644 + } + if config.MCPAddress != "" { - mcpSrv := rpc.NewServer(httpRpcCfg.RpcBatchConcurrency, httpRpcCfg.TraceRequests, httpRpcCfg.DebugSingleRequest, httpRpcCfg.RpcStreamingDisable, s.logger, httpRpcCfg.RPCSlowLogThreshold) - for _, api := range apisForNamespaces(allAPIs, mcpNamespaces) { + mcpSrv, err := newMCPRPCServer(s.apiList, &httpRpcCfg, s.logger) + if err != nil { diff --git a/node/ethconfig/config.go b/node/ethconfig/config.go -index 45ac90e..a9b41d2 100644 +index 039f756..535af5b 100644 --- a/node/ethconfig/config.go +++ b/node/ethconfig/config.go @@ -250,6 +250,8 @@ type Config struct { diff --git a/patches/erigontech/erigon/v3.3.10/base.patch b/patches/erigontech/erigon/v3.3.10/base.patch index 92d0826..f5b3dc5 100644 --- a/patches/erigontech/erigon/v3.3.10/base.patch +++ b/patches/erigontech/erigon/v3.3.10/base.patch @@ -255,7 +255,7 @@ index ffbfe15..5ecbbba 100644 + + // Xatu: Allow custom intrinsic gas schedule overrides for gas simulation + if st.evm.GasSchedule != nil && st.evm.GasSchedule.HasIntrinsicOverrides() { -+ gas, floorGas7623 = vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, false, uint64(len(auths))) ++ gas, floorGas7623 = vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, uint64(len(auths))) + overflow = false + } if overflow { diff --git a/patches/erigontech/erigon/v3.7.0/base.patch b/patches/erigontech/erigon/v3.7.0/base.patch index 495055c..dd41efe 100644 --- a/patches/erigontech/erigon/v3.7.0/base.patch +++ b/patches/erigontech/erigon/v3.7.0/base.patch @@ -258,7 +258,7 @@ index cee4e5d..af82190 100644 + rules := st.evm.ChainRules() + vmConfig := st.evm.Config() + isEIP3860 := vmConfig.HasEip3860(rules) -+ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, false, uint64(len(auths))) ++ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, uint64(len(auths))) + intrinsicGasResult = mdgas.IntrinsicGasCalcResult{ExecutionGas: gas, FloorGasCost: floorGas} + overflow = false + } diff --git a/patches/erigontech/erigon/v3.7.1/base.patch b/patches/erigontech/erigon/v3.7.1/base.patch index 36867b9..1f657ba 100644 --- a/patches/erigontech/erigon/v3.7.1/base.patch +++ b/patches/erigontech/erigon/v3.7.1/base.patch @@ -258,7 +258,7 @@ index cee4e5d..af82190 100644 + rules := st.evm.ChainRules() + vmConfig := st.evm.Config() + isEIP3860 := vmConfig.HasEip3860(rules) -+ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, false, uint64(len(auths))) ++ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, uint64(len(auths))) + intrinsicGasResult = mdgas.IntrinsicGasCalcResult{ExecutionGas: gas, FloorGasCost: floorGas} + overflow = false + } diff --git a/patches/erigontech/erigon/v3.8.0/base.patch b/patches/erigontech/erigon/v3.8.0/base.patch index bcd7c4d..7add1f3 100644 --- a/patches/erigontech/erigon/v3.8.0/base.patch +++ b/patches/erigontech/erigon/v3.8.0/base.patch @@ -56,7 +56,7 @@ index e78a83c..6f8929e 100644 + rules := st.evm.ChainRules() + vmConfig := st.evm.Config() + isEIP3860 := vmConfig.HasEip3860(rules) -+ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, false, uint64(len(auths))) ++ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, uint64(len(auths))) + intrinsicGasResult = mdgas.IntrinsicGasCalcResult{ExecutionGas: gas, FloorGasCost: floorGas} + overflow = false + } diff --git a/patches/erigontech/erigon/v3.8.1/base.patch b/patches/erigontech/erigon/v3.8.1/base.patch index 7d0b4ff..87f30c2 100644 --- a/patches/erigontech/erigon/v3.8.1/base.patch +++ b/patches/erigontech/erigon/v3.8.1/base.patch @@ -56,7 +56,7 @@ index e78a83c..6f8929e 100644 + rules := st.evm.ChainRules() + vmConfig := st.evm.Config() + isEIP3860 := vmConfig.HasEip3860(rules) -+ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, false, uint64(len(auths))) ++ gas, floorGas := vm.CalcCustomIntrinsicGas(st.evm.GasSchedule, st.data, uint64(len(accessTuples)), uint64(accessTuples.StorageKeys()), contractCreation, rules.IsHomestead, rules.IsIstanbul, isEIP3860, rules.IsPrague, uint64(len(auths))) + intrinsicGasResult = mdgas.IntrinsicGasCalcResult{ExecutionGas: gas, FloorGasCost: floorGas} + overflow = false + } From 496cc8440f31266f58f856d6f23a1c8645d859a5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 27 Nov 2026 03:32:56 +0000 Subject: [PATCH 2/2] Update patches [skip ci] - Updated patches for erigontech/erigon v3.3.10 (commit: e7de183) - Updated patches for erigontech/erigon v3.7.0 (commit: bdc78cc) - Updated patches for erigontech/erigon v3.7.1 (commit: 8c1e389) - Updated patches for erigontech/erigon v3.8.0 (commit: 7539da1) - Updated patches for erigontech/erigon v3.8.1 (commit: cf6f141) --- patches/erigontech/erigon/v3.3.10/base.patch | 2 +- patches/erigontech/erigon/v3.7.0/base.patch | 2 +- patches/erigontech/erigon/v3.7.1/base.patch | 2 +- patches/erigontech/erigon/v3.8.0/base.patch | 2 +- patches/erigontech/erigon/v3.8.1/base.patch | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/patches/erigontech/erigon/v3.3.10/base.patch b/patches/erigontech/erigon/v3.3.10/base.patch index f5b3dc5..1f8d1a1 100644 --- a/patches/erigontech/erigon/v3.3.10/base.patch +++ b/patches/erigontech/erigon/v3.3.10/base.patch @@ -245,7 +245,7 @@ index 6ad846b..f7c908c 100644 + return x - y +} diff --git a/execution/protocol/state_transition.go b/execution/protocol/state_transition.go -index ffbfe15..5ecbbba 100644 +index ffbfe15..c4e5b09 100644 --- a/execution/protocol/state_transition.go +++ b/execution/protocol/state_transition.go @@ -504,6 +504,12 @@ func (st *StateTransition) TransitionDb(refunds bool, gasBailout bool) (result * diff --git a/patches/erigontech/erigon/v3.7.0/base.patch b/patches/erigontech/erigon/v3.7.0/base.patch index dd41efe..c7dcaa4 100644 --- a/patches/erigontech/erigon/v3.7.0/base.patch +++ b/patches/erigontech/erigon/v3.7.0/base.patch @@ -245,7 +245,7 @@ index 95ca56f..7344d2a 100644 + return x - y +} diff --git a/execution/protocol/txn_executor.go b/execution/protocol/txn_executor.go -index cee4e5d..af82190 100644 +index cee4e5d..32b77b9 100644 --- a/execution/protocol/txn_executor.go +++ b/execution/protocol/txn_executor.go @@ -612,6 +612,16 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. diff --git a/patches/erigontech/erigon/v3.7.1/base.patch b/patches/erigontech/erigon/v3.7.1/base.patch index 1f657ba..6df9dbc 100644 --- a/patches/erigontech/erigon/v3.7.1/base.patch +++ b/patches/erigontech/erigon/v3.7.1/base.patch @@ -245,7 +245,7 @@ index 95ca56f..7344d2a 100644 + return x - y +} diff --git a/execution/protocol/txn_executor.go b/execution/protocol/txn_executor.go -index cee4e5d..af82190 100644 +index cee4e5d..32b77b9 100644 --- a/execution/protocol/txn_executor.go +++ b/execution/protocol/txn_executor.go @@ -612,6 +612,16 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. diff --git a/patches/erigontech/erigon/v3.8.0/base.patch b/patches/erigontech/erigon/v3.8.0/base.patch index 7add1f3..0985a8a 100644 --- a/patches/erigontech/erigon/v3.8.0/base.patch +++ b/patches/erigontech/erigon/v3.8.0/base.patch @@ -43,7 +43,7 @@ index 95ca56f..7344d2a 100644 + return x - y +} diff --git a/execution/protocol/txn_executor.go b/execution/protocol/txn_executor.go -index e78a83c..6f8929e 100644 +index e78a83c..3b99580 100644 --- a/execution/protocol/txn_executor.go +++ b/execution/protocol/txn_executor.go @@ -595,6 +595,16 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. diff --git a/patches/erigontech/erigon/v3.8.1/base.patch b/patches/erigontech/erigon/v3.8.1/base.patch index 87f30c2..403a12e 100644 --- a/patches/erigontech/erigon/v3.8.1/base.patch +++ b/patches/erigontech/erigon/v3.8.1/base.patch @@ -43,7 +43,7 @@ index 95ca56f..7344d2a 100644 + return x - y +} diff --git a/execution/protocol/txn_executor.go b/execution/protocol/txn_executor.go -index e78a83c..6f8929e 100644 +index e78a83c..3b99580 100644 --- a/execution/protocol/txn_executor.go +++ b/execution/protocol/txn_executor.go @@ -595,6 +595,16 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes.