Skip to content

Commit

Permalink
feat: prevent fswap and fbridge module in Submessages
Browse files Browse the repository at this point in the history
  • Loading branch information
da1suk8 committed Apr 25, 2024
1 parent a348dc5 commit 407a2fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions x/wasm/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"sort"
"strings"

abci "github.com/tendermint/tendermint/abci/types"

Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions x/wasm/keeper/msg_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 407a2fd

Please sign in to comment.