diff --git a/.golangci.yml b/.golangci.yml index 266d1de4..7e17e593 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -101,6 +101,8 @@ linters-settings: alias: mrand - pkg: github.com/consensys/gnark-crypto/ecc/bn254/ecdsa alias: ecdsa_bn254 + - pkg: github.com/strangelove-ventures/horcrux/signer/bn254 + alias: horcrux_bn254 maligned: suggest-new: true govet: diff --git a/cmd/horcrux/cmd/shards_test.go b/cmd/horcrux/cmd/shards_test.go index 05a895fc..e5ccc88c 100644 --- a/cmd/horcrux/cmd/shards_test.go +++ b/cmd/horcrux/cmd/shards_test.go @@ -167,6 +167,7 @@ func TestPrivValidatorBn254(t *testing.T) { var sigs = make([][]byte, len(shards)) for i, shard := range shards { + shard := shard signers[i], err = signer.NewThresholdSignerSoftBn254(&shard, 2, 3) require.NoError(t, err) diff --git a/signer/bn254/shamir.go b/signer/bn254/shamir.go index 78c2e6cf..e81c206d 100644 --- a/signer/bn254/shamir.go +++ b/signer/bn254/shamir.go @@ -46,7 +46,7 @@ func GenFromSecret(secret []byte, threshold uint8, total uint8) (Polynomial, Sha } func lagrangeCoeff(point int64, points ...int64) *big.Int { - var prodElements []*big.Int + var prodElements []*big.Int //nolint:prealloc for _, j := range points { if point == j { diff --git a/signer/bn254/threshold.go b/signer/bn254/threshold.go index e80d7c72..695495af 100644 --- a/signer/bn254/threshold.go +++ b/signer/bn254/threshold.go @@ -29,7 +29,9 @@ func init() { func CombinePublicKeys(pks []*bn254.G1Affine, evaluationPoints ...int64) *bn254.G1Affine { var sum = new(bn254.G1Affine) zeroG1Bz := zeroG1.Bytes() - sum.SetBytes(zeroG1Bz[:]) + if _, err := sum.SetBytes(zeroG1Bz[:]); err != nil { + panic(err) + } for i := 0; i < len(evaluationPoints); i++ { var inc = new(bn254.G1Affine) @@ -44,7 +46,9 @@ func CombinePublicKeys(pks []*bn254.G1Affine, evaluationPoints ...int64) *bn254. func CombineSignatures(signatures []*bn254.G2Affine, evaluationPoints ...int64) *bn254.G2Affine { var sum = new(bn254.G2Affine) zeroG2Bz := zeroG2.Bytes() - sum.SetBytes(zeroG2Bz[:]) + if _, err := sum.SetBytes(zeroG2Bz[:]); err != nil { + panic(err) + } var signatureIndex int for _, evaluationPoint := range evaluationPoints { diff --git a/signer/bn254/threshold_test.go b/signer/bn254/threshold_test.go index f1f0b149..d9b3af82 100644 --- a/signer/bn254/threshold_test.go +++ b/signer/bn254/threshold_test.go @@ -52,23 +52,23 @@ func TestThresholdBn254(t *testing.T) { digest := sha3.NewLegacyKeccak256().Sum(msg) - var signatures []*bn254.G2Affine - for _, shard := range shards { - signature, err := horcrux_bn254.SignWithShard(shard, digest[:]) + signatures := make([]*bn254.G2Affine, len(shards)) + for i, shard := range shards { + signature, err := horcrux_bn254.SignWithShard(shard, digest) require.NoError(t, err) var pubKey bn254.G1Affine pubKey.ScalarMultiplication(&horcrux_bn254.G1Gen, shard) - err = horcrux_bn254.VerifyShardSignature(&pubKey, digest[:], signature) + err = horcrux_bn254.VerifyShardSignature(&pubKey, digest, signature) require.NoError(t, err) - signatures = append(signatures, signature) + signatures[i] = signature } thresholdSignature := horcrux_bn254.CombineSignatures(signatures[:2], 1, 2) thresholdSignatureBz := thresholdSignature.Bytes() - valid := pubKey.VerifySignature(digest[:], thresholdSignatureBz[:]) + valid := pubKey.VerifySignature(digest, thresholdSignatureBz[:]) require.True(t, valid) } diff --git a/signer/cosigner_key.go b/signer/cosigner_key.go index 0424e843..62371f0f 100644 --- a/signer/cosigner_key.go +++ b/signer/cosigner_key.go @@ -8,9 +8,9 @@ import ( cometcrypto "github.com/cometbft/cometbft/crypto" cometcryptoed25519 "github.com/cometbft/cometbft/crypto/ed25519" - "github.com/strangelove-ventures/horcrux/signer/bn254" - "github.com/strangelove-ventures/horcrux/signer/encoding" - "github.com/strangelove-ventures/horcrux/signer/proto" + "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + "github.com/strangelove-ventures/horcrux/v3/signer/encoding" + "github.com/strangelove-ventures/horcrux/v3/signer/proto" "github.com/tendermint/go-amino" ) diff --git a/signer/cosigner_key_shares.go b/signer/cosigner_key_shares.go index fe8d4ba6..3efadc0e 100644 --- a/signer/cosigner_key_shares.go +++ b/signer/cosigner_key_shares.go @@ -12,7 +12,6 @@ import ( "github.com/cometbft/cometbft/privval" "github.com/ethereum/go-ethereum/crypto/ecies" "github.com/ethereum/go-ethereum/crypto/secp256k1" - "github.com/strangelove-ventures/horcrux/signer/bn254" horcrux_bn254 "github.com/strangelove-ventures/horcrux/signer/bn254" tsed25519 "gitlab.com/unit410/threshold-ed25519/pkg" "golang.org/x/sync/errgroup" @@ -35,7 +34,7 @@ func CreateCosignerShards(pv *privval.FilePVKey, threshold, shards uint8) ([]Cos switch pv.PrivKey.(type) { case cometcryptoed25519.PrivKey: return CreateCosignerEd25519Shards(pv, threshold, shards), nil - case bn254.PrivKey: + case horcrux_bn254.PrivKey: return CreateCosignerBn254Shards(pv, threshold, shards), nil default: return nil, ErrUnsupportedKeyType @@ -44,7 +43,10 @@ func CreateCosignerShards(pv *privval.FilePVKey, threshold, shards uint8) ([]Cos // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey func CreateCosignerEd25519Shards(pv *privval.FilePVKey, threshold, shards uint8) []CosignerKey { - privShards := tsed25519.DealShares(tsed25519.ExpandSecret(pv.PrivKey.(cometcryptoed25519.PrivKey).Bytes()[:32]), threshold, shards) + privShards := tsed25519.DealShares( + tsed25519.ExpandSecret(pv.PrivKey.(cometcryptoed25519.PrivKey).Bytes()[:32]), + threshold, shards, + ) out := make([]CosignerKey, shards) for i, shard := range privShards { out[i] = CosignerKey{ @@ -60,7 +62,6 @@ func CreateCosignerEd25519Shards(pv *privval.FilePVKey, threshold, shards uint8) // CreateCosignerEd25519Shards creates CosignerKey objects from a privval.FilePVKey func CreateCosignerBn254Shards(pv *privval.FilePVKey, threshold, shards uint8) []CosignerKey { _, privShards := horcrux_bn254.GenFromSecret(pv.PrivKey.Bytes(), threshold, shards) - //pks := horcrux_bn254.CreatePublicKeys(privShards) out := make([]CosignerKey, shards) for i, shard := range privShards { diff --git a/signer/encoding/codec.go b/signer/encoding/codec.go index ee58cd20..bdee34c6 100644 --- a/signer/encoding/codec.go +++ b/signer/encoding/codec.go @@ -7,8 +7,8 @@ import ( "github.com/cometbft/cometbft/crypto/ed25519" "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/cometbft/cometbft/libs/json" - "github.com/strangelove-ventures/horcrux/signer/bn254" - "github.com/strangelove-ventures/horcrux/signer/proto" + "github.com/strangelove-ventures/horcrux/v3/signer/bn254" + "github.com/strangelove-ventures/horcrux/v3/signer/proto" ) func init() {