diff --git a/x/payment/types/errors.go b/x/payment/types/errors.go index ebc8cadc02..7e167f693e 100644 --- a/x/payment/types/errors.go +++ b/x/payment/types/errors.go @@ -18,4 +18,5 @@ var ( ErrTailPaddingNamespace = sdkerrors.Register(ModuleName, 11118, "cannot use tail padding namespace ID") ErrTxNamespace = sdkerrors.Register(ModuleName, 11119, "cannot use transaction namespace ID") ErrEvidenceNamespace = sdkerrors.Register(ModuleName, 11120, "cannot use evidence namespace ID") + ErrNoMessageShareCommitments = sdkerrors.Register(ModuleName, 11121, "no message share commitments") ) diff --git a/x/payment/types/payfordata.go b/x/payment/types/payfordata.go index b9e2e6c88f..7e5ddbcdb2 100644 --- a/x/payment/types/payfordata.go +++ b/x/payment/types/payfordata.go @@ -47,6 +47,10 @@ func (msg *MsgPayForData) ValidateBasic() error { return err } + if len(msg.MessageShareCommitment) == 0 { + return ErrNoMessageShareCommitments + } + return nil } diff --git a/x/payment/types/payfordata_test.go b/x/payment/types/payfordata_test.go index 5e89708508..3d56cff42e 100644 --- a/x/payment/types/payfordata_test.go +++ b/x/payment/types/payfordata_test.go @@ -357,6 +357,10 @@ func TestValidateBasic(t *testing.T) { maxReservedNamespaceMsg := validMsgPayForData(t) maxReservedNamespaceMsg.MessageNamespaceId = namespace.ID{0, 0, 0, 0, 0, 0, 0, 255} + // MsgPayForData that has no message share commitments + noMessageShareCommitments := validMsgPayForData(t) + noMessageShareCommitments.MessageShareCommitment = []byte{} + tests := []test{ { name: "valid msg", @@ -393,6 +397,11 @@ func TestValidateBasic(t *testing.T) { msg: maxReservedNamespaceMsg, wantErr: ErrReservedNamespace, }, + { + name: "no message share commitments", + msg: noMessageShareCommitments, + wantErr: ErrNoMessageShareCommitments, + }, } for _, tt := range tests { diff --git a/x/payment/types/wirepayfordata.go b/x/payment/types/wirepayfordata.go index 7bc598aae7..5f8443af7f 100644 --- a/x/payment/types/wirepayfordata.go +++ b/x/payment/types/wirepayfordata.go @@ -118,6 +118,10 @@ func (msg *MsgWirePayForData) ValidateBasic() error { } } + if len(msg.MessageShareCommitment) == 0 { + return ErrNoMessageShareCommitments + } + return nil } diff --git a/x/payment/types/wirepayfordata_test.go b/x/payment/types/wirepayfordata_test.go index 5d2be5dd8d..95f07a21f2 100644 --- a/x/payment/types/wirepayfordata_test.go +++ b/x/payment/types/wirepayfordata_test.go @@ -49,6 +49,10 @@ func TestWirePayForData_ValidateBasic(t *testing.T) { badSquareSizeMsg := validWirePayForData(t) badSquareSizeMsg.MessageShareCommitment[0].K = 4 + // pfd that signed over no squares + noMessageShareCommitments := validWirePayForData(t) + noMessageShareCommitments.MessageShareCommitment = []ShareCommitAndSignature{} + tests := []test{ { name: "valid msg", @@ -95,6 +99,11 @@ func TestWirePayForData_ValidateBasic(t *testing.T) { msg: tailPaddingMsg, wantErr: ErrTailPaddingNamespace, }, + { + name: "no message share commitments", + msg: noMessageShareCommitments, + wantErr: ErrNoMessageShareCommitments, + }, } for _, tt := range tests {