From 407a2fddf0f04554852e46f938612bc6e3bab89c Mon Sep 17 00:00:00 2001 From: Daisuke Iuchi <42408108+da1suk8@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:09:42 +0900 Subject: [PATCH] feat: prevent fswap and fbridge module in Submessages --- x/wasm/keeper/msg_dispatcher.go | 9 +++++++++ x/wasm/keeper/msg_dispatcher_test.go | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/x/wasm/keeper/msg_dispatcher.go b/x/wasm/keeper/msg_dispatcher.go index 15ea530e27..166e26f7ce 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,14 @@ 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 fswap and fbridge module 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 && + (strings.Contains(stargateMsg.TypeURL, "lbm.fswap.v1") || strings.Contains(stargateMsg.TypeURL, "lbm.fbridge.v1")) { + return nil, sdkerrors.Wrap(types.ErrUnsupportedForContract, "fswap and fbridge not supported of 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) {