Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into zale144/1370-rename-i…
Browse files Browse the repository at this point in the history
…ro-base-denoms
  • Loading branch information
zale144 committed Nov 7, 2024
2 parents 87a1e13 + 4fe9719 commit a2cd738
Show file tree
Hide file tree
Showing 226 changed files with 8,129 additions and 7,551 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ build/
.DS_Store
proposal.json
.go-version
**/testdata/rapid/
**/testdata/rapid/
**/__debug_bin*
5 changes: 3 additions & 2 deletions app/ante/ante_options.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ante

import (
ante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ethante "github.com/evmos/ethermint/app/ante"

lightclientkeeper "github.com/dymensionxyz/dymension/v3/x/lightclient/keeper"
rollappkeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
ethante "github.com/evmos/ethermint/app/ante"

errorsmod "cosmossdk.io/errors"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down
15 changes: 6 additions & 9 deletions app/ante/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package ante

import (
sdk "github.com/cosmos/cosmos-sdk/types"
ante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ethante "github.com/evmos/ethermint/app/ante"
txfeesante "github.com/osmosis-labs/osmosis/v15/x/txfees/ante"

vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"

delayedack "github.com/dymensionxyz/dymension/v3/x/delayedack"
"github.com/dymensionxyz/dymension/v3/x/delayedack"
lightclientante "github.com/dymensionxyz/dymension/v3/x/lightclient/ante"
"github.com/dymensionxyz/dymension/v3/x/rollapp/genesisbridge"
)
Expand Down Expand Up @@ -45,13 +45,12 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
See https://jumpcrypto.com/writing/bypassing-ethermint-ante-handlers/
for an explanation of these message blocking decorators
*/
NewRejectMessagesDecorator(), // reject MsgEthereumTxs
ethante.NewAuthzLimiterDecorator([]string{ // disable the Msg types that cannot be included on an authz.MsgExec msgs field
NewRejectMessagesDecorator(
// reject MsgEthereumTxs and disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}),
},
),

ante.NewSetUpContextDecorator(),
Expand Down Expand Up @@ -84,14 +83,12 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
deductFeeDecorator := txfeesante.NewDeductFeeDecorator(*options.TxFeesKeeper, options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper)

return sdk.ChainAnteDecorators(

NewRejectMessagesDecorator(), // reject MsgEthereumTxs and vesting msgs
ethante.NewAuthzLimiterDecorator([]string{ // disable the Msg types that cannot be included on an authz.MsgExec msgs field
NewRejectMessagesDecorator(
// reject MsgEthereumTxs and disable the Msg types that cannot be included on an authz.MsgExec msgs field
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreateVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePeriodicVestingAccount{}),
sdk.MsgTypeURL(&vestingtypes.MsgCreatePermanentLockedAccount{}),
},
),
ante.NewSetUpContextDecorator(),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
Expand Down
118 changes: 95 additions & 23 deletions app/ante/reject_msgs.go
Original file line number Diff line number Diff line change
@@ -1,48 +1,120 @@
package ante

import (
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/group"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

// RejectMessagesDecorator prevents invalid msg types from being executed
type RejectMessagesDecorator struct {
disabledMsgTypeURLs []string
disabledMsgTypeURLs map[string]struct{}
}

var _ sdk.AnteDecorator = RejectMessagesDecorator{}

// NewRejectMessagesDecorator creates a decorator to block vesting messages from reaching the mempool
func NewRejectMessagesDecorator() RejectMessagesDecorator {
// NewRejectMessagesDecorator creates a decorator to block provided messages from reaching the mempool
func NewRejectMessagesDecorator(disabledMsgTypeURLs ...string) RejectMessagesDecorator {
disabledMsgsMap := make(map[string]struct{})
for _, url := range disabledMsgTypeURLs {
disabledMsgsMap[url] = struct{}{}
}

return RejectMessagesDecorator{
disabledMsgTypeURLs: []string{},
disabledMsgTypeURLs: disabledMsgsMap,
}
}

// AnteHandle rejects messages that requires ethereum-specific authentication.
// For example `MsgEthereumTx` requires fee to be deducted in the antehandler in
// AnteHandle recursively rejects messages such as those that requires ethereum-specific authentication.
// For example `MsgEthereumTx` requires fee to be deducted in the ante handler in
// order to perform the refund.
func (rmd RejectMessagesDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
for _, msg := range tx.GetMsgs() {
if _, ok := msg.(*evmtypes.MsgEthereumTx); ok {
return ctx, errorsmod.Wrapf(
sdkerrors.ErrInvalidType,
"MsgEthereumTx needs to be contained within a tx with 'ExtensionOptionsEthereumTx' option",
)
func (rmd RejectMessagesDecorator) AnteHandle(
ctx sdk.Context,
tx sdk.Tx,
simulate bool,
next sdk.AnteHandler,
) (sdk.Context, error) {
if err := rmd.checkMsgs(ctx, tx.GetMsgs(), 0); err != nil {
return ctx, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, err.Error())
}
return next(ctx, tx, simulate)
}

const maxNestedMsgs = 6

func (rmd RejectMessagesDecorator) checkMsgs(ctx sdk.Context, msgs []sdk.Msg, nestedMsgs int) error {
for _, msg := range msgs {
if err := rmd.checkMsg(ctx, msg, nestedMsgs); err != nil {
return err
}
}
return nil
}

func (rmd RejectMessagesDecorator) checkMsg(ctx sdk.Context, msg sdk.Msg, nestedMsgs int) error {
typeURL := sdk.MsgTypeURL(msg)
if _, ok := rmd.disabledMsgTypeURLs[typeURL]; ok {
return fmt.Errorf("found disabled msg type: %s", typeURL)
}

if _, ok := msg.(*evmtypes.MsgEthereumTx); ok {
return errorsmod.Wrapf(
sdkerrors.ErrInvalidType,
"MsgEthereumTx needs to be contained within a tx with 'ExtensionOptionsEthereumTx' option",
)
}

typeURL := sdk.MsgTypeURL(msg)
for _, disabledTypeURL := range rmd.disabledMsgTypeURLs {
if typeURL == disabledTypeURL {
return ctx, errorsmod.Wrapf(
sdkerrors.ErrUnauthorized,
"MsgTypeURL %s not supported",
typeURL,
)
}
if nestedMsgs >= maxNestedMsgs {
return fmt.Errorf("found more nested msgs than permitted. Limit is : %d", maxNestedMsgs)
}

innerMsgs, err := extractMsgs(msg)
if err != nil {
return err
}
switch concreteMsg := msg.(type) {
case *authz.MsgExec:
nestedMsgs++
if err := rmd.checkMsgs(ctx, innerMsgs, nestedMsgs); err != nil {
return err
}
case *authz.MsgGrant:
authorization, err := concreteMsg.GetAuthorization()
if err != nil {
return err
}
url := authorization.MsgTypeURL()
if _, ok := rmd.disabledMsgTypeURLs[url]; ok {
return fmt.Errorf("granting disabled msg type: %s is not allowed", url)
}
case *govtypesv1.MsgSubmitProposal:
nestedMsgs++
if err := rmd.checkMsgs(ctx, innerMsgs, nestedMsgs); err != nil {
return err
}
case *group.MsgSubmitProposal:
nestedMsgs++
if err := rmd.checkMsgs(ctx, innerMsgs, nestedMsgs); err != nil {
return err
}
default:
}
return next(ctx, tx, simulate)

return nil
}

func extractMsgs(msg any) ([]sdk.Msg, error) {
if msgWithMsgs, ok := msg.(interface{ GetMsgs() ([]sdk.Msg, error) }); ok {
return msgWithMsgs.GetMsgs()
}
if msgWithMessages, ok := msg.(interface{ GetMessages() ([]sdk.Msg, error) }); ok {
return msgWithMessages.GetMessages()
}
return nil, nil
}
Loading

0 comments on commit a2cd738

Please sign in to comment.