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
14 changes: 9 additions & 5 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {

defer Recover(ctx.Logger(), &err)

evmParams := options.EvmKeeper.GetParams(ctx)
feemarketParams := options.FeeMarketKeeper.GetParams(ctx)
txWithExtensions, ok := tx.(authante.HasExtensionOptionsTx)
if ok {
opts := txWithExtensions.GetExtensionOptions()
Expand All @@ -67,13 +69,15 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
options.FeeMarketKeeper,
options.EvmKeeper,
options.MaxTxGasWanted,
&evmParams,
&feemarketParams,
))
case "/cosmos.evm.types.v1.ExtensionOptionsWeb3Tx":
// Deprecated: Handle as normal Cosmos SDK tx, except signature is checked for Legacy EIP712 representation
anteHandler = NewLegacyCosmosAnteHandlerEip712(options)
anteHandler = NewLegacyCosmosAnteHandlerEip712(ctx, options)
case "/cosmos.evm.types.v1.ExtensionOptionDynamicFeeTx":
// cosmos-sdk tx with dynamic fee extension
anteHandler = newCosmosAnteHandler(options)
anteHandler = newCosmosAnteHandler(ctx, options)
default:
return ctx, errorsmod.Wrapf(
errortypes.ErrUnknownExtensionOptions,
Expand All @@ -89,7 +93,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
switch tx.(type) {
case sdk.Tx:
// default: handle as normal Cosmos SDK tx
anteHandler = newCosmosAnteHandler(options)
anteHandler = newCosmosAnteHandler(ctx, options)

// if tx is a system tx, and singer is authorized, use system tx handler

Expand All @@ -98,14 +102,14 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
}

if IsSystemTx(tx, isAuthorized) {
anteHandler = newCosmosAnteHandlerForSystemTx(options)
anteHandler = newCosmosAnteHandlerForSystemTx(ctx, options)
}

// if tx is MsgCreatorValidator, use the newCosmosAnteHandlerForSystemTx handler to
// exempt gas fee requirement in genesis because it's not possible to pay gas fee in genesis
if len(tx.GetMsgs()) == 1 {
if _, ok := tx.GetMsgs()[0].(*stakingtypes.MsgCreateValidator); ok && ctx.BlockHeight() == 0 {
anteHandler = newCosmosAnteHandlerForSystemTx(options)
anteHandler = newCosmosAnteHandlerForSystemTx(ctx, options)
}
}

Expand Down
25 changes: 15 additions & 10 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
cosmosante "github.com/cosmos/evm/ante/cosmos"
evmante "github.com/cosmos/evm/ante/evm"
cosmosevmtypes "github.com/cosmos/evm/types"
evmtypes "github.com/cosmos/evm/x/vm/types"

observerkeeper "github.com/zeta-chain/node/x/observer/keeper"
Expand All @@ -36,15 +35,17 @@ type HandlerOptions struct {
ObserverKeeper *observerkeeper.Keeper
}

func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
func NewLegacyCosmosAnteHandlerEip712(ctx sdk.Context, options HandlerOptions) sdk.AnteHandler {
feemarketParams := options.FeeMarketKeeper.GetParams(ctx)

return sdk.ChainAnteDecorators(
cosmosante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator(options.DisabledAuthzMsgs...),
NewVestingAccountDecorator(),
ante.NewSetUpContextDecorator(),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
cosmosante.NewMinGasPriceDecorator(&feemarketParams),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(
Expand All @@ -63,11 +64,13 @@ func NewLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
// TODO: enable back IBC
// check if this ante handler is needed in non legacy cosmos ante handlers
// ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper, &feemarketParams),
)
}

func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandler {
feemarketParams := options.FeeMarketKeeper.GetParams(ctx)

return sdk.ChainAnteDecorators(
cosmosante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator(options.DisabledAuthzMsgs...),
Expand All @@ -76,7 +79,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
cosmosante.NewMinGasPriceDecorator(&feemarketParams),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(
Expand All @@ -91,12 +94,14 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper, &feemarketParams),
)
}

// this applies to special cosmos tx that calls EVM, in which case the EVM overrides the gas limit
func newCosmosAnteHandlerForSystemTx(options HandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandlerForSystemTx(ctx sdk.Context, options HandlerOptions) sdk.AnteHandler {
feemarketParams := options.FeeMarketKeeper.GetParams(ctx)

return sdk.ChainAnteDecorators(
cosmosante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
NewAuthzLimiterDecorator(options.DisabledAuthzMsgs...),
Expand All @@ -122,7 +127,7 @@ func newCosmosAnteHandlerForSystemTx(options HandlerOptions) sdk.AnteHandler {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper, &feemarketParams),
)
}

Expand Down Expand Up @@ -193,5 +198,5 @@ func SetGasMeter(_ bool, ctx sdk.Context, gasLimit uint64) sdk.Context {
//
//return ctx.WithGasMeter(sdk.NewGasMeter(gasLimit))

return ctx.WithGasMeter(cosmosevmtypes.NewInfiniteGasMeterWithLimit(gasLimit))
return ctx.WithGasMeter(evmtypes.NewInfiniteGasMeterWithLimit(gasLimit))
}
1 change: 0 additions & 1 deletion app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ type EVMKeeper interface {
type FeeMarketKeeper interface {
GetParams(ctx sdk.Context) (params feemarkettypes.Params)
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
GetBaseFeeEnabled(ctx sdk.Context) bool
GetBaseFee(ctx sdk.Context) math.LegacyDec
}
36 changes: 29 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
Expand Down Expand Up @@ -80,8 +81,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/staking"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
evmante "github.com/cosmos/evm/ante"
evmosencoding "github.com/cosmos/evm/encoding"
cosmosevmtypes "github.com/cosmos/evm/types"
evmmempool "github.com/cosmos/evm/mempool"
"github.com/cosmos/evm/utils"
erc20keeper "github.com/cosmos/evm/x/erc20/keeper"
erc20types "github.com/cosmos/evm/x/erc20/types"
"github.com/cosmos/evm/x/feemarket"
Expand All @@ -90,6 +93,7 @@ import (
"github.com/cosmos/evm/x/vm"
evmkeeper "github.com/cosmos/evm/x/vm/keeper"
evmtypes "github.com/cosmos/evm/x/vm/types"
"github.com/ethereum/go-ethereum/common"
_ "github.com/ethereum/go-ethereum/eth/tracers/native" // register native tracers
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -140,7 +144,7 @@ const Name = "zetacore"

func init() {
// manually update the power reduction by replacing micro (u) -> atto (a) evmos
sdk.DefaultPowerReduction = cosmosevmtypes.AttoPowerReduction
sdk.DefaultPowerReduction = utils.AttoPowerReduction
// modify fee market parameter defaults through global
//feemarkettypes.DefaultMinGasPrice = v5.MainnetMinGasPrices
//feemarkettypes.DefaultMinGasMultiplier = v5.MainnetMinGasMultiplier
Expand Down Expand Up @@ -204,10 +208,12 @@ var (
type App struct {
*baseapp.BaseApp

cdc *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
invCheckPeriod uint
cdc *codec.LegacyAmino
appCodec codec.Codec
interfaceRegistry types.InterfaceRegistry
invCheckPeriod uint
clientCtx client.Context
pendingTxListeners []evmante.PendingTxListener

// keys to access the substores
keys map[string]*storetypes.KVStoreKey
Expand Down Expand Up @@ -246,6 +252,7 @@ type App struct {
EvmKeeper *evmkeeper.Keeper
Erc20Keeper erc20keeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
EVMMempool *evmmempool.ExperimentalEVMMempool

// zetachain keepers
AuthorityKeeper authoritykeeper.Keeper
Expand Down Expand Up @@ -532,6 +539,7 @@ func New(
app.FeeMarketKeeper,
app.ConsensusParamsKeeper,
&app.Erc20Keeper,
evmChainID,
tracer,
)

Expand Down Expand Up @@ -712,7 +720,7 @@ func New(
//transfer.NewAppModule(app.TransferKeeper),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, interfaceRegistry),
feemarket.NewAppModule(app.FeeMarketKeeper),
vm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.AccountKeeper.AddressCodec()),
vm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.BankKeeper, app.AccountKeeper.AddressCodec()),
authoritymodule.NewAppModule(appCodec, app.AuthorityKeeper),
lightclientmodule.NewAppModule(appCodec, app.LightclientKeeper),
crosschainmodule.NewAppModule(appCodec, app.CrosschainKeeper),
Expand Down Expand Up @@ -744,6 +752,7 @@ func New(
app.mm.SetOrderPreBlockers(
upgradetypes.ModuleName,
authtypes.ModuleName,
evmtypes.ModuleName,
)

app.mm.SetOrderBeginBlockers(orderBeginBlockers()...)
Expand Down Expand Up @@ -904,6 +913,19 @@ func (app *App) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

func (app *App) SetClientCtx(clientCtx client.Context) { // TODO:VLAD - Remove this if possible
app.clientCtx = clientCtx
}

func (app *App) GetMempool() sdkmempool.ExtMempool {
return app.EVMMempool
}

// RegisterPendingTxListener is used by json-rpc server to listen to pending transactions callback.
func (app *App) RegisterPendingTxListener(listener func(common.Hash)) {
app.pendingTxListeners = append(app.pendingTxListeners, listener)
}

// AutoCliOpts returns the autocli options for the app.
func (app *App) AutoCliOpts() autocli.AppOptions {
modules := make(map[string]appmodule.AppModule, 0)
Expand Down
7 changes: 3 additions & 4 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
evidencetypes "cosmossdk.io/x/evidence/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/types/module/testutil"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
Expand All @@ -19,7 +18,7 @@ import (
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
evmosencoding "github.com/cosmos/evm/encoding"
cosmosevmtypes "github.com/cosmos/evm/types"
"github.com/cosmos/evm/ethereum/eip712"
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
evmtypes "github.com/cosmos/evm/x/vm/types"

Expand All @@ -32,7 +31,7 @@ import (
)

// MakeEncodingConfig creates an EncodingConfig
func MakeEncodingConfig(chainID uint64) testutil.TestEncodingConfig {
func MakeEncodingConfig(chainID uint64) evmosencoding.Config {
encodingConfig := evmosencoding.MakeConfig(chainID)
registry := encodingConfig.InterfaceRegistry
// TODO test if we need to register these interfaces again as MakeConfig already registers them
Expand All @@ -48,7 +47,7 @@ func MakeEncodingConfig(chainID uint64) testutil.TestEncodingConfig {
evidencetypes.RegisterInterfaces(registry)
crisistypes.RegisterInterfaces(registry)
evmtypes.RegisterInterfaces(registry)
cosmosevmtypes.RegisterInterfaces(registry)
eip712.RegisterInterfaces(registry)
authoritytypes.RegisterInterfaces(registry)
crosschaintypes.RegisterInterfaces(registry)
emissionstypes.RegisterInterfaces(registry)
Expand Down
2 changes: 1 addition & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func simulationModules(
),
params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
vm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.AccountKeeper.AddressCodec()),
vm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.BankKeeper, app.AccountKeeper.AddressCodec()),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
crosschainmodule.NewAppModule(appCodec, app.CrosschainKeeper),
Expand Down
43 changes: 22 additions & 21 deletions app/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
distributionKeeper distributionkeeper.Keeper,
bankKeeper cmn.BankKeeper,
erc20Keeper erc20Keeper.Keeper,
evmKeeper *evmkeeper.Keeper,

Check failure on line 76 in app/precompiles.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'evmKeeper' seems to be unused, consider removing or renaming it as _ (revive)
govKeeper govkeeper.Keeper,
slashingKeeper slashingkeeper.Keeper,
codec codec.Codec,
Expand All @@ -94,39 +94,40 @@
panic(fmt.Errorf("failed to instantiate bech32 precompile: %w", err))
}

stakingPrecompile, err := stakingprecompile.NewPrecompile(stakingKeeper, options.AddressCodec)
if err != nil {
panic(fmt.Errorf("failed to instantiate staking precompile: %w", err))
}
stakingPrecompile := stakingprecompile.NewPrecompile(
stakingKeeper,
stakingkeeper.NewMsgServerImpl(&stakingKeeper),
stakingkeeper.NewQuerier(&stakingKeeper),
bankKeeper,
options.AddressCodec,
)

distributionPrecompile, err := distprecompile.NewPrecompile(
distributionPrecompile := distprecompile.NewPrecompile(
distributionKeeper,
distributionkeeper.NewMsgServerImpl(distributionKeeper),
distributionkeeper.NewQuerier(distributionKeeper),
stakingKeeper,
evmKeeper,
bankKeeper,
options.AddressCodec,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate distribution precompile: %w", err))
}

bankPrecompile, err := bankprecompile.NewPrecompile(bankKeeper, erc20Keeper)
if err != nil {
panic(fmt.Errorf("failed to instantiate bank precompile: %w", err))
}
bankPrecompile := bankprecompile.NewPrecompile(bankKeeper, erc20Keeper)

govPrecompile, err := govprecompile.NewPrecompile(govKeeper, codec, options.AddressCodec)
if err != nil {
panic(fmt.Errorf("failed to instantiate gov precompile: %w", err))
}
govPrecompile := govprecompile.NewPrecompile(
govkeeper.NewMsgServerImpl(&govKeeper),
govkeeper.NewQueryServer(&govKeeper),
bankKeeper,
codec,
options.AddressCodec,
)

slashingPrecompile, err := slashingprecompile.NewPrecompile(
slashingPrecompile := slashingprecompile.NewPrecompile(
slashingKeeper,
slashingkeeper.NewMsgServerImpl(slashingKeeper),
bankKeeper,
options.ValidatorAddrCodec,
options.ConsensusAddrCodec,
)
if err != nil {
panic(fmt.Errorf("failed to instantiate slashing precompile: %w", err))
}

// Stateless precompiles
precompiles[bech32Precompile.Address()] = bech32Precompile
Expand Down
Loading
Loading