Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ on:
- v[0-9]+.[0-9]+

env:
GO_VERSION: "1.25"
LINT_VERSION: "v2.4.0"
GO_VERSION: "1.26"
LINT_VERSION: "v2.12.2"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
Expand Down
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ linters:
- linters:
- govet
text: "unsafeptr" # disable flagging unsafeptr usage
# ecdsa.go wraps crypto/ecdsa, whose Sign/Verify still consume the raw
# PrivateKey.D and PublicKey.X/Y fields.
# Go 1.26 deprecated direct access to those fields, but the recommended
# replacement API (ecdsa.ParseRawPrivateKey / ParseUncompressedPublicKey /
# (*PrivateKey).Bytes / (*PublicKey).Bytes) supports only the NIST curves and
# rejects secp256k1, which this package supports via btcec's custom
# elliptic.Curve, so the package has to keep using the low-level fields.
- path: (^|/)ecdsa(_test)?\.go$
linters:
- staticcheck
text: "SA1019"
formatters:
exclusions:
paths:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Notes:

## Module import

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

Expand Down
6 changes: 3 additions & 3 deletions bls12381_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func TestMapToG1(t *testing.T) {
// Hashing to G1 bench
func BenchmarkMapToG1(b *testing.B) {
input := make([]byte, expandMsgOutput)
for i := 0; i < len(input); i++ {
for i := range input {
input[i] = byte(i)
}
b.ResetTimer()
Expand Down Expand Up @@ -248,7 +248,7 @@ func TestReadWriteG1(t *testing.T) {
// and compare it the original point
t.Run("random points", func(t *testing.T) {
iterations := 50
for i := 0; i < iterations; i++ {
for range iterations {
var p, q pointE1
_, err := prg.Read(seed)
unsafeMapToG1(&p, seed)
Expand Down Expand Up @@ -326,7 +326,7 @@ func BenchmarkPairing(b *testing.B) {

pointsG1 := make([]pointE1, pairingsNumber)
pointsG2 := make([]pointE2, pairingsNumber)
for i := 0; i < pairingsNumber; i++ {
for i := range pairingsNumber {
unsafeMapToG1(&pointsG1[i], seed[i*frBytesLen:(i+1)*frBytesLen])
unsafeMapToG2(&pointsG2[i], seed[i*frBytesLen:(i+1)*frBytesLen])
}
Expand Down
34 changes: 17 additions & 17 deletions bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestBLSPOP(t *testing.T) {

t.Run("PoP tests", func(t *testing.T) {
loops := 10
for j := 0; j < loops; j++ {
for range loops {
n, err := rand.Read(seed)
require.Equal(t, n, KeyGenSeedMinLen)
require.NoError(t, err)
Expand Down Expand Up @@ -360,7 +360,7 @@ func TestBLSAggregateSignatures(t *testing.T) {
var aggSig, expectedSig Signature

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

// create the signatures
for i := 0; i < pkNum; i++ {
for range pkNum {
sk := randomSK(t, rand)
sks = append(sks, sk)
pks = append(pks, sk.PublicKey())
Expand Down Expand Up @@ -599,7 +599,7 @@ func TestBLSRemovePubKeys(t *testing.T) {
pks := make([]PublicKey, 0, pkNum)

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

// create the signatures
for i := 0; i < sigsNum; i++ {
for range sigsNum {
sk := randomSK(t, rand)
s, err := sk.Sign(input, kmac)
require.NoError(t, err)
Expand Down Expand Up @@ -761,7 +761,7 @@ func TestBLSBatchVerify(t *testing.T) {
// generate a random permutation of indices to pick the
// invalid signatures.
indices := make([]int, 0, sigsNum)
for i := 0; i < sigsNum; i++ {
for i := range sigsNum {
indices = append(indices, i)
}
rand.Shuffle(sigsNum, func(i, j int) {
Expand All @@ -770,7 +770,7 @@ func TestBLSBatchVerify(t *testing.T) {

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

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

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

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

// create the signatures
for i := 0; i < sigsNum; i++ {
for range sigsNum {
_, err := crand.Read(seed)
require.NoError(b, err)
sk, err := GeneratePrivateKey(BLSBLS12381, seed)
Expand Down Expand Up @@ -927,15 +927,15 @@ func TestBLSAggregateSignaturesManyMessages(t *testing.T) {
keysNum := rand.Intn(sigsNum) + 1
sks := make([]PrivateKey, 0, keysNum)
// generate the keys
for i := 0; i < keysNum; i++ {
for range keysNum {
sk := randomSK(t, rand)
sks = append(sks, sk)
}

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

// create the signatures
for i := 0; i < sigsNum; i++ {
for range sigsNum {
kmac := NewExpandMsgXOFKMAC128("test tag")
// pick a key randomly from the list
skRand := rand.Intn(keysNum)
Expand Down Expand Up @@ -1041,7 +1041,7 @@ func TestBLSAggregateSignaturesManyMessages(t *testing.T) {
pks := make([]PublicKey, 0, N)
kmacs := make([]hash.Hasher, 0, N)
kmac := NewExpandMsgXOFKMAC128("test tag")
for i := 0; i < N; i++ {
for range N {
// distinct message
msg := make([]byte, 20)
msgs = append(msgs, msg)
Expand Down Expand Up @@ -1112,7 +1112,7 @@ func BenchmarkVerifySignatureManyMessages(b *testing.B) {
seed := make([]byte, KeyGenSeedMinLen)

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

// create the signatures
for i := 0; i < sigsNum; i++ {
for range sigsNum {
_, err := crand.Read(seed)
require.NoError(b, err)
sk, err := GeneratePrivateKey(BLSBLS12381, seed)
Expand Down
22 changes: 11 additions & 11 deletions bls_thresholdsign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func testCentralizedStatefulAPI(t *testing.T) {
// hasher
kmac := NewExpandMsgXOFKMAC128(thresholdSignatureTag)
// fill the signers list and shuffle it
for i := 0; i < n; i++ {
for i := range n {
signers = append(signers, i)
}
rand.Shuffle(n, func(i, j int) {
Expand Down Expand Up @@ -343,7 +343,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
processors := make([]testDKGProcessor, 0, n)

// create n processors for all participants
for current := 0; current < n; current++ {
for current := range n {
processors = append(processors, testDKGProcessor{
current: current,
chans: chans,
Expand All @@ -357,7 +357,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
}

// create the participant (buffered) communication channels
for i := 0; i < n; i++ {
for i := range n {
chans[i] = make(chan *message, 2*n)
}
// start DKG in all participants
Expand All @@ -366,7 +366,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
require.Equal(t, read, KeyGenSeedMinLen)
require.NoError(t, err)
sync.Add(n)
for current := 0; current < n; current++ {
for current := range n {
err := processors[current].dkg.Start(seed)
require.NoError(t, err)
go tsDkgRunChan(&processors[current], &sync, t, 2)
Expand All @@ -381,7 +381,7 @@ func testDistributedStatefulAPI_FeldmanVSS(t *testing.T) {
// Start TS
log.Info("TS starts")
sync.Add(n)
for i := 0; i < n; i++ {
for i := range n {
go tsRunChan(&processors[i], &sync, t)
}
// synchronize the main thread to end TS
Expand All @@ -403,7 +403,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
processors := make([]testDKGProcessor, 0, n)

// create n processors for all participants
for current := 0; current < n; current++ {
for current := range n {
processors = append(processors, testDKGProcessor{
current: current,
chans: chans,
Expand All @@ -417,7 +417,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
}

// create the participant (buffered) communication channels
for i := 0; i < n; i++ {
for i := range n {
chans[i] = make(chan *message, 2*n)
}
// start DKG in all participants but the
Expand All @@ -426,7 +426,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
require.Equal(t, read, KeyGenSeedMinLen)
require.NoError(t, err)
sync.Add(n)
for current := 0; current < n; current++ {
for current := range n {
err := processors[current].dkg.Start(seed)
require.NoError(t, err)
go tsDkgRunChan(&processors[current], &sync, t, 0)
Expand All @@ -436,7 +436,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
for phase := 1; phase <= 2; phase++ {
sync.Wait()
sync.Add(n)
for current := 0; current < n; current++ {
for current := range n {
go tsDkgRunChan(&processors[current], &sync, t, phase)
}
}
Expand All @@ -451,7 +451,7 @@ func testDistributedStatefulAPI_JointFeldman(t *testing.T) {
// Start TS
log.Info("TS starts")
sync.Add(n)
for current := 0; current < n; current++ {
for current := range n {
go tsRunChan(&processors[current], &sync, t)
}
// synchronize the main thread to end TS
Expand Down Expand Up @@ -577,7 +577,7 @@ func testCentralizedStatelessAPI(t *testing.T) {
signShares := make([]Signature, 0, n)
signers := make([]int, 0, n)
// fill the signers list and shuffle it
for i := 0; i < n; i++ {
for i := range n {
signers = append(signers, i)
}
rand.Shuffle(n, func(i, j int) {
Expand Down
6 changes: 3 additions & 3 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func overwrite(data []byte) {
_, err := rand.Read(data) // checking err is enough
if err != nil {
// zero the buffer if randomizing failed
for i := 0; i < len(data); i++ {
for i := range data {
data[i] = 0
}
}
Expand All @@ -63,7 +63,7 @@ func (e invalidInputsError) Unwrap() error {
}

// invalidInputsErrorf constructs a new invalidInputsError
func invalidInputsErrorf(msg string, args ...interface{}) error {
func invalidInputsErrorf(msg string, args ...any) error {
return &invalidInputsError{
error: fmt.Errorf(msg, args...),
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (e invalidHasherSizeError) Unwrap() error {
}

// invalidHasherSizeErrorf constructs a new invalidHasherSizeError
func invalidHasherSizeErrorf(msg string, args ...interface{}) error {
func invalidHasherSizeErrorf(msg string, args ...any) error {
return &invalidHasherSizeError{
error: fmt.Errorf(msg, args...),
}
Expand Down
4 changes: 2 additions & 2 deletions dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type dkgFailureError struct {
}

// dkgFailureErrorf constructs a new dkgFailureError
func dkgFailureErrorf(msg string, args ...interface{}) error {
func dkgFailureErrorf(msg string, args ...any) error {
return &dkgFailureError{
error: fmt.Errorf(msg, args...),
}
Expand All @@ -121,7 +121,7 @@ func (e dkgInvalidStateTransitionError) Unwrap() error {
}

// dkgInvalidStateTransitionErrorf constructs a new dkgInvalidStateTransitionError
func dkgInvalidStateTransitionErrorf(msg string, args ...interface{}) error {
func dkgInvalidStateTransitionErrorf(msg string, args ...any) error {
return &dkgInvalidStateTransitionError{
error: fmt.Errorf(msg, args...),
}
Expand Down
Loading
Loading