From 311af35a51f4f9501bc9555a954179564e5dcc16 Mon Sep 17 00:00:00 2001 From: lauener Date: Sun, 18 Aug 2024 22:05:02 +0200 Subject: [PATCH 1/8] Update golangci-lint workflow --- .github/workflows/golangci-lint.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a18fe8de3..2cde2e58a 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.1 # 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" From 3cfe79eb61dd4b915c1c71353e21de3ff33f4cc4 Mon Sep 17 00:00:00 2001 From: lauener Date: Sun, 18 Aug 2024 22:09:50 +0200 Subject: [PATCH 2/8] Remove func min/max shadowing --- group/mod/int.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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) From 147dd90611de1a1342d2d411f4b9ec0fbd01c612 Mon Sep 17 00:00:00 2001 From: lauener Date: Sun, 18 Aug 2024 22:11:39 +0200 Subject: [PATCH 3/8] Remove min() redefinition --- pairing/bn254/point_test.go | 7 ------- 1 file changed, 7 deletions(-) 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 -} From 3440396f316ecdc907f14f8cf15e888465d6b262 Mon Sep 17 00:00:00 2001 From: lauener Date: Sun, 18 Aug 2024 22:13:24 +0200 Subject: [PATCH 4/8] Fix ineffectual compiler directive --- pairing/bn254/gfp_decl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 3d876afcf394607ce511172f9e5a9d850d85a978 Mon Sep 17 00:00:00 2001 From: lauener Date: Wed, 4 Sep 2024 10:34:35 +0200 Subject: [PATCH 5/8] Enable linter in Makefile --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f480eb391..f394c8f95 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.1 + @go mod tidy + golangci-lint run vet: tidy go vet ./... From 9eec7ef2f674a74acf4d52ea3a13fc01b07582fc Mon Sep 17 00:00:00 2001 From: lauener Date: Wed, 4 Sep 2024 10:42:20 +0200 Subject: [PATCH 6/8] Fix improper Errorf() usage --- pairing/bls12381/bls12381_test.go | 8 ++++---- util/test/test.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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/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") From 442b5a8871cbbf88ec6602a5e58a40ccb728546c Mon Sep 17 00:00:00 2001 From: lauener Date: Wed, 4 Sep 2024 10:48:59 +0200 Subject: [PATCH 7/8] Fix undetected uint8 overflow --- pairing/bn254/point.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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())) From 814694466c76f83f10b61322d3b9dc7447056c8f Mon Sep 17 00:00:00 2001 From: lauener Date: Wed, 4 Sep 2024 11:11:54 +0200 Subject: [PATCH 8/8] Update golangci version, avoid false positive SA1003 --- .github/workflows/golangci-lint.yml | 2 +- .golangci.yml | 1 + Makefile | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 2cde2e58a..bd624c384 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -26,7 +26,7 @@ jobs: # 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.60.1 + version: v1.60.3 # Optional: working directory, useful for monorepos # working-directory: somedir 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 f394c8f95..b71342497 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ generate: tidy # Coding style static check. lint: tidy - @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 + @go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3 @go mod tidy golangci-lint run