Skip to content

Commit

Permalink
chore: add (start share == end share) check in parse namespace (#3709)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview

The start share shouldn't be equal to the end share because the range is
end-exclusive. This PR adds this check.

(cherry picked from commit 535802c)

# Conflicts:
#	pkg/proof/querier.go
  • Loading branch information
rach-id authored and mergify[bot] committed Jul 19, 2024
1 parent 3474812 commit a09a521
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -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: 7 additions & 2 deletions pkg/proof/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ 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.
<<<<<<< HEAD

Check failure on line 126 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: non-declaration statement outside function body

Check failure on line 126 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

expected declaration, found '<<' (typecheck)

Check failure on line 126 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: non-declaration statement outside function body

Check failure on line 126 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-short

syntax error: non-declaration statement outside function body

Check failure on line 126 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test

syntax error: non-declaration statement outside function body

Check failure on line 126 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

syntax error: non-declaration statement outside function body

Check failure on line 126 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-race

syntax error: non-declaration statement outside function body
func ParseNamespace(rawShares []shares.Share, startShare, endShare int) (appns.Namespace, error) {
=======

Check failure on line 128 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: unexpected ==, expected }

Check failure on line 128 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: unexpected ==, expected }

Check failure on line 128 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-short

syntax error: unexpected ==, expected }

Check failure on line 128 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test

syntax error: unexpected ==, expected }

Check failure on line 128 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

syntax error: unexpected ==, expected }

Check failure on line 128 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-race

syntax error: unexpected ==, expected }
// The provided range, defined by startShare and endShare, is end-exclusive.
func ParseNamespace(rawShares []shares.Share, startShare int, endShare int) (appns.Namespace, error) {
>>>>>>> 535802c1 (chore: add (start share == end share) check in parse namespace (#3709))

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

syntax error: unexpected >>, expected }

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

invalid character U+0023 '#' (typecheck)

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / lint / golangci-lint

illegal character U+0023 '#' (typecheck)

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-short

syntax error: unexpected >>, expected }

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-short

invalid character U+0023 '#'

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test

syntax error: unexpected >>, expected }

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test

invalid character U+0023 '#'

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

syntax error: unexpected >>, expected }

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-coverage

invalid character U+0023 '#'

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-race

syntax error: unexpected >>, expected }

Check failure on line 131 in pkg/proof/querier.go

View workflow job for this annotation

GitHub Actions / test / test-race

invalid character U+0023 '#'
if startShare < 0 {
return appns.Namespace{}, fmt.Errorf("start share %d should be positive", startShare)
}
Expand All @@ -132,8 +137,8 @@ func ParseNamespace(rawShares []shares.Share, startShare, endShare int) (appns.N
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 a09a521

Please sign in to comment.