diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a18fe8de3..bd624c384 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -15,18 +15,18 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: '1.20' + go-version: '1.21' cache: false - name: golangci-lint - uses: golangci/golangci-lint-action@v4 + uses: golangci/golangci-lint-action@v6 with: # Require: The version of golangci-lint to use. # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. - version: v1.56.2 + version: v1.60.3 # Optional: working directory, useful for monorepos # working-directory: somedir @@ -51,4 +51,4 @@ jobs: # skip-build-cache: true # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. - # install-mode: "goinstall" \ No newline at end of file + # install-mode: "goinstall" diff --git a/.golangci.yml b/.golangci.yml index bf818a8b7..28d5417d2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -96,6 +96,7 @@ linters-settings: excludes: - G107 # variables in URLs - G404 # use of weak random generator + - G115 # Disable for now due to the *many* warnings gocritic: disabled-checks: diff --git a/Makefile b/Makefile index f480eb391..b71342497 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ generate: tidy # Coding style static check. lint: tidy - @echo "Please setup a linter!" - #golangci-lint run - #staticcheck go list ./... + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3 + @go mod tidy + golangci-lint run vet: tidy go vet ./... diff --git a/group/mod/int.go b/group/mod/int.go index 741b5ca0e..c7d2c3fab 100644 --- a/group/mod/int.go +++ b/group/mod/int.go @@ -363,13 +363,13 @@ func (i *Int) UnmarshalFrom(r io.Reader) (int, error) { // BigEndian encodes the value of this Int into a big-endian byte-slice // at least min bytes but no more than max bytes long. // Panics if max != 0 and the Int cannot be represented in max bytes. -func (i *Int) BigEndian(min, max int) []byte { +func (i *Int) BigEndian(minBytes, maxBytes int) []byte { act := i.MarshalSize() pad, ofs := act, 0 - if pad < min { - pad, ofs = min, min-act + if pad < minBytes { + pad, ofs = minBytes, minBytes-act } - if max != 0 && pad > max { + if maxBytes != 0 && pad > maxBytes { panic("Int not representable in max bytes") } buf := make([]byte, pad) @@ -392,7 +392,7 @@ func (i *Int) SetBytes(a []byte) kyber.Scalar { // LittleEndian encodes the value of this Int into a little-endian byte-slice // at least min bytes but no more than max bytes long. // Panics if max != 0 and the Int cannot be represented in max bytes. -func (i *Int) LittleEndian(min, max int) []byte { +func (i *Int) LittleEndian(minByte, maxBytes int) []byte { act := i.MarshalSize() vBytes := i.V.Bytes() vSize := len(vBytes) @@ -400,10 +400,10 @@ func (i *Int) LittleEndian(min, max int) []byte { act = vSize } pad := act - if pad < min { - pad = min + if pad < minByte { + pad = minByte } - if max != 0 && pad > max { + if maxBytes != 0 && pad > maxBytes { panic("Int not representable in max bytes") } buf := make([]byte, pad) diff --git a/pairing/bls12381/bls12381_test.go b/pairing/bls12381/bls12381_test.go index 5b9e007ee..46ec9eb6e 100644 --- a/pairing/bls12381/bls12381_test.go +++ b/pairing/bls12381/bls12381_test.go @@ -356,10 +356,10 @@ func testGroup(t *testing.T, g kyber.Group, rand cipher.Stream) []kyber.Point { buf.Reset() s := g.Scalar().Pick(rand) if _, err := s.MarshalTo(buf); err != nil { - t.Fatalf("encoding of secret fails: " + err.Error()) + t.Fatalf("encoding of secret fails: %s", err.Error()) } if _, err := stmp.UnmarshalFrom(buf); err != nil { - t.Fatalf("decoding of secret fails: " + err.Error()) + t.Fatalf("decoding of secret fails: %s", err.Error()) } if !stmp.Equal(s) { t.Fatalf("decoding produces different secret than encoded") @@ -368,10 +368,10 @@ func testGroup(t *testing.T, g kyber.Group, rand cipher.Stream) []kyber.Point { buf.Reset() p := pick(rand) if _, err := p.MarshalTo(buf); err != nil { - t.Fatalf("encoding of point fails: " + err.Error()) + t.Fatalf("encoding of point fails: %s", err) } if _, err := ptmp.UnmarshalFrom(buf); err != nil { - t.Fatalf("decoding of point fails: " + err.Error()) + t.Fatalf("decoding of point fails: %s", err.Error()) } if !ptmp.Equal(p) { diff --git a/pairing/bn254/gfp_decl.go b/pairing/bn254/gfp_decl.go index 21a7e21e6..63e6d930b 100644 --- a/pairing/bn254/gfp_decl.go +++ b/pairing/bn254/gfp_decl.go @@ -13,7 +13,7 @@ import ( //nolint:unused // maybe useful var hasBMI2 = cpu.X86.HasBMI2 -// go:noescape +//go:noescape func gfpNeg(c, a *gfP) //go:noescape diff --git a/pairing/bn254/point.go b/pairing/bn254/point.go index 0acd3cf0f..a5ff2087a 100644 --- a/pairing/bn254/point.go +++ b/pairing/bn254/point.go @@ -289,10 +289,11 @@ func mapToPoint(domain []byte, u *gfP) kyber.Point { // Borrowed from: https://github.com/kilic/bls12-381/blob/master/hash_to_field.go func expandMsgXmdKeccak256(domain, msg []byte, outLen int) []byte { h := sha3.NewLegacyKeccak256() - domainLen := uint8(len(domain)) - if domainLen > 255 { + if len(domain) > 255 { panic("invalid domain length") } + domainLen := uint8(len(domain)) + // DST_prime = DST || I2OSP(len(DST), 1) // b_0 = H(Z_pad || msg || l_i_b_str || I2OSP(0, 1) || DST_prime) _, _ = h.Write(make([]byte, h.BlockSize())) diff --git a/pairing/bn254/point_test.go b/pairing/bn254/point_test.go index 2275b996d..b9ed16723 100644 --- a/pairing/bn254/point_test.go +++ b/pairing/bn254/point_test.go @@ -199,10 +199,3 @@ func gnarkExpandMsgXmd(msg, dst []byte, lenInBytes int) ([]byte, error) { } return res, nil } - -func min(a, b int) int { - if a < b { - return a - } - return b -} diff --git a/util/test/test.go b/util/test/test.go index 1a6ffefdb..928e449bc 100644 --- a/util/test/test.go +++ b/util/test/test.go @@ -297,10 +297,10 @@ func testEncodingDecoding(t *testing.T, g kyber.Group, ptmp kyber.Point, stmp ky buf.Reset() s := g.Scalar().Pick(rand) if _, err := s.MarshalTo(buf); err != nil { - t.Errorf("encoding of secret fails: " + err.Error()) + t.Errorf("encoding of secret fails: %s", err.Error()) } if _, err := stmp.UnmarshalFrom(buf); err != nil { - t.Errorf("decoding of secret fails: " + err.Error()) + t.Errorf("decoding of secret fails: %s", err.Error()) } if !stmp.Equal(s) { t.Errorf("decoding produces different secret than encoded") @@ -309,10 +309,10 @@ func testEncodingDecoding(t *testing.T, g kyber.Group, ptmp kyber.Point, stmp ky buf.Reset() p := g.Point().Pick(rand) if _, err := p.MarshalTo(buf); err != nil { - t.Errorf("encoding of point fails: " + err.Error()) + t.Errorf("encoding of point fails: %s", err.Error()) } if _, err := ptmp.UnmarshalFrom(buf); err != nil { - t.Errorf("decoding of point fails: " + err.Error()) + t.Errorf("decoding of point fails: %s", err.Error()) } if !ptmp.Equal(p) { t.Errorf("decoding produces different point than encoded")