diff --git a/app/app.go b/app/app.go index be99bc0..cc4dd70 100644 --- a/app/app.go +++ b/app/app.go @@ -360,7 +360,7 @@ func NewMinitiaApp( runtime.NewKVStoreService(keys[opchildtypes.StoreKey]), app.AccountKeeper, app.BankKeeper, - apphook.NewEVMBridgeHook(app.EVMKeeper).Hook, + apphook.NewEVMBridgeHook(ac, app.EVMKeeper).Hook, app.MsgServiceRouter(), authorityAddr, vc, diff --git a/app/hook/evm.go b/app/hook/evm.go index aacfd14..072fe94 100644 --- a/app/hook/evm.go +++ b/app/hook/evm.go @@ -5,7 +5,9 @@ import ( "encoding/json" "strings" + "cosmossdk.io/core/address" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" evmkeeper "github.com/initia-labs/minievm/x/evm/keeper" evmtypes "github.com/initia-labs/minievm/x/evm/types" @@ -13,15 +15,16 @@ import ( // bridge hook implementation for evm type EVMBridgeHook struct { + ac address.Codec evmKeeper *evmkeeper.Keeper } -func NewEVMBridgeHook(evmKeeper *evmkeeper.Keeper) EVMBridgeHook { - return EVMBridgeHook{evmKeeper} +func NewEVMBridgeHook(ac address.Codec, evmKeeper *evmkeeper.Keeper) EVMBridgeHook { + return EVMBridgeHook{ac, evmKeeper} } func (mbh EVMBridgeHook) Hook(ctx context.Context, sender sdk.AccAddress, msgBytes []byte) error { - msg := evmtypes.MsgCall{} + var msg evmtypes.MsgCall decoder := json.NewDecoder(strings.NewReader(string(msgBytes))) decoder.DisallowUnknownFields() err := decoder.Decode(&msg) @@ -29,6 +32,13 @@ func (mbh EVMBridgeHook) Hook(ctx context.Context, sender sdk.AccAddress, msgByt 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 := evmkeeper.NewMsgServerImpl(mbh.evmKeeper) _, err = ms.Call(ctx, &msg)