From d7b6d1cda875252363ecded650e068185447c196 Mon Sep 17 00:00:00 2001 From: Natthakun Kitthaworn Date: Thu, 5 Sep 2024 17:18:44 +0700 Subject: [PATCH] [Tss] fix router (#207) * add isInternal in Content interface * fix error types --- x/bandtss/keeper/msg_server.go | 7 ++++--- x/bandtss/keeper/msg_server_test.go | 17 +++++++++++++++++ x/bandtss/types/errors.go | 2 +- x/bandtss/types/signature_order.go | 3 +++ x/feeds/types/signature_order.go | 3 +++ x/oracle/types/signature_order.go | 3 +++ x/tss/types/content.go | 1 + x/tss/types/signature_order.go | 3 +++ 8 files changed, 35 insertions(+), 4 deletions(-) diff --git a/x/bandtss/keeper/msg_server.go b/x/bandtss/keeper/msg_server.go index 5eadf8359..3fbefbe73 100644 --- a/x/bandtss/keeper/msg_server.go +++ b/x/bandtss/keeper/msg_server.go @@ -143,9 +143,10 @@ func (k msgServer) RequestSignature( } content := req.GetContent() - if content.OrderRoute() == types.RouterKey && content.OrderType() == types.GroupTransitionPath { - return nil, types.ErrInvalidRequestSignature.Wrapf( - "invalid request order route: %s order type: %s", content.OrderRoute(), content.OrderType()) + if content.IsInternal() { + return nil, types.ErrContentNotAllowed.Wrapf( + "order route: %s, type: %s", content.OrderRoute(), content.OrderType(), + ) } // Execute the handler to process the request. diff --git a/x/bandtss/keeper/msg_server_test.go b/x/bandtss/keeper/msg_server_test.go index 65f11c6dc..00a7500fc 100644 --- a/x/bandtss/keeper/msg_server_test.go +++ b/x/bandtss/keeper/msg_server_test.go @@ -446,6 +446,23 @@ func (s *AppTestSuite) TestSuccessRequestSignatureOnCurrentGroup() { s.Require().Equal(bandtssSigningID, bandtssSigningIDMapping) } +func (s *AppTestSuite) TestFailRequestSignatureInternalMessage() { + ctx, msgSrvr, k := s.ctx, s.msgSrvr, s.app.BandtssKeeper + + _ = s.SetupNewGroup(5, 3) + k.DeleteGroupTransition(ctx) + + msg, err := types.NewMsgRequestSignature( + types.NewGroupTransitionSignatureOrder([]byte("msg")), + sdk.NewCoins(sdk.NewInt64Coin("uband", 100)), + bandtesting.FeePayer.Address, + ) + s.Require().NoError(err) + + _, err = msgSrvr.RequestSignature(ctx, msg) + s.Require().ErrorIs(err, types.ErrContentNotAllowed) +} + func (s *AppTestSuite) TestSuccessRequestSignatureOnIncomingGroup() { ctx, msgSrvr := s.ctx, s.msgSrvr diff --git a/x/bandtss/types/errors.go b/x/bandtss/types/errors.go index 7e2bcfd32..ce8ab029d 100644 --- a/x/bandtss/types/errors.go +++ b/x/bandtss/types/errors.go @@ -16,7 +16,7 @@ var ( ErrMemberAlreadyActive = errorsmod.Register(ModuleName, 11, "member already active") ErrMemberDuplicate = errorsmod.Register(ModuleName, 12, "duplicated member found within the list") ErrInvalidSigningThreshold = errorsmod.Register(ModuleName, 13, "invalid signing threshold number") - ErrInvalidRequestSignature = errorsmod.Register(ModuleName, 14, "request signature is invalid") + ErrContentNotAllowed = errorsmod.Register(ModuleName, 14, "content not allowed") ErrInvalidIncomingGroup = errorsmod.Register(ModuleName, 15, "invalid incoming group") ErrNoActiveGroup = errorsmod.Register(ModuleName, 16, "no active group supported") ErrNoIncomingGroup = errorsmod.Register(ModuleName, 17, "no incoming group") diff --git a/x/bandtss/types/signature_order.go b/x/bandtss/types/signature_order.go index db5613573..594d0828a 100644 --- a/x/bandtss/types/signature_order.go +++ b/x/bandtss/types/signature_order.go @@ -29,6 +29,9 @@ func (rs *GroupTransitionSignatureOrder) OrderType() string { return GroupTransitionPath } +// IsInternal returns true for GroupTransitionSignatureOrder (internal module-based request signature). +func (rs *GroupTransitionSignatureOrder) IsInternal() bool { return true } + // ValidateBasic performs no-op for this type func (rs *GroupTransitionSignatureOrder) ValidateBasic() error { return nil } diff --git a/x/feeds/types/signature_order.go b/x/feeds/types/signature_order.go index bdcbcee4b..84f2b503d 100644 --- a/x/feeds/types/signature_order.go +++ b/x/feeds/types/signature_order.go @@ -30,6 +30,9 @@ func (f *FeedsSignatureOrder) OrderType() string { return SignatureOrderTypeFeeds } +// IsInternal returns false for FeedsSignatureOrder (allow user to submit this content type). +func (f *FeedsSignatureOrder) IsInternal() bool { return false } + // ValidateBasic validates the request's title and description of the request signature func (f *FeedsSignatureOrder) ValidateBasic() error { if len(f.SignalIDs) == 0 { diff --git a/x/oracle/types/signature_order.go b/x/oracle/types/signature_order.go index 521138ee5..d5e4bf81e 100644 --- a/x/oracle/types/signature_order.go +++ b/x/oracle/types/signature_order.go @@ -30,6 +30,9 @@ func (o *OracleResultSignatureOrder) OrderType() string { return SignatureOrderTypeOracleResult } +// IsInternal returns false for OracleResultSignatureOrder (allow user to submit this content type). +func (o *OracleResultSignatureOrder) IsInternal() bool { return false } + // ValidateBasic validates the request's title and description of the request signature func (o *OracleResultSignatureOrder) ValidateBasic() error { if o.RequestID == 0 { diff --git a/x/tss/types/content.go b/x/tss/types/content.go index dea5858f8..43846a482 100644 --- a/x/tss/types/content.go +++ b/x/tss/types/content.go @@ -83,6 +83,7 @@ func wrapHandler(path string, handler Handler) Handler { type Content interface { OrderRoute() string OrderType() string + IsInternal() bool ValidateBasic() error String() string diff --git a/x/tss/types/signature_order.go b/x/tss/types/signature_order.go index 884ac7f0b..f4f49dd47 100644 --- a/x/tss/types/signature_order.go +++ b/x/tss/types/signature_order.go @@ -20,5 +20,8 @@ func (rs *TextSignatureOrder) OrderType() string { return SignatureOrderTypeText } +// IsInternal returns false for TextSignatureOrder (allow user to submit this content type). +func (rs *TextSignatureOrder) IsInternal() bool { return false } + // ValidateBasic performs no-op for this type func (rs *TextSignatureOrder) ValidateBasic() error { return nil }