Skip to content
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions docs/migrations/v0.4.0_to_v0.5.0_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 13 additions & 17 deletions evmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
precompiletypes "github.com/cosmos/evm/precompiles/types"
"io"

"os"
Expand Down Expand Up @@ -486,6 +487,18 @@ func NewExampleApp(
&app.ConsensusParamsKeeper,
&app.Erc20Keeper,
tracer,
).WithStaticPrecompiles(
precompiletypes.DefaultStaticPrecompiles(
*app.StakingKeeper,
app.DistrKeeper,
app.BankKeeper,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It changed from the PreciseBankKeeper to normal BankKeeper here, is that intentional?

&app.Erc20Keeper,
&app.TransferKeeper,
app.IBCKeeper.ChannelKeeper,
app.GovKeeper,
app.SlashingKeeper,
appCodec,
),
)

app.Erc20Keeper = erc20keeper.NewKeeper(
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
23 changes: 11 additions & 12 deletions evmd/precompiles.go → precompiles/types/defaults.go
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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"
Expand All @@ -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()),
}
}

Expand All @@ -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,
Expand Down
Loading