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!: add filtering function in StargateMsg of wasm #352

Merged
merged 9 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

### Breaking Changes
* (app) [\#352](https://github.com/Finschia/finschia/pull/352) Add filtering function in StargateMsg of wasm

### Build, CI
* (build) [\#340](https://github.com/Finschia/finschia/pull/340) Set Finschia/ostracon version
Expand Down
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ func NewLinkApp(
panic("error while reading wasm config: " + err.Error())
}

// change wasm's StargateMsgEncoder to filtered encoder
wasmOpts = append(wasmOpts, wasmkeeper.WithMessageEncoders(filteredStargateMsgEncoders(appCodec)))

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
availableCapabilities := "iterator,staking,stargate,cosmwasm_1_1"
Expand Down
35 changes: 35 additions & 0 deletions app/wasm_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package app

import (
"strings"

"github.com/Finschia/finschia-sdk/codec"
codectypes "github.com/Finschia/finschia-sdk/codec/types"
sdk "github.com/Finschia/finschia-sdk/types"
sdkerrors "github.com/Finschia/finschia-sdk/types/errors"
wasmkeeper "github.com/Finschia/wasmd/x/wasm/keeper"
wasmtypes "github.com/Finschia/wasmd/x/wasm/types"
wasmvmtypes "github.com/Finschia/wasmvm/types"
)

// deniedModulesInStargateMsg is deny list in StargateMsg of wasm
var deniedModulesInStargateMsg = []string{"/lbm.fswap.v1", "/lbm.fbridge.v1"}
tkxkd0159 marked this conversation as resolved.
Show resolved Hide resolved

func filteredStargateMsgEncoders(cdc codec.Codec) *wasmkeeper.MessageEncoders {
return &wasmkeeper.MessageEncoders{
Stargate: wasmFilteredEncodeStargateMsg(cdc),
}
}

func wasmFilteredEncodeStargateMsg(unpakcer codectypes.AnyUnpacker) wasmkeeper.StargateEncoder {
stargateMsgEncoder := wasmkeeper.EncodeStargateMsg(unpakcer)
return func(sender sdk.AccAddress, msg *wasmvmtypes.StargateMsg) ([]sdk.Msg, error) {
for _, moduleName := range deniedModulesInStargateMsg {
if strings.HasPrefix(msg.TypeURL, moduleName) {
return nil, sdkerrors.Wrap(wasmtypes.ErrUnsupportedForContract, moduleName+" not supported by Stargate")
loloicci marked this conversation as resolved.
Show resolved Hide resolved
}
}

return stargateMsgEncoder(sender, msg)
}
}
Loading
Loading