Repository: celestiaorg/nmt
Pull request #83 (2022-11-01 20:22:57)

chore: add overflow test
Addresses feedback from https://github.com/celestiaorg/nmt/pull/79

codecov[bot]: # [Codecov](https://codecov.io/gh/celestiaorg/nmt/pull/83?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=celestiaorg) Report
> Merging [#83](https://codecov.io/gh/celestiaorg/nmt/pull/83?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=celestiaorg) (8a47d13) into [master](https://codecov.io/gh/celestiaorg/nmt/commit/51cedb1e14abea8c1afe5f6dc846ccc188ff9d9f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=celestiaorg) (51cedb1) will **increase** coverage by `0.50%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
+ Coverage   96.23%   96.73%   +0.50%     
==========================================
  Files           6        6              
  Lines         398      398              
==========================================
+ Hits          383      385       +2     
+ Misses          8        7       -1     
+ Partials        7        6       -1     
```


| [Impacted Files](https://codecov.io/gh/celestiaorg/nmt/pull/83?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=celestiaorg) | Coverage Δ | |
|---|---|---|
| [subrootpaths.go](https://codecov.io/gh/celestiaorg/nmt/pull/83/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=celestiaorg#diff-c3Vicm9vdHBhdGhzLmdv) | `90.58% <100.00%> (+2.35%)` | :arrow_up: |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=celestiaorg). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=celestiaorg)


Patch:
diff --git a/subrootpaths.go b/subrootpaths.go
index 8ca6be5..febeda6 100644
--- a/subrootpaths.go
+++ b/subrootpaths.go
@@ -9,8 +9,7 @@ var (
 	srpNotPowerOf2       = errors.New("GetSubrootPaths: Supplied square size is not a power of 2")
 	srpInvalidShareCount = errors.New("GetSubrootPaths: Can't compute path for 0 share count slice")
 	srpPastSquareSize    = errors.New("GetSubrootPaths: Share slice can't be past the square size")
-
-	srpInvalidIdxStartShareCountSum = errors.New("invalid idxStart+shareCount value")
+	srpInvalidIdxEnd     = errors.New("GetSubrootPaths: idxEnd must be larger than idxStart and shareCount")
 )
 
 // merkle path to a node is equivalent to the index's binary representation
@@ -136,15 +135,15 @@ func GetSubrootPaths(squareSize uint, idxStart uint, shareCount uint) ([][][]int
 		return nil, srpInvalidShareCount
 	}
 
-	isn := idxStart + shareCount
-	if isn < idxStart || isn < shareCount {
-		return nil, srpInvalidIdxStartShareCountSum
+	idxEnd := idxStart + shareCount
+	if idxEnd < idxStart || idxEnd < shareCount {
+		return nil, srpInvalidIdxEnd
 	}
 
 	shares := squareSize * squareSize
 
 	// sanity checking
-	if idxStart >= shares || isn > shares {
+	if idxStart >= shares || idxEnd > shares {
 		return nil, srpPastSquareSize
 	}
 


Test patch:
diff --git a/subrootpaths_test.go b/subrootpaths_test.go
index 54185ef..b8705c7 100644
--- a/subrootpaths_test.go
+++ b/subrootpaths_test.go
@@ -26,6 +26,7 @@ func TestArgValidation(t *testing.T) {
 		{input: pathSpan{squareSize: 20, startNode: 0, length: 1}, want: srpNotPowerOf2},
 		{input: pathSpan{squareSize: 4, startNode: 0, length: 17}, want: srpPastSquareSize},
 		{input: pathSpan{squareSize: 4, startNode: 0, length: 0}, want: srpInvalidShareCount},
+		{input: pathSpan{squareSize: 128, startNode: 1, length: 18446744073709551615}, want: srpInvalidIdxEnd},
 	}
 
 	for _, tc := range tests {