diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b39de675f..066f726913 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased](https://github.com/Finschia/wasmd/compare/v0.3.0...HEAD) ### Features +* [\#123](https://github.com/Finschia/wasmd/pull/123) prevent fswap and fbridge module in Submessages ### Improvements diff --git a/x/wasm/keeper/msg_dispatcher.go b/x/wasm/keeper/msg_dispatcher.go index 15ea530e27..98a0f258f2 100644 --- a/x/wasm/keeper/msg_dispatcher.go +++ b/x/wasm/keeper/msg_dispatcher.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "sort" + "strings" abci "github.com/tendermint/tendermint/abci/types" @@ -81,6 +82,18 @@ func (d MessageDispatcher) dispatchMsgWithGasLimit(ctx sdk.Context, contractAddr func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk.AccAddress, ibcPort string, msgs []wasmvmtypes.SubMsg) ([]byte, error) { var rsp []byte for _, msg := range msgs { + + // Prevent the use of specific modules in Submessages + // https://github.com/Finschia/finschia-sdk/pull/1336, https://github.com/Finschia/finschia-sdk/pull/1340 + if stargateMsg := msg.Msg.Stargate; stargateMsg != nil { + deniedModules := []string{"/lbm.fswap.v1", "/lbm.fbridge.v1"} + for _, moduleName := range deniedModules { + if strings.HasPrefix(stargateMsg.TypeURL, moduleName) { + return nil, sdkerrors.Wrap(types.ErrUnsupportedForContract, moduleName+" not supported by Stargate") + } + } + } + switch msg.ReplyOn { case wasmvmtypes.ReplySuccess, wasmvmtypes.ReplyError, wasmvmtypes.ReplyAlways, wasmvmtypes.ReplyNever: default: diff --git a/x/wasm/keeper/msg_dispatcher_test.go b/x/wasm/keeper/msg_dispatcher_test.go index a0ce9e6655..b8032e0ad7 100644 --- a/x/wasm/keeper/msg_dispatcher_test.go +++ b/x/wasm/keeper/msg_dispatcher_test.go @@ -386,6 +386,14 @@ func TestDispatchSubmessages(t *testing.T) { sdk.NewEvent("stargate-reply"), }, }, + "stargate msg with invalid fswap TypeURL": { + msgs: []wasmvmtypes.SubMsg{{Msg: wasmvmtypes.CosmosMsg{Stargate: &wasmvmtypes.StargateMsg{TypeURL: "/lbm.fswap.v1.MsgSwapRequest"}}}}, + expErr: true, + }, + "stargate msg with invalid fbridge TypeURL": { + msgs: []wasmvmtypes.SubMsg{{Msg: wasmvmtypes.CosmosMsg{Stargate: &wasmvmtypes.StargateMsg{TypeURL: "/lbm.fbridge.v1.MsgTransfer"}}}}, + expErr: true, + }, } for name, spec := range specs { t.Run(name, func(t *testing.T) {