diff --git a/cmd/rpcdaemon/commands/zkevm_api.go b/cmd/rpcdaemon/commands/zkevm_api.go index 6f50ce40351..c1b45e4857d 100644 --- a/cmd/rpcdaemon/commands/zkevm_api.go +++ b/cmd/rpcdaemon/commands/zkevm_api.go @@ -14,13 +14,12 @@ import ( "github.com/holiman/uint256" "github.com/ledgerwatch/erigon/common/hexutil" - "github.com/ledgerwatch/erigon/common/u256" + "github.com/ledgerwatch/erigon/core" eritypes "github.com/ledgerwatch/erigon/core/types" "github.com/ledgerwatch/erigon/rpc" "github.com/ledgerwatch/erigon/sync_stages" "github.com/ledgerwatch/erigon/zk/hermez_db" types "github.com/ledgerwatch/erigon/zk/rpcdaemon" - zktypes "github.com/ledgerwatch/erigon/zk/types" "github.com/ledgerwatch/erigon/zkevm/jsonrpc/client" ) @@ -534,13 +533,8 @@ func convertReceipt( } var effectiveGasPrice *types.ArgBig - gas := gasPrice.Clone() - if effectiveGasPricePercentage > zktypes.EFFECTIVE_GAS_PRICE_PERCENTAGE_DISABLED && gasPrice != nil { - clone := gasPrice.Clone() - effectiveGasPricePerc := new(uint256.Int).SetUint64(uint64(effectiveGasPricePercentage)) - effectiveGasPricePerc.Add(effectiveGasPricePerc, u256.Num1) - clone.Mul(clone, effectiveGasPricePerc) - gas.Div(clone, zktypes.EFFECTIVE_GAS_PRICE_MAX_VAL) + if gasPrice != nil { + gas := core.CalculateEffectiveGas(gasPrice, effectiveGasPricePercentage) asBig := types.ArgBig(*gas.ToBig()) effectiveGasPrice = &asBig } diff --git a/core/state_transition.go b/core/state_transition.go index cde726e2b76..931eca0a651 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -157,14 +157,9 @@ func NewStateTransition(evm vm.VMInterface, msg Message, gp *GasPool) *StateTran gas := msg.GasPrice() - // check if we have an effective gas price percentage in the message and apply it - ep := msg.EffectiveGasPricePercentage() - if ep > zktypes.EFFECTIVE_GAS_PRICE_PERCENTAGE_DISABLED { - val := gas.Clone() - epi := new(uint256.Int).SetUint64(uint64(ep)) - epi = epi.Add(epi, u256.Num1) - val = val.Mul(val, epi) - gas = gas.Div(val, zktypes.EFFECTIVE_GAS_PRICE_MAX_VAL) + if evm.ChainRules().IsMordor { + ep := msg.EffectiveGasPricePercentage() + gas = CalculateEffectiveGas(gas, ep) } return &StateTransition{ @@ -185,6 +180,16 @@ func NewStateTransition(evm vm.VMInterface, msg Message, gp *GasPool) *StateTran } } +func CalculateEffectiveGas(gas *uint256.Int, ep uint8) *uint256.Int { + val := gas.Clone() + epi := new(uint256.Int).SetUint64(uint64(ep)) + epi = epi.Add(epi, u256.Num1) + val = val.Mul(val, epi) + gas = gas.Div(val, zktypes.EFFECTIVE_GAS_PRICE_MAX_VAL) + + return gas +} + // ApplyMessage computes the new state by applying the given message // against the old state within the environment. //