Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add (start share == end share) check in parse namespace (backport #3709) #3710

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/proof/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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
9 changes: 3 additions & 6 deletions pkg/proof/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,14 @@ 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, endShare int) (appns.Namespace, error) {
if startShare < 0 {
return appns.Namespace{}, fmt.Errorf("start share %d should be positive", startShare)
}

if endShare < 0 {
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
Loading