Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from b-harvest/abci1.0/remove-not-core-modules
Browse files Browse the repository at this point in the history
refactor!: remove not core modules
  • Loading branch information
dongsam authored Jul 26, 2024
2 parents 46fe4b7 + 778643d commit febe40a
Show file tree
Hide file tree
Showing 237 changed files with 10,386 additions and 58,876 deletions.
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0
GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos
COSMOS_SDK_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.45.1
ETHERMINT_URL = https://raw.githubusercontent.com/Canto-Network/ethermint-v2/v0.10.0
IBC_GO_URL = https://raw.githubusercontent.com/cosmos/ibc-go/v3.0.0-rc0
COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master

TM_CRYPTO_TYPES = third_party/proto/tendermint/crypto
Expand Down
32 changes: 2 additions & 30 deletions app/ante/comission.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand All @@ -30,40 +29,13 @@ func NewValidatorCommissionDecorator(cdc codec.BinaryCodec) ValidatorCommissionD
// It errors if the the commission rate is below the min threshold.
func (vcd ValidatorCommissionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
for _, msg := range tx.GetMsgs() {
switch msg := msg.(type) {
case *authz.MsgExec:
// Check for bypassing authorization
if err := vcd.validateAuthz(ctx, msg); err != nil {
return ctx, err
}

default:
if err := vcd.validateMsg(ctx, msg); err != nil {
return ctx, err
}
if err := vcd.validateMsg(ctx, msg); err != nil {
return ctx, err
}
}

return next(ctx, tx, simulate)
}

// validateAuthz validates the authorization internal message
func (vcd ValidatorCommissionDecorator) validateAuthz(ctx sdk.Context, execMsg *authz.MsgExec) error {
for _, v := range execMsg.Msgs {
var innerMsg sdk.Msg
err := vcd.cdc.UnpackAny(v, &innerMsg)
if err != nil {
return sdkerrors.Wrap(err, "cannot unmarshal authz exec msgs")
}

if err := vcd.validateMsg(ctx, innerMsg); err != nil {
return err
}
}

return nil
}

// validateMsg checks that the commission rate is over 5% for create and edit validator msgs
func (vcd ValidatorCommissionDecorator) validateMsg(_ sdk.Context, msg sdk.Msg) error {
switch msg := msg.(type) {
Expand Down
100 changes: 0 additions & 100 deletions app/ante/cosmos/authz.go

This file was deleted.

53 changes: 53 additions & 0 deletions app/ante/cosmos/disabled_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package cosmos

import (
"fmt"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
)

// DisabledMsgsDecorator blocks certain msg types from being granted or executed
// within the authorization module.
type DisabledMsgsDecorator struct {
// disabledMsgTypes is the type urls of the msgs to block.
disabledMsgTypes []string
}

// NewDisabledMsgDecorator creates a decorator to block certain msg types
func NewDisabledMsgDecorator(disabledMsgTypes ...string) DisabledMsgsDecorator {
return DisabledMsgsDecorator{
disabledMsgTypes: disabledMsgTypes,
}
}

func (ald DisabledMsgsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
if err := ald.checkDisabledMsgs(tx.GetMsgs()); err != nil {
return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, err.Error())
}
return next(ctx, tx, simulate)
}

// checkDisabledMsgs iterates through the msgs and returns an error if it finds any unauthorized msgs.
func (ald DisabledMsgsDecorator) checkDisabledMsgs(msgs []sdk.Msg) error {
for _, msg := range msgs {
url := sdk.MsgTypeURL(msg)
if ald.isDisabledMsg(url) {
return fmt.Errorf("found disabled msg type: %s", url)
}
}
return nil
}

// isDisabledMsg returns true if the given message is in the list of restricted
// messages from the AnteHandler.
func (ald DisabledMsgsDecorator) isDisabledMsg(msgTypeURL string) bool {
for _, disabledType := range ald.disabledMsgTypes {
if msgTypeURL == disabledType {
return true
}
}

return false
}
3 changes: 2 additions & 1 deletion app/ante/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*Package ante defines the SDK auth module's AnteHandler as well as an internal
/*
Package ante defines the SDK auth module's AnteHandler as well as an internal
AnteHandler for an Ethereum transaction (i.e MsgEthereumTx).
During CheckTx, the transaction is passed through a series of
Expand Down
12 changes: 3 additions & 9 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth/ante"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"

ethante "github.com/evmos/ethermint/app/ante"
evmtypes "github.com/evmos/ethermint/x/evm/types"
Expand All @@ -23,7 +21,6 @@ import (
type HandlerOptions struct {
AccountKeeper evmtypes.AccountKeeper
BankKeeper evmtypes.BankKeeper
IBCKeeper *ibckeeper.Keeper
FeeMarketKeeper evmtypes.FeeMarketKeeper
EvmKeeper ethante.EVMKeeper
FeegrantKeeper ante.FeegrantKeeper
Expand Down Expand Up @@ -75,7 +72,7 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmosante.NewAuthzLimiterDecorator(
cosmosante.NewDisabledMsgDecorator(
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
),
Expand All @@ -95,7 +92,6 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
)
}
Expand All @@ -104,7 +100,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
func newCosmosSimulationAnteHandler(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmosante.NewAuthzLimiterDecorator(
cosmosante.NewDisabledMsgDecorator(
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
),
Expand All @@ -124,7 +120,6 @@ func newCosmosSimulationAnteHandler(options HandlerOptions) sdk.AnteHandler {
//ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
//ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
)
}
Expand All @@ -133,7 +128,7 @@ func newCosmosSimulationAnteHandler(options HandlerOptions) sdk.AnteHandler {
func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
return sdk.ChainAnteDecorators(
ethante.RejectMessagesDecorator{}, // reject MsgEthereumTxs
cosmosante.NewAuthzLimiterDecorator(
cosmosante.NewDisabledMsgDecorator(
sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}),
sdk.MsgTypeURL(&sdkvesting.MsgCreateVestingAccount{}),
),
Expand All @@ -153,7 +148,6 @@ func newCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
// Note: signature verification uses EIP instead of the cosmos signature validator
ethante.NewEip712SigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewAnteDecorator(options.IBCKeeper),
ethante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
)
}
Loading

0 comments on commit febe40a

Please sign in to comment.