diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c35ffcc..7293956 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,4 +24,4 @@ jobs: with: version: latest args: --timeout 10m - if: env.GIT_DIFF \ No newline at end of file + if: env.GIT_DIFF diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..5ea7614 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,11 @@ +run: + timeout: 5m + modules-download-mode: readonly + +linters: + enable: + - exportloopref + - gofumpt + - misspell + - revive + - prealloc diff --git a/hasher_test.go b/hasher_test.go index e7c7325..1574068 100644 --- a/hasher_test.go +++ b/hasher_test.go @@ -3,7 +3,6 @@ package nmt import ( "crypto" "crypto/sha256" - _ "crypto/sha256" "reflect" "testing" diff --git a/nmt_test.go b/nmt_test.go index eeabe4b..67eb94a 100644 --- a/nmt_test.go +++ b/nmt_test.go @@ -618,7 +618,8 @@ func TestNMT_forgedNamespaceEmptinessProof(t *testing.T) { append(namespace.ID{1}, []byte("leaf_0")...), append(namespace.ID{1}, []byte("leaf_1")...), append(namespace.ID{2}, []byte("leaf_2")...), - append(namespace.ID{2}, []byte("leaf_3")...)} + append(namespace.ID{2}, []byte("leaf_3")...), + } // Init a tree with the namespace size as well as // the underlying hash function: tree := New(sha256.New(), NamespaceIDSize(1)) diff --git a/proof.go b/proof.go index a50c0e3..660ae1f 100644 --- a/proof.go +++ b/proof.go @@ -120,8 +120,7 @@ func NewAbsenceProof(proofStart, proofEnd int, proofNodes [][]byte, leafHash []b // `end-1` of the tree. // // `root` is the root of the NMT against which the `proof` is verified. -func (proof Proof) VerifyNamespace( - h hash.Hash, nID namespace.ID, data [][]byte, root []byte) bool { +func (proof Proof) VerifyNamespace(h hash.Hash, nID namespace.ID, data [][]byte, root []byte) bool { nth := NewNmtHasher(h, nID.Size(), proof.isMaxNamespaceIDIgnored) min := namespace.ID(MinNamespace(root, nID.Size())) max := namespace.ID(MaxNamespace(root, nID.Size())) diff --git a/subrootpaths.go b/subrootpaths.go index febeda6..4494f80 100644 --- a/subrootpaths.go +++ b/subrootpaths.go @@ -6,10 +6,10 @@ import ( ) 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") - srpInvalidIdxEnd = errors.New("GetSubrootPaths: idxEnd must be larger than idxStart and shareCount") + errNotPowerOf2 = errors.New("GetSubrootPaths: Supplied square size is not a power of 2") + errInvalidShareCount = errors.New("GetSubrootPaths: Can't compute path for 0 share count slice") + errPastSquareSize = errors.New("GetSubrootPaths: Share slice can't be past the square size") + errInvalidIdxEnd = errors.New("GetSubrootPaths: idxEnd must be larger than idxStart and shareCount") ) // merkle path to a node is equivalent to the index's binary representation @@ -51,9 +51,8 @@ func prune(idxStart uint, idxEnd uint, maxWidth uint) [][]int { if idxStart+1 >= idxEnd { if idxStart%2 == 1 { return [][]int{pathStart, pathEnd} - } else { - return [][]int{pathStart[:len(pathStart)-1]} } + return [][]int{pathStart[:len(pathStart)-1]} } var prunedPaths [][]int @@ -127,24 +126,24 @@ func GetSubrootPaths(squareSize uint, idxStart uint, shareCount uint) ([][][]int // check squareSize is at least 2 and that it's // a power of 2 by checking that only 1 bit is on if squareSize < 2 || bits.OnesCount(squareSize) != 1 { - return nil, srpNotPowerOf2 + return nil, errNotPowerOf2 } // no path exists for 0 count slice if shareCount == 0 { - return nil, srpInvalidShareCount + return nil, errInvalidShareCount } idxEnd := idxStart + shareCount if idxEnd < idxStart || idxEnd < shareCount { - return nil, srpInvalidIdxEnd + return nil, errInvalidIdxEnd } shares := squareSize * squareSize // sanity checking if idxStart >= shares || idxEnd > shares { - return nil, srpPastSquareSize + return nil, errPastSquareSize } startRow := idxStart / squareSize diff --git a/subrootpaths_test.go b/subrootpaths_test.go index e5b1964..d2d2b67 100644 --- a/subrootpaths_test.go +++ b/subrootpaths_test.go @@ -20,12 +20,12 @@ func TestArgValidation(t *testing.T) { } tests := []test{ - {input: pathSpan{squareSize: 0, startNode: 0, length: 0}, want: srpNotPowerOf2}, - {input: pathSpan{squareSize: 1, startNode: 0, length: 1}, want: srpNotPowerOf2}, - {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}, + {input: pathSpan{squareSize: 0, startNode: 0, length: 0}, want: errNotPowerOf2}, + {input: pathSpan{squareSize: 1, startNode: 0, length: 1}, want: errNotPowerOf2}, + {input: pathSpan{squareSize: 20, startNode: 0, length: 1}, want: errNotPowerOf2}, + {input: pathSpan{squareSize: 4, startNode: 0, length: 17}, want: errPastSquareSize}, + {input: pathSpan{squareSize: 4, startNode: 0, length: 0}, want: errInvalidShareCount}, + {input: pathSpan{squareSize: 128, startNode: 1, length: 18446744073709551615}, want: errInvalidIdxEnd}, } for _, tc := range tests {