Skip to content

Commit b566d9b

Browse files
authored
Merge pull request #42 from onflow/bastian/go-1.26
Update to Go 1.26
2 parents e421d4b + c456e72 commit b566d9b

20 files changed

Lines changed: 138 additions & 74 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ on:
1111
- v[0-9]+.[0-9]+
1212

1313
env:
14-
GO_VERSION: "1.25"
15-
LINT_VERSION: "v2.4.0"
14+
GO_VERSION: "1.26"
15+
LINT_VERSION: "v2.12.2"
1616

1717
concurrency:
1818
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}

.golangci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ linters:
1010
- linters:
1111
- govet
1212
text: "unsafeptr" # disable flagging unsafeptr usage
13+
# ecdsa.go wraps crypto/ecdsa, whose Sign/Verify still consume the raw
14+
# PrivateKey.D and PublicKey.X/Y fields.
15+
# Go 1.26 deprecated direct access to those fields, but the recommended
16+
# replacement API (ecdsa.ParseRawPrivateKey / ParseUncompressedPublicKey /
17+
# (*PrivateKey).Bytes / (*PublicKey).Bytes) supports only the NIST curves and
18+
# rejects secp256k1, which this package supports via btcec's custom
19+
# elliptic.Curve, so the package has to keep using the low-level fields.
20+
- path: (^|/)ecdsa(_test)?\.go$
21+
linters:
22+
- staticcheck
23+
text: "SA1019"
1324
formatters:
1425
exclusions:
1526
paths:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Notes:
1010

1111
## Module import
1212

13-
🚧 Flow cryptography package is tested for Go version 1.25.
13+
🚧 Flow cryptography package is tested for Go version 1.26.
1414
It is recommended to not build the package with a later Go version.
1515
The package is not guaranteed to behave as expected with later Go versions. 🚧
1616

