Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions params/extras/network_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 0 additions & 4 deletions params/hooks_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
11 changes: 7 additions & 4 deletions precompile/allowlist/allowlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
1 change: 0 additions & 1 deletion precompile/contract/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ type AccessibleState interface {
GetStateDB() StateDB
GetBlockContext() BlockContext
GetSnowContext() *snow.Context
GetChainConfig() precompileconfig.ChainConfig
GetRules() precompileconfig.Rules
}

Expand Down
14 changes: 0 additions & 14 deletions precompile/contract/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions precompile/contract/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,3 @@ func ParseABI(rawABI string) abi.ABI {

return parsed
}

func IsDurangoActivated(evm AccessibleState) bool {
return evm.GetChainConfig().IsDurango(evm.GetBlockContext().Timestamp())
}
5 changes: 3 additions & 2 deletions precompile/contracts/feemanager/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions precompile/contracts/nativeminter/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions precompile/contracts/rewardmanager/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions precompile/precompileconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 0 additions & 1 deletion precompile/precompiletest/test_precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading