-
Notifications
You must be signed in to change notification settings - Fork 774
feat: disable consumer chain creation #3959
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8836930
disable consumer chain creation
dasanchez e0b05ad
fix linter errors
dasanchez 1d14596
update changelog
dasanchez 04bef66
upgrade chain after consumer creation
dasanchez c54d197
upgrade chain at the end of suite setup
dasanchez f3afb8c
remove post-upgrade launch test
dasanchez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package ante | ||
|
|
||
| import ( | ||
| providertypes "github.com/cosmos/interchain-security/v7/x/ccv/provider/types" | ||
|
|
||
| errorsmod "cosmossdk.io/errors" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/codec" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| "github.com/cosmos/cosmos-sdk/x/authz" | ||
|
|
||
| gaiaerrors "github.com/cosmos/gaia/v26/types/errors" | ||
| ) | ||
|
|
||
| const maxWrappedMessageDepthProvider = 4 | ||
|
|
||
| // ProviderDecorator prevents MsgCreateConsumer messages from being processed | ||
| type ProviderDecorator struct { | ||
| cdc codec.BinaryCodec | ||
| } | ||
|
|
||
| func NewProviderDecorator(cdc codec.BinaryCodec) ProviderDecorator { | ||
| return ProviderDecorator{ | ||
| cdc: cdc, | ||
| } | ||
| } | ||
|
|
||
| func (p ProviderDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { | ||
| for _, m := range tx.GetMsgs() { | ||
| if err := p.validateMsgRecursive(m, 0); err != nil { | ||
| return ctx, err | ||
| } | ||
| } | ||
|
|
||
| return next(ctx, tx, simulate) | ||
| } | ||
|
|
||
| func (p ProviderDecorator) validateMsgRecursive(m sdk.Msg, iters int) error { | ||
| if iters >= maxWrappedMessageDepthProvider { | ||
| return errorsmod.Wrap(gaiaerrors.ErrNestedMessageLimitExceeded, "too many wrapped sdk messages") | ||
| } | ||
|
|
||
| // Handle authz wrapped messages | ||
| if msg, ok := m.(*authz.MsgExec); ok { | ||
| for _, v := range msg.Msgs { | ||
| var innerMsg sdk.Msg | ||
| if err := p.cdc.UnpackAny(v, &innerMsg); err != nil { | ||
| return errorsmod.Wrap(gaiaerrors.ErrUnauthorized, "cannot unmarshal authz exec msgs") | ||
| } | ||
| if err := p.validateMsgRecursive(innerMsg, iters+1); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| return p.validMsg(m) | ||
| } | ||
|
|
||
| func (p ProviderDecorator) validMsg(m sdk.Msg) error { | ||
| // Block MsgCreateConsumer | ||
| if _, ok := m.(*providertypes.MsgCreateConsumer); ok { | ||
| return errorsmod.Wrap(gaiaerrors.ErrUnauthorized, "MsgCreateConsumer is disabled") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| package ante_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| providertypes "github.com/cosmos/interchain-security/v7/x/ccv/provider/types" | ||
|
|
||
| "cosmossdk.io/math" | ||
|
|
||
| codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| "github.com/cosmos/cosmos-sdk/x/authz" | ||
| banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
|
|
||
| "github.com/cosmos/gaia/v26/ante" | ||
| "github.com/cosmos/gaia/v26/app/helpers" | ||
| ) | ||
|
|
||
| func TestProviderDecorator_BlockMsgCreateConsumer(t *testing.T) { | ||
| app := helpers.Setup(t) | ||
| ctx := app.NewContext(false) | ||
| cdc := app.AppCodec() | ||
|
|
||
| decorator := ante.NewProviderDecorator(cdc) | ||
|
|
||
| // Create a mock MsgCreateConsumer | ||
| msgCreateConsumer := &providertypes.MsgCreateConsumer{ | ||
| Submitter: "cosmos1abcdef1234567890abcdef1234567890abcdef", | ||
| } | ||
|
|
||
| // Create a transaction with the MsgCreateConsumer | ||
| txBuilder := app.GetTxConfig().NewTxBuilder() | ||
| err := txBuilder.SetMsgs(msgCreateConsumer) | ||
| require.NoError(t, err) | ||
| tx := txBuilder.GetTx() | ||
|
|
||
| // Test that the decorator blocks the MsgCreateConsumer | ||
| _, err = decorator.AnteHandle(ctx, tx, false, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { | ||
| require.Fail(t, "next handler should not be called") | ||
| return ctx, nil | ||
| }) | ||
|
|
||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "MsgCreateConsumer is disabled") | ||
| } | ||
|
|
||
| func TestProviderDecorator_AllowOtherMessages(t *testing.T) { | ||
| app := helpers.Setup(t) | ||
| ctx := app.NewContext(false) | ||
| cdc := app.AppCodec() | ||
|
|
||
| decorator := ante.NewProviderDecorator(cdc) | ||
|
|
||
| // Create a normal bank message (should be allowed) | ||
| msgSend := &banktypes.MsgSend{ | ||
| FromAddress: "cosmos1abcdef1234567890abcdef1234567890abcdef", | ||
| ToAddress: "cosmos1fedcba0987654321fedcba0987654321fedcba", | ||
| Amount: sdk.NewCoins(sdk.NewCoin("uatom", math.NewInt(100))), | ||
| } | ||
|
|
||
| // Create a transaction with the MsgSend | ||
| txBuilder := app.GetTxConfig().NewTxBuilder() | ||
| err := txBuilder.SetMsgs(msgSend) | ||
| require.NoError(t, err) | ||
| tx := txBuilder.GetTx() | ||
|
|
||
| // Test that the decorator allows other messages and calls next handler | ||
| nextCalled := false | ||
| _, err = decorator.AnteHandle(ctx, tx, false, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { | ||
| nextCalled = true | ||
| return ctx, nil | ||
| }) | ||
|
|
||
| require.NoError(t, err) | ||
| require.True(t, nextCalled, "next handler should have been called") | ||
| } | ||
|
|
||
| func TestProviderDecorator_BlockAuthzWrappedMsgCreateConsumer(t *testing.T) { | ||
| app := helpers.Setup(t) | ||
| ctx := app.NewContext(false) | ||
| cdc := app.AppCodec() | ||
|
|
||
| decorator := ante.NewProviderDecorator(cdc) | ||
|
|
||
| // Create a mock MsgCreateConsumer | ||
| msgCreateConsumer := &providertypes.MsgCreateConsumer{ | ||
| Submitter: "cosmos1abcdef1234567890abcdef1234567890abcdef", | ||
| } | ||
|
|
||
| // Wrap it in an authz MsgExec | ||
| anyMsg, err := codectypes.NewAnyWithValue(msgCreateConsumer) | ||
| require.NoError(t, err) | ||
|
|
||
| msgExec := &authz.MsgExec{ | ||
| Grantee: "cosmos1fedcba0987654321fedcba0987654321fedcba", | ||
| Msgs: []*codectypes.Any{anyMsg}, | ||
| } | ||
|
|
||
| // Create a transaction with the wrapped message | ||
| txBuilder := app.GetTxConfig().NewTxBuilder() | ||
| err = txBuilder.SetMsgs(msgExec) | ||
| require.NoError(t, err) | ||
| tx := txBuilder.GetTx() | ||
|
|
||
| // Test that the decorator blocks the wrapped MsgCreateConsumer | ||
| _, err = decorator.AnteHandle(ctx, tx, false, func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) { | ||
| require.Fail(t, "next handler should not be called") | ||
| return ctx, nil | ||
| }) | ||
|
|
||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "MsgCreateConsumer is disabled") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.