Skip to content

Commit

Permalink
feat: check that MsgPayForBlob components are non-zero (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Jan 23, 2023
1 parent a98b999 commit 1aec723
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions x/blob/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ var (
ErrMultipleMsgsInBlobTx = sdkerrors.Register(ModuleName, 11129, "not yet supported: multiple sdk.Msgs found in BlobTx")
ErrMismatchedNumberOfPFBComponent = sdkerrors.Register(ModuleName, 11130, "number of each component in a MsgPayForBlob must be identical")
ErrNoBlobs = sdkerrors.Register(ModuleName, 11131, "no blobs provided")
ErrNoNamespaceIds = sdkerrors.Register(ModuleName, 11132, "no namespace IDs provided")
ErrNoShareVersions = sdkerrors.Register(ModuleName, 11133, "no share versions provided")
ErrNoBlobSizes = sdkerrors.Register(ModuleName, 11134, "no blob sizes provided")
ErrNoShareCommitments = sdkerrors.Register(ModuleName, 11135, "no share commitments provided")
)
16 changes: 16 additions & 0 deletions x/blob/types/payforblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ func (msg *MsgPayForBlob) Type() string {
// ValidateBasic fulfills the sdk.Msg interface by performing stateless
// validity checks on the msg that also don't require having the actual blob
func (msg *MsgPayForBlob) ValidateBasic() error {
if len(msg.NamespaceIds) == 0 {
return ErrNoNamespaceIds
}

if len(msg.ShareVersions) == 0 {
return ErrNoShareVersions
}

if len(msg.BlobSizes) == 0 {
return ErrNoBlobSizes
}

if len(msg.ShareCommitments) == 0 {
return ErrNoShareCommitments
}

if len(msg.NamespaceIds) != len(msg.ShareVersions) || len(msg.NamespaceIds) != len(msg.BlobSizes) || len(msg.NamespaceIds) != len(msg.ShareCommitments) {
return ErrMismatchedNumberOfPFBComponent.Wrapf(
"namespaces %d blob sizes %d versions %d share commitments %d",
Expand Down
36 changes: 36 additions & 0 deletions x/blob/types/payforblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ func TestValidateBasic(t *testing.T) {
emptyShareCommitment := validMsgPayForBlob(t)
emptyShareCommitment.ShareCommitments[0] = []byte{}

// MsgPayForBlob that has no namespace ids
noNamespaceIds := validMsgPayForBlob(t)
noNamespaceIds.NamespaceIds = [][]byte{}

// MsgPayForBlob that has no share versions
noShareVersions := validMsgPayForBlob(t)
noShareVersions.ShareVersions = []uint32{}

// MsgPayForBlob that has no blob sizes
noBlobSizes := validMsgPayForBlob(t)
noBlobSizes.BlobSizes = []uint32{}

// MsgPayForBlob that has no share commitments
noShareCommitments := validMsgPayForBlob(t)
noShareCommitments.ShareCommitments = [][]byte{}

tests := []test{
{
name: "valid msg",
Expand Down Expand Up @@ -188,6 +204,26 @@ func TestValidateBasic(t *testing.T) {
msg: emptyShareCommitment,
wantErr: ErrEmptyShareCommitment,
},
{
name: "no namespace ids",
msg: noNamespaceIds,
wantErr: ErrNoNamespaceIds,
},
{
name: "no share versions",
msg: noShareVersions,
wantErr: ErrNoShareVersions,
},
{
name: "no blob sizes",
msg: noBlobSizes,
wantErr: ErrNoBlobSizes,
},
{
name: "no share commitments",
msg: noShareCommitments,
wantErr: ErrNoShareCommitments,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 1aec723

Please sign in to comment.