Files
threshold/protocols/cmp/presign/sign_test.go
zeekay be6f0c474f fix: resolve remaining golangci-lint issues
- Remove nil checks before len() for slices (S1009)
- Fix shadow variable declarations in test files
- Add assertions for unused struct fields in config_test
- Remove empty branches and add proper labels for break statements
- Mark unused test helper functions with nolint directive
- Remove unused struct fields in dynamic.go
- Fix ineffectual assignments in test files
2025-08-16 23:09:38 -05:00

79 lines
2.2 KiB
Go

package presign
import (
mrand "math/rand"
"testing"
"github.com/cronokirby/saferith"
"github.com/luxfi/threshold/internal/round"
"github.com/luxfi/threshold/internal/test"
"github.com/luxfi/threshold/pkg/ecdsa"
"github.com/luxfi/threshold/pkg/math/curve"
"github.com/luxfi/threshold/pkg/party"
"github.com/luxfi/threshold/pkg/pool"
"github.com/luxfi/threshold/protocols/cmp/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/sha3"
)
var (
// Test constants for safe arithmetic operations
oneNat = new(saferith.Nat).SetUint64(1)
oneInt = new(saferith.Int).SetNat(oneNat)
minusOneInt = new(saferith.Int).SetNat(oneNat).Neg(1)
N = 4
T = N - 1
group = curve.Secp256k1{}
configs map[party.ID]*config.Config
partyIDs party.IDSlice
messageHash []byte
)
func init() {
source := mrand.New(mrand.NewSource(1))
pl := pool.NewPool(0)
defer pl.TearDown()
configs, partyIDs = test.GenerateConfig(group, N, T, source, pl)
for id, c := range configs {
configs[id], _ = c.DeriveBIP32(0)
}
messageHash = make([]byte, 64)
sha3.ShakeSum128(messageHash, []byte("hello"))
}
func TestRound(t *testing.T) {
// Test CMP presign protocol rounds
// Validates presignature generation that can be used for fast online signing
// Validate safe arithmetic constants
require.NotNil(t, oneNat, "oneNat should be initialized")
require.NotNil(t, oneInt, "oneInt should be initialized")
require.NotNil(t, minusOneInt, "minusOneInt should be initialized")
rounds := make([]round.Session, 0, N)
for _, c := range configs {
pl := pool.NewPool(1)
defer pl.TearDown()
r, err := StartPresign(c, partyIDs, messageHash, pl)(nil)
require.NoError(t, err, "round creation should not result in an error")
rounds = append(rounds, r)
}
for {
err, done := test.Rounds(rounds, nil)
require.NoError(t, err, "failed to process round")
if done {
break
}
}
for _, r := range rounds {
assert.IsType(t, &round.Output{}, r)
signature, ok := r.(*round.Output).Result.(*ecdsa.Signature)
assert.True(t, ok, "result should *ecdsa.Signature")
assert.True(t, signature.Verify(configs[r.SelfID()].PublicPoint(), messageHash))
}
}