Skip to content

Commit

Permalink
add msg filter decorator for evm ante handler
Browse files Browse the repository at this point in the history
  • Loading branch information
shenao78 committed Oct 9, 2023
1 parent 7a8ca72 commit aea9c67
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions app/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
sdkvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
democracyante "github.com/cosmos/interchain-security/v3/app/consumer-democracy/ante"
consumerante "github.com/cosmos/interchain-security/v3/app/consumer/ante"
ibcconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
appante "github.com/evmos/evmos/v14/app/ante"
Expand All @@ -35,10 +36,10 @@ func NewAnteHandler(options appante.HandlerOptions, consumerKeeper ibcconsumerke
switch typeURL := opts[0].GetTypeUrl(); typeURL {
case "/ethermint.evm.v1.ExtensionOptionsEthereumTx":
// handle as *evmtypes.MsgEthereumTx
anteHandler = newEVMAnteHandler(options)
anteHandler = newEVMAnteHandler(options, consumerKeeper)
case "/ethermint.types.v1.ExtensionOptionsWeb3Tx":
// handle as normal Cosmos SDK tx, except signature is checked for EIP712 representation
anteHandler = newLegacyCosmosAnteHandlerEip712(options)
anteHandler = newLegacyCosmosAnteHandlerEip712(options, consumerKeeper)
case "/ethermint.types.v1.ExtensionOptionDynamicFeeTx":
// cosmos-sdk tx with dynamic fee extension
anteHandler = newCosmosAnteHandler(options, consumerKeeper)
Expand Down Expand Up @@ -66,8 +67,9 @@ func NewAnteHandler(options appante.HandlerOptions, consumerKeeper ibcconsumerke
}

// newEVMAnteHandler creates the default authante handler for Ethereum transactions
func newEVMAnteHandler(options appante.HandlerOptions) sdk.AnteHandler {
func newEVMAnteHandler(options appante.HandlerOptions, consumerKeeper ibcconsumerkeeper.Keeper) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
consumerante.NewMsgFilterDecorator(consumerKeeper),
// outermost AnteDecorator. SetUpContext must be called first
evmante.NewEthSetUpContextDecorator(options.EvmKeeper),
// Check eth effective gas price against the node's minimal-gas-prices config
Expand Down Expand Up @@ -99,6 +101,7 @@ func newCosmosAnteHandler(options appante.HandlerOptions, consumerKeeper ibccons
authante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
consumerante.NewMsgFilterDecorator(consumerKeeper),
consumerante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing"),
democracyante.NewForbiddenProposalsDecorator(IsProposalWhitelisted, IsModuleWhiteList),
authante.NewValidateBasicDecorator(),
authante.NewTxTimeoutHeightDecorator(),
authante.NewValidateMemoDecorator(options.AccountKeeper),
Expand All @@ -118,14 +121,17 @@ func newCosmosAnteHandler(options appante.HandlerOptions, consumerKeeper ibccons
}

// newCosmosAnteHandlerEip712 creates the authante handler for transactions signed with EIP712
func newLegacyCosmosAnteHandlerEip712(options appante.HandlerOptions) sdk.AnteHandler {
func newLegacyCosmosAnteHandlerEip712(options appante.HandlerOptions, consumerKeeper ibcconsumerkeeper.Keeper) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
cosmosante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmosante.NewAuthzLimiterDecorator( // disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
),
authante.NewSetUpContextDecorator(),
consumerante.NewMsgFilterDecorator(consumerKeeper),
consumerante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing"),
democracyante.NewForbiddenProposalsDecorator(IsProposalWhitelisted, IsModuleWhiteList),
authante.NewValidateBasicDecorator(),
authante.NewTxTimeoutHeightDecorator(),
cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
Expand Down
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ func (app *App) setAnteHandler(txConfig client.TxConfig, maxGasWanted uint64) {
panic(err)
}

app.SetAnteHandler(ante.NewAnteHandler(options))
app.SetAnteHandler(NewAnteHandler(options, app.ConsumerKeeper))
}

func (app *App) setPostHandler() {
Expand Down

0 comments on commit aea9c67

Please sign in to comment.