bls12381_utils_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestMapToG1(t *testing.T) {
176176
// Hashing to G1 bench
177177
func BenchmarkMapToG1(b *testing.B) {
178178
input := make([]byte, expandMsgOutput)
179-
for i := 0; i < len(input); i++ {
179+
for i := range input {
180180
input[i] = byte(i)
181181
}
182182
b.ResetTimer()
@@ -248,7 +248,7 @@ func TestReadWriteG1(t *testing.T) {
248248
// and compare it the original point
249249
t.Run("random points", func(t *testing.T) {
250250
iterations := 50
251-
for i := 0; i < iterations; i++ {
251+
for range iterations {
252252
var p, q pointE1
253253
_, err := prg.Read(seed)
254254
unsafeMapToG1(&p, seed)
@@ -326,7 +326,7 @@ func BenchmarkPairing(b *testing.B) {
326326

327327
pointsG1 := make([]pointE1, pairingsNumber)
328328
pointsG2 := make([]pointE2, pairingsNumber)
329-
for i := 0; i < pairingsNumber; i++ {
329+
for i := range pairingsNumber {
330330
unsafeMapToG1(&pointsG1[i], seed[i*frBytesLen:(i+1)*frBytesLen])
331331
unsafeMapToG2(&pointsG2[i], seed[i*frBytesLen:(i+1)*frBytesLen])
332332
}

bls_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func TestBLSPOP(t *testing.T) {
296296

297297
t.Run("PoP tests", func(t *testing.T) {
298298
loops := 10
299-
for j := 0; j < loops; j++ {
299+
for range loops {
300300
n, err := rand.Read(seed)
301301
require.Equal(t, n, KeyGenSeedMinLen)
302302
require.NoError(t, err)
@@ -360,7 +360,7 @@ func TestBLSAggregateSignatures(t *testing.T) {
360360
var aggSig, expectedSig Signature
361361

362362
// create the signatures
363-
for i := 0; i < sigsNum; i++ {
363+
for range sigsNum {
364364
sk := randomSK(t, rand)
365365
s, err := sk.Sign(input, kmac)
366366
require.NoError(t, err)
@@ -477,7 +477,7 @@ func TestBLSAggregatePublicKeys(t *testing.T) {
477477
sks := make([]PrivateKey, 0, pkNum)
478478

479479
// create the signatures
480-
for i := 0; i < pkNum; i++ {
480+
for range pkNum {
481481
sk := randomSK(t, rand)
482482
sks = append(sks, sk)
483483
pks = append(pks, sk.PublicKey())
@@ -599,7 +599,7 @@ func TestBLSRemovePubKeys(t *testing.T) {
599599
pks := make([]PublicKey, 0, pkNum)
600600

601601
// generate public keys
602-
for i := 0; i < pkNum; i++ {
602+
for range pkNum {
603603
sk := randomSK(t, rand)
604604
pks = append(pks, sk.PublicKey())
605605
}
@@ -695,7 +695,7 @@ func TestBLSBatchVerify(t *testing.T) {
695695
expectedValid := make([]bool, 0, sigsNum)
696696

697697
// create the signatures
698-
for i := 0; i < sigsNum; i++ {
698+
for range sigsNum {
699699
sk := randomSK(t, rand)
700700
s, err := sk.Sign(input, kmac)
701701
require.NoError(t, err)
@@ -761,7 +761,7 @@ func TestBLSBatchVerify(t *testing.T) {
761761
// generate a random permutation of indices to pick the
762762
// invalid signatures.
763763
indices := make([]int, 0, sigsNum)
764-
for i := 0; i < sigsNum; i++ {
764+
for i := range sigsNum {
765765
indices = append(indices, i)
766766
}
767767
rand.Shuffle(sigsNum, func(i, j int) {
@@ -770,7 +770,7 @@ func TestBLSBatchVerify(t *testing.T) {
770770

771771
// some signatures are invalid
772772
t.Run("some signatures are invalid", func(t *testing.T) {
773-
for i := 0; i < invalidSigsNum; i++ { // alter invalidSigsNum random signatures
773+
for i := range invalidSigsNum { // alter invalidSigsNum random signatures
774774
alterSignature(sigs[indices[i]])
775775
expectedValid[indices[i]] = false
776776
}
@@ -805,7 +805,7 @@ func TestBLSBatchVerify(t *testing.T) {
805805

806806
// test incorrect inputs
807807
t.Run("inconsistent inputs", func(t *testing.T) {
808-
for i := 0; i < sigsNum; i++ {
808+
for i := range sigsNum {
809809
expectedValid[i] = false
810810
}
811811
valid, err := BatchVerifyBLSSignaturesOneMessage(pks[:len(pks)-1], sigs, input, kmac)
@@ -816,7 +816,7 @@ func TestBLSBatchVerify(t *testing.T) {
816816

817817
// test wrong hasher
818818
t.Run("invalid hasher", func(t *testing.T) {
819-
for i := 0; i < sigsNum; i++ {
819+
for i := range sigsNum {
820820
expectedValid[i] = false
821821
}
822822
valid, err := BatchVerifyBLSSignaturesOneMessage(pks, sigs, input, nil)
@@ -828,7 +828,7 @@ func TestBLSBatchVerify(t *testing.T) {
828828

829829
// test wrong key
830830
t.Run("wrong key", func(t *testing.T) {
831-
for i := 0; i < sigsNum; i++ {
831+
for i := range sigsNum {
832832
expectedValid[i] = false
833833
}
834834
pks[0] = invalidSK(t).PublicKey()
@@ -870,7 +870,7 @@ func BenchmarkBatchVerify(b *testing.B) {
870870
seed := make([]byte, KeyGenSeedMinLen)
871871

872872
// create the signatures
873-
for i := 0; i < sigsNum; i++ {
873+
for range sigsNum {
874874
_, err := crand.Read(seed)
875875
require.NoError(b, err)
876876
sk, err := GeneratePrivateKey(BLSBLS12381, seed)
@@ -927,15 +927,15 @@ func TestBLSAggregateSignaturesManyMessages(t *testing.T) {
927927
keysNum := rand.Intn(sigsNum) + 1
928928
sks := make([]PrivateKey, 0, keysNum)
929929
// generate the keys
930-
for i := 0; i < keysNum; i++ {
930+
for range keysNum {
931931
sk := randomSK(t, rand)
932932
sks = append(sks, sk)
933933
}
934934

935935
// number of messages (could be larger or smaller than the number of keys)
936936
msgsNum := rand.Intn(sigsNum) + 1
937937
messages := make([][20]byte, msgsNum)
938-
for i := 0; i < msgsNum; i++ {
938+
for i := range msgsNum {
939939
_, err := rand.Read(messages[i][:])
940940
require.NoError(t, err)
941941
}
@@ -945,7 +945,7 @@ func TestBLSAggregateSignaturesManyMessages(t *testing.T) {
945945
inputKmacs := make([]hash.Hasher, 0, sigsNum)
946946

947947
// create the signatures
948-
for i := 0; i < sigsNum; i++ {
948+
for range sigsNum {
949949
kmac := NewExpandMsgXOFKMAC128("test tag")
950950
// pick a key randomly from the list
951951
skRand := rand.Intn(keysNum)
@@ -1041,7 +1041,7 @@ func TestBLSAggregateSignaturesManyMessages(t *testing.T) {
10411041
pks := make([]PublicKey, 0, N)
10421042
kmacs := make([]hash.Hasher, 0, N)
10431043
kmac := NewExpandMsgXOFKMAC128("test tag")
1044-
for i := 0; i < N; i++ {
1044+
for range N {
10451045
// distinct message
10461046
msg := make([]byte, 20)
10471047
msgs = append(msgs, msg)
@@ -1112,7 +1112,7 @@ func BenchmarkVerifySignatureManyMessages(b *testing.B) {
11121112
seed := make([]byte, KeyGenSeedMinLen)
11131113

11141114
// create the signatures
1115-
for i := 0; i < sigsNum; i++ {
1115+
for range sigsNum {
11161116
input := make([]byte, 100)
11171117
_, err := crand.Read(input)
11181118
require.NoError(b, err)
@@ -1155,7 +1155,7 @@ func BenchmarkAggregate(b *testing.B) {
11551155
pks := make([]PublicKey, 0, sigsNum)
11561156

11571157
// create the signatures
1158-
for i := 0; i < sigsNum; i++ {
1158+
for range sigsNum {
11591159
_, err := crand.Read(seed)
11601160
require.NoError(b, err)
11611161
sk, err := GeneratePrivateKey(BLSBLS12381, seed)

bls_thresholdsign_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func testCentralizedStatefulAPI(t *testing.T) {
6161
// hasher
6262
kmac := NewExpandMsgXOFKMAC128(thresholdSignatureTag)
6363
// fill the signers list and shuffle it
64-
for i := 0; i < n; i++ {
64+
for i := range n {
6565
signers = append(signers, i)
6666
}
6767
rand.Shuffle(n, func(i, j int) {
@@ -343,7 +343,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
343343
processors := make([]testDKGProcessor, 0, n)
344344

345345
// create n processors for all participants
346-
for current := 0; current < n; current++ {
346+
for current := range n {
347347
processors = append(processors, testDKGProcessor{
348348
current: current,
349349
chans: chans,
@@ -357,7 +357,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
357357
}
358358

359359
// create the participant (buffered) communication channels
360-
for i := 0; i < n; i++ {
360+
for i := range n {
361361
chans[i] = make(chan *message, 2*n)
362362
}
363363
// start DKG in all participants
@@ -366,7 +366,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
366366
require.Equal(t, read, KeyGenSeedMinLen)
367367
require.NoError(t, err)
368368
sync.Add(n)
369-
for current := 0; current < n; current++ {
369+
for current := range n {
370370
err := processors[current].dkg.Start(seed)
371371
require.NoError(t, err)
372372
go tsDkgRunChan(&processors[current], &sync, t, 2)
@@ -381,7 +381,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
381381
// Start TS
382382
log.Info("TS starts")
383383
sync.Add(n)
384-
for i := 0; i < n; i++ {
384+
for i := range n {
385385
go tsRunChan(&processors[i], &sync, t)
386386
}
387387
// synchronize the main thread to end TS
@@ -403,7 +403,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
403403
processors := make([]testDKGProcessor, 0, n)
404404

405405
// create n processors for all participants
406-
for current := 0; current < n; current++ {
406+
for current := range n {
407407
processors = append(processors, testDKGProcessor{
408408
current: current,
409409
chans: chans,
@@ -417,7 +417,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
417417
}
418418

419419
// create the participant (buffered) communication channels
420-
for i := 0; i < n; i++ {
420+
for i := range n {
421421
chans[i] = make(chan *message, 2*n)
422422
}
423423
// start DKG in all participants but the
@@ -426,7 +426,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
426426
require.Equal(t, read, KeyGenSeedMinLen)
427427
require.NoError(t, err)
428428
sync.Add(n)
429-
for current := 0; current < n; current++ {
429+
for current := range n {
430430
err := processors[current].dkg.Start(seed)
431431
require.NoError(t, err)
432432
go tsDkgRunChan(&processors[current], &sync, t, 0)
@@ -436,7 +436,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
436436
for phase := 1; phase <= 2; phase++ {
437437
sync.Wait()
438438
sync.Add(n)
439-
for current := 0; current < n; current++ {
439+
for current := range n {
440440
go tsDkgRunChan(&processors[current], &sync, t, phase)
441441
}
442442
}
@@ -451,7 +451,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
451451
// Start TS
452452
log.Info("TS starts")
453453
sync.Add(n)
454-
for current := 0; current < n; current++ {
454+
for current := range n {
455455
go tsRunChan(&processors[current], &sync, t)
456456
}
457457
// synchronize the main thread to end TS
@@ -577,7 +577,7 @@ func testCentralizedStatelessAPI(t *testing.T) {
577577
signShares := make([]Signature, 0, n)
578578
signers := make([]int, 0, n)
579579
// fill the signers list and shuffle it
580-
for i := 0; i < n; i++ {
580+
for i := range n {
581581
signers = append(signers, i)
582582
}
583583
rand.Shuffle(n, func(i, j int) {

common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func overwrite(data []byte) {
4545
_, err := rand.Read(data) // checking err is enough
4646
if err != nil {
4747
// zero the buffer if randomizing failed
48-
for i := 0; i < len(data); i++ {
48+
for i := range data {
4949
data[i] = 0
5050
}
5151
}
@@ -63,7 +63,7 @@ func (e invalidInputsError) Unwrap() error {
6363
}
6464

6565
// invalidInputsErrorf constructs a new invalidInputsError
66-
func invalidInputsErrorf(msg string, args ...interface{}) error {
66+
func invalidInputsErrorf(msg string, args ...any) error {
6767
return &invalidInputsError{
6868
error: fmt.Errorf(msg, args...),
6969
}
@@ -97,7 +97,7 @@ func (e invalidHasherSizeError) Unwrap() error {
9797
}
9898

9999
// invalidHasherSizeErrorf constructs a new invalidHasherSizeError
100-
func invalidHasherSizeErrorf(msg string, args ...interface{}) error {
100+
func invalidHasherSizeErrorf(msg string, args ...any) error {
101101
return &invalidHasherSizeError{
102102
error: fmt.Errorf(msg, args...),
103103
}

dkg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ type dkgFailureError struct {
9898
}
9999

100100
// dkgFailureErrorf constructs a new dkgFailureError
101-
func dkgFailureErrorf(msg string, args ...interface{}) error {
101+
func dkgFailureErrorf(msg string, args ...any) error {
102102
return &dkgFailureError{
103103
error: fmt.Errorf(msg, args...),
104104
}
@@ -121,7 +121,7 @@ func (e dkgInvalidStateTransitionError) Unwrap() error {
121121
}
122122

123123
// dkgInvalidStateTransitionErrorf constructs a new dkgInvalidStateTransitionError
124-
func dkgInvalidStateTransitionErrorf(msg string, args ...interface{}) error {
124+
func dkgInvalidStateTransitionErrorf(msg string, args ...any) error {
125125
return &dkgInvalidStateTransitionError{
126126
error: fmt.Errorf(msg, args...),
127127
}

0 commit comments

Comments
 (0)