Skip to content

Commit

Permalink
chore: add (start share == end share) check in parse namespace (backp…
Browse files Browse the repository at this point in the history
…ort #3709) (#3711)

## Overview

The start share shouldn't be equal to the end share because the range is
end-exclusive. This PR adds this check.
<hr>This is an automatic backport of pull request #3709 done by
[Mergify](https://mergify.com).

Co-authored-by: CHAMI Rachid <[email protected]>
  • Loading branch information
mergify[bot] and rach-id authored Jul 19, 2024
1 parent b63b118 commit 35cad92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/proof/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ func TestNewShareInclusionProof(t *testing.T) {
namespaceID: appns.TxNamespace,
expectErr: true,
},
{
name: "ending share is equal to the starting share",
startingShare: 1,
endingShare: 1,
namespaceID: appns.TxNamespace,
expectErr: true,
},
{
name: "ending share higher than number of shares available in square size of 32",
startingShare: 0,
Expand Down
5 changes: 3 additions & 2 deletions pkg/proof/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func QueryShareInclusionProof(_ sdk.Context, path []string, req abci.RequestQuer

// ParseNamespace validates the share range, checks if it only contains one namespace and returns
// that namespace ID.
// The provided range, defined by startShare and endShare, is end-exclusive.
func ParseNamespace(rawShares []shares.Share, startShare int, endShare int) (appns.Namespace, error) {
if startShare < 0 {
return appns.Namespace{}, fmt.Errorf("start share %d should be positive", startShare)
Expand All @@ -139,8 +140,8 @@ func ParseNamespace(rawShares []shares.Share, startShare int, endShare int) (app
return appns.Namespace{}, fmt.Errorf("end share %d should be positive", endShare)
}

if endShare < startShare {
return appns.Namespace{}, fmt.Errorf("end share %d cannot be lower than starting share %d", endShare, startShare)
if endShare <= startShare {
return appns.Namespace{}, fmt.Errorf("end share %d cannot be lower or equal to the starting share %d", endShare, startShare)
}

if endShare > len(rawShares) {
Expand Down

0 comments on commit 35cad92

Please sign in to comment.