diff --git a/CHANGELOG.md b/CHANGELOG.md index f69f2d315..cea85a8e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ - [\#598](https://github.com/cosmos/evm/pull/598) Reduce number of times CreateQueryContext in mempool. - [\#606](https://github.com/cosmos/evm/pull/606) Regenerate mock file for bank keeper related test. - [\#624](https://github.com/cosmos/evm/pull/624) Cleanup unnecessary `fix-revert-gas-refund-height`. +- [\#635](https://github.com/cosmos/evm/pull/635) Move DefaultStaticPrecompiles to /evm and allow projects to set it by default alongside the keeper. + ### FEATURES diff --git a/docs/migrations/v0.4.0_to_v0.5.0_UNRELEASED.md b/docs/migrations/v0.4.0_to_v0.5.0_UNRELEASED.md index 57965a9bd..10fc61266 100644 --- a/docs/migrations/v0.4.0_to_v0.5.0_UNRELEASED.md +++ b/docs/migrations/v0.4.0_to_v0.5.0_UNRELEASED.md @@ -80,6 +80,39 @@ mempoolConfig.CosmosPoolConfig = &cosmosCfg mempoolConfig.BroadCastTxFn = func(txs []*ethtypes.Transaction) error { return nil } ``` +### Default Precompiles + +Default precompiles have been moved to `/evm/precompiles/types/defaults.go` and the function name was +changed to `DefaultStaticPrecompiles`. The function signature has also changed, and now takes pointers +as inputs for the `Erc20Keeper` and `TransferKeeper`. Finally, the `WithStaticPrecompiles` builder +function can now happen *alongside the keeper instantiation*, and not after. The new wiring is shown below: + +```go + app.EVMKeeper = evmkeeper.NewKeeper( + appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], keys, + authtypes.NewModuleAddress(govtypes.ModuleName), + app.AccountKeeper, + app.PreciseBankKeeper, + app.StakingKeeper, + app.FeeMarketKeeper, + &app.ConsensusParamsKeeper, + &app.Erc20Keeper, + tracer, + ).WithStaticPrecompiles( + precompiletypes.DefaultStaticPrecompiles( + *app.StakingKeeper, + app.DistrKeeper, + app.BankKeeper, + &app.Erc20Keeper, // UPDATED + &app.TransferKeeper, // UPDATED + app.IBCKeeper.ChannelKeeper, + app.GovKeeper, + app.SlashingKeeper, + appCodec, + ), + ) +``` + --- ## 3) Build & quick tests diff --git a/evmd/app.go b/evmd/app.go index d4ec9ebe3..e47152852 100644 --- a/evmd/app.go +++ b/evmd/app.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + precompiletypes "github.com/cosmos/evm/precompiles/types" "io" "os" @@ -486,6 +487,18 @@ func NewExampleApp( &app.ConsensusParamsKeeper, &app.Erc20Keeper, tracer, + ).WithStaticPrecompiles( + precompiletypes.DefaultStaticPrecompiles( + *app.StakingKeeper, + app.DistrKeeper, + app.BankKeeper, + &app.Erc20Keeper, + &app.TransferKeeper, + app.IBCKeeper.ChannelKeeper, + app.GovKeeper, + app.SlashingKeeper, + appCodec, + ), ) app.Erc20Keeper = erc20keeper.NewKeeper( @@ -561,23 +574,6 @@ func NewExampleApp( // Override the ICS20 app module transferModule := transfer.NewAppModule(app.TransferKeeper) - // NOTE: we are adding all available Cosmos EVM EVM extensions. - // Not all of them need to be enabled, which can be configured on a per-chain basis. - app.EVMKeeper.WithStaticPrecompiles( - NewAvailableStaticPrecompiles( - *app.StakingKeeper, - app.DistrKeeper, - app.PreciseBankKeeper, - app.Erc20Keeper, - app.TransferKeeper, - app.IBCKeeper.ChannelKeeper, - app.EVMKeeper, - app.GovKeeper, - app.SlashingKeeper, - app.AppCodec(), - ), - ) - /**** Module Options ****/ // NOTE: Any module instantiated in the module manager that is later modified diff --git a/go.mod b/go.mod index 4166dd6d3..2e66b7626 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,6 @@ require ( github.com/onsi/ginkgo/v2 v2.23.4 github.com/onsi/gomega v1.38.0 github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.22.0 github.com/rs/cors v1.11.1 github.com/spf13/cast v1.9.2 github.com/spf13/cobra v1.9.1 @@ -181,7 +180,6 @@ require ( github.com/klauspost/cpuid/v2 v2.2.10 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect - github.com/kylelemons/godebug v1.1.0 // indirect github.com/lib/pq v1.10.9 // indirect github.com/manifoldco/promptui v0.9.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect @@ -207,6 +205,7 @@ require ( github.com/pion/transport/v3 v3.0.1 // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/prometheus/client_golang v1.22.0 // indirect github.com/prometheus/client_model v0.6.1 // indirect github.com/prometheus/common v0.63.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect diff --git a/evmd/precompiles.go b/precompiles/types/defaults.go similarity index 88% rename from evmd/precompiles.go rename to precompiles/types/defaults.go index cd7fe94b4..b64570365 100644 --- a/evmd/precompiles.go +++ b/precompiles/types/defaults.go @@ -1,11 +1,9 @@ -package evmd +package types import ( "fmt" "maps" - addresscodec "github.com/cosmos/cosmos-sdk/codec/address" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" @@ -20,11 +18,13 @@ import ( stakingprecompile "github.com/cosmos/evm/precompiles/staking" erc20Keeper "github.com/cosmos/evm/x/erc20/keeper" transferkeeper "github.com/cosmos/evm/x/ibc/transfer/keeper" - evmkeeper "github.com/cosmos/evm/x/vm/keeper" channelkeeper "github.com/cosmos/ibc-go/v10/modules/core/04-channel/keeper" "cosmossdk.io/core/address" + "github.com/cosmos/cosmos-sdk/codec" + addresscodec "github.com/cosmos/cosmos-sdk/codec/address" + sdktypes "github.com/cosmos/cosmos-sdk/types" distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" @@ -42,9 +42,9 @@ type Optionals struct { func defaultOptionals() Optionals { return Optionals{ - AddressCodec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), - ValidatorAddrCodec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), - ConsensusAddrCodec: addresscodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), + AddressCodec: addresscodec.NewBech32Codec(sdktypes.GetConfig().GetBech32AccountAddrPrefix()), + ValidatorAddrCodec: addresscodec.NewBech32Codec(sdktypes.GetConfig().GetBech32ValidatorAddrPrefix()), + ConsensusAddrCodec: addresscodec.NewBech32Codec(sdktypes.GetConfig().GetBech32ConsensusAddrPrefix()), } } @@ -70,17 +70,16 @@ func WithConsensusAddrCodec(codec address.Codec) Option { const bech32PrecompileBaseGas = 6_000 -// NewAvailableStaticPrecompiles returns the list of all available static precompiled contracts from Cosmos EVM. +// DefaultStaticPrecompiles returns the list of all available static precompiled contracts from Cosmos EVM. // // NOTE: this should only be used during initialization of the Keeper. -func NewAvailableStaticPrecompiles( +func DefaultStaticPrecompiles( stakingKeeper stakingkeeper.Keeper, distributionKeeper distributionkeeper.Keeper, bankKeeper cmn.BankKeeper, - erc20Keeper erc20Keeper.Keeper, - transferKeeper transferkeeper.Keeper, + erc20Keeper *erc20Keeper.Keeper, + transferKeeper *transferkeeper.Keeper, channelKeeper *channelkeeper.Keeper, - evmKeeper *evmkeeper.Keeper, govKeeper govkeeper.Keeper, slashingKeeper slashingkeeper.Keeper, codec codec.Codec,