From 11a7be9a4473eef232ae25deafc44b717d44954d Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Fri, 10 Oct 2025 15:28:40 +0300 Subject: [PATCH] remove unused GetChainConfig from the precompile interface (#1334) --- params/extras/network_upgrades.go | 5 +++++ params/hooks_libevm.go | 4 ---- precompile/allowlist/allowlist.go | 11 +++++++---- precompile/contract/interfaces.go | 1 - precompile/contract/mocks.go | 14 -------------- precompile/contract/utils.go | 4 ---- precompile/contracts/feemanager/contract.go | 5 +++-- precompile/contracts/nativeminter/contract.go | 5 +++-- precompile/contracts/rewardmanager/contract.go | 9 +++++---- precompile/precompileconfig/config.go | 1 + precompile/precompiletest/test_precompile.go | 1 - 11 files changed, 24 insertions(+), 36 deletions(-) diff --git a/params/extras/network_upgrades.go b/params/extras/network_upgrades.go index 4b9b4c05b2..40660c8c89 100644 --- a/params/extras/network_upgrades.go +++ b/params/extras/network_upgrades.go @@ -193,6 +193,11 @@ func (a AvalancheRules) IsGraniteActivated() bool { return a.IsGranite } +// IsDurangoActivated is used by the warp precompile to determine which gas costs to use. +func (a AvalancheRules) IsDurangoActivated() bool { + return a.IsDurango +} + func (n *NetworkUpgrades) GetAvalancheRules(time uint64) AvalancheRules { return AvalancheRules{ IsSubnetEVM: n.IsSubnetEVM(time), diff --git a/params/hooks_libevm.go b/params/hooks_libevm.go index 23ce067baa..42c7835ac0 100644 --- a/params/hooks_libevm.go +++ b/params/hooks_libevm.go @@ -168,10 +168,6 @@ func (a accessibleState) GetBlockContext() contract.BlockContext { return a.blockContext } -func (a accessibleState) GetChainConfig() precompileconfig.ChainConfig { - return GetExtra(a.env.ChainConfig()) -} - func (a accessibleState) GetRules() precompileconfig.Rules { chainConfigExtra := GetExtra(a.GetPrecompileEnv().ChainConfig()) return chainConfigExtra.GetAvalancheRules(a.GetBlockContext().Timestamp()) diff --git a/precompile/allowlist/allowlist.go b/precompile/allowlist/allowlist.go index 5aa0ce5827..91b81692e1 100644 --- a/precompile/allowlist/allowlist.go +++ b/precompile/allowlist/allowlist.go @@ -93,7 +93,7 @@ func createAllowListRoleSetter(precompileAddr common.Address, role Role) contrac } // do not use strict mode after Durango - useStrictMode := !contract.IsDurangoActivated(evm) + useStrictMode := !evm.GetRules().IsDurangoActivated() modifyAddress, err := UnpackModifyAllowListInput(input, role, useStrictMode) if err != nil { return nil, remainingGas, err @@ -112,7 +112,7 @@ func createAllowListRoleSetter(precompileAddr common.Address, role Role) contrac if !callerStatus.CanModify(modifyStatus, role) { return nil, remainingGas, fmt.Errorf("%w: modify address: %s, from role: %s, to role: %s", ErrCannotModifyAllowList, callerAddr, modifyStatus, role) } - if contract.IsDurangoActivated(evm) { + if evm.GetRules().IsDurangoActivated() { if remainingGas, err = contract.DeductGas(remainingGas, AllowListEventGasCost); err != nil { return nil, 0, err } @@ -164,7 +164,7 @@ func createReadAllowList(precompileAddr common.Address) contract.RunStatefulPrec } // We skip the fixed length check with Durango - useStrictMode := !contract.IsDurangoActivated(evm) + useStrictMode := !evm.GetRules().IsDurangoActivated() readAddress, err := UnpackReadAllowListInput(input, useStrictMode) if err != nil { return nil, remainingGas, err @@ -192,6 +192,9 @@ func CreateAllowListPrecompile(precompileAddr common.Address) contract.StatefulP func CreateAllowListFunctions(precompileAddr common.Address) []*contract.StatefulPrecompileFunction { functions := make([]*contract.StatefulPrecompileFunction, 0, len(AllowListABI.Methods)) + durangoActivationFunc := func(evm contract.AccessibleState) bool { + return evm.GetRules().IsDurangoActivated() + } for name, method := range AllowListABI.Methods { var fn *contract.StatefulPrecompileFunction @@ -204,7 +207,7 @@ func CreateAllowListFunctions(precompileAddr common.Address) []*contract.Statefu } else if noRoleFnName, _ := NoRole.GetSetterFunctionName(); name == noRoleFnName { fn = contract.NewStatefulPrecompileFunction(method.ID, createAllowListRoleSetter(precompileAddr, NoRole)) } else if managerFnName, _ := ManagerRole.GetSetterFunctionName(); name == managerFnName { - fn = contract.NewStatefulPrecompileFunctionWithActivator(method.ID, createAllowListRoleSetter(precompileAddr, ManagerRole), contract.IsDurangoActivated) + fn = contract.NewStatefulPrecompileFunctionWithActivator(method.ID, createAllowListRoleSetter(precompileAddr, ManagerRole), durangoActivationFunc) } else { panic("unexpected method name: " + name) } diff --git a/precompile/contract/interfaces.go b/precompile/contract/interfaces.go index b108e17fd0..a77ee997c3 100644 --- a/precompile/contract/interfaces.go +++ b/precompile/contract/interfaces.go @@ -57,7 +57,6 @@ type AccessibleState interface { GetStateDB() StateDB GetBlockContext() BlockContext GetSnowContext() *snow.Context - GetChainConfig() precompileconfig.ChainConfig GetRules() precompileconfig.Rules } diff --git a/precompile/contract/mocks.go b/precompile/contract/mocks.go index 788a0dc98d..faf9fc1799 100644 --- a/precompile/contract/mocks.go +++ b/precompile/contract/mocks.go @@ -128,20 +128,6 @@ func (mr *MockAccessibleStateMockRecorder) GetBlockContext() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockContext", reflect.TypeOf((*MockAccessibleState)(nil).GetBlockContext)) } -// GetChainConfig mocks base method. -func (m *MockAccessibleState) GetChainConfig() precompileconfig.ChainConfig { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetChainConfig") - ret0, _ := ret[0].(precompileconfig.ChainConfig) - return ret0 -} - -// GetChainConfig indicates an expected call of GetChainConfig. -func (mr *MockAccessibleStateMockRecorder) GetChainConfig() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChainConfig", reflect.TypeOf((*MockAccessibleState)(nil).GetChainConfig)) -} - // GetRules mocks base method. func (m *MockAccessibleState) GetRules() precompileconfig.Rules { m.ctrl.T.Helper() diff --git a/precompile/contract/utils.go b/precompile/contract/utils.go index e396a91647..ef9f6ea1b0 100644 --- a/precompile/contract/utils.go +++ b/precompile/contract/utils.go @@ -59,7 +59,3 @@ func ParseABI(rawABI string) abi.ABI { return parsed } - -func IsDurangoActivated(evm AccessibleState) bool { - return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Timestamp()) -} diff --git a/precompile/contracts/feemanager/contract.go b/precompile/contracts/feemanager/contract.go index 413b700ca2..7a82a9ae35 100644 --- a/precompile/contracts/feemanager/contract.go +++ b/precompile/contracts/feemanager/contract.go @@ -217,7 +217,8 @@ func setFeeConfig(accessibleState contract.AccessibleState, caller common.Addres } // do not use strict mode after Durango - useStrictMode := !contract.IsDurangoActivated(accessibleState) + rules := accessibleState.GetRules() + useStrictMode := !rules.IsDurangoActivated() feeConfig, err := UnpackSetFeeConfigInput(input, useStrictMode) if err != nil { return nil, remainingGas, err @@ -230,7 +231,7 @@ func setFeeConfig(accessibleState contract.AccessibleState, caller common.Addres return nil, remainingGas, fmt.Errorf("%w: %s", ErrCannotChangeFee, caller) } - if contract.IsDurangoActivated(accessibleState) { + if rules.IsDurangoActivated() { if remainingGas, err = contract.DeductGas(remainingGas, FeeConfigChangedEventGasCost); err != nil { return nil, 0, err } diff --git a/precompile/contracts/nativeminter/contract.go b/precompile/contracts/nativeminter/contract.go index 97a8aa3d97..3c8f004caf 100644 --- a/precompile/contracts/nativeminter/contract.go +++ b/precompile/contracts/nativeminter/contract.go @@ -88,7 +88,8 @@ func mintNativeCoin(accessibleState contract.AccessibleState, caller common.Addr return nil, remainingGas, vm.ErrWriteProtection } - useStrictMode := !contract.IsDurangoActivated(accessibleState) + rules := accessibleState.GetRules() + useStrictMode := !rules.IsDurangoActivated() to, amount, err := UnpackMintNativeCoinInput(input, useStrictMode) if err != nil { return nil, remainingGas, err @@ -101,7 +102,7 @@ func mintNativeCoin(accessibleState contract.AccessibleState, caller common.Addr return nil, remainingGas, fmt.Errorf("%w: %s", ErrCannotMint, caller) } - if contract.IsDurangoActivated(accessibleState) { + if rules.IsDurangoActivated() { if remainingGas, err = contract.DeductGas(remainingGas, NativeCoinMintedEventGasCost); err != nil { return nil, 0, err } diff --git a/precompile/contracts/rewardmanager/contract.go b/precompile/contracts/rewardmanager/contract.go index bcaac93863..fe5fe4419f 100644 --- a/precompile/contracts/rewardmanager/contract.go +++ b/precompile/contracts/rewardmanager/contract.go @@ -98,7 +98,7 @@ func allowFeeRecipients(accessibleState contract.AccessibleState, caller common. } // allow list code ends here. - if contract.IsDurangoActivated(accessibleState) { + if accessibleState.GetRules().IsDurangoActivated() { if remainingGas, err = contract.DeductGas(remainingGas, FeeRecipientsAllowedEventGasCost); err != nil { return nil, 0, err } @@ -199,10 +199,11 @@ func setRewardAddress(accessibleState contract.AccessibleState, caller common.Ad if readOnly { return nil, remainingGas, vm.ErrWriteProtection } + rules := accessibleState.GetRules() // attempts to unpack [input] into the arguments to the SetRewardAddressInput. // Assumes that [input] does not include selector // do not use strict mode after Durango - useStrictMode := !contract.IsDurangoActivated(accessibleState) + useStrictMode := !rules.IsDurangoActivated() rewardAddress, err := UnpackSetRewardAddressInput(input, useStrictMode) if err != nil { return nil, remainingGas, err @@ -225,7 +226,7 @@ func setRewardAddress(accessibleState contract.AccessibleState, caller common.Ad } // Add a log to be handled if this action is finalized. - if contract.IsDurangoActivated(accessibleState) { + if rules.IsDurangoActivated() { if remainingGas, err = contract.DeductGas(remainingGas, RewardAddressChangedEventGasCost); err != nil { return nil, 0, err } @@ -289,7 +290,7 @@ func disableRewards(accessibleState contract.AccessibleState, caller common.Addr } // allow list code ends here. - if contract.IsDurangoActivated(accessibleState) { + if accessibleState.GetRules().IsDurangoActivated() { if remainingGas, err = contract.DeductGas(remainingGas, RewardsDisabledEventGasCost); err != nil { return nil, 0, err } diff --git a/precompile/precompileconfig/config.go b/precompile/precompileconfig/config.go index 8ea4b3ab48..c70f009459 100644 --- a/precompile/precompileconfig/config.go +++ b/precompile/precompileconfig/config.go @@ -88,4 +88,5 @@ type ChainConfig interface { // Rules defines the interface that provides information about the current rules of the chain. type Rules interface { IsGraniteActivated() bool + IsDurangoActivated() bool } diff --git a/precompile/precompiletest/test_precompile.go b/precompile/precompiletest/test_precompile.go index c751b1f2ea..eaac32060c 100644 --- a/precompile/precompiletest/test_precompile.go +++ b/precompile/precompiletest/test_precompile.go @@ -195,7 +195,6 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state *tes accessibleState.EXPECT().GetStateDB().Return(state).AnyTimes() accessibleState.EXPECT().GetBlockContext().Return(blockContext).AnyTimes() accessibleState.EXPECT().GetSnowContext().Return(snowContext).AnyTimes() - accessibleState.EXPECT().GetChainConfig().Return(chainConfig).AnyTimes() accessibleState.EXPECT().GetRules().Return(test.Rules).AnyTimes() if test.Config != nil {