Skip to content

Commit

Permalink
chore: add golangci-lint config
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp committed Feb 17, 2023
1 parent fa98a59 commit 542bc79
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
with:
version: latest
args: --timeout 10m
if: env.GIT_DIFF
if: env.GIT_DIFF
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
run:
timeout: 5m
modules-download-mode: readonly

linters:
enable:
- exportloopref
- gofumpt
- misspell
- revive
- prealloc
1 change: 0 additions & 1 deletion hasher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package nmt
import (
"crypto"
"crypto/sha256"
_ "crypto/sha256"
"reflect"
"testing"

Expand Down
3 changes: 2 additions & 1 deletion nmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
19 changes: 9 additions & 10 deletions subrootpaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions subrootpaths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 542bc79

Please sign in to comment.