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: prevent fswap and fbridge module in Submessages #123

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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")) {
loloicci marked this conversation as resolved.
Show resolved Hide resolved
return nil, sdkerrors.Wrap(types.ErrUnsupportedForContract, "fswap and fbridge not supported of Stargate")
loloicci marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading