diff --git a/x/tokenfactory/keeper/createdenom_test.go b/x/tokenfactory/keeper/createdenom_test.go index 7d25a9d5d8c..a74b8066954 100644 --- a/x/tokenfactory/keeper/createdenom_test.go +++ b/x/tokenfactory/keeper/createdenom_test.go @@ -47,4 +47,8 @@ func (suite *KeeperTestSuite) TestMsgCreateDenom() { res, err = msgServer.CreateDenom(sdk.WrapSDKContext(suite.ctx), types.NewMsgCreateDenom(addr2.String(), "bitcoin")) suite.Require().NoError(err) suite.Require().NotEmpty(res.GetNewTokenDenom()) + + // Make sure that an address with a "/" in it can't create denoms + res, err = msgServer.CreateDenom(sdk.WrapSDKContext(suite.ctx), types.NewMsgCreateDenom("osmosis.eth/creator", "bitcoin")) + suite.Require().Error(err) } diff --git a/x/tokenfactory/types/denoms.go b/x/tokenfactory/types/denoms.go index b4b6eaa50b6..892122606ae 100644 --- a/x/tokenfactory/types/denoms.go +++ b/x/tokenfactory/types/denoms.go @@ -12,6 +12,9 @@ const ( ) func GetTokenDenom(creator, nonce string) (string, error) { + if strings.Contains(creator, "/") { + return "", ErrInvalidCreator + } denom := strings.Join([]string{ModuleDenomPrefix, creator, nonce}, "/") return denom, sdk.ValidateDenom(denom) } diff --git a/x/tokenfactory/types/errors.go b/x/tokenfactory/types/errors.go index b90cfd92deb..cb6e7c23d41 100644 --- a/x/tokenfactory/types/errors.go +++ b/x/tokenfactory/types/errors.go @@ -11,6 +11,7 @@ var ( ErrDenomExists = sdkerrors.Register(ModuleName, 1, "denom already exists") ErrUnauthorized = sdkerrors.Register(ModuleName, 2, "unauthorized account") ErrInvalidDenom = sdkerrors.Register(ModuleName, 3, "invalid denom") - ErrInvalidAuthorityMetadata = sdkerrors.Register(ModuleName, 4, "invalid authority metadata") - ErrInvalidGenesis = sdkerrors.Register(ModuleName, 5, "invalid genesis") + ErrInvalidCreator = sdkerrors.Register(ModuleName, 4, "invalid creator") + ErrInvalidAuthorityMetadata = sdkerrors.Register(ModuleName, 5, "invalid authority metadata") + ErrInvalidGenesis = sdkerrors.Register(ModuleName, 6, "invalid genesis") )