Skip to content

Commit

Permalink
fix bridge hook to check sender addr
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Mar 6, 2024
1 parent f815b4d commit c22254d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func NewMinitiaApp(
runtime.NewKVStoreService(keys[opchildtypes.StoreKey]),
app.AccountKeeper,
app.BankKeeper,
apphook.NewWasmBridgeHook(app.WasmKeeper).Hook,
apphook.NewWasmBridgeHook(ac, app.WasmKeeper).Hook,
app.MsgServiceRouter(),
authorityAddr,
vc,
Expand Down
14 changes: 12 additions & 2 deletions app/hook/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ import (
"encoding/json"
"strings"

"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)

// bridge hook implementation for move
type WasmBridgeHook struct {
ac address.Codec
wasmKeeper *wasmkeeper.Keeper
}

func NewWasmBridgeHook(wasmKeeper *wasmkeeper.Keeper) WasmBridgeHook {
return WasmBridgeHook{wasmKeeper}
func NewWasmBridgeHook(ac address.Codec, wasmKeeper *wasmkeeper.Keeper) WasmBridgeHook {
return WasmBridgeHook{ac, wasmKeeper}
}

func (mbh WasmBridgeHook) Hook(ctx context.Context, sender sdk.AccAddress, msgBytes []byte) error {
Expand All @@ -29,6 +32,13 @@ func (mbh WasmBridgeHook) Hook(ctx context.Context, sender sdk.AccAddress, msgBy
return err
}

senderAddr, err := mbh.ac.StringToBytes(msg.Sender)
if err != nil {
return err
} else if !sender.Equals(sdk.AccAddress(senderAddr)) {
return sdkerrors.ErrUnauthorized
}

ms := wasmkeeper.NewMsgServerImpl(mbh.wasmKeeper)
_, err = ms.ExecuteContract(ctx, &msg)

Expand Down

0 comments on commit c22254d

Please sign in to comment.