diff --git a/patches/erigontech/erigon/main/base.patch b/patches/erigontech/erigon/main/base.patch index 44c63c3..ceefb63 100644 --- a/patches/erigontech/erigon/main/base.patch +++ b/patches/erigontech/erigon/main/base.patch @@ -43,10 +43,10 @@ index dc353bf..52a46f1 100644 + return x - y +} diff --git a/execution/protocol/txn_executor.go b/execution/protocol/txn_executor.go -index 30a0a51..70b4981 100644 +index 6666276..fdd45e7 100644 --- a/execution/protocol/txn_executor.go +++ b/execution/protocol/txn_executor.go -@@ -510,6 +510,17 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. +@@ -512,6 +512,17 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. // Check clause 1: compute intrinsic gas before preCheck so the EIP-7825 // cap can be checked there (before buyGas) for all fork variants. intrinsicGasResult, overflow := st.calcIntrinsicGas(contractCreation, auths, accessTuples) @@ -64,7 +64,7 @@ index 30a0a51..70b4981 100644 if overflow { return nil, ErrGasUintOverflow } -@@ -519,10 +530,6 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. +@@ -521,10 +532,6 @@ func (st *TxnExecutor) Execute(refunds bool, gasBailout bool) (result *evmtypes. return nil, err } @@ -219,37 +219,36 @@ index 2ba00fe..2523c10 100644 } diff --git a/execution/vm/evm.go b/execution/vm/evm.go -index b5e03c1..caaf128 100644 +index f18630a..85ea9d4 100644 --- a/execution/vm/evm.go +++ b/execution/vm/evm.go -@@ -94,6 +94,10 @@ type EVM struct { +@@ -94,6 +94,9 @@ type EVM struct { readOnly bool // Whether to throw on stateful modifications returnData []byte // Last CALL's return data for subsequent reuse + // GasSchedule allows overriding gas costs for simulation. + // When nil, standard params.X values are used. + GasSchedule *GasSchedule -+ - stateGasConsumed uint64 // total state gas charged during tx execution (restored on depth>0 revert, kept on depth-0) - regularGasConsumed uint64 // total regular gas charged during tx execution (for block-level accounting) - revertedSpillGas uint64 // state gas that spilled to regular and was restored on depth-0 revert -@@ -375,7 +379,7 @@ func (evm *EVM) call(typ OpCode, caller accounts.Address, callerAddress accounts + } + + // NewEVM returns a new EVM. The returned EVM is not thread safe and should +@@ -335,7 +338,7 @@ func (evm *EVM) call(typ OpCode, caller accounts.Address, callerAddress accounts + // It is allowed to call precompiles, even via delegatecall if isPrecompile { - preGas := gas.Regular - ret, gas.Regular, err = RunPrecompiledContract(p, input, gas.Regular, evm.Config().Tracer) + ret, gas.Regular, err = RunPrecompiledContract(p, input, gas.Regular, evm.Config().Tracer, evm.GasSchedule) - if evm.chainRules.IsAmsterdam { - evm.regularGasConsumed += preGas - gas.Regular - } -@@ -643,7 +647,7 @@ func (evm *EVM) create(caller accounts.Address, codeAndHash *codeAndHash, gasRem + } else if len(code) == 0 { + // If the account has no code, we can abort here + // The depth-check is already done, and precompiles handled above +@@ -612,7 +615,7 @@ func (evm *EVM) create(caller accounts.Address, codeAndHash *codeAndHash, gasRem // HASH_COST(L) = 6*ceil(L/32); the state component (cpsb*L) is charged above. regularGas = params.Keccak256WordGas * ToWordSize(uint64(len(ret))) } else { - regularGas = uint64(len(ret)) * params.CreateDataGas + regularGas = uint64(len(ret)) * evm.GasSchedule.GetOr(GasKeyCreateData, params.CreateDataGas) } - gasRemaining, regularGasOk = useMdGas(evm, gasRemaining, regularGas, mdgas.RegularGas, evm.Config().Tracer, tracing.GasChangeCallCodeStorage) + gasRemaining, regularGasOk = useMdGas(gasRemaining, regularGas, mdgas.RegularGas, evm.Config().Tracer, tracing.GasChangeCallCodeStorage) } diff --git a/execution/vm/export_test.go b/execution/vm/export_test.go index 97ff0ec..0636e08 100644 @@ -263,7 +262,7 @@ index 97ff0ec..0636e08 100644 + return memoryGasCost(&EVM{}, callContext, newMemSize) } diff --git a/execution/vm/gas_table.go b/execution/vm/gas_table.go -index 78defa8..3d037da 100644 +index 820a2e4..b8c2642 100644 --- a/execution/vm/gas_table.go +++ b/execution/vm/gas_table.go @@ -33,7 +33,7 @@ import ( @@ -502,7 +501,7 @@ index 78defa8..3d037da 100644 } @@ -514,7 +514,7 @@ func statefulGasCall(evm *EVM, callContext *CallContext, gas mdgas.MdGas, availa if rules.IsAmsterdam { - stateGas = params.StateBytesNewAccount * evm.Context.CostPerStateByte + stateGas = params.StateGasNewAccount } else { - accountGas = params.CallNewAccountGas + accountGas = evm.GasSchedule.GetOr(GasKeyCallNewAccount, params.CallNewAccountGas) @@ -573,7 +572,7 @@ index 78defa8..3d037da 100644 } } diff --git a/execution/vm/interpreter.go b/execution/vm/interpreter.go -index 159b4e2..6cf873e 100644 +index d87639a..6e7f01c 100644 --- a/execution/vm/interpreter.go +++ b/execution/vm/interpreter.go @@ -48,6 +48,10 @@ type Config struct { @@ -587,7 +586,7 @@ index 159b4e2..6cf873e 100644 } func (vmConfig *Config) HasEip3860(rules *chain.Rules) bool { -@@ -295,7 +299,18 @@ func copyJumpTable(jt *JumpTable) *JumpTable { +@@ -321,7 +325,18 @@ func copyJumpTable(jt *JumpTable) *JumpTable { return © } @@ -629,7 +628,7 @@ index daae81f..e704a18 100644 frontierInstructionSet = newFrontierInstructionSet() homesteadInstructionSet = newHomesteadInstructionSet() diff --git a/execution/vm/operations_acl.go b/execution/vm/operations_acl.go -index f56ccda..02663a6 100644 +index 9b603fd..2e8cc77 100644 --- a/execution/vm/operations_acl.go +++ b/execution/vm/operations_acl.go @@ -54,7 +54,7 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { @@ -652,7 +651,7 @@ index f56ccda..02663a6 100644 var original, _ = evm.IntraBlockState().GetCommittedState(callContext.Address(), slot) @@ -76,7 +76,7 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { if rules.IsAmsterdam { - return mdgas.MdGas{Regular: cost + params.SstoreSetGasEIP8037, State: 32 * evm.Context.CostPerStateByte}, nil + return mdgas.MdGas{Regular: cost + params.SstoreSetGasEIP8037, State: params.StateGasPerStorageSet}, nil } else { - return mdgas.MdGas{Regular: cost + params.SstoreSetGasEIP2200}, nil + return mdgas.MdGas{Regular: cost + evm.GasSchedule.GetOr(GasKeySstoreSet, params.SstoreSetGasEIP2200)}, nil @@ -669,9 +668,9 @@ index f56ccda..02663a6 100644 } if !original.IsZero() { if current.IsZero() { // recreate slot (2.2.1.1) -@@ -101,7 +102,8 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { - evm.IntraBlockState().AddRefund(params.SstoreSetGasEIP8037 - params.WarmStorageReadCostEIP2929) - evm.IntraBlockState().AddStateRefund(32 * evm.Context.CostPerStateByte) +@@ -106,7 +107,8 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { + // caller on successful return. + callContext.creditStateGasRefund(params.StateGasPerStorageSet) } else { - evm.IntraBlockState().AddRefund(params.SstoreSetGasEIP2200 - params.WarmStorageReadCostEIP2929) + // Use SafeSubClamp to prevent underflow with custom gas schedules @@ -679,7 +678,7 @@ index f56ccda..02663a6 100644 } } else { // reset to original existing slot (2.2.2.2) // EIP 2200 Original clause: -@@ -109,12 +111,13 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { +@@ -114,12 +116,13 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc { // - SSTORE_RESET_GAS redefined as (5000 - COLD_SLOAD_COST) // - SLOAD_GAS redefined as WARM_STORAGE_READ_COST // Final: (5000 - COLD_SLOAD_COST) - WARM_STORAGE_READ_COST @@ -695,7 +694,7 @@ index f56ccda..02663a6 100644 } } -@@ -127,9 +130,9 @@ func gasSLoadEIP2929(evm *EVM, callContext *CallContext, scopeGas mdgas.MdGas, m +@@ -132,9 +135,9 @@ 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 _, slotMod := evm.IntraBlockState().AddSlotToAccessList(callContext.Address(), callContext.peekStorageKey()); slotMod { @@ -707,7 +706,7 @@ index f56ccda..02663a6 100644 } // gasExtCodeCopyEIP2929 implements extcodecopy according to EIP-2929 -@@ -148,7 +151,7 @@ func gasExtCodeCopyEIP2929(evm *EVM, callContext *CallContext, scopeGas mdgas.Md +@@ -153,7 +156,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 @@ -716,7 +715,7 @@ index f56ccda..02663a6 100644 return mdgas.MdGas{}, ErrGasUintOverflow } return gas, nil -@@ -168,7 +171,7 @@ func gasEip2929AccountCheck(evm *EVM, callContext *CallContext, scopeGas mdgas.M +@@ -173,7 +176,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 @@ -725,7 +724,7 @@ index f56ccda..02663a6 100644 } return mdgas.MdGas{}, nil } -@@ -178,7 +181,7 @@ func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc { +@@ -183,7 +186,7 @@ func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc { addr := accounts.InternAddress(callContext.Stack.Back(1).Bytes20()) // 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 @@ -734,7 +733,7 @@ index f56ccda..02663a6 100644 warmAccess := evm.IntraBlockState().AddressInAccessList(addr) if !warmAccess { // Charge the remaining difference here already, to correctly calculate available -@@ -248,7 +251,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { +@@ -253,7 +256,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { } // If the caller cannot afford the cost, this change will be rolled back if !evm.IntraBlockState().AddressInAccessList(address) { @@ -743,16 +742,16 @@ index f56ccda..02663a6 100644 if _, ok := useGas(scopeGas.Regular, gas.Regular, evm.Config().Tracer, tracing.GasChangeCallStorageColdAccess); !ok { return mdgas.MdGas{}, ErrOutOfGas } -@@ -293,7 +296,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { +@@ -298,7 +301,7 @@ func makeSelfdestructGasFn(refundsEnabled bool) gasFunc { if evm.chainRules.IsAmsterdam { - gas.State = params.StateBytesNewAccount * evm.Context.CostPerStateByte + gas.State = params.StateGasNewAccount } else { - gas.Regular += params.CreateBySelfdestructGas + gas.Regular += evm.GasSchedule.GetOr(GasKeyCreateBySelfDestruct, params.CreateBySelfdestructGas) } } -@@ -330,7 +333,7 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu +@@ -335,7 +338,7 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu if !evm.intraBlockState.AddressInAccessList(addr) { // 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 @@ -761,7 +760,7 @@ index f56ccda..02663a6 100644 // Charge the remaining difference here already, to correctly calculate available // gas for call if availableGas.Regular < accessGas { -@@ -389,9 +392,9 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu +@@ -394,9 +397,9 @@ func makeCallVariantGasCallEIP7702(statelessCalculator statelessGasFunc, statefu var delegationGas uint64 if ok { if !evm.intraBlockState.AddressInAccessList(dd) {