Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Dec 21, 2023
1 parent 778c5f9 commit 40daed9
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions cmd/horcrux/cmd/shards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion signer/bn254/shamir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions signer/bn254/threshold.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions signer/bn254/threshold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions signer/cosigner_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
9 changes: 5 additions & 4 deletions signer/cosigner_key_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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{
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions signer/encoding/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 40daed9

Please sign in to comment.