Skip to content

Commit

Permalink
[Tss] fix router (#207)
Browse files Browse the repository at this point in the history
* add isInternal in Content interface

* fix error types
  • Loading branch information
nkitlabs authored Sep 5, 2024
1 parent f4e856c commit d7b6d1c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
7 changes: 4 additions & 3 deletions x/bandtss/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions x/bandtss/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion x/bandtss/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions x/bandtss/types/signature_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
3 changes: 3 additions & 0 deletions x/feeds/types/signature_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions x/oracle/types/signature_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions x/tss/types/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func wrapHandler(path string, handler Handler) Handler {
type Content interface {
OrderRoute() string
OrderType() string
IsInternal() bool

ValidateBasic() error
String() string
Expand Down
3 changes: 3 additions & 0 deletions x/tss/types/signature_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

0 comments on commit d7b6d1c

Please sign in to comment.