Skip to content
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

feat: allowlist host param using msg typeURLs #576

Merged
merged 20 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
aa508b2
add ica params
colin-axner Nov 26, 2021
5d009b5
regenerate params proto into host and controller submodules
colin-axner Nov 29, 2021
d0c6c0a
split params implementation into host/controller
colin-axner Nov 29, 2021
d43a945
add keeper params logic
colin-axner Nov 29, 2021
ff79bd9
Apply suggestions from code review
colin-axner Nov 30, 2021
cb0b4f8
fix merge conflicts
colin-axner Nov 30, 2021
4c47cd4
Merge branch 'colin/523-controller-host-param' of github.com:cosmos/i…
colin-axner Nov 30, 2021
df27451
add host genesis init/export params test case
colin-axner Nov 30, 2021
40a6382
fix merge conflicts with interchain-accounts branch
colin-axner Nov 30, 2021
a54e639
updating host proto params to include msg allowlist
damiannolan Dec 1, 2021
c55752c
adding surrounds for new allowlist host param
damiannolan Dec 1, 2021
dc916be
enforcing msg is present in allowlist in AuthenticateTx, updating tests
damiannolan Dec 1, 2021
286237b
Merge branch 'interchain-accounts' into damian/511-sdk-msg-allowlist-…
damiannolan Dec 1, 2021
7f8e35b
regenerating protos post merge conflict
damiannolan Dec 1, 2021
fbbd7a3
Merge branch 'interchain-accounts' into damian/511-sdk-msg-allowlist-…
damiannolan Dec 1, 2021
fdd7f5b
applying suggestinons from review
damiannolan Dec 1, 2021
5f60dc9
Merge branch 'interchain-accounts' into damian/511-sdk-msg-allowlist-…
damiannolan Dec 1, 2021
53aea06
adding strings.Trimspace as suggested
damiannolan Dec 1, 2021
3c46bbc
Merge branch 'damian/511-sdk-msg-allowlist-params' of github.com:cosm…
damiannolan Dec 1, 2021
8f5987e
Merge branch 'interchain-accounts' into damian/511-sdk-msg-allowlist-…
damiannolan Dec 1, 2021
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
9 changes: 6 additions & 3 deletions modules/apps/27-interchain-accounts/host/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false))
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, false,
},
{
Expand Down Expand Up @@ -260,7 +260,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() {
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false))
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, false,
},
{
Expand Down Expand Up @@ -399,7 +399,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
},
{
"host submodule disabled", func() {
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false))
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{}))
}, false,
},
{
Expand Down Expand Up @@ -452,6 +452,9 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() {
}
packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)

// malleate packetData for test cases
tc.malleate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
suite.Require().True(found)
suite.Require().Equal(TestAccAddress.String(), accountAdrr)

expParams := types.NewParams(false)
expParams := types.NewParams(false, nil)
params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(expParams, params)
}
Expand Down
9 changes: 8 additions & 1 deletion modules/apps/27-interchain-accounts/host/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,16 @@ func (k Keeper) IsHostEnabled(ctx sdk.Context) bool {
return res
}

// GetAllowMessages retrieves the host enabled msg types from the paramstore
func (k Keeper) GetAllowMessages(ctx sdk.Context) []string {
var res []string
k.paramSpace.Get(ctx, types.KeyAllowMessages, &res)
return res
}

// GetParams returns the total set of the host submodule parameters.
func (k Keeper) GetParams(ctx sdk.Context) types.Params {
return types.NewParams(k.IsHostEnabled(ctx))
return types.NewParams(k.IsHostEnabled(ctx), k.GetAllowMessages(ctx))
}

// SetParams sets the total set of the host submodule parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func (suite *KeeperTestSuite) TestParams() {
suite.Require().Equal(expParams, params)

expParams.HostEnabled = false
expParams.AllowMessages = []string{"/cosmos.staking.v1beta1.MsgDelegate"}
suite.chainA.GetSimApp().ICAHostKeeper.SetParams(suite.chainA.GetContext(), expParams)
params = suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext())
suite.Require().Equal(expParams, params)
Expand Down
6 changes: 6 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
)
Expand All @@ -16,7 +17,12 @@ func (k Keeper) AuthenticateTx(ctx sdk.Context, msgs []sdk.Msg, portID string) e
return sdkerrors.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID)
}

allowMsgs := k.GetAllowMessages(ctx)
for _, msg := range msgs {
if !types.ContainsMsgType(allowMsgs, msg) {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "message type not allowed: %s", sdk.MsgTypeURL(msg))
}

for _, signer := range msg.GetSigners() {
if interchainAccountAddr != signer.String() {
return sdkerrors.Wrapf(sdkerrors.ErrUnauthorized, "unexpected signer address: expected %s, got %s", interchainAccountAddr, signer.String())
Expand Down
49 changes: 49 additions & 0 deletions modules/apps/27-interchain-accounts/host/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/host/types"
icatypes "github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
transfertypes "github.com/cosmos/ibc-go/v2/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v2/modules/core/02-client/types"
Expand Down Expand Up @@ -49,6 +50,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand All @@ -74,6 +78,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand Down Expand Up @@ -105,6 +112,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msgDelegate), sdk.MsgTypeURL(msgUndelegate)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand Down Expand Up @@ -137,6 +147,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand Down Expand Up @@ -173,6 +186,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand All @@ -196,6 +212,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand All @@ -219,6 +238,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand Down Expand Up @@ -253,6 +275,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
true,
},
Expand Down Expand Up @@ -309,6 +334,27 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
},
false,
},
{
"unauthorised: message type not allowed", // NOTE: do not update params to explicitly force the error
func() {
msg := &banktypes.MsgSend{
FromAddress: suite.chainB.SenderAccount.GetAddress().String(),
ToAddress: suite.chainB.SenderAccount.GetAddress().String(),
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))),
}

data, err := icatypes.SerializeCosmosTx(suite.chainA.GetSimApp().AppCodec(), []sdk.Msg{msg})
suite.Require().NoError(err)

icaPacketData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: data,
}

packetData = icaPacketData.GetBytes()
},
false,
},
{
"unauthorised: signer address is not the interchain account associated with the controller portID",
func() {
Expand All @@ -327,6 +373,9 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() {
}

packetData = icaPacketData.GetBytes()

params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)})
suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params)
},
false,
},
Expand Down
95 changes: 77 additions & 18 deletions modules/apps/27-interchain-accounts/host/types/host.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
// ModuleName defines the interchain accounts host module name
ModuleName = "icahost"

// StoreKey is the store key string for the interchain accounts host module
StoreKey = ModuleName
)

// ContainsMsgType returns true if the sdk.Msg TypeURL is present in allowMsgs, otherwise false
func ContainsMsgType(allowMsgs []string, msg sdk.Msg) bool {
for _, v := range allowMsgs {
if v == sdk.MsgTypeURL(msg) {
return true
}
}

return false
}
Loading