From 321dd524fff0dcbe31100bb62df946452a2961b6 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Fri, 13 Dec 2024 14:05:32 -0500 Subject: [PATCH 01/56] Move local-signer to its own package --- network/peer/test_peer.go | 4 +- network/test_network.go | 4 +- snow/snowtest/context.go | 4 +- utils/crypto/bls/ciphersuite.go | 9 + utils/crypto/bls/public.go | 4 +- utils/crypto/bls/secret.go | 85 -------- utils/crypto/bls/signature.go | 12 +- utils/crypto/bls/signer.go | 10 + utils/crypto/bls/signers/local/local.go | 74 +++++++ .../bls/{ => test}/bls_benchmark_test.go | 42 ++-- utils/crypto/bls/{ => test}/bls_test.go | 188 +++++++++--------- utils/crypto/bls/{ => test}/public_test.go | 26 +-- utils/crypto/bls/{ => test}/signature_test.go | 18 +- .../{secret_test.go => test/signer_test.go} | 17 +- 14 files changed, 257 insertions(+), 240 deletions(-) create mode 100644 utils/crypto/bls/ciphersuite.go delete mode 100644 utils/crypto/bls/secret.go create mode 100644 utils/crypto/bls/signer.go create mode 100644 utils/crypto/bls/signers/local/local.go rename utils/crypto/bls/{ => test}/bls_benchmark_test.go (69%) rename utils/crypto/bls/{ => test}/bls_test.go (61%) rename utils/crypto/bls/{ => test}/public_test.go (52%) rename utils/crypto/bls/{ => test}/signature_test.go (61%) rename utils/crypto/bls/{secret_test.go => test/signer_test.go} (62%) diff --git a/network/peer/test_peer.go b/network/peer/test_peer.go index bd40196ebfd5..6803efb5f043 100644 --- a/network/peer/test_peer.go +++ b/network/peer/test_peer.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" @@ -101,7 +101,7 @@ func StartTestPeer( } tlsKey := tlsCert.PrivateKey.(crypto.Signer) - blsKey, err := bls.NewSigner() + blsKey, err := local.NewSigner() if err != nil { return nil, err } diff --git a/network/test_network.go b/network/test_network.go index 2e00f4bb9449..465492ebb426 100644 --- a/network/test_network.go +++ b/network/test_network.go @@ -28,7 +28,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" @@ -84,7 +84,7 @@ func NewTestNetworkConfig( return nil, err } - blsKey, err := bls.NewSigner() + blsKey, err := local.NewSigner() if err != nil { return nil, err } diff --git a/snow/snowtest/context.go b/snow/snowtest/context.go index 36af84e5c79c..4f66f682ecaa 100644 --- a/snow/snowtest/context.go +++ b/snow/snowtest/context.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" "github.com/ava-labs/avalanchego/utils/logging" ) @@ -52,7 +52,7 @@ func ConsensusContext(ctx *snow.Context) *snow.ConsensusContext { func Context(tb testing.TB, chainID ids.ID) *snow.Context { require := require.New(tb) - secretKey, err := bls.NewSigner() + secretKey, err := local.NewSigner() require.NoError(err) publicKey := secretKey.PublicKey() diff --git a/utils/crypto/bls/ciphersuite.go b/utils/crypto/bls/ciphersuite.go new file mode 100644 index 000000000000..1c48eb1a7273 --- /dev/null +++ b/utils/crypto/bls/ciphersuite.go @@ -0,0 +1,9 @@ +package bls + +var ( + // The ciphersuite is more commonly known as G2ProofOfPossession. + // There are two digests to ensure that message space for normal + // signatures and the proof of possession are distinct. + CiphersuiteSignature = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") + CiphersuiteProofOfPossession = []byte("BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") +) diff --git a/utils/crypto/bls/public.go b/utils/crypto/bls/public.go index e6d5aa6a7198..f30b4402ca77 100644 --- a/utils/crypto/bls/public.go +++ b/utils/crypto/bls/public.go @@ -74,7 +74,7 @@ func AggregatePublicKeys(pks []*PublicKey) (*PublicKey, error) { // The [sig] and [pk] may have been an aggregation of other signatures and keys. // Invariant: [pk] and [sig] have both been validated. func Verify(pk *PublicKey, sig *Signature, msg []byte) bool { - return sig.Verify(false, pk, false, msg, ciphersuiteSignature) + return sig.Verify(false, pk, false, msg, CiphersuiteSignature) } // Verify the possession of the secret pre-image of [sk] by verifying a [sig] of @@ -82,5 +82,5 @@ func Verify(pk *PublicKey, sig *Signature, msg []byte) bool { // The [sig] and [pk] may have been an aggregation of other signatures and keys. // Invariant: [pk] and [sig] have both been validated. func VerifyProofOfPossession(pk *PublicKey, sig *Signature, msg []byte) bool { - return sig.Verify(false, pk, false, msg, ciphersuiteProofOfPossession) + return sig.Verify(false, pk, false, msg, CiphersuiteProofOfPossession) } diff --git a/utils/crypto/bls/secret.go b/utils/crypto/bls/secret.go deleted file mode 100644 index 540126cae23d..000000000000 --- a/utils/crypto/bls/secret.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package bls - -import ( - "crypto/rand" - "errors" - "runtime" - - blst "github.com/supranational/blst/bindings/go" -) - -const SecretKeyLen = blst.BLST_SCALAR_BYTES - -var ( - errFailedSecretKeyDeserialize = errors.New("couldn't deserialize secret key") - - // The ciphersuite is more commonly known as G2ProofOfPossession. - // There are two digests to ensure that message space for normal - // signatures and the proof of possession are distinct. - ciphersuiteSignature = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") - ciphersuiteProofOfPossession = []byte("BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") - _ Signer = (*LocalSigner)(nil) -) - -type SecretKey = blst.SecretKey - -type Signer interface { - PublicKey() *PublicKey - Sign(msg []byte) *Signature - SignProofOfPossession(msg []byte) *Signature -} - -type LocalSigner struct { - sk *SecretKey -} - -// NewSecretKey generates a new secret key from the local source of -// cryptographically secure randomness. -func NewSigner() (*LocalSigner, error) { - var ikm [32]byte - _, err := rand.Read(ikm[:]) - if err != nil { - return nil, err - } - sk := blst.KeyGen(ikm[:]) - ikm = [32]byte{} // zero out the ikm - - return &LocalSigner{sk: sk}, nil -} - -// ToBytes returns the big-endian format of the secret key. -func (s *LocalSigner) ToBytes() []byte { - return s.sk.Serialize() -} - -// SecretKeyFromBytes parses the big-endian format of the secret key into a -// secret key. -func SecretKeyFromBytes(skBytes []byte) (*LocalSigner, error) { - sk := new(SecretKey).Deserialize(skBytes) - if sk == nil { - return nil, errFailedSecretKeyDeserialize - } - runtime.SetFinalizer(sk, func(sk *SecretKey) { - sk.Zeroize() - }) - return &LocalSigner{sk: sk}, nil -} - -// PublicKey returns the public key that corresponds to this secret -// key. -func (s *LocalSigner) PublicKey() *PublicKey { - return new(PublicKey).From(s.sk) -} - -// Sign [msg] to authorize this message -func (s *LocalSigner) Sign(msg []byte) *Signature { - return new(Signature).Sign(s.sk, msg, ciphersuiteSignature) -} - -// Sign [msg] to prove the ownership -func (s *LocalSigner) SignProofOfPossession(msg []byte) *Signature { - return new(Signature).Sign(s.sk, msg, ciphersuiteProofOfPossession) -} diff --git a/utils/crypto/bls/signature.go b/utils/crypto/bls/signature.go index 0d0d029b796e..51a3c11f0da6 100644 --- a/utils/crypto/bls/signature.go +++ b/utils/crypto/bls/signature.go @@ -13,9 +13,9 @@ const SignatureLen = blst.BLST_P2_COMPRESS_BYTES var ( ErrFailedSignatureDecompress = errors.New("couldn't decompress signature") - errInvalidSignature = errors.New("invalid signature") - errNoSignatures = errors.New("no signatures") - errFailedSignatureAggregation = errors.New("couldn't aggregate signatures") + ErrInvalidSignature = errors.New("invalid signature") + ErrNoSignatures = errors.New("no signatures") + ErrFailedSignatureAggregation = errors.New("couldn't aggregate signatures") ) type ( @@ -36,7 +36,7 @@ func SignatureFromBytes(sigBytes []byte) (*Signature, error) { return nil, ErrFailedSignatureDecompress } if !sig.SigValidate(false) { - return nil, errInvalidSignature + return nil, ErrInvalidSignature } return sig, nil } @@ -46,12 +46,12 @@ func SignatureFromBytes(sigBytes []byte) (*Signature, error) { // Invariant: all [sigs] have been validated. func AggregateSignatures(sigs []*Signature) (*Signature, error) { if len(sigs) == 0 { - return nil, errNoSignatures + return nil, ErrNoSignatures } var agg AggregateSignature if !agg.Aggregate(sigs, false) { - return nil, errFailedSignatureAggregation + return nil, ErrFailedSignatureAggregation } return agg.ToAffine(), nil } diff --git a/utils/crypto/bls/signer.go b/utils/crypto/bls/signer.go new file mode 100644 index 000000000000..40c5a79cfba6 --- /dev/null +++ b/utils/crypto/bls/signer.go @@ -0,0 +1,10 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package bls + +type Signer interface { + PublicKey() *PublicKey + Sign(msg []byte) *Signature + SignProofOfPossession(msg []byte) *Signature +} diff --git a/utils/crypto/bls/signers/local/local.go b/utils/crypto/bls/signers/local/local.go new file mode 100644 index 000000000000..4c59daebdebc --- /dev/null +++ b/utils/crypto/bls/signers/local/local.go @@ -0,0 +1,74 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package local + +import ( + "crypto/rand" + "errors" + "runtime" + + "github.com/ava-labs/avalanchego/utils/crypto/bls" // Import the parent package + blst "github.com/supranational/blst/bindings/go" +) + +const SecretKeyLen = blst.BLST_SCALAR_BYTES + +var ( + ErrFailedSecretKeyDeserialize = errors.New("couldn't deserialize secret key") + _ bls.Signer = (*LocalSigner)(nil) // Use the Signer interface from the parent package +) + +type secretKey = blst.SecretKey + +type LocalSigner struct { + sk *secretKey +} + +// NewSecretKey generates a new secret key from the local source of +// cryptographically secure randomness. +func NewSigner() (*LocalSigner, error) { + var ikm [32]byte + _, err := rand.Read(ikm[:]) + if err != nil { + return nil, err + } + sk := blst.KeyGen(ikm[:]) + ikm = [32]byte{} // zero out the ikm + + return &LocalSigner{sk: sk}, nil +} + +// ToBytes returns the big-endian format of the secret key. +func (s *LocalSigner) ToBytes() []byte { + return s.sk.Serialize() +} + +// SecretKeyFromBytes parses the big-endian format of the secret key into a +// secret key. +func SecretKeyFromBytes(skBytes []byte) (*LocalSigner, error) { + sk := new(secretKey).Deserialize(skBytes) + if sk == nil { + return nil, ErrFailedSecretKeyDeserialize + } + runtime.SetFinalizer(sk, func(sk *secretKey) { + sk.Zeroize() + }) + return &LocalSigner{sk: sk}, nil +} + +// PublicKey returns the public key that corresponds to this secret +// key. +func (s *LocalSigner) PublicKey() *bls.PublicKey { + return new(bls.PublicKey).From(s.sk) +} + +// Sign [msg] to authorize this message +func (s *LocalSigner) Sign(msg []byte) *bls.Signature { + return new(bls.Signature).Sign(s.sk, msg, bls.CiphersuiteSignature) +} + +// Sign [msg] to prove the ownership +func (s *LocalSigner) SignProofOfPossession(msg []byte) *bls.Signature { + return new(bls.Signature).Sign(s.sk, msg, bls.CiphersuiteProofOfPossession) +} diff --git a/utils/crypto/bls/bls_benchmark_test.go b/utils/crypto/bls/test/bls_benchmark_test.go similarity index 69% rename from utils/crypto/bls/bls_benchmark_test.go rename to utils/crypto/bls/test/bls_benchmark_test.go index 71a80044154f..d05836bb2d5b 100644 --- a/utils/crypto/bls/bls_benchmark_test.go +++ b/utils/crypto/bls/test/bls_benchmark_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls +package bls_test import ( "strconv" @@ -10,6 +10,8 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" ) var ( @@ -35,7 +37,7 @@ var ( ) func BenchmarkSign(b *testing.B) { - privateKey, err := NewSigner() + privateKey, err := local.NewSigner() require.NoError(b, err) for _, messageSize := range sizes { b.Run(strconv.Itoa(messageSize), func(b *testing.B) { @@ -51,7 +53,7 @@ func BenchmarkSign(b *testing.B) { } func BenchmarkVerify(b *testing.B) { - privateKey, err := NewSigner() + privateKey, err := local.NewSigner() require.NoError(b, err) publicKey := privateKey.PublicKey() @@ -63,16 +65,16 @@ func BenchmarkVerify(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - require.True(b, Verify(publicKey, signature, message)) + require.True(b, bls.Verify(publicKey, signature, message)) } }) } } func BenchmarkAggregatePublicKeys(b *testing.B) { - keys := make([]*PublicKey, biggestSize) + keys := make([]*bls.PublicKey, biggestSize) for i := range keys { - privateKey, err := NewSigner() + privateKey, err := local.NewSigner() require.NoError(b, err) keys[i] = privateKey.PublicKey() @@ -81,7 +83,7 @@ func BenchmarkAggregatePublicKeys(b *testing.B) { for _, size := range sizes { b.Run(strconv.Itoa(size), func(b *testing.B) { for n := 0; n < b.N; n++ { - _, err := AggregatePublicKeys(keys[:size]) + _, err := bls.AggregatePublicKeys(keys[:size]) require.NoError(b, err) } }) @@ -89,65 +91,65 @@ func BenchmarkAggregatePublicKeys(b *testing.B) { } func BenchmarkPublicKeyToCompressedBytes(b *testing.B) { - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(b, err) pk := sk.PublicKey() b.ResetTimer() for range b.N { - PublicKeyToCompressedBytes(pk) + bls.PublicKeyToCompressedBytes(pk) } } func BenchmarkPublicKeyFromCompressedBytes(b *testing.B) { - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(b, err) pk := sk.PublicKey() - pkBytes := PublicKeyToCompressedBytes(pk) + pkBytes := bls.PublicKeyToCompressedBytes(pk) b.ResetTimer() for range b.N { - _, _ = PublicKeyFromCompressedBytes(pkBytes) + _, _ = bls.PublicKeyFromCompressedBytes(pkBytes) } } func BenchmarkPublicKeyToUncompressedBytes(b *testing.B) { - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(b, err) pk := sk.PublicKey() b.ResetTimer() for range b.N { - PublicKeyToUncompressedBytes(pk) + bls.PublicKeyToUncompressedBytes(pk) } } func BenchmarkPublicKeyFromValidUncompressedBytes(b *testing.B) { - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(b, err) pk := sk.PublicKey() - pkBytes := PublicKeyToUncompressedBytes(pk) + pkBytes := bls.PublicKeyToUncompressedBytes(pk) b.ResetTimer() for range b.N { - _ = PublicKeyFromValidUncompressedBytes(pkBytes) + _ = bls.PublicKeyFromValidUncompressedBytes(pkBytes) } } func BenchmarkSignatureFromBytes(b *testing.B) { - privateKey, err := NewSigner() + privateKey, err := local.NewSigner() require.NoError(b, err) message := utils.RandomBytes(32) signature := privateKey.Sign(message) - signatureBytes := SignatureToBytes(signature) + signatureBytes := bls.SignatureToBytes(signature) b.ResetTimer() for range b.N { - _, _ = SignatureFromBytes(signatureBytes) + _, _ = bls.SignatureFromBytes(signatureBytes) } } diff --git a/utils/crypto/bls/bls_test.go b/utils/crypto/bls/test/bls_test.go similarity index 61% rename from utils/crypto/bls/bls_test.go rename to utils/crypto/bls/test/bls_test.go index 9d09d6aebfae..f85cb104cd0c 100644 --- a/utils/crypto/bls/bls_test.go +++ b/utils/crypto/bls/test/bls_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls +package bls_test import ( "testing" @@ -9,12 +9,14 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" ) func TestAggregation(t *testing.T) { type test struct { name string - setup func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) + setup func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) expectedSigAggError error expectedPubKeyAggError error expectedValid bool @@ -23,15 +25,15 @@ func TestAggregation(t *testing.T) { tests := []test{ { name: "valid", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), @@ -39,7 +41,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), @@ -51,17 +53,17 @@ func TestAggregation(t *testing.T) { }, { name: "valid single key", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk.PublicKey(), } msg := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk.Sign(msg), } @@ -71,15 +73,15 @@ func TestAggregation(t *testing.T) { }, { name: "wrong message", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), @@ -87,7 +89,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), @@ -101,15 +103,15 @@ func TestAggregation(t *testing.T) { }, { name: "one sig over different message", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), @@ -118,7 +120,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) msg2 := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), sk2.Sign(msg2), @@ -130,17 +132,17 @@ func TestAggregation(t *testing.T) { }, { name: "one incorrect pubkey", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) - sk3, err := NewSigner() + sk3, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), sk3.PublicKey(), @@ -148,7 +150,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), @@ -160,15 +162,15 @@ func TestAggregation(t *testing.T) { }, { name: "num pubkeys > num sigs", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), @@ -176,7 +178,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), } @@ -187,22 +189,22 @@ func TestAggregation(t *testing.T) { }, { name: "num pubkeys < num sigs", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), } msg := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), @@ -214,17 +216,17 @@ func TestAggregation(t *testing.T) { }, { name: "no pub keys", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) msg := utils.RandomBytes(1234) - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), @@ -232,20 +234,20 @@ func TestAggregation(t *testing.T) { return nil, sigs, msg }, - expectedPubKeyAggError: ErrNoPublicKeys, + expectedPubKeyAggError: bls.ErrNoPublicKeys, expectedValid: false, }, { name: "no sigs", - setup: func(require *require.Assertions) ([]*PublicKey, []*Signature, []byte) { - sk0, err := NewSigner() + setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), @@ -254,7 +256,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) return pks, nil, msg }, - expectedSigAggError: errNoSignatures, + expectedSigAggError: bls.ErrNoSignatures, expectedValid: false, }, } @@ -265,13 +267,13 @@ func TestAggregation(t *testing.T) { pks, sigs, msg := tt.setup(require) - aggSig, err := AggregateSignatures(sigs) + aggSig, err := bls.AggregateSignatures(sigs) require.ErrorIs(err, tt.expectedSigAggError) - aggPK, err := AggregatePublicKeys(pks) + aggPK, err := bls.AggregatePublicKeys(pks) require.ErrorIs(err, tt.expectedPubKeyAggError) - valid := Verify(aggPK, aggSig, msg) + valid := bls.Verify(aggPK, aggSig, msg) require.Equal(tt.expectedValid, valid) }) } @@ -281,15 +283,15 @@ func TestAggregationThreshold(t *testing.T) { require := require.New(t) // People in the network would privately generate their secret keys - sk0, err := NewSigner() + sk0, err := local.NewSigner() require.NoError(err) - sk1, err := NewSigner() + sk1, err := local.NewSigner() require.NoError(err) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) // All the public keys would be registered on chain - pks := []*PublicKey{ + pks := []*bls.PublicKey{ sk0.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), @@ -299,7 +301,7 @@ func TestAggregationThreshold(t *testing.T) { msg := utils.RandomBytes(1234) // People may attempt time sign the transaction. - sigs := []*Signature{ + sigs := []*bls.Signature{ sk0.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), @@ -310,8 +312,8 @@ func TestAggregationThreshold(t *testing.T) { // until it has found a sufficient threshold of valid signatures. var ( indices = []int{0, 2} - filteredPKs = make([]*PublicKey, len(indices)) - filteredSigs = make([]*Signature, len(indices)) + filteredPKs = make([]*bls.PublicKey, len(indices)) + filteredSigs = make([]*bls.Signature, len(indices)) ) for i, index := range indices { pk := pks[index] @@ -319,36 +321,36 @@ func TestAggregationThreshold(t *testing.T) { sig := sigs[index] filteredSigs[i] = sig - valid := Verify(pk, sig, msg) + valid := bls.Verify(pk, sig, msg) require.True(valid) } // Once the aggregator has the required threshold of signatures, it can // aggregate the signatures. - aggregatedSig, err := AggregateSignatures(filteredSigs) + aggregatedSig, err := bls.AggregateSignatures(filteredSigs) require.NoError(err) // For anyone looking for a proof of the aggregated signature's correctness, // they can aggregate the public keys and verify the aggregated signature. - aggregatedPK, err := AggregatePublicKeys(filteredPKs) + aggregatedPK, err := bls.AggregatePublicKeys(filteredPKs) require.NoError(err) - valid := Verify(aggregatedPK, aggregatedSig, msg) + valid := bls.Verify(aggregatedPK, aggregatedSig, msg) require.True(valid) } func TestVerify(t *testing.T) { type test struct { name string - setup func(*require.Assertions) (pk *PublicKey, sig *Signature, msg []byte) + setup func(*require.Assertions) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) expectedValid bool } tests := []test{ { name: "valid", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() msg := utils.RandomBytes(1234) @@ -359,8 +361,8 @@ func TestVerify(t *testing.T) { }, { name: "wrong message", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() msg := utils.RandomBytes(1234) @@ -372,13 +374,13 @@ func TestVerify(t *testing.T) { }, { name: "wrong pub key", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) msg := utils.RandomBytes(1234) sig := sk.Sign(msg) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) pk := sk2.PublicKey() return pk, sig, msg @@ -387,8 +389,8 @@ func TestVerify(t *testing.T) { }, { name: "wrong sig", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() msg := utils.RandomBytes(1234) @@ -405,9 +407,9 @@ func TestVerify(t *testing.T) { t.Run(tt.name, func(t *testing.T) { require := require.New(t) pk, sig, msg := tt.setup(require) - valid := Verify(pk, sig, msg) + valid := bls.Verify(pk, sig, msg) require.Equal(tt.expectedValid, valid) - valid = VerifyProofOfPossession(pk, sig, msg) + valid = bls.VerifyProofOfPossession(pk, sig, msg) require.False(valid) }) } @@ -416,15 +418,15 @@ func TestVerify(t *testing.T) { func TestVerifyProofOfPossession(t *testing.T) { type test struct { name string - setup func(*require.Assertions) (pk *PublicKey, sig *Signature, msg []byte) + setup func(*require.Assertions) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) expectedValid bool } tests := []test{ { name: "valid", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() msg := utils.RandomBytes(1234) @@ -435,8 +437,8 @@ func TestVerifyProofOfPossession(t *testing.T) { }, { name: "wrong message", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() msg := utils.RandomBytes(1234) @@ -448,13 +450,13 @@ func TestVerifyProofOfPossession(t *testing.T) { }, { name: "wrong pub key", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) msg := utils.RandomBytes(1234) sig := sk.SignProofOfPossession(msg) - sk2, err := NewSigner() + sk2, err := local.NewSigner() require.NoError(err) pk := sk2.PublicKey() return pk, sig, msg @@ -463,8 +465,8 @@ func TestVerifyProofOfPossession(t *testing.T) { }, { name: "wrong sig", - setup: func(require *require.Assertions) (*PublicKey, *Signature, []byte) { - sk, err := NewSigner() + setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() msg := utils.RandomBytes(1234) @@ -481,9 +483,9 @@ func TestVerifyProofOfPossession(t *testing.T) { t.Run(tt.name, func(t *testing.T) { require := require.New(t) pk, sig, msg := tt.setup(require) - valid := VerifyProofOfPossession(pk, sig, msg) + valid := bls.VerifyProofOfPossession(pk, sig, msg) require.Equal(tt.expectedValid, valid) - valid = Verify(pk, sig, msg) + valid = bls.Verify(pk, sig, msg) require.False(valid) }) } diff --git a/utils/crypto/bls/public_test.go b/utils/crypto/bls/test/public_test.go similarity index 52% rename from utils/crypto/bls/public_test.go rename to utils/crypto/bls/test/public_test.go index 087905f8c534..3e9801b8d361 100644 --- a/utils/crypto/bls/public_test.go +++ b/utils/crypto/bls/test/public_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls +package bls_test import ( "testing" @@ -9,28 +9,30 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" ) func TestPublicKeyFromCompressedBytesWrongSize(t *testing.T) { require := require.New(t) - pkBytes := utils.RandomBytes(PublicKeyLen + 1) - _, err := PublicKeyFromCompressedBytes(pkBytes) - require.ErrorIs(err, ErrFailedPublicKeyDecompress) + pkBytes := utils.RandomBytes(bls.PublicKeyLen + 1) + _, err := bls.PublicKeyFromCompressedBytes(pkBytes) + require.ErrorIs(err, bls.ErrFailedPublicKeyDecompress) } func TestPublicKeyBytes(t *testing.T) { require := require.New(t) - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() - pkBytes := PublicKeyToCompressedBytes(pk) + pkBytes := bls.PublicKeyToCompressedBytes(pk) - pk2, err := PublicKeyFromCompressedBytes(pkBytes) + pk2, err := bls.PublicKeyFromCompressedBytes(pkBytes) require.NoError(err) - pk2Bytes := PublicKeyToCompressedBytes(pk2) + pk2Bytes := bls.PublicKeyToCompressedBytes(pk2) require.Equal(pk, pk2) require.Equal(pkBytes, pk2Bytes) @@ -39,16 +41,16 @@ func TestPublicKeyBytes(t *testing.T) { func TestAggregatePublicKeysNoop(t *testing.T) { require := require.New(t) - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(err) pk := sk.PublicKey() - pkBytes := PublicKeyToCompressedBytes(pk) + pkBytes := bls.PublicKeyToCompressedBytes(pk) - aggPK, err := AggregatePublicKeys([]*PublicKey{pk}) + aggPK, err := bls.AggregatePublicKeys([]*bls.PublicKey{pk}) require.NoError(err) - aggPKBytes := PublicKeyToCompressedBytes(aggPK) + aggPKBytes := bls.PublicKeyToCompressedBytes(aggPK) require.NoError(err) require.Equal(pk, aggPK) diff --git a/utils/crypto/bls/signature_test.go b/utils/crypto/bls/test/signature_test.go similarity index 61% rename from utils/crypto/bls/signature_test.go rename to utils/crypto/bls/test/signature_test.go index 3fcfa28b71e8..efc7b8643d94 100644 --- a/utils/crypto/bls/signature_test.go +++ b/utils/crypto/bls/test/signature_test.go @@ -9,6 +9,8 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" ) func TestSignatureBytes(t *testing.T) { @@ -16,14 +18,14 @@ func TestSignatureBytes(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(err) sig := sk.Sign(msg) - sigBytes := SignatureToBytes(sig) + sigBytes := bls.SignatureToBytes(sig) - sig2, err := SignatureFromBytes(sigBytes) + sig2, err := bls.SignatureFromBytes(sigBytes) require.NoError(err) - sig2Bytes := SignatureToBytes(sig2) + sig2Bytes := bls.SignatureToBytes(sig2) require.Equal(sig, sig2) require.Equal(sigBytes, sig2Bytes) @@ -34,16 +36,16 @@ func TestAggregateSignaturesNoop(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(err) sig := sk.Sign(msg) - sigBytes := SignatureToBytes(sig) + sigBytes := bls.SignatureToBytes(sig) - aggSig, err := AggregateSignatures([]*Signature{sig}) + aggSig, err := bls.AggregateSignatures([]*bls.Signature{sig}) require.NoError(err) - aggSigBytes := SignatureToBytes(aggSig) + aggSigBytes := bls.SignatureToBytes(aggSig) require.NoError(err) require.Equal(sig, aggSig) diff --git a/utils/crypto/bls/secret_test.go b/utils/crypto/bls/test/signer_test.go similarity index 62% rename from utils/crypto/bls/secret_test.go rename to utils/crypto/bls/test/signer_test.go index c2f5662abad2..dcba26422a6a 100644 --- a/utils/crypto/bls/secret_test.go +++ b/utils/crypto/bls/test/signer_test.go @@ -9,23 +9,24 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" ) func TestSecretKeyFromBytesZero(t *testing.T) { require := require.New(t) - var skArr [SecretKeyLen]byte + var skArr [local.SecretKeyLen]byte skBytes := skArr[:] - _, err := SecretKeyFromBytes(skBytes) - require.ErrorIs(err, errFailedSecretKeyDeserialize) + _, err := local.SecretKeyFromBytes(skBytes) + require.ErrorIs(err, local.ErrFailedSecretKeyDeserialize) } func TestSecretKeyFromBytesWrongSize(t *testing.T) { require := require.New(t) - skBytes := utils.RandomBytes(SecretKeyLen + 1) - _, err := SecretKeyFromBytes(skBytes) - require.ErrorIs(err, errFailedSecretKeyDeserialize) + skBytes := utils.RandomBytes(local.SecretKeyLen + 1) + _, err := local.SecretKeyFromBytes(skBytes) + require.ErrorIs(err, local.ErrFailedSecretKeyDeserialize) } func TestSecretKeyBytes(t *testing.T) { @@ -33,12 +34,12 @@ func TestSecretKeyBytes(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := NewSigner() + sk, err := local.NewSigner() require.NoError(err) sig := sk.Sign(msg) skBytes := sk.ToBytes() - sk2, err := SecretKeyFromBytes(skBytes) + sk2, err := local.SecretKeyFromBytes(skBytes) require.NoError(err) sig2 := sk2.Sign(msg) sk2Bytes := sk2.ToBytes() From b731e7e376a073036f89e217d76d7d64f926dc94 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Wed, 18 Dec 2024 18:42:49 -0500 Subject: [PATCH 02/56] Prepare bls-tests for multiple signer-types --- utils/crypto/bls/test/bls_test.go | 60 ++++++++++++++++++------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/utils/crypto/bls/test/bls_test.go b/utils/crypto/bls/test/bls_test.go index f85cb104cd0c..2773c63eb690 100644 --- a/utils/crypto/bls/test/bls_test.go +++ b/utils/crypto/bls/test/bls_test.go @@ -418,31 +418,34 @@ func TestVerify(t *testing.T) { func TestVerifyProofOfPossession(t *testing.T) { type test struct { name string - setup func(*require.Assertions) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) + signers []func() (bls.Signer, error) + setup func(*require.Assertions, bls.Signer) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) expectedValid bool } tests := []test{ { name: "valid", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) - pk := sk.PublicKey() + signers: []func() (bls.Signer, error){ + func() (bls.Signer, error) { return local.NewSigner() }, + }, + setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + pk := signer.PublicKey() msg := utils.RandomBytes(1234) - sig := sk.SignProofOfPossession(msg) + sig := signer.SignProofOfPossession(msg) return pk, sig, msg }, expectedValid: true, }, { name: "wrong message", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) - pk := sk.PublicKey() + signers: []func() (bls.Signer, error){ + func() (bls.Signer, error) { return local.NewSigner() }, + }, + setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + pk := signer.PublicKey() msg := utils.RandomBytes(1234) - sig := sk.SignProofOfPossession(msg) + sig := signer.SignProofOfPossession(msg) msg[0]++ return pk, sig, msg }, @@ -450,11 +453,12 @@ func TestVerifyProofOfPossession(t *testing.T) { }, { name: "wrong pub key", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) + signers: []func() (bls.Signer, error){ + func() (bls.Signer, error) { return local.NewSigner() }, + }, + setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { msg := utils.RandomBytes(1234) - sig := sk.SignProofOfPossession(msg) + sig := signer.SignProofOfPossession(msg) sk2, err := local.NewSigner() require.NoError(err) @@ -465,14 +469,15 @@ func TestVerifyProofOfPossession(t *testing.T) { }, { name: "wrong sig", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) - pk := sk.PublicKey() + signers: []func() (bls.Signer, error){ + func() (bls.Signer, error) { return local.NewSigner() }, + }, + setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + pk := signer.PublicKey() msg := utils.RandomBytes(1234) msg2 := utils.RandomBytes(1234) - sig2 := sk.SignProofOfPossession(msg2) + sig2 := signer.SignProofOfPossession(msg2) return pk, sig2, msg }, expectedValid: false, @@ -482,11 +487,16 @@ func TestVerifyProofOfPossession(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { require := require.New(t) - pk, sig, msg := tt.setup(require) - valid := bls.VerifyProofOfPossession(pk, sig, msg) - require.Equal(tt.expectedValid, valid) - valid = bls.Verify(pk, sig, msg) - require.False(valid) + + for _, newSigner := range tt.signers { + signer, err := newSigner() + require.NoError(err) + pk, sig, msg := tt.setup(require, signer) + valid := bls.VerifyProofOfPossession(pk, sig, msg) + require.Equal(tt.expectedValid, valid) + valid = bls.Verify(pk, sig, msg) + require.False(valid) + } }) } } From 435d1164330bfa03cd3926567f9a3b4cd4f63aca Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Wed, 18 Dec 2024 19:10:22 -0500 Subject: [PATCH 03/56] Add test for networked signer --- utils/crypto/bls/signers/json-rpc/client.go | 92 +++++++ utils/crypto/bls/signers/json-rpc/messages.go | 23 ++ utils/crypto/bls/signers/json-rpc/server.go | 108 ++++++++ utils/crypto/bls/test/bls_test.go | 253 ++++++++++-------- 4 files changed, 371 insertions(+), 105 deletions(-) create mode 100644 utils/crypto/bls/signers/json-rpc/client.go create mode 100644 utils/crypto/bls/signers/json-rpc/messages.go create mode 100644 utils/crypto/bls/signers/json-rpc/server.go diff --git a/utils/crypto/bls/signers/json-rpc/client.go b/utils/crypto/bls/signers/json-rpc/client.go new file mode 100644 index 000000000000..481bf714aff6 --- /dev/null +++ b/utils/crypto/bls/signers/json-rpc/client.go @@ -0,0 +1,92 @@ +package jsonrpc + +import ( + "bytes" + "net/http" + "net/url" + + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/gorilla/rpc/v2/json2" +) + +type Client struct { + // http client + http *http.Client + url url.URL +} + +func NewClient(url url.URL) *Client { + return &Client{ + http: &http.Client{}, + url: url, + } +} + +func (client *Client) call(method string, params []interface{}, result interface{}) error { + requestBody, err := json2.EncodeClientRequest(method, params) + + if err != nil { + return err + } + + resp, err := client.http.Post(client.url.String(), "application/json", bytes.NewBuffer(requestBody)) + + if err != nil { + return err + } + + return json2.DecodeClientResponse(resp.Body, result) +} + +func (c *Client) PublicKey() *bls.PublicKey { + reply := new(PublicKeyReply) + + err := c.call("Signer.PublicKey", []interface{}{PublicKeyArgs{}}, reply) + + if err != nil { + panic(err) + } + + pk := new(bls.PublicKey) + pk = pk.Deserialize(reply.PublicKey) + + return pk +} + +// Sign [msg] to authorize this message +func (c *Client) Sign(msg []byte) *bls.Signature { + // request the public key from the json-rpc server + reply := new(SignReply) + err := c.call("Signer.Sign", []interface{}{SignArgs{msg}}, reply) + + // TODO: handle this + if err != nil { + panic(err) + } + + // deserialize the public key + sig := new(bls.Signature) + sig = sig.Deserialize(reply.Signature) + + // can be nil if the public key is invalid + return sig +} + +// Sign [msg] to prove the ownership +func (c *Client) SignProofOfPossession(msg []byte) *bls.Signature { + // request the public key from the json-rpc server + reply := new(SignReply) + err := c.call("Signer.SignProofOfPossession", []interface{}{SignArgs{msg}}, reply) + + // TODO: handle this + if err != nil { + panic(err) + } + + // deserialize the public key + sig := new(bls.Signature) + sig = sig.Deserialize(reply.Signature) + + // can be nil if the public key is invalid + return sig +} diff --git a/utils/crypto/bls/signers/json-rpc/messages.go b/utils/crypto/bls/signers/json-rpc/messages.go new file mode 100644 index 000000000000..ded2ec8e3b8d --- /dev/null +++ b/utils/crypto/bls/signers/json-rpc/messages.go @@ -0,0 +1,23 @@ +package jsonrpc + +type PublicKeyArgs struct{} + +type SignArgs struct { + Msg []byte +} + +type SignProofOfPossessionArgs struct { + Msg []byte +} + +type PublicKeyReply struct { + PublicKey []byte +} + +type SignReply struct { + Signature []byte +} + +type SignProofOfPossessionReply struct { + Signature []byte +} diff --git a/utils/crypto/bls/signers/json-rpc/server.go b/utils/crypto/bls/signers/json-rpc/server.go new file mode 100644 index 000000000000..392d787d8aa0 --- /dev/null +++ b/utils/crypto/bls/signers/json-rpc/server.go @@ -0,0 +1,108 @@ +package jsonrpc + +import ( + "context" + "log" + "net" + "net/http" + "time" + + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" + "github.com/gorilla/rpc/v2" + "github.com/gorilla/rpc/v2/json" +) + +type signerService struct { + signer *local.LocalSigner +} + +type Server struct { + httpServer *http.Server + listener net.Listener +} + +func NewSignerService() *signerService { + signer, err := local.NewSigner() + + if err != nil { + panic(err) + } + + return &signerService{signer: signer} +} + +func Serve(service *signerService) (*Server, error) { + server := rpc.NewServer() + server.RegisterCodec(json.NewCodec(), "application/json") + + err := server.RegisterService(service, "Signer") + if err != nil { + return nil, err + } + + httpServer := &http.Server{ + Handler: server, + } + + listener, err := net.Listen("tcp", "") + if err != nil { + return nil, err + } + + go func() { + if err := httpServer.Serve(listener); err != nil && err != http.ErrServerClosed { + log.Fatal(err) + } + }() + + return &Server{ + httpServer: httpServer, + listener: listener, + }, nil +} + +func (s *Server) Addr() net.Addr { + return s.listener.Addr() +} + +func (s *Server) Close() error { + // Create a context with a timeout to allow for graceful shutdown + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + + // Shutdown the HTTP server + if err := s.httpServer.Shutdown(ctx); err != nil { + return err + } + + // Close the listener + return s.listener.Close() +} + +func (s *signerService) PublicKey(r *http.Request, args *PublicKeyArgs, reply *PublicKeyReply) error { + *reply = toPkReply(s.signer.PublicKey()) + return nil +} + +func (s *signerService) Sign(r *http.Request, args *struct{ Msg []byte }, reply *SignReply) error { + *reply = toSignReply(s.signer.Sign(args.Msg)) + return nil +} + +func (s *signerService) SignProofOfPossession(r *http.Request, args *struct{ Msg []byte }, reply *SignProofOfPossessionReply) error { + *reply = toSignProofOfPossessionReply(s.signer.SignProofOfPossession(args.Msg)) + return nil +} + +func toPkReply(pk *bls.PublicKey) PublicKeyReply { + return PublicKeyReply{PublicKey: pk.Serialize()} +} + +func toSignReply(sig *bls.Signature) SignReply { + return SignReply{Signature: sig.Serialize()} +} + +func toSignProofOfPossessionReply(sig *bls.Signature) SignProofOfPossessionReply { + return SignProofOfPossessionReply{Signature: sig.Serialize()} +} diff --git a/utils/crypto/bls/test/bls_test.go b/utils/crypto/bls/test/bls_test.go index 2773c63eb690..98a8a7481c20 100644 --- a/utils/crypto/bls/test/bls_test.go +++ b/utils/crypto/bls/test/bls_test.go @@ -4,19 +4,72 @@ package bls_test import ( + "io" + "net/url" "testing" "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" + jsonrpc "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/json-rpc" "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" ) +type Signer interface { + bls.Signer + io.Closer +} + +type jsonRPCSigner struct { + *jsonrpc.Client + server *jsonrpc.Server +} + +func (s jsonRPCSigner) Close() error { + return s.server.Close() +} + +type localSigner struct { + *local.LocalSigner +} + +func (s localSigner) Close() error { + return nil +} + +var localSignerFn = func() (Signer, error) { + signer, err := local.NewSigner() + return &localSigner{LocalSigner: signer}, err +} +var serverSignerFn = func() (Signer, error) { + // do I need to make sure the server gets closed properly? + service := jsonrpc.NewSignerService() + server, err := jsonrpc.Serve(service) + if err != nil { + return nil, err + } + + url := url.URL{ + Scheme: "http", + Host: server.Addr().String(), + } + + client := jsonrpc.NewClient(url) + + return jsonRPCSigner{server: server, Client: client}, nil +} + +var signerFns = []func() (Signer, error){ + localSignerFn, + serverSignerFn, +} + func TestAggregation(t *testing.T) { type test struct { name string - setup func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) + signers []func() (Signer, error) + setup func(*require.Assertions, bls.Signer) (pks []*bls.PublicKey, sigs []*bls.Signature, msg []byte) expectedSigAggError error expectedPubKeyAggError error expectedValid bool @@ -24,17 +77,16 @@ func TestAggregation(t *testing.T) { tests := []test{ { - name: "valid", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + name: "valid", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ - sk0.PublicKey(), + signer.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), } @@ -42,7 +94,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk0.Sign(msg), + signer.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), } @@ -52,19 +104,18 @@ func TestAggregation(t *testing.T) { expectedValid: true, }, { - name: "valid single key", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) + name: "valid single key", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { pks := []*bls.PublicKey{ - sk.PublicKey(), + signer.PublicKey(), } msg := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk.Sign(msg), + signer.Sign(msg), } return pks, sigs, msg @@ -73,16 +124,14 @@ func TestAggregation(t *testing.T) { }, { name: "wrong message", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ - sk0.PublicKey(), + signer.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), } @@ -90,7 +139,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk0.Sign(msg), + signer.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), } @@ -102,17 +151,16 @@ func TestAggregation(t *testing.T) { expectedValid: false, }, { - name: "one sig over different message", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + name: "one sig over different message", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ - sk0.PublicKey(), + signer.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), } @@ -121,7 +169,7 @@ func TestAggregation(t *testing.T) { msg2 := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk0.Sign(msg), + signer.Sign(msg), sk1.Sign(msg), sk2.Sign(msg2), } @@ -131,10 +179,9 @@ func TestAggregation(t *testing.T) { expectedValid: false, }, { - name: "one incorrect pubkey", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + name: "one incorrect pubkey", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() @@ -143,7 +190,7 @@ func TestAggregation(t *testing.T) { require.NoError(err) pks := []*bls.PublicKey{ - sk0.PublicKey(), + signer.PublicKey(), sk1.PublicKey(), sk3.PublicKey(), } @@ -151,7 +198,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk0.Sign(msg), + signer.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), } @@ -161,17 +208,16 @@ func TestAggregation(t *testing.T) { expectedValid: false, }, { - name: "num pubkeys > num sigs", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + name: "num pubkeys > num sigs", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ - sk0.PublicKey(), + signer.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), } @@ -179,7 +225,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk0.Sign(msg), + signer.Sign(msg), sk1.Sign(msg), } @@ -188,24 +234,23 @@ func TestAggregation(t *testing.T) { expectedValid: false, }, { - name: "num pubkeys < num sigs", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + name: "num pubkeys < num sigs", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ - sk0.PublicKey(), + signer.PublicKey(), sk1.PublicKey(), } msg := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk0.Sign(msg), + signer.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), } @@ -215,10 +260,9 @@ func TestAggregation(t *testing.T) { expectedValid: false, }, { - name: "no pub keys", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + name: "no pub keys", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() @@ -227,7 +271,7 @@ func TestAggregation(t *testing.T) { msg := utils.RandomBytes(1234) sigs := []*bls.Signature{ - sk0.Sign(msg), + signer.Sign(msg), sk1.Sign(msg), sk2.Sign(msg), } @@ -238,17 +282,16 @@ func TestAggregation(t *testing.T) { expectedValid: false, }, { - name: "no sigs", - setup: func(require *require.Assertions) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk0, err := local.NewSigner() - require.NoError(err) + name: "no sigs", + signers: signerFns, + setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := local.NewSigner() require.NoError(err) sk2, err := local.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ - sk0.PublicKey(), + signer.PublicKey(), sk1.PublicKey(), sk2.PublicKey(), } @@ -263,18 +306,24 @@ func TestAggregation(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - require := require.New(t) + for _, newSigner := range tt.signers { + require := require.New(t) - pks, sigs, msg := tt.setup(require) + signer, err := newSigner() + require.NoError(err) - aggSig, err := bls.AggregateSignatures(sigs) - require.ErrorIs(err, tt.expectedSigAggError) + pks, sigs, msg := tt.setup(require, signer) - aggPK, err := bls.AggregatePublicKeys(pks) - require.ErrorIs(err, tt.expectedPubKeyAggError) + aggSig, err := bls.AggregateSignatures(sigs) + require.ErrorIs(err, tt.expectedSigAggError) - valid := bls.Verify(aggPK, aggSig, msg) - require.Equal(tt.expectedValid, valid) + aggPK, err := bls.AggregatePublicKeys(pks) + require.ErrorIs(err, tt.expectedPubKeyAggError) + + valid := bls.Verify(aggPK, aggSig, msg) + require.Equal(tt.expectedValid, valid) + signer.Close() + } }) } } @@ -283,9 +332,12 @@ func TestAggregationThreshold(t *testing.T) { require := require.New(t) // People in the network would privately generate their secret keys - sk0, err := local.NewSigner() + sk0, err := localSignerFn() require.NoError(err) - sk1, err := local.NewSigner() + sk1, err := serverSignerFn() + require.NoError(err) + defer sk1.Close() + require.NoError(err) sk2, err := local.NewSigner() require.NoError(err) @@ -342,31 +394,28 @@ func TestAggregationThreshold(t *testing.T) { func TestVerify(t *testing.T) { type test struct { name string - setup func(*require.Assertions) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) + signers []func() (Signer, error) + setup func(*require.Assertions, bls.Signer) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) expectedValid bool } tests := []test{ { name: "valid", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) - pk := sk.PublicKey() + setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + pk := signer.PublicKey() msg := utils.RandomBytes(1234) - sig := sk.Sign(msg) + sig := signer.Sign(msg) return pk, sig, msg }, expectedValid: true, }, { name: "wrong message", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) - pk := sk.PublicKey() + setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + pk := signer.PublicKey() msg := utils.RandomBytes(1234) - sig := sk.Sign(msg) + sig := signer.Sign(msg) msg[0]++ return pk, sig, msg }, @@ -374,11 +423,9 @@ func TestVerify(t *testing.T) { }, { name: "wrong pub key", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) + setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { msg := utils.RandomBytes(1234) - sig := sk.Sign(msg) + sig := signer.Sign(msg) sk2, err := local.NewSigner() require.NoError(err) @@ -389,14 +436,12 @@ func TestVerify(t *testing.T) { }, { name: "wrong sig", - setup: func(require *require.Assertions) (*bls.PublicKey, *bls.Signature, []byte) { - sk, err := local.NewSigner() - require.NoError(err) - pk := sk.PublicKey() + setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + pk := signer.PublicKey() msg := utils.RandomBytes(1234) msg2 := utils.RandomBytes(1234) - sig2 := sk.Sign(msg2) + sig2 := signer.Sign(msg2) return pk, sig2, msg }, expectedValid: false, @@ -405,12 +450,17 @@ func TestVerify(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - require := require.New(t) - pk, sig, msg := tt.setup(require) - valid := bls.Verify(pk, sig, msg) - require.Equal(tt.expectedValid, valid) - valid = bls.VerifyProofOfPossession(pk, sig, msg) - require.False(valid) + for _, newSigner := range tt.signers { + require := require.New(t) + signer, err := newSigner() + require.NoError(err) + pk, sig, msg := tt.setup(require, signer) + valid := bls.Verify(pk, sig, msg) + require.Equal(tt.expectedValid, valid) + valid = bls.VerifyProofOfPossession(pk, sig, msg) + require.False(valid) + signer.Close() + } }) } } @@ -418,17 +468,15 @@ func TestVerify(t *testing.T) { func TestVerifyProofOfPossession(t *testing.T) { type test struct { name string - signers []func() (bls.Signer, error) + signers []func() (Signer, error) setup func(*require.Assertions, bls.Signer) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) expectedValid bool } tests := []test{ { - name: "valid", - signers: []func() (bls.Signer, error){ - func() (bls.Signer, error) { return local.NewSigner() }, - }, + name: "valid", + signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) @@ -438,10 +486,8 @@ func TestVerifyProofOfPossession(t *testing.T) { expectedValid: true, }, { - name: "wrong message", - signers: []func() (bls.Signer, error){ - func() (bls.Signer, error) { return local.NewSigner() }, - }, + name: "wrong message", + signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) @@ -452,10 +498,8 @@ func TestVerifyProofOfPossession(t *testing.T) { expectedValid: false, }, { - name: "wrong pub key", - signers: []func() (bls.Signer, error){ - func() (bls.Signer, error) { return local.NewSigner() }, - }, + name: "wrong pub key", + signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { msg := utils.RandomBytes(1234) sig := signer.SignProofOfPossession(msg) @@ -468,10 +512,8 @@ func TestVerifyProofOfPossession(t *testing.T) { expectedValid: false, }, { - name: "wrong sig", - signers: []func() (bls.Signer, error){ - func() (bls.Signer, error) { return local.NewSigner() }, - }, + name: "wrong sig", + signers: signerFns, setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) @@ -496,6 +538,7 @@ func TestVerifyProofOfPossession(t *testing.T) { require.Equal(tt.expectedValid, valid) valid = bls.Verify(pk, sig, msg) require.False(valid) + signer.Close() } }) } From a2ab5d404689d8e3e7eca65070f01321db7a500c Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 12:54:29 -0500 Subject: [PATCH 04/56] Expose secret-key-length from the bls package --- utils/crypto/bls/public.go | 1 + utils/crypto/bls/signers/local/local.go | 2 -- utils/crypto/bls/test/signer_test.go | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/utils/crypto/bls/public.go b/utils/crypto/bls/public.go index f30b4402ca77..43ee139eeaa9 100644 --- a/utils/crypto/bls/public.go +++ b/utils/crypto/bls/public.go @@ -9,6 +9,7 @@ import ( blst "github.com/supranational/blst/bindings/go" ) +const SecretKeyLen = blst.BLST_SCALAR_BYTES const PublicKeyLen = blst.BLST_P1_COMPRESS_BYTES var ( diff --git a/utils/crypto/bls/signers/local/local.go b/utils/crypto/bls/signers/local/local.go index 4c59daebdebc..7b0cef2dff31 100644 --- a/utils/crypto/bls/signers/local/local.go +++ b/utils/crypto/bls/signers/local/local.go @@ -12,8 +12,6 @@ import ( blst "github.com/supranational/blst/bindings/go" ) -const SecretKeyLen = blst.BLST_SCALAR_BYTES - var ( ErrFailedSecretKeyDeserialize = errors.New("couldn't deserialize secret key") _ bls.Signer = (*LocalSigner)(nil) // Use the Signer interface from the parent package diff --git a/utils/crypto/bls/test/signer_test.go b/utils/crypto/bls/test/signer_test.go index dcba26422a6a..e8d58b3ec1ef 100644 --- a/utils/crypto/bls/test/signer_test.go +++ b/utils/crypto/bls/test/signer_test.go @@ -15,7 +15,7 @@ import ( func TestSecretKeyFromBytesZero(t *testing.T) { require := require.New(t) - var skArr [local.SecretKeyLen]byte + var skArr [SecretKeyLen]byte skBytes := skArr[:] _, err := local.SecretKeyFromBytes(skBytes) require.ErrorIs(err, local.ErrFailedSecretKeyDeserialize) @@ -24,7 +24,7 @@ func TestSecretKeyFromBytesZero(t *testing.T) { func TestSecretKeyFromBytesWrongSize(t *testing.T) { require := require.New(t) - skBytes := utils.RandomBytes(local.SecretKeyLen + 1) + skBytes := utils.RandomBytes(SecretKeyLen + 1) _, err := local.SecretKeyFromBytes(skBytes) require.ErrorIs(err, local.ErrFailedSecretKeyDeserialize) } From 7f49c8575dbabcaea3a1886fc60debe2c625563f Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 13:04:58 -0500 Subject: [PATCH 05/56] Rename signers/local to signers/localsigner --- utils/crypto/bls/signers/{local => localsigner}/local.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename utils/crypto/bls/signers/{local => localsigner}/local.go (98%) diff --git a/utils/crypto/bls/signers/local/local.go b/utils/crypto/bls/signers/localsigner/local.go similarity index 98% rename from utils/crypto/bls/signers/local/local.go rename to utils/crypto/bls/signers/localsigner/local.go index 7b0cef2dff31..aaad26342c66 100644 --- a/utils/crypto/bls/signers/local/local.go +++ b/utils/crypto/bls/signers/localsigner/local.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package local +package localsigner import ( "crypto/rand" From 9ad13b22c34e9d3cffd04ee402fe5c67499acb9f Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 14:47:55 -0500 Subject: [PATCH 06/56] Remove redundant comment --- utils/crypto/bls/signers/localsigner/local.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/crypto/bls/signers/localsigner/local.go b/utils/crypto/bls/signers/localsigner/local.go index aaad26342c66..bd6c6ae4d45f 100644 --- a/utils/crypto/bls/signers/localsigner/local.go +++ b/utils/crypto/bls/signers/localsigner/local.go @@ -14,7 +14,7 @@ import ( var ( ErrFailedSecretKeyDeserialize = errors.New("couldn't deserialize secret key") - _ bls.Signer = (*LocalSigner)(nil) // Use the Signer interface from the parent package + _ bls.Signer = (*LocalSigner)(nil) ) type secretKey = blst.SecretKey From 9fd0c12740f8e5dd7eca6adbb53a4543e79f0883 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 14:57:41 -0500 Subject: [PATCH 07/56] Rename local.go to localsigner.go --- utils/crypto/bls/signers/localsigner/{local.go => localsigner.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/signers/localsigner/{local.go => localsigner.go} (100%) diff --git a/utils/crypto/bls/signers/localsigner/local.go b/utils/crypto/bls/signers/localsigner/localsigner.go similarity index 100% rename from utils/crypto/bls/signers/localsigner/local.go rename to utils/crypto/bls/signers/localsigner/localsigner.go From 67885b3db6572f97fe53868ee2aec8f25d163178 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 14:58:40 -0500 Subject: [PATCH 08/56] Rename bls_test to blstest --- utils/crypto/bls/test/bls_benchmark_test.go | 2 +- utils/crypto/bls/test/bls_test.go | 2 +- utils/crypto/bls/test/public_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/crypto/bls/test/bls_benchmark_test.go b/utils/crypto/bls/test/bls_benchmark_test.go index d05836bb2d5b..27a5735e0a07 100644 --- a/utils/crypto/bls/test/bls_benchmark_test.go +++ b/utils/crypto/bls/test/bls_benchmark_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls_test +package blstest import ( "strconv" diff --git a/utils/crypto/bls/test/bls_test.go b/utils/crypto/bls/test/bls_test.go index 98a8a7481c20..7378f917ce85 100644 --- a/utils/crypto/bls/test/bls_test.go +++ b/utils/crypto/bls/test/bls_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls_test +package blstest import ( "io" diff --git a/utils/crypto/bls/test/public_test.go b/utils/crypto/bls/test/public_test.go index 3e9801b8d361..2af45d330a83 100644 --- a/utils/crypto/bls/test/public_test.go +++ b/utils/crypto/bls/test/public_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls_test +package blstest import ( "testing" From 65d61a075dd65d6a1b911a33723bd57392084eec Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 14:59:22 -0500 Subject: [PATCH 09/56] Rename bls/test dir to blstest --- utils/crypto/bls/{test => blstest}/bls_benchmark_test.go | 0 utils/crypto/bls/{test => blstest}/bls_test.go | 0 utils/crypto/bls/{test => blstest}/public_test.go | 0 utils/crypto/bls/{test => blstest}/signature_test.go | 0 utils/crypto/bls/{test => blstest}/signer_test.go | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/{test => blstest}/bls_benchmark_test.go (100%) rename utils/crypto/bls/{test => blstest}/bls_test.go (100%) rename utils/crypto/bls/{test => blstest}/public_test.go (100%) rename utils/crypto/bls/{test => blstest}/signature_test.go (100%) rename utils/crypto/bls/{test => blstest}/signer_test.go (100%) diff --git a/utils/crypto/bls/test/bls_benchmark_test.go b/utils/crypto/bls/blstest/bls_benchmark_test.go similarity index 100% rename from utils/crypto/bls/test/bls_benchmark_test.go rename to utils/crypto/bls/blstest/bls_benchmark_test.go diff --git a/utils/crypto/bls/test/bls_test.go b/utils/crypto/bls/blstest/bls_test.go similarity index 100% rename from utils/crypto/bls/test/bls_test.go rename to utils/crypto/bls/blstest/bls_test.go diff --git a/utils/crypto/bls/test/public_test.go b/utils/crypto/bls/blstest/public_test.go similarity index 100% rename from utils/crypto/bls/test/public_test.go rename to utils/crypto/bls/blstest/public_test.go diff --git a/utils/crypto/bls/test/signature_test.go b/utils/crypto/bls/blstest/signature_test.go similarity index 100% rename from utils/crypto/bls/test/signature_test.go rename to utils/crypto/bls/blstest/signature_test.go diff --git a/utils/crypto/bls/test/signer_test.go b/utils/crypto/bls/blstest/signer_test.go similarity index 100% rename from utils/crypto/bls/test/signer_test.go rename to utils/crypto/bls/blstest/signer_test.go From 77367f227e89ed2d608950e9475182e37296fa23 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 15:04:13 -0500 Subject: [PATCH 10/56] Revert "Rename bls/test dir to blstest" This reverts commit 65d61a075dd65d6a1b911a33723bd57392084eec. --- utils/crypto/bls/{blstest => test}/bls_benchmark_test.go | 0 utils/crypto/bls/{blstest => test}/bls_test.go | 0 utils/crypto/bls/{blstest => test}/public_test.go | 0 utils/crypto/bls/{blstest => test}/signature_test.go | 0 utils/crypto/bls/{blstest => test}/signer_test.go | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/{blstest => test}/bls_benchmark_test.go (100%) rename utils/crypto/bls/{blstest => test}/bls_test.go (100%) rename utils/crypto/bls/{blstest => test}/public_test.go (100%) rename utils/crypto/bls/{blstest => test}/signature_test.go (100%) rename utils/crypto/bls/{blstest => test}/signer_test.go (100%) diff --git a/utils/crypto/bls/blstest/bls_benchmark_test.go b/utils/crypto/bls/test/bls_benchmark_test.go similarity index 100% rename from utils/crypto/bls/blstest/bls_benchmark_test.go rename to utils/crypto/bls/test/bls_benchmark_test.go diff --git a/utils/crypto/bls/blstest/bls_test.go b/utils/crypto/bls/test/bls_test.go similarity index 100% rename from utils/crypto/bls/blstest/bls_test.go rename to utils/crypto/bls/test/bls_test.go diff --git a/utils/crypto/bls/blstest/public_test.go b/utils/crypto/bls/test/public_test.go similarity index 100% rename from utils/crypto/bls/blstest/public_test.go rename to utils/crypto/bls/test/public_test.go diff --git a/utils/crypto/bls/blstest/signature_test.go b/utils/crypto/bls/test/signature_test.go similarity index 100% rename from utils/crypto/bls/blstest/signature_test.go rename to utils/crypto/bls/test/signature_test.go diff --git a/utils/crypto/bls/blstest/signer_test.go b/utils/crypto/bls/test/signer_test.go similarity index 100% rename from utils/crypto/bls/blstest/signer_test.go rename to utils/crypto/bls/test/signer_test.go From eeb846a8d7d9b34192f05f9224ee69c291a5b33e Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 15:04:26 -0500 Subject: [PATCH 11/56] Revert "Rename bls_test to blstest" This reverts commit 67885b3db6572f97fe53868ee2aec8f25d163178. --- utils/crypto/bls/test/bls_benchmark_test.go | 2 +- utils/crypto/bls/test/bls_test.go | 2 +- utils/crypto/bls/test/public_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/crypto/bls/test/bls_benchmark_test.go b/utils/crypto/bls/test/bls_benchmark_test.go index 27a5735e0a07..d05836bb2d5b 100644 --- a/utils/crypto/bls/test/bls_benchmark_test.go +++ b/utils/crypto/bls/test/bls_benchmark_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package blstest +package bls_test import ( "strconv" diff --git a/utils/crypto/bls/test/bls_test.go b/utils/crypto/bls/test/bls_test.go index 7378f917ce85..98a8a7481c20 100644 --- a/utils/crypto/bls/test/bls_test.go +++ b/utils/crypto/bls/test/bls_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package blstest +package bls_test import ( "io" diff --git a/utils/crypto/bls/test/public_test.go b/utils/crypto/bls/test/public_test.go index 2af45d330a83..3e9801b8d361 100644 --- a/utils/crypto/bls/test/public_test.go +++ b/utils/crypto/bls/test/public_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package blstest +package bls_test import ( "testing" From 7027a47216b2ea2f4e5ecb17ab38c24bc094caa4 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 15:23:12 -0500 Subject: [PATCH 12/56] Fix bls tests --- config/config.md | 2 +- genesis/genesis_local.go | 2 +- network/peer/test_peer.go | 4 +- network/test_network.go | 4 +- scripts/configure-local-metrics-collection.sh | 4 +- snow/snowtest/context.go | 4 +- utils/crypto/bls/signers/json-rpc/server.go | 6 +-- utils/crypto/bls/test/bls_benchmark_test.go | 18 ++++---- utils/crypto/bls/test/bls_test.go | 46 +++++++++---------- utils/crypto/bls/test/public_test.go | 6 +-- utils/crypto/bls/test/signature_test.go | 8 ++-- utils/crypto/bls/test/signer_test.go | 21 +++++---- .../ghttp/gresponsewriter/writer_server.go | 4 +- 13 files changed, 65 insertions(+), 64 deletions(-) diff --git a/config/config.md b/config/config.md index 7e0c490ac854..b0e71a3d649c 100644 --- a/config/config.md +++ b/config/config.md @@ -445,7 +445,7 @@ These are the main properties in the JSON file: - `cChainGenesis`: The genesis info to be passed to the C-Chain. - `message`: A message to include in the genesis. Not required. -For an example of a JSON representation of genesis data, see [genesis_local.json](https://github.com/ava-labs/avalanchego/blob/master/genesis/genesis_local.json). +For an example of a JSON representation of genesis data, see [genesis_localsigner.json](https://github.com/ava-labs/avalanchego/blob/master/genesis/genesis_localsigner.json). #### `--genesis-file-content` (string) diff --git a/genesis/genesis_local.go b/genesis/genesis_local.go index 338c326f6bed..da38413e48e7 100644 --- a/genesis/genesis_local.go +++ b/genesis/genesis_local.go @@ -35,7 +35,7 @@ var ( VMRQKey *secp256k1.PrivateKey EWOQKey *secp256k1.PrivateKey - //go:embed genesis_local.json + //go:embed genesis_localsigner.json localGenesisConfigJSON []byte // LocalParams are the params used for local networks diff --git a/network/peer/test_peer.go b/network/peer/test_peer.go index 6803efb5f043..86b66f66c244 100644 --- a/network/peer/test_peer.go +++ b/network/peer/test_peer.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" @@ -101,7 +101,7 @@ func StartTestPeer( } tlsKey := tlsCert.PrivateKey.(crypto.Signer) - blsKey, err := local.NewSigner() + blsKey, err := localsigner.NewSigner() if err != nil { return nil, err } diff --git a/network/test_network.go b/network/test_network.go index 465492ebb426..df62eb961de8 100644 --- a/network/test_network.go +++ b/network/test_network.go @@ -28,7 +28,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" @@ -84,7 +84,7 @@ func NewTestNetworkConfig( return nil, err } - blsKey, err := local.NewSigner() + blsKey, err := localsigner.NewSigner() if err != nil { return nil, err } diff --git a/scripts/configure-local-metrics-collection.sh b/scripts/configure-local-metrics-collection.sh index 4ba3027be509..edc240aef458 100755 --- a/scripts/configure-local-metrics-collection.sh +++ b/scripts/configure-local-metrics-collection.sh @@ -15,7 +15,7 @@ METRICS_UUID="$(uuidgen)" echo "Configuring metrics and log collection for a local node with API port ${API_PORT} and logs path ${LOGS_PATH}" PROMETHEUS_CONFIG_PATH="${HOME}/.tmpnet/prometheus/file_sd_configs" -PROMETHEUS_CONFIG_FILE="${PROMETHEUS_CONFIG_PATH}/local.json" +PROMETHEUS_CONFIG_FILE="${PROMETHEUS_CONFIG_PATH}/localsigner.json" mkdir -p "${PROMETHEUS_CONFIG_PATH}" cat > "${PROMETHEUS_CONFIG_FILE}" < "${PROMTAIL_CONFIG_FILE}" < num sigs", signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := local.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(err) - sk2, err := local.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ @@ -237,9 +237,9 @@ func TestAggregation(t *testing.T) { name: "num pubkeys < num sigs", signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := local.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(err) - sk2, err := local.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ @@ -263,9 +263,9 @@ func TestAggregation(t *testing.T) { name: "no pub keys", signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := local.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(err) - sk2, err := local.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) msg := utils.RandomBytes(1234) @@ -285,9 +285,9 @@ func TestAggregation(t *testing.T) { name: "no sigs", signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := local.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(err) - sk2, err := local.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) pks := []*bls.PublicKey{ @@ -339,7 +339,7 @@ func TestAggregationThreshold(t *testing.T) { defer sk1.Close() require.NoError(err) - sk2, err := local.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) // All the public keys would be registered on chain @@ -427,7 +427,7 @@ func TestVerify(t *testing.T) { msg := utils.RandomBytes(1234) sig := signer.Sign(msg) - sk2, err := local.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) pk := sk2.PublicKey() return pk, sig, msg @@ -504,7 +504,7 @@ func TestVerifyProofOfPossession(t *testing.T) { msg := utils.RandomBytes(1234) sig := signer.SignProofOfPossession(msg) - sk2, err := local.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) pk := sk2.PublicKey() return pk, sig, msg diff --git a/utils/crypto/bls/test/public_test.go b/utils/crypto/bls/test/public_test.go index 3e9801b8d361..6bd343abf8cc 100644 --- a/utils/crypto/bls/test/public_test.go +++ b/utils/crypto/bls/test/public_test.go @@ -10,7 +10,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestPublicKeyFromCompressedBytesWrongSize(t *testing.T) { @@ -24,7 +24,7 @@ func TestPublicKeyFromCompressedBytesWrongSize(t *testing.T) { func TestPublicKeyBytes(t *testing.T) { require := require.New(t) - sk, err := local.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() @@ -41,7 +41,7 @@ func TestPublicKeyBytes(t *testing.T) { func TestAggregatePublicKeysNoop(t *testing.T) { require := require.New(t) - sk, err := local.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() diff --git a/utils/crypto/bls/test/signature_test.go b/utils/crypto/bls/test/signature_test.go index efc7b8643d94..e2a5c1afe957 100644 --- a/utils/crypto/bls/test/signature_test.go +++ b/utils/crypto/bls/test/signature_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls +package bls_test import ( "testing" @@ -10,7 +10,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestSignatureBytes(t *testing.T) { @@ -18,7 +18,7 @@ func TestSignatureBytes(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := local.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) sig := sk.Sign(msg) sigBytes := bls.SignatureToBytes(sig) @@ -36,7 +36,7 @@ func TestAggregateSignaturesNoop(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := local.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) sig := sk.Sign(msg) diff --git a/utils/crypto/bls/test/signer_test.go b/utils/crypto/bls/test/signer_test.go index e8d58b3ec1ef..ce7ac5cdd1f1 100644 --- a/utils/crypto/bls/test/signer_test.go +++ b/utils/crypto/bls/test/signer_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls +package bls_test import ( "testing" @@ -9,24 +9,25 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/local" + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestSecretKeyFromBytesZero(t *testing.T) { require := require.New(t) - var skArr [SecretKeyLen]byte + var skArr [bls.SecretKeyLen]byte skBytes := skArr[:] - _, err := local.SecretKeyFromBytes(skBytes) - require.ErrorIs(err, local.ErrFailedSecretKeyDeserialize) + _, err := localsigner.SecretKeyFromBytes(skBytes) + require.ErrorIs(err, localsigner.ErrFailedSecretKeyDeserialize) } func TestSecretKeyFromBytesWrongSize(t *testing.T) { require := require.New(t) - skBytes := utils.RandomBytes(SecretKeyLen + 1) - _, err := local.SecretKeyFromBytes(skBytes) - require.ErrorIs(err, local.ErrFailedSecretKeyDeserialize) + skBytes := utils.RandomBytes(bls.SecretKeyLen + 1) + _, err := localsigner.SecretKeyFromBytes(skBytes) + require.ErrorIs(err, localsigner.ErrFailedSecretKeyDeserialize) } func TestSecretKeyBytes(t *testing.T) { @@ -34,12 +35,12 @@ func TestSecretKeyBytes(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := local.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) sig := sk.Sign(msg) skBytes := sk.ToBytes() - sk2, err := local.SecretKeyFromBytes(skBytes) + sk2, err := localsigner.SecretKeyFromBytes(skBytes) require.NoError(err) sig2 := sk2.Sign(msg) sk2Bytes := sk2.ToBytes() diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go index 86dd996369fc..453eabf7c881 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go @@ -111,8 +111,8 @@ func (s *Server) Hijack(context.Context, *emptypb.Empty) (*responsewriterpb.Hija remote := conn.RemoteAddr() return &responsewriterpb.HijackResponse{ - LocalNetwork: local.Network(), - LocalString: local.String(), + LocalNetwork: localsigner.Network(), + LocalString: localsigner.String(), RemoteNetwork: remote.Network(), RemoteString: remote.String(), ServerAddr: serverListener.Addr().String(), From 18d1f7c42f3b6f9fd916094953a0f51e8477aba7 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 15:25:53 -0500 Subject: [PATCH 13/56] Follow test package pattern from the rest of the repo --- utils/crypto/bls/{test => }/bls_benchmark_test.go | 0 utils/crypto/bls/{test => }/bls_test.go | 0 utils/crypto/bls/{test => }/public_test.go | 0 utils/crypto/bls/{test => }/signature_test.go | 0 utils/crypto/bls/{test => }/signer_test.go | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/{test => }/bls_benchmark_test.go (100%) rename utils/crypto/bls/{test => }/bls_test.go (100%) rename utils/crypto/bls/{test => }/public_test.go (100%) rename utils/crypto/bls/{test => }/signature_test.go (100%) rename utils/crypto/bls/{test => }/signer_test.go (100%) diff --git a/utils/crypto/bls/test/bls_benchmark_test.go b/utils/crypto/bls/bls_benchmark_test.go similarity index 100% rename from utils/crypto/bls/test/bls_benchmark_test.go rename to utils/crypto/bls/bls_benchmark_test.go diff --git a/utils/crypto/bls/test/bls_test.go b/utils/crypto/bls/bls_test.go similarity index 100% rename from utils/crypto/bls/test/bls_test.go rename to utils/crypto/bls/bls_test.go diff --git a/utils/crypto/bls/test/public_test.go b/utils/crypto/bls/public_test.go similarity index 100% rename from utils/crypto/bls/test/public_test.go rename to utils/crypto/bls/public_test.go diff --git a/utils/crypto/bls/test/signature_test.go b/utils/crypto/bls/signature_test.go similarity index 100% rename from utils/crypto/bls/test/signature_test.go rename to utils/crypto/bls/signature_test.go diff --git a/utils/crypto/bls/test/signer_test.go b/utils/crypto/bls/signer_test.go similarity index 100% rename from utils/crypto/bls/test/signer_test.go rename to utils/crypto/bls/signer_test.go From c4170e71dce7d0f3290c7c47016f523cbfbb3c40 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 15:31:46 -0500 Subject: [PATCH 14/56] Revert "Follow test package pattern from the rest of the repo" This reverts commit 18d1f7c42f3b6f9fd916094953a0f51e8477aba7. --- utils/crypto/bls/{ => test}/bls_benchmark_test.go | 0 utils/crypto/bls/{ => test}/bls_test.go | 0 utils/crypto/bls/{ => test}/public_test.go | 0 utils/crypto/bls/{ => test}/signature_test.go | 0 utils/crypto/bls/{ => test}/signer_test.go | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/{ => test}/bls_benchmark_test.go (100%) rename utils/crypto/bls/{ => test}/bls_test.go (100%) rename utils/crypto/bls/{ => test}/public_test.go (100%) rename utils/crypto/bls/{ => test}/signature_test.go (100%) rename utils/crypto/bls/{ => test}/signer_test.go (100%) diff --git a/utils/crypto/bls/bls_benchmark_test.go b/utils/crypto/bls/test/bls_benchmark_test.go similarity index 100% rename from utils/crypto/bls/bls_benchmark_test.go rename to utils/crypto/bls/test/bls_benchmark_test.go diff --git a/utils/crypto/bls/bls_test.go b/utils/crypto/bls/test/bls_test.go similarity index 100% rename from utils/crypto/bls/bls_test.go rename to utils/crypto/bls/test/bls_test.go diff --git a/utils/crypto/bls/public_test.go b/utils/crypto/bls/test/public_test.go similarity index 100% rename from utils/crypto/bls/public_test.go rename to utils/crypto/bls/test/public_test.go diff --git a/utils/crypto/bls/signature_test.go b/utils/crypto/bls/test/signature_test.go similarity index 100% rename from utils/crypto/bls/signature_test.go rename to utils/crypto/bls/test/signature_test.go diff --git a/utils/crypto/bls/signer_test.go b/utils/crypto/bls/test/signer_test.go similarity index 100% rename from utils/crypto/bls/signer_test.go rename to utils/crypto/bls/test/signer_test.go From 15326983d5008a5a1d2d2ebcbfdebc4ae1fc3f60 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 16:04:08 -0500 Subject: [PATCH 15/56] Use blstest convention --- utils/crypto/bls/{test => blstest}/bls_benchmark_test.go | 0 utils/crypto/bls/{test => blstest}/bls_test.go | 0 utils/crypto/bls/{test => blstest}/public_test.go | 0 utils/crypto/bls/{test => blstest}/signature_test.go | 0 utils/crypto/bls/{test => blstest}/signer_test.go | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/{test => blstest}/bls_benchmark_test.go (100%) rename utils/crypto/bls/{test => blstest}/bls_test.go (100%) rename utils/crypto/bls/{test => blstest}/public_test.go (100%) rename utils/crypto/bls/{test => blstest}/signature_test.go (100%) rename utils/crypto/bls/{test => blstest}/signer_test.go (100%) diff --git a/utils/crypto/bls/test/bls_benchmark_test.go b/utils/crypto/bls/blstest/bls_benchmark_test.go similarity index 100% rename from utils/crypto/bls/test/bls_benchmark_test.go rename to utils/crypto/bls/blstest/bls_benchmark_test.go diff --git a/utils/crypto/bls/test/bls_test.go b/utils/crypto/bls/blstest/bls_test.go similarity index 100% rename from utils/crypto/bls/test/bls_test.go rename to utils/crypto/bls/blstest/bls_test.go diff --git a/utils/crypto/bls/test/public_test.go b/utils/crypto/bls/blstest/public_test.go similarity index 100% rename from utils/crypto/bls/test/public_test.go rename to utils/crypto/bls/blstest/public_test.go diff --git a/utils/crypto/bls/test/signature_test.go b/utils/crypto/bls/blstest/signature_test.go similarity index 100% rename from utils/crypto/bls/test/signature_test.go rename to utils/crypto/bls/blstest/signature_test.go diff --git a/utils/crypto/bls/test/signer_test.go b/utils/crypto/bls/blstest/signer_test.go similarity index 100% rename from utils/crypto/bls/test/signer_test.go rename to utils/crypto/bls/blstest/signer_test.go From 988920fab96545d5d8fd2b00567fd69d3895a9ca Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 16:31:11 -0500 Subject: [PATCH 16/56] Fix accidental search-and-replace --- genesis/genesis_local.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genesis/genesis_local.go b/genesis/genesis_local.go index da38413e48e7..338c326f6bed 100644 --- a/genesis/genesis_local.go +++ b/genesis/genesis_local.go @@ -35,7 +35,7 @@ var ( VMRQKey *secp256k1.PrivateKey EWOQKey *secp256k1.PrivateKey - //go:embed genesis_localsigner.json + //go:embed genesis_local.json localGenesisConfigJSON []byte // LocalParams are the params used for local networks From 8885a5c44c63b3a90bebb05de4bbeb2e8af47cb2 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 16:42:05 -0500 Subject: [PATCH 17/56] Fix remaining references to old bls methods --- config/config.go | 9 +++++---- tests/e2e/p/workflow.go | 4 ++-- tests/fixture/tmpnet/node.go | 6 +++--- vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go | 4 ++-- .../primary/examples/register-l1-validator/main.go | 3 ++- .../primary/examples/set-l1-validator-weight/main.go | 3 ++- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/config/config.go b/config/config.go index 2fea0667e989..f71991ff2e11 100644 --- a/config/config.go +++ b/config/config.go @@ -37,6 +37,7 @@ import ( "github.com/ava-labs/avalanchego/utils/compression" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/ips" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/perms" @@ -647,7 +648,7 @@ func getStakingTLSCert(v *viper.Viper) (tls.Certificate, error) { func getStakingSigner(v *viper.Viper) (bls.Signer, error) { if v.GetBool(StakingEphemeralSignerEnabledKey) { - key, err := bls.NewSigner() + key, err := localsigner.NewSigner() if err != nil { return nil, fmt.Errorf("couldn't generate ephemeral signing key: %w", err) } @@ -660,7 +661,7 @@ func getStakingSigner(v *viper.Viper) (bls.Signer, error) { if err != nil { return nil, fmt.Errorf("unable to decode base64 content: %w", err) } - key, err := bls.SecretKeyFromBytes(signerKeyContent) + key, err := localsigner.SecretKeyFromBytes(signerKeyContent) if err != nil { return nil, fmt.Errorf("couldn't parse signing key: %w", err) } @@ -674,7 +675,7 @@ func getStakingSigner(v *viper.Viper) (bls.Signer, error) { if err != nil { return nil, err } - key, err := bls.SecretKeyFromBytes(signingKeyBytes) + key, err := localsigner.SecretKeyFromBytes(signingKeyBytes) if err != nil { return nil, fmt.Errorf("couldn't parse signing key: %w", err) } @@ -685,7 +686,7 @@ func getStakingSigner(v *viper.Viper) (bls.Signer, error) { return nil, errMissingStakingSigningKeyFile } - key, err := bls.NewSigner() + key, err := localsigner.NewSigner() if err != nil { return nil, fmt.Errorf("couldn't generate new signing key: %w", err) } diff --git a/tests/e2e/p/workflow.go b/tests/e2e/p/workflow.go index e55b187819f7..1a542ccadc37 100644 --- a/tests/e2e/p/workflow.go +++ b/tests/e2e/p/workflow.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/tests/fixture/e2e" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm" @@ -115,7 +115,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() { } tc.By("issuing an AddPermissionlessValidatorTx", func() { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pop := signer.NewProofOfPossession(sk) diff --git a/tests/fixture/tmpnet/node.go b/tests/fixture/tmpnet/node.go index 570d1d616d5d..ca696ebde160 100644 --- a/tests/fixture/tmpnet/node.go +++ b/tests/fixture/tmpnet/node.go @@ -22,7 +22,7 @@ import ( "github.com/ava-labs/avalanchego/config" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/staking" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms/platformvm/signer" ) @@ -267,7 +267,7 @@ func (n *Node) EnsureBLSSigningKey() error { } // Generate a new signing key - newKey, err := bls.NewSigner() + newKey, err := localsigner.NewSigner() if err != nil { return fmt.Errorf("failed to generate staking signer key: %w", err) } @@ -317,7 +317,7 @@ func (n *Node) GetProofOfPossession() (*signer.ProofOfPossession, error) { if err != nil { return nil, err } - secretKey, err := bls.SecretKeyFromBytes(signingKeyBytes) + secretKey, err := localsigner.SecretKeyFromBytes(signingKeyBytes) if err != nil { return nil, err } diff --git a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go index 453eabf7c881..86dd996369fc 100644 --- a/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go +++ b/vms/rpcchainvm/ghttp/gresponsewriter/writer_server.go @@ -111,8 +111,8 @@ func (s *Server) Hijack(context.Context, *emptypb.Empty) (*responsewriterpb.Hija remote := conn.RemoteAddr() return &responsewriterpb.HijackResponse{ - LocalNetwork: localsigner.Network(), - LocalString: localsigner.String(), + LocalNetwork: local.Network(), + LocalString: local.String(), RemoteNetwork: remote.Network(), RemoteString: remote.String(), ServerAddr: serverListener.Addr().String(), diff --git a/wallet/subnet/primary/examples/register-l1-validator/main.go b/wallet/subnet/primary/examples/register-l1-validator/main.go index 42aeb3a0f36a..333b21076ef2 100644 --- a/wallet/subnet/primary/examples/register-l1-validator/main.go +++ b/wallet/subnet/primary/examples/register-l1-validator/main.go @@ -14,6 +14,7 @@ import ( "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/platformvm/warp" @@ -38,7 +39,7 @@ func main() { log.Fatalf("failed to decode secret key: %s\n", err) } - sk, err := bls.SecretKeyFromBytes(blsSKBytes) + sk, err := localsigner.SecretKeyFromBytes(blsSKBytes) if err != nil { log.Fatalf("failed to parse secret key: %s\n", err) } diff --git a/wallet/subnet/primary/examples/set-l1-validator-weight/main.go b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go index e6e86e5cdb36..169a22a42f40 100644 --- a/wallet/subnet/primary/examples/set-l1-validator-weight/main.go +++ b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go @@ -13,6 +13,7 @@ import ( "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" @@ -37,7 +38,7 @@ func main() { log.Fatalf("failed to decode secret key: %s\n", err) } - sk, err := bls.SecretKeyFromBytes(blsSKBytes) + sk, err := localsigner.SecretKeyFromBytes(blsSKBytes) if err != nil { log.Fatalf("failed to parse secret key: %s\n", err) } From 1ca1be19e72f79190b4598d8f6a20e187e12d3e8 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 6 Jan 2025 18:23:38 -0500 Subject: [PATCH 18/56] Add updated coreth --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d03653f13775..29ab7ec85e46 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.14.1-0.20241230191223-351149733d35 + github.com/ava-labs/coreth v0.14.1-0.20250106222550-c575b84e58f7 github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 diff --git a/go.sum b/go.sum index c7216e28f9f7..393134fdff3b 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/coreth v0.14.1-0.20241230191223-351149733d35 h1:qBNnMleaJ7yWjNiDdV7wIf/e/PxubB+Ww7Mfx4QN4p8= -github.com/ava-labs/coreth v0.14.1-0.20241230191223-351149733d35/go.mod h1:nvQqJem4MuE0pU93aqBPsaEZx9NnXT0lI8d6rrQS5uY= +github.com/ava-labs/coreth v0.14.1-0.20250106222550-c575b84e58f7 h1:aAgV8u1Qnv3kev4cnV1PdwSL8rv1ic53sw6nmm0/ngs= +github.com/ava-labs/coreth v0.14.1-0.20250106222550-c575b84e58f7/go.mod h1:mzAii2r+iq2zCYTxk7obnOQ004BahdX26O8Lp0Ftpgc= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= From 41830aade9133b09140ee8c6f2492c6e7b4bb803 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 7 Jan 2025 13:00:29 -0500 Subject: [PATCH 19/56] Update tests to use localsigner --- network/network_test.go | 4 ++-- network/p2p/acp118/handler_test.go | 3 ++- network/peer/ip_signer_test.go | 4 ++-- network/peer/ip_test.go | 3 ++- network/peer/peer_test.go | 8 ++++---- .../gvalidators/validator_state_test.go | 9 +++++---- snow/validators/manager_test.go | 15 ++++++++------- snow/validators/set_test.go | 9 +++++---- vms/platformvm/block/builder/builder_test.go | 8 ++++---- .../block/executor/proposal_block_test.go | 6 +++--- vms/platformvm/block/executor/verifier_test.go | 3 ++- vms/platformvm/network/warp_test.go | 5 +++-- vms/platformvm/service_test.go | 8 ++++---- vms/platformvm/signer/proof_of_possession_test.go | 5 +++-- vms/platformvm/state/staker_test.go | 4 ++-- vms/platformvm/state/state_test.go | 15 ++++++++------- .../txs/add_permissionless_validator_tx_test.go | 3 ++- .../txs/convert_subnet_to_l1_tx_test.go | 3 ++- .../txs/executor/standard_tx_executor_test.go | 15 ++++++++------- vms/platformvm/txs/executor/state_changes_test.go | 3 ++- vms/platformvm/txs/executor/warp_verifier_test.go | 3 ++- vms/platformvm/validator_set_property_test.go | 7 ++++--- .../validators/manager_benchmark_test.go | 4 ++-- vms/platformvm/validators/manager_test.go | 4 ++-- vms/platformvm/vm_regression_test.go | 9 +++++---- vms/platformvm/vm_test.go | 10 +++++----- vms/platformvm/warp/gwarp/signer_test.go | 3 ++- .../warp/message/register_l1_validator_test.go | 3 ++- vms/platformvm/warp/signature_test.go | 3 ++- vms/platformvm/warp/signer_test.go | 4 ++-- vms/platformvm/warp/validator_test.go | 7 ++++--- wallet/chain/p/builder_test.go | 11 ++++++----- 32 files changed, 111 insertions(+), 90 deletions(-) diff --git a/network/network_test.go b/network/network_test.go index 9791060f6f35..a8a194e4e890 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -30,7 +30,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/bloom" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/ips" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" @@ -175,7 +175,7 @@ func newTestNetwork(t *testing.T, count int) (*testDialer, []*testListener, []id require.NoError(t, err) nodeID := ids.NodeIDFromCert(cert) - blsKey, err := bls.NewSigner() + blsKey, err := localsigner.NewSigner() require.NoError(t, err) config := defaultConfig diff --git a/network/p2p/acp118/handler_test.go b/network/p2p/acp118/handler_test.go index 0ec5dc93064a..b179c00efb91 100644 --- a/network/p2p/acp118/handler_test.go +++ b/network/p2p/acp118/handler_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" ) @@ -72,7 +73,7 @@ func TestHandler(t *testing.T) { require := require.New(t) ctx := context.Background() - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() networkID := uint32(123) diff --git a/network/peer/ip_signer_test.go b/network/peer/ip_signer_test.go index 7c6a9a5e5fbd..b1430748a3ee 100644 --- a/network/peer/ip_signer_test.go +++ b/network/peer/ip_signer_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/staking" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestIPSigner(t *testing.T) { @@ -28,7 +28,7 @@ func TestIPSigner(t *testing.T) { require.NoError(err) tlsKey := tlsCert.PrivateKey.(crypto.Signer) - blsKey, err := bls.NewSigner() + blsKey, err := localsigner.NewSigner() require.NoError(err) s := NewIPSigner(dynIP, tlsKey, blsKey) diff --git a/network/peer/ip_test.go b/network/peer/ip_test.go index 385940983870..6613fe6a48d7 100644 --- a/network/peer/ip_test.go +++ b/network/peer/ip_test.go @@ -13,6 +13,7 @@ import ( "github.com/ava-labs/avalanchego/staking" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestSignedIpVerify(t *testing.T) { @@ -21,7 +22,7 @@ func TestSignedIpVerify(t *testing.T) { cert1, err := staking.ParseCertificate(tlsCert1.Leaf.Raw) require.NoError(t, err) tlsKey1 := tlsCert1.PrivateKey.(crypto.Signer) - blsKey1, err := bls.NewSigner() + blsKey1, err := localsigner.NewSigner() require.NoError(t, err) tlsCert2, err := staking.NewTLSCert() diff --git a/network/peer/peer_test.go b/network/peer/peer_test.go index 0d617fecbc69..5ec43bf33f2d 100644 --- a/network/peer/peer_test.go +++ b/network/peer/peer_test.go @@ -25,7 +25,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" @@ -111,7 +111,7 @@ func newRawTestPeer(t *testing.T, config Config) *rawTestPeer { 1, )) tls := tlsCert.PrivateKey.(crypto.Signer) - bls, err := bls.NewSigner() + bls, err := localsigner.NewSigner() require.NoError(err) config.IPSigner = NewIPSigner(ip, tls, bls) @@ -327,7 +327,7 @@ func TestInvalidBLSKeyDisconnects(t *testing.T) { 1, )) - bogusBLSKey, err := bls.NewSigner() + bogusBLSKey, err := localsigner.NewSigner() require.NoError(err) require.NoError(rawPeer1.config.Validators.AddStaker( constants.PrimaryNetworkID, @@ -348,7 +348,7 @@ func TestInvalidBLSKeyDisconnects(t *testing.T) { func TestShouldDisconnect(t *testing.T) { peerID := ids.GenerateTestNodeID() txID := ids.GenerateTestID() - blsKey, err := bls.NewSigner() + blsKey, err := localsigner.NewSigner() require.NoError(t, err) tests := []struct { diff --git a/snow/validators/gvalidators/validator_state_test.go b/snow/validators/gvalidators/validator_state_test.go index f512e90a96b2..516ddd4d46c6 100644 --- a/snow/validators/gvalidators/validator_state_test.go +++ b/snow/validators/gvalidators/validator_state_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/snow/validators/validatorsmock" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils" pb "github.com/ava-labs/avalanchego/proto/pb/validatorstate" @@ -135,7 +136,7 @@ func TestGetValidatorSet(t *testing.T) { state := setupState(t, ctrl) // Happy path - sk0, err := bls.NewSigner() + sk0, err := localsigner.NewSigner() require.NoError(err) vdr0 := &validators.GetValidatorOutput{ NodeID: ids.GenerateTestNodeID(), @@ -143,7 +144,7 @@ func TestGetValidatorSet(t *testing.T) { Weight: 1, } - sk1, err := bls.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(err) vdr1 := &validators.GetValidatorOutput{ NodeID: ids.GenerateTestNodeID(), @@ -181,7 +182,7 @@ func TestGetValidatorSet(t *testing.T) { func TestPublicKeyDeserialize(t *testing.T) { require := require.New(t) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() @@ -222,7 +223,7 @@ func setupValidatorSet(b *testing.B, size int) map[ids.NodeID]*validators.GetVal b.Helper() set := make(map[ids.NodeID]*validators.GetValidatorOutput, size) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(b, err) pk := sk.PublicKey() for i := 0; i < size; i++ { diff --git a/snow/validators/manager_test.go b/snow/validators/manager_test.go index 2296b8c67328..50a5c871a6d0 100644 --- a/snow/validators/manager_test.go +++ b/snow/validators/manager_test.go @@ -11,6 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" safemath "github.com/ava-labs/avalanchego/utils/math" @@ -214,7 +215,7 @@ func TestGet(t *testing.T) { _, ok := m.GetValidator(subnetID, nodeID) require.False(ok) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() @@ -304,7 +305,7 @@ func TestGetMap(t *testing.T) { mp := m.GetMap(subnetID) require.Empty(mp) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() @@ -404,7 +405,7 @@ func TestSample(t *testing.T) { require.NoError(err) require.Empty(sampled) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) nodeID0 := ids.GenerateTestNodeID() @@ -464,7 +465,7 @@ func TestString(t *testing.T) { func TestAddCallback(t *testing.T) { require := require.New(t) - expectedSK, err := bls.NewSigner() + expectedSK, err := localsigner.NewSigner() require.NoError(err) var ( @@ -512,7 +513,7 @@ func TestAddCallback(t *testing.T) { func TestAddWeightCallback(t *testing.T) { require := require.New(t) - expectedSK, err := bls.NewSigner() + expectedSK, err := localsigner.NewSigner() require.NoError(err) var ( @@ -595,7 +596,7 @@ func TestAddWeightCallback(t *testing.T) { func TestRemoveWeightCallback(t *testing.T) { require := require.New(t) - expectedSK, err := bls.NewSigner() + expectedSK, err := localsigner.NewSigner() require.NoError(err) var ( @@ -678,7 +679,7 @@ func TestRemoveWeightCallback(t *testing.T) { func TestRemoveCallback(t *testing.T) { require := require.New(t) - expectedSK, err := bls.NewSigner() + expectedSK, err := localsigner.NewSigner() require.NoError(err) var ( diff --git a/snow/validators/set_test.go b/snow/validators/set_test.go index 8fb2a6c6b56d..59597eab644d 100644 --- a/snow/validators/set_test.go +++ b/snow/validators/set_test.go @@ -11,6 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" safemath "github.com/ava-labs/avalanchego/utils/math" @@ -165,7 +166,7 @@ func TestSetGet(t *testing.T) { _, ok := s.Get(nodeID) require.False(ok) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() @@ -232,7 +233,7 @@ func TestSetMap(t *testing.T) { m := s.Map() require.Empty(m) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() @@ -330,7 +331,7 @@ func TestSetSample(t *testing.T) { require.NoError(err) require.Empty(sampled) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) nodeID0 := ids.GenerateTestNodeID() @@ -385,7 +386,7 @@ func TestSetAddCallback(t *testing.T) { require := require.New(t) nodeID0 := ids.BuildTestNodeID([]byte{1}) - sk0, err := bls.NewSigner() + sk0, err := localsigner.NewSigner() require.NoError(err) pk0 := sk0.PublicKey() txID0 := ids.GenerateTestID() diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index dabcf5813cc4..32e831d854d5 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" @@ -112,7 +112,7 @@ func TestBuildBlockShouldReward(t *testing.T) { validatorEndTime = validatorStartTime.Add(360 * 24 * time.Hour) ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) rewardOwners := &secp256k1fx.OutputOwners{ @@ -320,7 +320,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { validatorEndTime = now.Add(env.config.MaxStakeDuration) ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -353,7 +353,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { // Add a validator ending past [MaxStakeDuration] validator2EndTime := now.Add(env.config.MaxStakeDuration + time.Second) - sk, err = bls.NewSigner() + sk, err = localsigner.NewSigner() require.NoError(err) tx2, err := wallet.IssueAddPermissionlessValidatorTx( diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index c44d3569b5df..97d6e16e6770 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -18,7 +18,7 @@ import ( "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/timer/mockable" @@ -1329,7 +1329,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { nodeID = ids.GenerateTestNodeID() ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -1414,7 +1414,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { validatorEndTime = validatorStartTime.Add(env.config.MinStakeDuration) nodeID = ids.GenerateTestNodeID() - sk, err = bls.NewSigner() + sk, err = localsigner.NewSigner() require.NoError(err) addValidatorTx2, err := wallet.IssueAddPermissionlessValidatorTx( diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index 74b932d67e7f..2d6a5c74ca5d 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -25,6 +25,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" @@ -1218,7 +1219,7 @@ func TestBlockExecutionWithComplexity(t *testing.T) { } func TestDeactivateLowBalanceL1Validators(t *testing.T) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) var ( diff --git a/vms/platformvm/network/warp_test.go b/vms/platformvm/network/warp_test.go index a9763df45d71..f7df8ca61c70 100644 --- a/vms/platformvm/network/warp_test.go +++ b/vms/platformvm/network/warp_test.go @@ -21,6 +21,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" @@ -177,7 +178,7 @@ func TestSignatureRequestVerifySubnetToL1Conversion(t *testing.T) { } func TestSignatureRequestVerifyL1ValidatorRegistrationRegistered(t *testing.T) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) var ( @@ -544,7 +545,7 @@ func TestSignatureRequestVerifyL1ValidatorRegistrationNotRegistered(t *testing.T } func TestSignatureRequestVerifyL1ValidatorWeight(t *testing.T) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) const ( diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 5e2eb96eac99..4692052bc77b 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -30,7 +30,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/formatting/address" @@ -312,7 +312,7 @@ func TestGetTx(t *testing.T) { func(t testing.TB, s *Service) *txs.Tx { wallet := newWallet(t, s.vm, walletConfig{}) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -848,7 +848,7 @@ func TestGetValidatorsAt(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) tx, err := wallet.IssueAddPermissionlessValidatorTx( @@ -1073,7 +1073,7 @@ func TestGetValidatorsAtReplyMarshalling(t *testing.T) { } { nodeID := ids.GenerateTestNodeID() - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) reply.Validators[nodeID] = &validators.GetValidatorOutput{ NodeID: nodeID, diff --git a/vms/platformvm/signer/proof_of_possession_test.go b/vms/platformvm/signer/proof_of_possession_test.go index 95e2de2b75b1..fac9744e9eda 100644 --- a/vms/platformvm/signer/proof_of_possession_test.go +++ b/vms/platformvm/signer/proof_of_possession_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestProofOfPossession(t *testing.T) { @@ -41,7 +42,7 @@ func TestProofOfPossession(t *testing.T) { func TestNewProofOfPossessionDeterministic(t *testing.T) { require := require.New(t) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) blsPOP0 := NewProofOfPossession(sk) @@ -60,7 +61,7 @@ func BenchmarkProofOfPossessionVerify(b *testing.B) { } func newProofOfPossession() (*ProofOfPossession, error) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() if err != nil { return nil, err } diff --git a/vms/platformvm/state/staker_test.go b/vms/platformvm/state/staker_test.go index 56d22b6c7028..78eab52cceff 100644 --- a/vms/platformvm/state/staker_test.go +++ b/vms/platformvm/state/staker_test.go @@ -12,7 +12,7 @@ import ( "go.uber.org/mock/gomock" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/signer/signermock" "github.com/ava-labs/avalanchego/vms/platformvm/txs" @@ -202,7 +202,7 @@ func TestNewPendingStaker(t *testing.T) { func generateStakerTx(require *require.Assertions) *txs.AddPermissionlessValidatorTx { nodeID := ids.GenerateTestNodeID() - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pop := signer.NewProofOfPossession(sk) subnetID := ids.GenerateTestID() diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index aacb8b0484b3..3ebc1bf75f24 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -28,6 +28,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" @@ -545,7 +546,7 @@ func TestState_writeStakers(t *testing.T) { func createPermissionlessValidatorTx(t testing.TB, subnetID ids.ID, validatorsData txs.Validator) *txs.AddPermissionlessValidatorTx { var sig signer.Signer = &signer.Empty{} if subnetID == constants.PrimaryNetworkID { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) sig = signer.NewProofOfPossession(sk) } @@ -785,7 +786,7 @@ func TestState_ApplyValidatorDiffs(t *testing.T) { subnetStakers = make([]Staker, numNodes) ) for i := range primaryStakers { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) timeOffset := time.Duration(i) * time.Second @@ -1514,12 +1515,12 @@ func TestL1Validators(t *testing.T) { NodeID: ids.GenerateTestNodeID(), } - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) - otherSK, err := bls.NewSigner() + otherSK, err := localsigner.NewSigner() require.NoError(t, err) otherPK := otherSK.PublicKey() otherPKBytes := bls.PublicKeyToUncompressedBytes(otherPK) @@ -2016,7 +2017,7 @@ func TestLoadL1ValidatorAndLegacy(t *testing.T) { } require.NoError(state.PutCurrentValidator(legacyStaker)) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) @@ -2094,12 +2095,12 @@ func TestGetCurrentValidators(t *testing.T) { subnetID2 := ids.GenerateTestID() subnetIDs := []ids.ID{subnetID1, subnetID2} - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) - otherSK, err := bls.NewSigner() + otherSK, err := localsigner.NewSigner() require.NoError(t, err) otherPK := otherSK.PublicKey() otherPKBytes := bls.PublicKeyToUncompressedBytes(otherPK) diff --git a/vms/platformvm/txs/add_permissionless_validator_tx_test.go b/vms/platformvm/txs/add_permissionless_validator_tx_test.go index a9d35af873d7..51287fdea762 100644 --- a/vms/platformvm/txs/add_permissionless_validator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_validator_tx_test.go @@ -16,6 +16,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/avax/avaxmock" @@ -1397,7 +1398,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { }, } - blsSK, err := bls.NewSigner() + blsSK, err := localsigner.NewSigner() require.NoError(t, err) blsPOP := signer.NewProofOfPossession(blsSK) diff --git a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go index 1192b2c52997..6041ff021bb1 100644 --- a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -545,7 +546,7 @@ func TestConvertSubnetToL1TxSerialization(t *testing.T) { } func TestConvertSubnetToL1TxSyntacticVerify(t *testing.T) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) var ( diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index 26216061aa52..18d78668f855 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -23,6 +23,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/logging" @@ -1450,7 +1451,7 @@ func TestDurangoMemoField(t *testing.T) { chainTime = env.state.GetTimestamp() endTime = chainTime.Add(defaultMaxStakingDuration) ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) wallet := newWallet(t, env, walletConfig{}) @@ -2547,7 +2548,7 @@ func TestStandardExecutorConvertSubnetToL1Tx(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) // Create the ConvertSubnetToL1Tx @@ -2748,7 +2749,7 @@ func TestStandardExecutorRegisterL1ValidatorTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - initialSK, err := bls.NewSigner() + initialSK, err := localsigner.NewSigner() require.NoError(t, err) const ( @@ -2801,7 +2802,7 @@ func TestStandardExecutorRegisterL1ValidatorTx(t *testing.T) { const weight = 1 // Create the Warp message - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) pop := signer.NewProofOfPossession(sk) pk := sk.PublicKey() @@ -3278,7 +3279,7 @@ func TestStandardExecutorSetL1ValidatorWeightTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) const ( @@ -3781,7 +3782,7 @@ func TestStandardExecutorIncreaseL1ValidatorBalanceTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) const ( @@ -4077,7 +4078,7 @@ func TestStandardExecutorDisableL1ValidatorTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) const ( diff --git a/vms/platformvm/txs/executor/state_changes_test.go b/vms/platformvm/txs/executor/state_changes_test.go index 372a05a431d5..b8554a3aa350 100644 --- a/vms/platformvm/txs/executor/state_changes_test.go +++ b/vms/platformvm/txs/executor/state_changes_test.go @@ -13,6 +13,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" @@ -228,7 +229,7 @@ func TestAdvanceTimeTo_RemovesStaleExpiries(t *testing.T) { } func TestAdvanceTimeTo_UpdateL1Validators(t *testing.T) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) const ( diff --git a/vms/platformvm/txs/executor/warp_verifier_test.go b/vms/platformvm/txs/executor/warp_verifier_test.go index 44a93cd2c829..f6ca17312ec5 100644 --- a/vms/platformvm/txs/executor/warp_verifier_test.go +++ b/vms/platformvm/txs/executor/warp_verifier_test.go @@ -15,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/warp" @@ -25,7 +26,7 @@ func TestVerifyWarpMessages(t *testing.T) { subnetID = ids.GenerateTestID() chainID = ids.GenerateTestID() newValidator = func() (bls.Signer, *validators.GetValidatorOutput) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) return sk, &validators.GetValidatorOutput{ diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index 5adee28a5fcd..8f639d748beb 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -33,6 +33,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" @@ -276,7 +277,7 @@ func addPrimaryValidatorWithBLSKey(t testing.TB, vm *VM, data *validatorInputDat wallet := newWallet(t, vm, walletConfig{}) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -414,7 +415,7 @@ func buildTimestampsList(events []uint8, currentTime time.Time, nodeID ids.NodeI currentTime = currentTime.Add(txexecutor.SyncBound) switch endTime := currentTime.Add(defaultMinStakingDuration); events[0] { case startPrimaryWithBLS: - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() if err != nil { return nil, fmt.Errorf("could not make private key: %w", err) } @@ -452,7 +453,7 @@ func buildTimestampsList(events []uint8, currentTime time.Time, nodeID ids.NodeI case startPrimaryWithBLS: currentTime = currentPrimaryVal.endTime.Add(txexecutor.SyncBound) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() if err != nil { return nil, fmt.Errorf("could not make private key: %w", err) } diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 460c28fc9f88..130a14f24ca3 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" @@ -109,7 +109,7 @@ func addPrimaryValidator( endTime time.Time, height uint64, ) (ids.NodeID, error) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() if err != nil { return ids.EmptyNodeID, err } diff --git a/vms/platformvm/validators/manager_test.go b/vms/platformvm/validators/manager_test.go index 9a15b353f3f4..dd4f32f9460d 100644 --- a/vms/platformvm/validators/manager_test.go +++ b/vms/platformvm/validators/manager_test.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/platformvm/block" @@ -39,7 +39,7 @@ func TestGetValidatorSet_AfterEtna(t *testing.T) { Upgrades: upgrades, }) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) var ( subnetID = ids.GenerateTestID() diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 89a3da49ab1d..6f514283b589 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -31,6 +31,7 @@ import ( "github.com/ava-labs/avalanchego/utils/bloom" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/version" @@ -1477,7 +1478,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } ) - sk1, err := bls.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(t, err) pk1 := sk1.PublicKey() @@ -1583,7 +1584,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { t.Logf("primaryEndHeight: %d", primaryEndHeight) // reinsert primary validator with a different BLS key - sk2, err := bls.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(t, err) pk2 := sk2.PublicKey() @@ -1749,7 +1750,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // reinsert primary validator with a different BLS key - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) primaryRestartTx, err := wallet.IssueAddPermissionlessValidatorTx( @@ -1918,7 +1919,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // reinsert primary validator with a different BLS key - sk2, err := bls.NewSigner() + sk2, err := localsigner.NewSigner() require.NoError(err) primaryRestartTx, err := wallet.IssueAddPermissionlessValidatorTx( diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 7d2268c7d20d..db5f11ed4925 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -38,7 +38,7 @@ import ( "github.com/ava-labs/avalanchego/subnets" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" @@ -314,7 +314,7 @@ func TestAddValidatorCommit(t *testing.T) { } ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) // create valid tx @@ -470,7 +470,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { startTime := latestForkTime.Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -1905,7 +1905,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) nodeID := ids.GenerateTestNodeID() - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ Threshold: 1, @@ -2121,7 +2121,7 @@ func TestPruneMempool(t *testing.T) { endTime = startTime.Add(vm.MinStakeDuration) ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/warp/gwarp/signer_test.go b/vms/platformvm/warp/gwarp/signer_test.go index e272aee474ed..012d5436a9ba 100644 --- a/vms/platformvm/warp/gwarp/signer_test.go +++ b/vms/platformvm/warp/gwarp/signer_test.go @@ -11,6 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/signertest" "github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils" @@ -29,7 +30,7 @@ type testSigner struct { func setupSigner(t testing.TB) *testSigner { require := require.New(t) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(err) chainID := ids.GenerateTestID() diff --git a/vms/platformvm/warp/message/register_l1_validator_test.go b/vms/platformvm/warp/message/register_l1_validator_test.go index eab8a5a395ab..81e5bb6d8fd9 100644 --- a/vms/platformvm/warp/message/register_l1_validator_test.go +++ b/vms/platformvm/warp/message/register_l1_validator_test.go @@ -12,11 +12,12 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/hashing" ) func newBLSPublicKey(t *testing.T) [bls.PublicKeyLen]byte { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) pk := sk.PublicKey() diff --git a/vms/platformvm/warp/signature_test.go b/vms/platformvm/warp/signature_test.go index 6d21bbc09795..18af48027ec7 100644 --- a/vms/platformvm/warp/signature_test.go +++ b/vms/platformvm/warp/signature_test.go @@ -18,6 +18,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" ) @@ -44,7 +45,7 @@ func (v *testValidator) Compare(o *testValidator) int { } func newTestValidator() *testValidator { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() if err != nil { panic(err) } diff --git a/vms/platformvm/warp/signer_test.go b/vms/platformvm/warp/signer_test.go index 914647804441..2ea7e572db15 100644 --- a/vms/platformvm/warp/signer_test.go +++ b/vms/platformvm/warp/signer_test.go @@ -10,7 +10,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/signertest" ) @@ -18,7 +18,7 @@ import ( func TestSigner(t *testing.T) { for name, test := range signertest.SignerTests { t.Run(name, func(t *testing.T) { - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) chainID := ids.GenerateTestID() diff --git a/vms/platformvm/warp/validator_test.go b/vms/platformvm/warp/validator_test.go index 77ea14291d27..00a54b7fd0e7 100644 --- a/vms/platformvm/warp/validator_test.go +++ b/vms/platformvm/warp/validator_test.go @@ -17,6 +17,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators/validatorsmock" "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/set" ) @@ -162,7 +163,7 @@ func TestGetCanonicalValidatorSet(t *testing.T) { } func TestFilterValidators(t *testing.T) { - sk0, err := bls.NewSigner() + sk0, err := localsigner.NewSigner() require.NoError(t, err) pk0 := sk0.PublicKey() vdr0 := &Validator{ @@ -171,7 +172,7 @@ func TestFilterValidators(t *testing.T) { Weight: 1, } - sk1, err := bls.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(t, err) pk1 := sk1.PublicKey() vdr1 := &Validator{ @@ -315,7 +316,7 @@ func BenchmarkGetCanonicalValidatorSet(b *testing.B) { getValidatorOutputs := make([]*validators.GetValidatorOutput, 0, numNodes) for i := 0; i < numNodes; i++ { nodeID := ids.GenerateTestNodeID() - blsPrivateKey, err := bls.NewSigner() + blsPrivateKey, err := localsigner.NewSigner() require.NoError(b, err) blsPublicKey := blsPrivateKey.PublicKey() getValidatorOutputs = append(getValidatorOutputs, &validators.GetValidatorOutput{ diff --git a/wallet/chain/p/builder_test.go b/wallet/chain/p/builder_test.go index c4a9e39a7125..aff8cdcb35fa 100644 --- a/wallet/chain/p/builder_test.go +++ b/wallet/chain/p/builder_test.go @@ -15,6 +15,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/units" @@ -581,7 +582,7 @@ func TestAddPermissionlessValidatorTx(t *testing.T) { delegationShares uint32 = reward.PercentDenominator ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) pop := signer.NewProofOfPossession(sk) @@ -682,9 +683,9 @@ func TestAddPermissionlessDelegatorTx(t *testing.T) { } func TestConvertSubnetToL1Tx(t *testing.T) { - sk0, err := bls.NewSigner() + sk0, err := localsigner.NewSigner() require.NoError(t, err) - sk1, err := bls.NewSigner() + sk1, err := localsigner.NewSigner() require.NoError(t, err) var ( @@ -767,7 +768,7 @@ func TestRegisterL1ValidatorTx(t *testing.T) { balance = units.Avax ) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) pop := signer.NewProofOfPossession(sk) @@ -890,7 +891,7 @@ func TestSetL1ValidatorWeightTx(t *testing.T) { ) require.NoError(t, err) - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) warp, err := warp.NewMessage( From d92c69cdc5aa3d57ca3a4828fe7eba5cfac640ae Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 7 Jan 2025 13:19:22 -0500 Subject: [PATCH 20/56] Fix SecretKeyFromBytes --- vms/platformvm/network/warp_test.go | 2 +- vms/platformvm/txs/add_permissionless_validator_tx_test.go | 3 +-- vms/platformvm/txs/convert_subnet_to_l1_tx_test.go | 2 +- vms/platformvm/txs/register_l1_validator_tx_test.go | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/vms/platformvm/network/warp_test.go b/vms/platformvm/network/warp_test.go index f7df8ca61c70..7813548fcc68 100644 --- a/vms/platformvm/network/warp_test.go +++ b/vms/platformvm/network/warp_test.go @@ -241,7 +241,7 @@ func TestSignatureRequestVerifyL1ValidatorRegistrationNotRegistered(t *testing.T skBytes, err := hex.DecodeString("36a33c536d283dfa599d0a70839c67ded6c954e346c5e8e5b4794e2299907887") require.NoError(t, err) - sk, err := bls.SecretKeyFromBytes(skBytes) + sk, err := localsigner.SecretKeyFromBytes(skBytes) require.NoError(t, err) var ( diff --git a/vms/platformvm/txs/add_permissionless_validator_tx_test.go b/vms/platformvm/txs/add_permissionless_validator_tx_test.go index 51287fdea762..e1f7e90b1140 100644 --- a/vms/platformvm/txs/add_permissionless_validator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_validator_tx_test.go @@ -15,7 +15,6 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" @@ -42,7 +41,7 @@ func TestAddPermissionlessPrimaryValidator(t *testing.T) { skBytes, err := hex.DecodeString("6668fecd4595b81e4d568398c820bbf3f073cb222902279fa55ebb84764ed2e3") require.NoError(err) - sk, err := bls.SecretKeyFromBytes(skBytes) + sk, err := localsigner.SecretKeyFromBytes(skBytes) require.NoError(err) avaxAssetID, err := ids.FromString("FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z") diff --git a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go index 6041ff021bb1..fe80ae65d174 100644 --- a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go @@ -38,7 +38,7 @@ var ( func TestConvertSubnetToL1TxSerialization(t *testing.T) { skBytes, err := hex.DecodeString("6668fecd4595b81e4d568398c820bbf3f073cb222902279fa55ebb84764ed2e3") require.NoError(t, err) - sk, err := bls.SecretKeyFromBytes(skBytes) + sk, err := localsigner.SecretKeyFromBytes(skBytes) require.NoError(t, err) var ( diff --git a/vms/platformvm/txs/register_l1_validator_tx_test.go b/vms/platformvm/txs/register_l1_validator_tx_test.go index 5c1f126ac64c..ec7b5ac91902 100644 --- a/vms/platformvm/txs/register_l1_validator_tx_test.go +++ b/vms/platformvm/txs/register_l1_validator_tx_test.go @@ -15,7 +15,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/signer" @@ -34,7 +34,7 @@ func TestRegisterL1ValidatorTxSerialization(t *testing.T) { skBytes, err := hex.DecodeString("6668fecd4595b81e4d568398c820bbf3f073cb222902279fa55ebb84764ed2e3") require.NoError(err) - sk, err := bls.SecretKeyFromBytes(skBytes) + sk, err := localsigner.SecretKeyFromBytes(skBytes) require.NoError(err) var ( From a679b4420fc3bd24c4476c4d5b692c57f0f1f6dd Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 7 Jan 2025 13:45:38 -0500 Subject: [PATCH 21/56] Fix linter errors --- snow/consensus/snowball/tree.go | 168 +++++++++--------- utils/crypto/bls/blstest/bls_test.go | 5 +- utils/crypto/bls/public.go | 6 +- utils/crypto/bls/signers/json-rpc/client.go | 8 +- utils/crypto/bls/signers/json-rpc/server.go | 6 +- .../bls/signers/localsigner/localsigner.go | 1 + 6 files changed, 97 insertions(+), 97 deletions(-) diff --git a/snow/consensus/snowball/tree.go b/snow/consensus/snowball/tree.go index c6773e30c54e..d4c08c2c8e9f 100644 --- a/snow/consensus/snowball/tree.go +++ b/snow/consensus/snowball/tree.go @@ -175,8 +175,6 @@ func (u *unaryNode) DecidedPrefix() int { return u.decidedPrefix } -//nolint:gci,gofmt,gofumpt // this comment is formatted as intended -// // This is by far the most complicated function in this algorithm. // The intuition is that this instance represents a series of consecutive unary // snowball instances, and this function's purpose is convert one of these unary @@ -188,23 +186,23 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "00001" in this node: // -// +-------------------+ <-- This node will not be split -// | | -// | 0 0 0 | -// | | -// +-------------------+ <-- Pass the add to the child -// ^ -// | +// +-------------------+ <-- This node will not be split +// | | +// | 0 0 0 | +// | | +// +-------------------+ <-- Pass the add to the child +// ^ +// | // // Results in: // -// +-------------------+ -// | | -// | 0 0 0 | -// | | -// +-------------------+ <-- With the modified child -// ^ -// | +// +-------------------+ +// | | +// | 0 0 0 | +// | | +// +-------------------+ <-- With the modified child +// ^ +// | // // 2. This instance represents a series of only one unary instance and it must // be split. @@ -215,19 +213,19 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "1" in this tree: // -// +-------------------+ -// | | -// | 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ // // 3. This instance must be split on the first bit // @@ -237,26 +235,26 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "10" in this tree: // -// +-------------------+ -// | | -// | 0 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ -// ^ ^ -// / \ -// +-------------------+ +-------------------+ -// | | | | -// | 0 | | 0 | -// | | | | -// +-------------------+ +-------------------+ +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ +// ^ ^ +// / \ +// +-------------------+ +-------------------+ +// | | | | +// | 0 | | 0 | +// | | | | +// +-------------------+ +-------------------+ // // 4. This instance must be split on the last bit // @@ -267,26 +265,26 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "01" in this tree: // -// +-------------------+ -// | | -// | 0 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | -// | 0 | -// | | -// +-------------------+ -// ^ -// | -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 | +// | | +// +-------------------+ +// ^ +// | +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ // // 5. This instance must be split on an interior bit // @@ -298,33 +296,35 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "010" in this tree: // -// +-------------------+ -// | | -// | 0 0 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 0 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | -// | 0 | -// | | -// +-------------------+ -// ^ -// | -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ -// ^ ^ -// / \ -// +-------------------+ +-------------------+ -// | | | | -// | 0 | | 0 | -// | | | | -// +-------------------+ +-------------------+ +// +-------------------+ +// | | +// | 0 | +// | | +// +-------------------+ +// ^ +// | +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ +// ^ ^ +// / \ +// +-------------------+ +-------------------+ +// | | | | +// | 0 | | 0 | +// | | | | +// +-------------------+ +-------------------+ +// +//nolint:gci,gofmt,gofumpt // this comment is formatted as intended func (u *unaryNode) Add(newChoice ids.ID) node { if u.Finalized() { return u // Only happens if the tree is finalized, or it's a leaf node diff --git a/utils/crypto/bls/blstest/bls_test.go b/utils/crypto/bls/blstest/bls_test.go index 951e17a06dd8..82a5c9ea123d 100644 --- a/utils/crypto/bls/blstest/bls_test.go +++ b/utils/crypto/bls/blstest/bls_test.go @@ -12,8 +12,9 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" - jsonrpc "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/json-rpc" "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + + jsonrpc "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/json-rpc" ) type Signer interface { @@ -42,6 +43,7 @@ var localSignerFn = func() (Signer, error) { signer, err := localsigner.NewSigner() return &localSigner{LocalSigner: signer}, err } + var serverSignerFn = func() (Signer, error) { // do I need to make sure the server gets closed properly? service := jsonrpc.NewSignerService() @@ -107,7 +109,6 @@ func TestAggregation(t *testing.T) { name: "valid single key", signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - pks := []*bls.PublicKey{ signer.PublicKey(), } diff --git a/utils/crypto/bls/public.go b/utils/crypto/bls/public.go index 43ee139eeaa9..0d3dbaf9559b 100644 --- a/utils/crypto/bls/public.go +++ b/utils/crypto/bls/public.go @@ -9,8 +9,10 @@ import ( blst "github.com/supranational/blst/bindings/go" ) -const SecretKeyLen = blst.BLST_SCALAR_BYTES -const PublicKeyLen = blst.BLST_P1_COMPRESS_BYTES +const ( + SecretKeyLen = blst.BLST_SCALAR_BYTES + PublicKeyLen = blst.BLST_P1_COMPRESS_BYTES +) var ( ErrNoPublicKeys = errors.New("no public keys") diff --git a/utils/crypto/bls/signers/json-rpc/client.go b/utils/crypto/bls/signers/json-rpc/client.go index 481bf714aff6..16eade412e1a 100644 --- a/utils/crypto/bls/signers/json-rpc/client.go +++ b/utils/crypto/bls/signers/json-rpc/client.go @@ -5,8 +5,9 @@ import ( "net/http" "net/url" - "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/gorilla/rpc/v2/json2" + + "github.com/ava-labs/avalanchego/utils/crypto/bls" ) type Client struct { @@ -24,13 +25,11 @@ func NewClient(url url.URL) *Client { func (client *Client) call(method string, params []interface{}, result interface{}) error { requestBody, err := json2.EncodeClientRequest(method, params) - if err != nil { return err } resp, err := client.http.Post(client.url.String(), "application/json", bytes.NewBuffer(requestBody)) - if err != nil { return err } @@ -42,7 +41,6 @@ func (c *Client) PublicKey() *bls.PublicKey { reply := new(PublicKeyReply) err := c.call("Signer.PublicKey", []interface{}{PublicKeyArgs{}}, reply) - if err != nil { panic(err) } @@ -58,7 +56,6 @@ func (c *Client) Sign(msg []byte) *bls.Signature { // request the public key from the json-rpc server reply := new(SignReply) err := c.call("Signer.Sign", []interface{}{SignArgs{msg}}, reply) - // TODO: handle this if err != nil { panic(err) @@ -77,7 +74,6 @@ func (c *Client) SignProofOfPossession(msg []byte) *bls.Signature { // request the public key from the json-rpc server reply := new(SignReply) err := c.call("Signer.SignProofOfPossession", []interface{}{SignArgs{msg}}, reply) - // TODO: handle this if err != nil { panic(err) diff --git a/utils/crypto/bls/signers/json-rpc/server.go b/utils/crypto/bls/signers/json-rpc/server.go index e2e866f46334..224c1bcfa973 100644 --- a/utils/crypto/bls/signers/json-rpc/server.go +++ b/utils/crypto/bls/signers/json-rpc/server.go @@ -7,10 +7,11 @@ import ( "net/http" "time" - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" "github.com/gorilla/rpc/v2" "github.com/gorilla/rpc/v2/json" + + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) type signerService struct { @@ -24,7 +25,6 @@ type Server struct { func NewSignerService() *signerService { signer, err := localsigner.NewSigner() - if err != nil { panic(err) } diff --git a/utils/crypto/bls/signers/localsigner/localsigner.go b/utils/crypto/bls/signers/localsigner/localsigner.go index bd6c6ae4d45f..c467f71dcba1 100644 --- a/utils/crypto/bls/signers/localsigner/localsigner.go +++ b/utils/crypto/bls/signers/localsigner/localsigner.go @@ -9,6 +9,7 @@ import ( "runtime" "github.com/ava-labs/avalanchego/utils/crypto/bls" // Import the parent package + blst "github.com/supranational/blst/bindings/go" ) From 67bc45b3be500d9610b99982cd7c4e1aa88d6a2a Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 7 Jan 2025 13:58:51 -0500 Subject: [PATCH 22/56] More lint fixes --- scripts/configure-local-metrics-collection.sh | 4 ++-- utils/crypto/bls/signers/json-rpc/server.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/configure-local-metrics-collection.sh b/scripts/configure-local-metrics-collection.sh index edc240aef458..4ba3027be509 100755 --- a/scripts/configure-local-metrics-collection.sh +++ b/scripts/configure-local-metrics-collection.sh @@ -15,7 +15,7 @@ METRICS_UUID="$(uuidgen)" echo "Configuring metrics and log collection for a local node with API port ${API_PORT} and logs path ${LOGS_PATH}" PROMETHEUS_CONFIG_PATH="${HOME}/.tmpnet/prometheus/file_sd_configs" -PROMETHEUS_CONFIG_FILE="${PROMETHEUS_CONFIG_PATH}/localsigner.json" +PROMETHEUS_CONFIG_FILE="${PROMETHEUS_CONFIG_PATH}/local.json" mkdir -p "${PROMETHEUS_CONFIG_PATH}" cat > "${PROMETHEUS_CONFIG_FILE}" < "${PROMTAIL_CONFIG_FILE}" < Date: Tue, 7 Jan 2025 13:59:46 -0500 Subject: [PATCH 23/56] Reset tree.go file --- snow/consensus/snowball/tree.go | 168 ++++++++++++++++---------------- 1 file changed, 84 insertions(+), 84 deletions(-) diff --git a/snow/consensus/snowball/tree.go b/snow/consensus/snowball/tree.go index d4c08c2c8e9f..c6773e30c54e 100644 --- a/snow/consensus/snowball/tree.go +++ b/snow/consensus/snowball/tree.go @@ -175,6 +175,8 @@ func (u *unaryNode) DecidedPrefix() int { return u.decidedPrefix } +//nolint:gci,gofmt,gofumpt // this comment is formatted as intended +// // This is by far the most complicated function in this algorithm. // The intuition is that this instance represents a series of consecutive unary // snowball instances, and this function's purpose is convert one of these unary @@ -186,23 +188,23 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "00001" in this node: // -// +-------------------+ <-- This node will not be split -// | | -// | 0 0 0 | -// | | -// +-------------------+ <-- Pass the add to the child -// ^ -// | +// +-------------------+ <-- This node will not be split +// | | +// | 0 0 0 | +// | | +// +-------------------+ <-- Pass the add to the child +// ^ +// | // // Results in: // -// +-------------------+ -// | | -// | 0 0 0 | -// | | -// +-------------------+ <-- With the modified child -// ^ -// | +// +-------------------+ +// | | +// | 0 0 0 | +// | | +// +-------------------+ <-- With the modified child +// ^ +// | // // 2. This instance represents a series of only one unary instance and it must // be split. @@ -213,19 +215,19 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "1" in this tree: // -// +-------------------+ -// | | -// | 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ // // 3. This instance must be split on the first bit // @@ -235,26 +237,26 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "10" in this tree: // -// +-------------------+ -// | | -// | 0 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ -// ^ ^ -// / \ -// +-------------------+ +-------------------+ -// | | | | -// | 0 | | 0 | -// | | | | -// +-------------------+ +-------------------+ +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ +// ^ ^ +// / \ +// +-------------------+ +-------------------+ +// | | | | +// | 0 | | 0 | +// | | | | +// +-------------------+ +-------------------+ // // 4. This instance must be split on the last bit // @@ -265,26 +267,26 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "01" in this tree: // -// +-------------------+ -// | | -// | 0 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | -// | 0 | -// | | -// +-------------------+ -// ^ -// | -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 | +// | | +// +-------------------+ +// ^ +// | +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ // // 5. This instance must be split on an interior bit // @@ -296,35 +298,33 @@ func (u *unaryNode) DecidedPrefix() int { // // For example, attempting to insert the value "010" in this tree: // -// +-------------------+ -// | | -// | 0 0 0 | -// | | -// +-------------------+ +// +-------------------+ +// | | +// | 0 0 0 | +// | | +// +-------------------+ // // Results in: // -// +-------------------+ -// | | -// | 0 | -// | | -// +-------------------+ -// ^ -// | -// +-------------------+ -// | | | -// | 0 | 1 | -// | | | -// +-------------------+ -// ^ ^ -// / \ -// +-------------------+ +-------------------+ -// | | | | -// | 0 | | 0 | -// | | | | -// +-------------------+ +-------------------+ -// -//nolint:gci,gofmt,gofumpt // this comment is formatted as intended +// +-------------------+ +// | | +// | 0 | +// | | +// +-------------------+ +// ^ +// | +// +-------------------+ +// | | | +// | 0 | 1 | +// | | | +// +-------------------+ +// ^ ^ +// / \ +// +-------------------+ +-------------------+ +// | | | | +// | 0 | | 0 | +// | | | | +// +-------------------+ +-------------------+ func (u *unaryNode) Add(newChoice ids.ID) node { if u.Finalized() { return u // Only happens if the tree is finalized, or it's a leaf node From 695329ffa07526ed96e543c5a7eb681303e2fba0 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 7 Jan 2025 14:11:08 -0500 Subject: [PATCH 24/56] Add missing license header --- utils/crypto/bls/ciphersuite.go | 3 +++ utils/crypto/bls/signers/json-rpc/client.go | 3 +++ utils/crypto/bls/signers/json-rpc/messages.go | 3 +++ utils/crypto/bls/signers/json-rpc/server.go | 3 +++ 4 files changed, 12 insertions(+) diff --git a/utils/crypto/bls/ciphersuite.go b/utils/crypto/bls/ciphersuite.go index 1c48eb1a7273..7eb0e27eb263 100644 --- a/utils/crypto/bls/ciphersuite.go +++ b/utils/crypto/bls/ciphersuite.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package bls var ( diff --git a/utils/crypto/bls/signers/json-rpc/client.go b/utils/crypto/bls/signers/json-rpc/client.go index 16eade412e1a..a1ce830f2833 100644 --- a/utils/crypto/bls/signers/json-rpc/client.go +++ b/utils/crypto/bls/signers/json-rpc/client.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package jsonrpc import ( diff --git a/utils/crypto/bls/signers/json-rpc/messages.go b/utils/crypto/bls/signers/json-rpc/messages.go index ded2ec8e3b8d..c79d7f293b69 100644 --- a/utils/crypto/bls/signers/json-rpc/messages.go +++ b/utils/crypto/bls/signers/json-rpc/messages.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package jsonrpc type PublicKeyArgs struct{} diff --git a/utils/crypto/bls/signers/json-rpc/server.go b/utils/crypto/bls/signers/json-rpc/server.go index 9025b055193a..d5c409bc5a0c 100644 --- a/utils/crypto/bls/signers/json-rpc/server.go +++ b/utils/crypto/bls/signers/json-rpc/server.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package jsonrpc import ( From 885230d2e84323ba8909fb7d68f6106a54753f65 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Wed, 8 Jan 2025 12:03:37 -0500 Subject: [PATCH 25/56] More lint-fixes --- utils/crypto/bls/blstest/bls_test.go | 14 +++++++------- utils/crypto/bls/signers/json-rpc/client.go | 18 ++++++++++++++++-- utils/crypto/bls/signers/json-rpc/server.go | 6 +++--- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/utils/crypto/bls/blstest/bls_test.go b/utils/crypto/bls/blstest/bls_test.go index 82a5c9ea123d..71633dea1dfb 100644 --- a/utils/crypto/bls/blstest/bls_test.go +++ b/utils/crypto/bls/blstest/bls_test.go @@ -35,7 +35,7 @@ type localSigner struct { *localsigner.LocalSigner } -func (s localSigner) Close() error { +func (localSigner) Close() error { return nil } @@ -108,7 +108,7 @@ func TestAggregation(t *testing.T) { { name: "valid single key", signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { + setup: func(_ *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { pks := []*bls.PublicKey{ signer.PublicKey(), } @@ -403,7 +403,7 @@ func TestVerify(t *testing.T) { tests := []test{ { name: "valid", - setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) sig := signer.Sign(msg) @@ -413,7 +413,7 @@ func TestVerify(t *testing.T) { }, { name: "wrong message", - setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) sig := signer.Sign(msg) @@ -437,7 +437,7 @@ func TestVerify(t *testing.T) { }, { name: "wrong sig", - setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) @@ -478,7 +478,7 @@ func TestVerifyProofOfPossession(t *testing.T) { { name: "valid", signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) sig := signer.SignProofOfPossession(msg) @@ -489,7 +489,7 @@ func TestVerifyProofOfPossession(t *testing.T) { { name: "wrong message", signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { + setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) sig := signer.SignProofOfPossession(msg) diff --git a/utils/crypto/bls/signers/json-rpc/client.go b/utils/crypto/bls/signers/json-rpc/client.go index a1ce830f2833..7f9a1197fde5 100644 --- a/utils/crypto/bls/signers/json-rpc/client.go +++ b/utils/crypto/bls/signers/json-rpc/client.go @@ -5,14 +5,18 @@ package jsonrpc import ( "bytes" + "context" "net/http" "net/url" + "time" "github.com/gorilla/rpc/v2/json2" "github.com/ava-labs/avalanchego/utils/crypto/bls" ) +var _ bls.Signer = (*Client)(nil) + type Client struct { // http client http *http.Client @@ -26,16 +30,26 @@ func NewClient(url url.URL) *Client { } } -func (client *Client) call(method string, params []interface{}, result interface{}) error { +func (c *Client) call(method string, params []interface{}, result interface{}) error { requestBody, err := json2.EncodeClientRequest(method, params) if err != nil { return err } - resp, err := client.http.Post(client.url.String(), "application/json", bytes.NewBuffer(requestBody)) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() // Ensure the context is canceled to release resources + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url.String(), bytes.NewBuffer(requestBody)) + if err != nil { + return err + } + req.Header.Set("Content-Type", "application/json") + + resp, err := c.http.Do(req) if err != nil { return err } + defer resp.Body.Close() return json2.DecodeClientResponse(resp.Body, result) } diff --git a/utils/crypto/bls/signers/json-rpc/server.go b/utils/crypto/bls/signers/json-rpc/server.go index d5c409bc5a0c..02f6b79d3a9c 100644 --- a/utils/crypto/bls/signers/json-rpc/server.go +++ b/utils/crypto/bls/signers/json-rpc/server.go @@ -84,17 +84,17 @@ func (s *Server) Close() error { return s.listener.Close() } -func (s *signerService) PublicKey(r *http.Request, args *PublicKeyArgs, reply *PublicKeyReply) error { +func (s *signerService) PublicKey(_ *http.Request, _ *PublicKeyArgs, reply *PublicKeyReply) error { *reply = toPkReply(s.signer.PublicKey()) return nil } -func (s *signerService) Sign(r *http.Request, args *struct{ Msg []byte }, reply *SignReply) error { +func (s *signerService) Sign(_ *http.Request, args *struct{ Msg []byte }, reply *SignReply) error { *reply = toSignReply(s.signer.Sign(args.Msg)) return nil } -func (s *signerService) SignProofOfPossession(r *http.Request, args *struct{ Msg []byte }, reply *SignProofOfPossessionReply) error { +func (s *signerService) SignProofOfPossession(_ *http.Request, args *struct{ Msg []byte }, reply *SignProofOfPossessionReply) error { *reply = toSignProofOfPossessionReply(s.signer.SignProofOfPossession(args.Msg)) return nil } From 494864f47f02efef04ca9595080d77ba158ab635 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Wed, 8 Jan 2025 17:39:04 -0500 Subject: [PATCH 26/56] Fix bls-tests --- utils/crypto/bls/blstest/bls_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/crypto/bls/blstest/bls_test.go b/utils/crypto/bls/blstest/bls_test.go index 71633dea1dfb..f4886a9e124b 100644 --- a/utils/crypto/bls/blstest/bls_test.go +++ b/utils/crypto/bls/blstest/bls_test.go @@ -402,7 +402,8 @@ func TestVerify(t *testing.T) { tests := []test{ { - name: "valid", + name: "valid", + signers: signerFns, setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) @@ -412,7 +413,8 @@ func TestVerify(t *testing.T) { expectedValid: true, }, { - name: "wrong message", + name: "wrong message", + signers: signerFns, setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) @@ -423,7 +425,8 @@ func TestVerify(t *testing.T) { expectedValid: false, }, { - name: "wrong pub key", + name: "wrong pub key", + signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { msg := utils.RandomBytes(1234) sig := signer.Sign(msg) @@ -436,7 +439,8 @@ func TestVerify(t *testing.T) { expectedValid: false, }, { - name: "wrong sig", + name: "wrong sig", + signers: signerFns, setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { pk := signer.PublicKey() msg := utils.RandomBytes(1234) From 3b7858bc24d860de0047c5cca016b6bb76ab9f6c Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Wed, 8 Jan 2025 17:52:09 -0500 Subject: [PATCH 27/56] Make sure there are signers for the test --- utils/crypto/bls/blstest/bls_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/crypto/bls/blstest/bls_test.go b/utils/crypto/bls/blstest/bls_test.go index f4886a9e124b..5d5030cecb99 100644 --- a/utils/crypto/bls/blstest/bls_test.go +++ b/utils/crypto/bls/blstest/bls_test.go @@ -534,6 +534,7 @@ func TestVerifyProofOfPossession(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { require := require.New(t) + require.NotEmpty(tt.signers) for _, newSigner := range tt.signers { signer, err := newSigner() From 75c98c5d332367b45ee17299711a6ffd032efe6a Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Wed, 8 Jan 2025 17:57:21 -0500 Subject: [PATCH 28/56] More bls-test fixes --- utils/crypto/bls/blstest/bls_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/utils/crypto/bls/blstest/bls_test.go b/utils/crypto/bls/blstest/bls_test.go index 5d5030cecb99..67a9537c98ef 100644 --- a/utils/crypto/bls/blstest/bls_test.go +++ b/utils/crypto/bls/blstest/bls_test.go @@ -124,7 +124,8 @@ func TestAggregation(t *testing.T) { expectedValid: true, }, { - name: "wrong message", + name: "wrong message", + signers: signerFns, setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { sk1, err := localsigner.NewSigner() require.NoError(err) @@ -307,9 +308,10 @@ func TestAggregation(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - for _, newSigner := range tt.signers { - require := require.New(t) + require := require.New(t) + require.NotEmpty(tt.signers) + for _, newSigner := range tt.signers { signer, err := newSigner() require.NoError(err) @@ -455,8 +457,10 @@ func TestVerify(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + require := require.New(t) + require.NotEmpty(tt.signers) + for _, newSigner := range tt.signers { - require := require.New(t) signer, err := newSigner() require.NoError(err) pk, sig, msg := tt.setup(require, signer) From 58359885d99c83b2b667f11d4f60773326de8a15 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Thu, 9 Jan 2025 10:51:10 -0500 Subject: [PATCH 29/56] Reset config/config.md --- config/config.md | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config.md b/config/config.md index ba800611afdf..7716b89ef14e 100644 --- a/config/config.md +++ b/config/config.md @@ -399,6 +399,7 @@ specified. If not given, uses default genesis data. See the documentation for the genesis JSON format [here](https://github.com/ava-labs/avalanchego/blob/master/genesis/README.md) and an example used for the local network genesis [here](https://github.com/ava-labs/avalanchego/blob/master/genesis/). + #### `--genesis-file-content` (string) As an alternative to `--genesis-file`, it allows specifying base64 encoded genesis data to use. From 1bca3efdbeeb21accdb50d3541b1e0add440bcbf Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Fri, 10 Jan 2025 17:40:09 -0500 Subject: [PATCH 30/56] Split bls tests --- utils/crypto/bls/bls_test.go | 103 ++++ utils/crypto/bls/blstest/benchmark.go | 23 + .../crypto/bls/blstest/bls_benchmark_test.go | 97 ++- utils/crypto/bls/blstest/bls_test.go | 555 ------------------ utils/crypto/bls/blstest/blstest.go | 21 + utils/crypto/bls/blstest/public_test.go | 21 +- utils/crypto/bls/blstest/signature_test.go | 14 +- .../bls/signers/json-rpc/benchmark_test.go | 28 + utils/crypto/bls/signers/json-rpc/bls_test.go | 333 +++++++++++ .../bls/signers/localsigner/benchmark_test.go | 29 + .../bls/signers/localsigner/bls_test.go | 297 ++++++++++ .../localsigner/serialization_test.go} | 15 +- 12 files changed, 892 insertions(+), 644 deletions(-) create mode 100644 utils/crypto/bls/bls_test.go create mode 100644 utils/crypto/bls/blstest/benchmark.go delete mode 100644 utils/crypto/bls/blstest/bls_test.go create mode 100644 utils/crypto/bls/blstest/blstest.go create mode 100644 utils/crypto/bls/signers/json-rpc/benchmark_test.go create mode 100644 utils/crypto/bls/signers/json-rpc/bls_test.go create mode 100644 utils/crypto/bls/signers/localsigner/benchmark_test.go create mode 100644 utils/crypto/bls/signers/localsigner/bls_test.go rename utils/crypto/bls/{blstest/signer_test.go => signers/localsigner/serialization_test.go} (67%) diff --git a/utils/crypto/bls/bls_test.go b/utils/crypto/bls/bls_test.go new file mode 100644 index 000000000000..4365d0d87407 --- /dev/null +++ b/utils/crypto/bls/bls_test.go @@ -0,0 +1,103 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package bls + +import ( + "crypto/rand" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils" + + blst "github.com/supranational/blst/bindings/go" +) + +func newKey(require *require.Assertions) *blst.SecretKey { + var ikm [32]byte + _, err := rand.Read(ikm[:]) + require.NoError(err) + sk := blst.KeyGen(ikm[:]) + ikm = [32]byte{} // zero out the ikm + + return sk +} + +func publicKey(sk *blst.SecretKey) *PublicKey { + return new(PublicKey).From(sk) +} + +func sign(sk *blst.SecretKey, msg []byte) *Signature { + return new(Signature).Sign(sk, msg, CiphersuiteSignature) +} + +func AggregateAndVerify(publicKeys []*PublicKey, signatures []*Signature, message []byte) (bool, error) { + aggSig, err := AggregateSignatures(signatures) + if err != nil { + return false, err + } + aggPK, err := AggregatePublicKeys(publicKeys) + if err != nil { + return false, err + } + + return Verify(aggPK, aggSig, message), nil +} + +func TestAggregationThreshold(t *testing.T) { + require := require.New(t) + + // People in the network would privately generate their secret keys + sk0 := newKey(require) + sk1 := newKey(require) + sk2 := newKey(require) + + // All the public keys would be registered on chain + pks := []*PublicKey{ + publicKey(sk0), + publicKey(sk1), + publicKey(sk2), + } + + // The transaction's unsigned bytes are publicly known. + msg := utils.RandomBytes(1234) + + // People may attempt time sign the transaction. + sigs := []*Signature{ + sign(sk0, msg), + sign(sk1, msg), + sign(sk2, msg), + } + + // The signed transaction would specify which of the public keys have been + // used to sign it. The aggregator should verify each individual signature, + // until it has found a sufficient threshold of valid signatures. + var ( + indices = []int{0, 2} + filteredPKs = make([]*PublicKey, len(indices)) + filteredSigs = make([]*Signature, len(indices)) + ) + for i, index := range indices { + pk := pks[index] + filteredPKs[i] = pk + sig := sigs[index] + filteredSigs[i] = sig + + valid := Verify(pk, sig, msg) + require.True(valid) + } + + // Once the aggregator has the required threshold of signatures, it can + // aggregate the signatures. + aggregatedSig, err := AggregateSignatures(filteredSigs) + require.NoError(err) + + // For anyone looking for a proof of the aggregated signature's correctness, + // they can aggregate the public keys and verify the aggregated signature. + aggregatedPK, err := AggregatePublicKeys(filteredPKs) + require.NoError(err) + + valid := Verify(aggregatedPK, aggregatedSig, msg) + require.True(valid) +} diff --git a/utils/crypto/bls/blstest/benchmark.go b/utils/crypto/bls/blstest/benchmark.go new file mode 100644 index 000000000000..c317972e85b0 --- /dev/null +++ b/utils/crypto/bls/blstest/benchmark.go @@ -0,0 +1,23 @@ +package blstest + +var ( + BenchmarkSizes = []int{ + 1, + 2, + 4, + 8, + 16, + 32, + 64, + 128, + 256, + 512, + 1024, + 2048, + 4096, + 8192, + 16384, + 32768, + } + BiggestBenchmarkSize = BenchmarkSizes[len(BenchmarkSizes)-1] +) diff --git a/utils/crypto/bls/blstest/bls_benchmark_test.go b/utils/crypto/bls/blstest/bls_benchmark_test.go index 4075bcdb89d1..751403b71a68 100644 --- a/utils/crypto/bls/blstest/bls_benchmark_test.go +++ b/utils/crypto/bls/blstest/bls_benchmark_test.go @@ -1,9 +1,10 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls_test +package blstest import ( + "crypto/rand" "strconv" "testing" @@ -11,56 +12,37 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" -) -var ( - sizes = []int{ - 1, - 2, - 4, - 8, - 16, - 32, - 64, - 128, - 256, - 512, - 1024, - 2048, - 4096, - 8192, - 16384, - 32768, - } - biggestSize = sizes[len(sizes)-1] + blst "github.com/supranational/blst/bindings/go" ) -func BenchmarkSign(b *testing.B) { - privateKey, err := localsigner.NewSigner() - require.NoError(b, err) - for _, messageSize := range sizes { - b.Run(strconv.Itoa(messageSize), func(b *testing.B) { - message := utils.RandomBytes(messageSize) +func newKey(require *require.Assertions) *blst.SecretKey { + var ikm [32]byte + _, err := rand.Read(ikm[:]) + require.NoError(err) + sk := blst.KeyGen(ikm[:]) + ikm = [32]byte{} // zero out the ikm - b.ResetTimer() + return sk +} - for n := 0; n < b.N; n++ { - _ = privateKey.Sign(message) - } - }) - } +func sign(sk *blst.SecretKey, msg []byte) *bls.Signature { + return new(bls.Signature).Sign(sk, msg, bls.CiphersuiteSignature) +} + +func publicKey(sk *blst.SecretKey) *bls.PublicKey { + return new(bls.PublicKey).From(sk) } func BenchmarkVerify(b *testing.B) { - privateKey, err := localsigner.NewSigner() - require.NoError(b, err) - publicKey := privateKey.PublicKey() + privateKey := newKey(require.New(b)) + publicKey := publicKey(privateKey) - for _, messageSize := range sizes { + for _, messageSize := range BenchmarkSizes { b.Run(strconv.Itoa(messageSize), func(b *testing.B) { + message := utils.RandomBytes(messageSize) - signature := privateKey.Sign(message) + signature := sign(privateKey, message) b.ResetTimer() @@ -72,15 +54,15 @@ func BenchmarkVerify(b *testing.B) { } func BenchmarkAggregatePublicKeys(b *testing.B) { - keys := make([]*bls.PublicKey, biggestSize) + keys := make([]*bls.PublicKey, BiggestBenchmarkSize) + for i := range keys { - privateKey, err := localsigner.NewSigner() - require.NoError(b, err) + privateKey := newKey(require.New(b)) - keys[i] = privateKey.PublicKey() + keys[i] = publicKey(privateKey) } - for _, size := range sizes { + for _, size := range BenchmarkSizes { b.Run(strconv.Itoa(size), func(b *testing.B) { for n := 0; n < b.N; n++ { _, err := bls.AggregatePublicKeys(keys[:size]) @@ -91,10 +73,9 @@ func BenchmarkAggregatePublicKeys(b *testing.B) { } func BenchmarkPublicKeyToCompressedBytes(b *testing.B) { - sk, err := localsigner.NewSigner() - require.NoError(b, err) + sk := newKey(require.New(b)) - pk := sk.PublicKey() + pk := publicKey(sk) b.ResetTimer() for range b.N { @@ -103,10 +84,9 @@ func BenchmarkPublicKeyToCompressedBytes(b *testing.B) { } func BenchmarkPublicKeyFromCompressedBytes(b *testing.B) { - sk, err := localsigner.NewSigner() - require.NoError(b, err) + sk := newKey(require.New(b)) - pk := sk.PublicKey() + pk := publicKey(sk) pkBytes := bls.PublicKeyToCompressedBytes(pk) b.ResetTimer() @@ -116,10 +96,9 @@ func BenchmarkPublicKeyFromCompressedBytes(b *testing.B) { } func BenchmarkPublicKeyToUncompressedBytes(b *testing.B) { - sk, err := localsigner.NewSigner() - require.NoError(b, err) + sk := newKey(require.New(b)) - pk := sk.PublicKey() + pk := publicKey(sk) b.ResetTimer() for range b.N { @@ -128,10 +107,9 @@ func BenchmarkPublicKeyToUncompressedBytes(b *testing.B) { } func BenchmarkPublicKeyFromValidUncompressedBytes(b *testing.B) { - sk, err := localsigner.NewSigner() - require.NoError(b, err) + sk := newKey(require.New(b)) - pk := sk.PublicKey() + pk := publicKey(sk) pkBytes := bls.PublicKeyToUncompressedBytes(pk) b.ResetTimer() @@ -141,11 +119,10 @@ func BenchmarkPublicKeyFromValidUncompressedBytes(b *testing.B) { } func BenchmarkSignatureFromBytes(b *testing.B) { - privateKey, err := localsigner.NewSigner() - require.NoError(b, err) + sk := newKey(require.New(b)) message := utils.RandomBytes(32) - signature := privateKey.Sign(message) + signature := sign(sk, message) signatureBytes := bls.SignatureToBytes(signature) b.ResetTimer() diff --git a/utils/crypto/bls/blstest/bls_test.go b/utils/crypto/bls/blstest/bls_test.go deleted file mode 100644 index 67a9537c98ef..000000000000 --- a/utils/crypto/bls/blstest/bls_test.go +++ /dev/null @@ -1,555 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package bls_test - -import ( - "io" - "net/url" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" - - jsonrpc "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/json-rpc" -) - -type Signer interface { - bls.Signer - io.Closer -} - -type jsonRPCSigner struct { - *jsonrpc.Client - server *jsonrpc.Server -} - -func (s jsonRPCSigner) Close() error { - return s.server.Close() -} - -type localSigner struct { - *localsigner.LocalSigner -} - -func (localSigner) Close() error { - return nil -} - -var localSignerFn = func() (Signer, error) { - signer, err := localsigner.NewSigner() - return &localSigner{LocalSigner: signer}, err -} - -var serverSignerFn = func() (Signer, error) { - // do I need to make sure the server gets closed properly? - service := jsonrpc.NewSignerService() - server, err := jsonrpc.Serve(service) - if err != nil { - return nil, err - } - - url := url.URL{ - Scheme: "http", - Host: server.Addr().String(), - } - - client := jsonrpc.NewClient(url) - - return jsonRPCSigner{server: server, Client: client}, nil -} - -var signerFns = []func() (Signer, error){ - localSignerFn, - serverSignerFn, -} - -func TestAggregation(t *testing.T) { - type test struct { - name string - signers []func() (Signer, error) - setup func(*require.Assertions, bls.Signer) (pks []*bls.PublicKey, sigs []*bls.Signature, msg []byte) - expectedSigAggError error - expectedPubKeyAggError error - expectedValid bool - } - - tests := []test{ - { - name: "valid", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - pks := []*bls.PublicKey{ - signer.PublicKey(), - sk1.PublicKey(), - sk2.PublicKey(), - } - - msg := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - sk1.Sign(msg), - sk2.Sign(msg), - } - - return pks, sigs, msg - }, - expectedValid: true, - }, - { - name: "valid single key", - signers: signerFns, - setup: func(_ *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - pks := []*bls.PublicKey{ - signer.PublicKey(), - } - - msg := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - } - - return pks, sigs, msg - }, - expectedValid: true, - }, - { - name: "wrong message", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - pks := []*bls.PublicKey{ - signer.PublicKey(), - sk1.PublicKey(), - sk2.PublicKey(), - } - - msg := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - sk1.Sign(msg), - sk2.Sign(msg), - } - - msg[0]++ - - return pks, sigs, msg - }, - expectedValid: false, - }, - { - name: "one sig over different message", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - pks := []*bls.PublicKey{ - signer.PublicKey(), - sk1.PublicKey(), - sk2.PublicKey(), - } - - msg := utils.RandomBytes(1234) - msg2 := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - sk1.Sign(msg), - sk2.Sign(msg2), - } - - return pks, sigs, msg - }, - expectedValid: false, - }, - { - name: "one incorrect pubkey", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - sk3, err := localsigner.NewSigner() - require.NoError(err) - - pks := []*bls.PublicKey{ - signer.PublicKey(), - sk1.PublicKey(), - sk3.PublicKey(), - } - - msg := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - sk1.Sign(msg), - sk2.Sign(msg), - } - - return pks, sigs, msg - }, - expectedValid: false, - }, - { - name: "num pubkeys > num sigs", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - pks := []*bls.PublicKey{ - signer.PublicKey(), - sk1.PublicKey(), - sk2.PublicKey(), - } - - msg := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - sk1.Sign(msg), - } - - return pks, sigs, msg - }, - expectedValid: false, - }, - { - name: "num pubkeys < num sigs", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - pks := []*bls.PublicKey{ - signer.PublicKey(), - sk1.PublicKey(), - } - - msg := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - sk1.Sign(msg), - sk2.Sign(msg), - } - - return pks, sigs, msg - }, - expectedValid: false, - }, - { - name: "no pub keys", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - msg := utils.RandomBytes(1234) - - sigs := []*bls.Signature{ - signer.Sign(msg), - sk1.Sign(msg), - sk2.Sign(msg), - } - - return nil, sigs, msg - }, - expectedPubKeyAggError: bls.ErrNoPublicKeys, - expectedValid: false, - }, - { - name: "no sigs", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) ([]*bls.PublicKey, []*bls.Signature, []byte) { - sk1, err := localsigner.NewSigner() - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - pks := []*bls.PublicKey{ - signer.PublicKey(), - sk1.PublicKey(), - sk2.PublicKey(), - } - - msg := utils.RandomBytes(1234) - return pks, nil, msg - }, - expectedSigAggError: bls.ErrNoSignatures, - expectedValid: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - require := require.New(t) - require.NotEmpty(tt.signers) - - for _, newSigner := range tt.signers { - signer, err := newSigner() - require.NoError(err) - - pks, sigs, msg := tt.setup(require, signer) - - aggSig, err := bls.AggregateSignatures(sigs) - require.ErrorIs(err, tt.expectedSigAggError) - - aggPK, err := bls.AggregatePublicKeys(pks) - require.ErrorIs(err, tt.expectedPubKeyAggError) - - valid := bls.Verify(aggPK, aggSig, msg) - require.Equal(tt.expectedValid, valid) - signer.Close() - } - }) - } -} - -func TestAggregationThreshold(t *testing.T) { - require := require.New(t) - - // People in the network would privately generate their secret keys - sk0, err := localSignerFn() - require.NoError(err) - sk1, err := serverSignerFn() - require.NoError(err) - defer sk1.Close() - - require.NoError(err) - sk2, err := localsigner.NewSigner() - require.NoError(err) - - // All the public keys would be registered on chain - pks := []*bls.PublicKey{ - sk0.PublicKey(), - sk1.PublicKey(), - sk2.PublicKey(), - } - - // The transaction's unsigned bytes are publicly known. - msg := utils.RandomBytes(1234) - - // People may attempt time sign the transaction. - sigs := []*bls.Signature{ - sk0.Sign(msg), - sk1.Sign(msg), - sk2.Sign(msg), - } - - // The signed transaction would specify which of the public keys have been - // used to sign it. The aggregator should verify each individual signature, - // until it has found a sufficient threshold of valid signatures. - var ( - indices = []int{0, 2} - filteredPKs = make([]*bls.PublicKey, len(indices)) - filteredSigs = make([]*bls.Signature, len(indices)) - ) - for i, index := range indices { - pk := pks[index] - filteredPKs[i] = pk - sig := sigs[index] - filteredSigs[i] = sig - - valid := bls.Verify(pk, sig, msg) - require.True(valid) - } - - // Once the aggregator has the required threshold of signatures, it can - // aggregate the signatures. - aggregatedSig, err := bls.AggregateSignatures(filteredSigs) - require.NoError(err) - - // For anyone looking for a proof of the aggregated signature's correctness, - // they can aggregate the public keys and verify the aggregated signature. - aggregatedPK, err := bls.AggregatePublicKeys(filteredPKs) - require.NoError(err) - - valid := bls.Verify(aggregatedPK, aggregatedSig, msg) - require.True(valid) -} - -func TestVerify(t *testing.T) { - type test struct { - name string - signers []func() (Signer, error) - setup func(*require.Assertions, bls.Signer) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) - expectedValid bool - } - - tests := []test{ - { - name: "valid", - signers: signerFns, - setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - pk := signer.PublicKey() - msg := utils.RandomBytes(1234) - sig := signer.Sign(msg) - return pk, sig, msg - }, - expectedValid: true, - }, - { - name: "wrong message", - signers: signerFns, - setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - pk := signer.PublicKey() - msg := utils.RandomBytes(1234) - sig := signer.Sign(msg) - msg[0]++ - return pk, sig, msg - }, - expectedValid: false, - }, - { - name: "wrong pub key", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - msg := utils.RandomBytes(1234) - sig := signer.Sign(msg) - - sk2, err := localsigner.NewSigner() - require.NoError(err) - pk := sk2.PublicKey() - return pk, sig, msg - }, - expectedValid: false, - }, - { - name: "wrong sig", - signers: signerFns, - setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - pk := signer.PublicKey() - msg := utils.RandomBytes(1234) - - msg2 := utils.RandomBytes(1234) - sig2 := signer.Sign(msg2) - return pk, sig2, msg - }, - expectedValid: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - require := require.New(t) - require.NotEmpty(tt.signers) - - for _, newSigner := range tt.signers { - signer, err := newSigner() - require.NoError(err) - pk, sig, msg := tt.setup(require, signer) - valid := bls.Verify(pk, sig, msg) - require.Equal(tt.expectedValid, valid) - valid = bls.VerifyProofOfPossession(pk, sig, msg) - require.False(valid) - signer.Close() - } - }) - } -} - -func TestVerifyProofOfPossession(t *testing.T) { - type test struct { - name string - signers []func() (Signer, error) - setup func(*require.Assertions, bls.Signer) (pk *bls.PublicKey, sig *bls.Signature, msg []byte) - expectedValid bool - } - - tests := []test{ - { - name: "valid", - signers: signerFns, - setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - pk := signer.PublicKey() - msg := utils.RandomBytes(1234) - sig := signer.SignProofOfPossession(msg) - return pk, sig, msg - }, - expectedValid: true, - }, - { - name: "wrong message", - signers: signerFns, - setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - pk := signer.PublicKey() - msg := utils.RandomBytes(1234) - sig := signer.SignProofOfPossession(msg) - msg[0]++ - return pk, sig, msg - }, - expectedValid: false, - }, - { - name: "wrong pub key", - signers: signerFns, - setup: func(require *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - msg := utils.RandomBytes(1234) - sig := signer.SignProofOfPossession(msg) - - sk2, err := localsigner.NewSigner() - require.NoError(err) - pk := sk2.PublicKey() - return pk, sig, msg - }, - expectedValid: false, - }, - { - name: "wrong sig", - signers: signerFns, - setup: func(_ *require.Assertions, signer bls.Signer) (*bls.PublicKey, *bls.Signature, []byte) { - pk := signer.PublicKey() - msg := utils.RandomBytes(1234) - - msg2 := utils.RandomBytes(1234) - sig2 := signer.SignProofOfPossession(msg2) - return pk, sig2, msg - }, - expectedValid: false, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - require := require.New(t) - require.NotEmpty(tt.signers) - - for _, newSigner := range tt.signers { - signer, err := newSigner() - require.NoError(err) - pk, sig, msg := tt.setup(require, signer) - valid := bls.VerifyProofOfPossession(pk, sig, msg) - require.Equal(tt.expectedValid, valid) - valid = bls.Verify(pk, sig, msg) - require.False(valid) - signer.Close() - } - }) - } -} diff --git a/utils/crypto/bls/blstest/blstest.go b/utils/crypto/bls/blstest/blstest.go new file mode 100644 index 000000000000..88bc20c4bc99 --- /dev/null +++ b/utils/crypto/bls/blstest/blstest.go @@ -0,0 +1,21 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package blstest + +import ( + "github.com/ava-labs/avalanchego/utils/crypto/bls" +) + +func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature, message []byte) (bool, error) { + aggSig, err := bls.AggregateSignatures(signatures) + if err != nil { + return false, err + } + aggPK, err := bls.AggregatePublicKeys(publicKeys) + if err != nil { + return false, err + } + + return bls.Verify(aggPK, aggSig, message), nil +} diff --git a/utils/crypto/bls/blstest/public_test.go b/utils/crypto/bls/blstest/public_test.go index 6bd343abf8cc..3f21bbbfb543 100644 --- a/utils/crypto/bls/blstest/public_test.go +++ b/utils/crypto/bls/blstest/public_test.go @@ -1,16 +1,16 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls_test +package blstest import ( + "encoding/base64" "testing" "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestPublicKeyFromCompressedBytesWrongSize(t *testing.T) { @@ -24,28 +24,25 @@ func TestPublicKeyFromCompressedBytesWrongSize(t *testing.T) { func TestPublicKeyBytes(t *testing.T) { require := require.New(t) - sk, err := localsigner.NewSigner() + pkBytes, err := base64.StdEncoding.DecodeString("h5qt9SPxaCo+vOx6sn+QkkpP7Y40Yja7SEAs2MGb/mZT7oKTWgLogjy5c4/wWIGC") require.NoError(err) - pk := sk.PublicKey() - pkBytes := bls.PublicKeyToCompressedBytes(pk) - - pk2, err := bls.PublicKeyFromCompressedBytes(pkBytes) + pk, err := bls.PublicKeyFromCompressedBytes(pkBytes) require.NoError(err) - pk2Bytes := bls.PublicKeyToCompressedBytes(pk2) - require.Equal(pk, pk2) + pk2Bytes := bls.PublicKeyToCompressedBytes(pk) + require.Equal(pkBytes, pk2Bytes) } func TestAggregatePublicKeysNoop(t *testing.T) { require := require.New(t) - sk, err := localsigner.NewSigner() + pkBytes, err := base64.StdEncoding.DecodeString("h5qt9SPxaCo+vOx6sn+QkkpP7Y40Yja7SEAs2MGb/mZT7oKTWgLogjy5c4/wWIGC") require.NoError(err) - pk := sk.PublicKey() - pkBytes := bls.PublicKeyToCompressedBytes(pk) + pk, err := bls.PublicKeyFromCompressedBytes(pkBytes) + require.NoError(err) aggPK, err := bls.AggregatePublicKeys([]*bls.PublicKey{pk}) require.NoError(err) diff --git a/utils/crypto/bls/blstest/signature_test.go b/utils/crypto/bls/blstest/signature_test.go index e2a5c1afe957..843f38844515 100644 --- a/utils/crypto/bls/blstest/signature_test.go +++ b/utils/crypto/bls/blstest/signature_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls_test +package blstest import ( "testing" @@ -10,7 +10,6 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestSignatureBytes(t *testing.T) { @@ -18,9 +17,8 @@ func TestSignatureBytes(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := localsigner.NewSigner() - require.NoError(err) - sig := sk.Sign(msg) + sk := newKey(require) + sig := sign(sk, msg) sigBytes := bls.SignatureToBytes(sig) sig2, err := bls.SignatureFromBytes(sigBytes) @@ -36,10 +34,8 @@ func TestAggregateSignaturesNoop(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := localsigner.NewSigner() - require.NoError(err) - - sig := sk.Sign(msg) + sk := newKey(require) + sig := sign(sk, msg) sigBytes := bls.SignatureToBytes(sig) aggSig, err := bls.AggregateSignatures([]*bls.Signature{sig}) diff --git a/utils/crypto/bls/signers/json-rpc/benchmark_test.go b/utils/crypto/bls/signers/json-rpc/benchmark_test.go new file mode 100644 index 000000000000..84699517492c --- /dev/null +++ b/utils/crypto/bls/signers/json-rpc/benchmark_test.go @@ -0,0 +1,28 @@ +package jsonrpc + +import ( + "strconv" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" +) + +func BenchmarkSign(b *testing.B) { + server, privateKey, _ := NewSigner(require.New(b)) + defer server.Close() + + for _, messageSize := range blstest.BenchmarkSizes { + b.Run(strconv.Itoa(messageSize), func(b *testing.B) { + message := utils.RandomBytes(messageSize) + + b.ResetTimer() + + for n := 0; n < b.N; n++ { + _ = privateKey.Sign(message) + } + }) + } +} diff --git a/utils/crypto/bls/signers/json-rpc/bls_test.go b/utils/crypto/bls/signers/json-rpc/bls_test.go new file mode 100644 index 000000000000..4cac9a714e24 --- /dev/null +++ b/utils/crypto/bls/signers/json-rpc/bls_test.go @@ -0,0 +1,333 @@ +package jsonrpc + +import ( + "net/url" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" +) + +func NewLocalPair(require *require.Assertions) (*localsigner.LocalSigner, *bls.PublicKey) { + sk, err := localsigner.NewSigner() + require.NoError(err) + pk := sk.PublicKey() + return sk, pk +} + +func NewSigner(require *require.Assertions) (*Server, *Client, *bls.PublicKey) { + service := NewSignerService() + server, err := Serve(service) + require.NoError(err) + + url := url.URL{ + Scheme: "http", + Host: server.Addr().String(), + } + + client := NewClient(url) + pk := client.PublicKey() + + return server, client, pk +} + +func TestVerifyValidSignature(t *testing.T) { + require := require.New(t) + server, signer, pk := NewSigner(require) + defer server.Close() + + msg := []byte("TestVerifyValidSignature json-rpc") + + sig := signer.Sign(msg) + + isValid := bls.Verify(pk, sig, msg) + require.True(isValid) +} + +func TestVerifyWrongMessageSignature(t *testing.T) { + require := require.New(t) + server, signer, pk := NewSigner(require) + defer server.Close() + + msg := []byte("TestVerifyWrongMessageSignature json-rpc") + wrongMsg := []byte("TestVerifyWrongMessageSignature json-rpc with wrong message") + + sig := signer.Sign(msg) + + isValid := bls.Verify(pk, sig, wrongMsg) + require.False(isValid) +} + +func TestVerifyWrongPubkeySignature(t *testing.T) { + require := require.New(t) + server, signer, _ := NewSigner(require) + defer server.Close() + _, wrongPk := NewLocalPair(require) + + msg := []byte("TestVerifyWrongPubkeySignature json-rpc") + + sig := signer.Sign(msg) + + isValid := bls.Verify(wrongPk, sig, msg) + require.False(isValid) +} + +func TestVerifyWrongMessageSignedSignature(t *testing.T) { + require := require.New(t) + server, signer, pk := NewSigner(require) + defer server.Close() + + msg := []byte("TestVerifyWrongMessageSignedSignature json-rpc") + wrongMsg := []byte("TestVerifyWrongMessageSignedSignaturelocal json-rpc with wrong signature") + + wrongSig := signer.Sign(wrongMsg) + + isValid := bls.Verify(pk, wrongSig, msg) + require.False(isValid) +} +func TestValidAggregation(t *testing.T) { + require := require.New(t) + server, signer1, pk1 := NewSigner(require) + defer server.Close() + + signer2, pk2 := NewLocalPair(require) + signer3, pk3 := NewLocalPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestValidAggregation json-rpc") + + sigs := []*bls.Signature{ + signer1.Sign(msg), + signer2.Sign(msg), + signer3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) + require.NoError(err) + require.True(isValid) +} + +func TestSingleKeyAggregation(t *testing.T) { + require := require.New(t) + server, signer, pk := NewSigner(require) + defer server.Close() + + pks := []*bls.PublicKey{pk} + + msg := []byte("TestSingleKeyAggregation json-rpc") + + sig := signer.Sign(msg) + + isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + require.NoError(err) + require.True(isValid) +} + +func TestIncorrectMessageAggregation(t *testing.T) { + require := require.New(t) + server, sk1, pk1 := NewSigner(require) + defer server.Close() + + sk2, pk2 := NewLocalPair(require) + sk3, pk3 := NewLocalPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestIncorrectMessageAggregation json-rpc") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) + require.NoError(err) + require.False(isValid) +} + +func TestOneDifferentMessageAggregation(t *testing.T) { + require := require.New(t) + server, sk1, pk1 := NewSigner(require) + defer server.Close() + + sk2, pk2 := NewLocalPair(require) + sk3, pk3 := NewLocalPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestDifferentMessagesAggregation json-rpc") + differentMsg := []byte("TestDifferentMessagesAggregation json-rpc with different message") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(differentMsg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestOneIncorrectPubKeyAggregation(t *testing.T) { + require := require.New(t) + server, sk1, pk1 := NewSigner(require) + defer server.Close() + + sk2, pk2 := NewLocalPair(require) + sk3, _ := NewLocalPair(require) + _, wrongPk := NewLocalPair(require) + + pks := []*bls.PublicKey{pk1, pk2, wrongPk} + + msg := []byte("TestOneIncorrectPubKeyAggregation json-rpc") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { + require := require.New(t) + server, sk1, pk1 := NewSigner(require) + defer server.Close() + sk2, pk2 := NewLocalPair(require) + _, pk3 := NewLocalPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestMorePubkeysThanSignatures json-rpc") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { + require := require.New(t) + server, sk1, pk1 := NewSigner(require) + defer server.Close() + sk2, pk2 := NewLocalPair(require) + sk3, _ := NewLocalPair(require) + + pks := []*bls.PublicKey{pk1, pk2} + + msg := []byte("TestMoreSignaturesThanPubkeys json-rpc") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestNoPubkeysAggregation(t *testing.T) { + require := require.New(t) + server, sk1, _ := NewSigner(require) + defer server.Close() + sk2, _ := NewLocalPair(require) + sk3, _ := NewLocalPair(require) + + msg := []byte("TestNoPubkeysAggregation json-rpc") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) + require.ErrorIs(err, bls.ErrNoPublicKeys) + require.False(isValid) +} + +func TestNoSignaturesAggregation(t *testing.T) { + require := require.New(t) + server, _, pk1 := NewSigner(require) + defer server.Close() + _, pk2 := NewLocalPair(require) + _, pk3 := NewLocalPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestNoSignaturesAggregation json-rpc") + + isValid, err := blstest.AggregateAndVerify(pks, nil, msg) + require.ErrorIs(err, bls.ErrNoSignatures) + require.False(isValid) +} + +func TestVerifyValidProofOfPossession(t *testing.T) { + require := require.New(t) + server, signer, pk := NewSigner(require) + defer server.Close() + + msg := []byte("TestVerifyValidProofOfPossession json-rpc") + + sig := signer.SignProofOfPossession(msg) + + isValid := bls.VerifyProofOfPossession(pk, sig, msg) + require.True(isValid) +} + +func TestVerifyWrongMessageProofOfPossession(t *testing.T) { + require := require.New(t) + server, signer, pk := NewSigner(require) + defer server.Close() + + msg := []byte("TestVerifyWrongMessageProofOfPossession json-rpc") + wrongMsg := []byte("TestVerifyWrongMessageProofOfPossession json-rpc with wrong message") + + sig := signer.SignProofOfPossession(msg) + + isValid := bls.VerifyProofOfPossession(pk, sig, wrongMsg) + require.False(isValid) +} + +func TestVerifyWrongPubkeyProofOfPossession(t *testing.T) { + require := require.New(t) + server, signer, _ := NewSigner(require) + defer server.Close() + _, wrongPk := NewLocalPair(require) + + msg := []byte("TestVerifyWrongPubkeyProofOfPossession json-rpc") + + sig := signer.SignProofOfPossession(msg) + + isValid := bls.VerifyProofOfPossession(wrongPk, sig, msg) + require.False(isValid) +} + +func TestVerifyWrongMessageSignedProofOfPossession(t *testing.T) { + require := require.New(t) + server, signer, pk := NewSigner(require) + defer server.Close() + + msg := []byte("TestVerifyWrongMessageSignedProofOfPossession json-rpc") + wrongMsg := []byte("TestVerifyWrongMessageSignedProofOfPossession json-rpc with wrong signature") + + wrongSig := signer.SignProofOfPossession(wrongMsg) + + isValid := bls.VerifyProofOfPossession(pk, wrongSig, msg) + require.False(isValid) +} diff --git a/utils/crypto/bls/signers/localsigner/benchmark_test.go b/utils/crypto/bls/signers/localsigner/benchmark_test.go new file mode 100644 index 000000000000..701826918e39 --- /dev/null +++ b/utils/crypto/bls/signers/localsigner/benchmark_test.go @@ -0,0 +1,29 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package localsigner + +import ( + "strconv" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils" + "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" +) + +func BenchmarkSign(b *testing.B) { + privateKey, _ := NewKeyPair(require.New(b)) + for _, messageSize := range blstest.BenchmarkSizes { + b.Run(strconv.Itoa(messageSize), func(b *testing.B) { + message := utils.RandomBytes(messageSize) + + b.ResetTimer() + + for n := 0; n < b.N; n++ { + _ = privateKey.Sign(message) + } + }) + } +} diff --git a/utils/crypto/bls/signers/localsigner/bls_test.go b/utils/crypto/bls/signers/localsigner/bls_test.go new file mode 100644 index 000000000000..7602e7683d03 --- /dev/null +++ b/utils/crypto/bls/signers/localsigner/bls_test.go @@ -0,0 +1,297 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package localsigner + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" +) + +func NewKeyPair(require *require.Assertions) (*LocalSigner, *bls.PublicKey) { + sk, err := NewSigner() + require.NoError(err) + pk := sk.PublicKey() + return sk, pk +} + +func TestVerifyValidSignature(t *testing.T) { + require := require.New(t) + signer, pk := NewKeyPair(require) + + msg := []byte("TestVerifyValidSignature local signer") + + sig := signer.Sign(msg) + + isValid := bls.Verify(pk, sig, msg) + require.True(isValid) +} + +func TestVerifyWrongMessageSignature(t *testing.T) { + require := require.New(t) + signer, pk := NewKeyPair(require) + + msg := []byte("TestVerifyWrongMessageSignature local signer") + wrongMsg := []byte("TestVerifyWrongMessageSignature local signer with wrong message") + + sig := signer.Sign(msg) + + isValid := bls.Verify(pk, sig, wrongMsg) + require.False(isValid) +} + +func TestVerifyWrongPubkeySignature(t *testing.T) { + require := require.New(t) + signer, _ := NewKeyPair(require) + _, wrongPk := NewKeyPair(require) + + msg := []byte("TestVerifyWrongPubkeySignature local signer") + + sig := signer.Sign(msg) + + isValid := bls.Verify(wrongPk, sig, msg) + require.False(isValid) +} + +func TestVerifyWrongMessageSignedSignature(t *testing.T) { + require := require.New(t) + signer, pk := NewKeyPair(require) + + msg := []byte("TestVerifyWrongMessageSignedSignature local signer") + wrongMsg := []byte("TestVerifyWrongMessageSignedSignaturelocal local signer with wrong signature") + + wrongSig := signer.Sign(wrongMsg) + + isValid := bls.Verify(pk, wrongSig, msg) + require.False(isValid) +} + +func TestValidAggregation(t *testing.T) { + require := require.New(t) + sk1, pk1 := NewKeyPair(require) + sk2, pk2 := NewKeyPair(require) + sk3, pk3 := NewKeyPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestValidAggregation local signer") + + sigs := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) + require.NoError(err) + require.True(isValid) +} + +func TestSingleKeyAggregation(t *testing.T) { + require := require.New(t) + signer, pk := NewKeyPair(require) + + pks := []*bls.PublicKey{pk} + + msg := []byte("TestSingleKeyAggregation local signer") + + sig := signer.Sign(msg) + + isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + require.NoError(err) + require.True(isValid) +} +func TestIncorrectMessageAggregation(t *testing.T) { + require := require.New(t) + sk1, pk1 := NewKeyPair(require) + sk2, pk2 := NewKeyPair(require) + sk3, pk3 := NewKeyPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestIncorrectMessageAggregation local signer") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) + require.NoError(err) + require.False(isValid) +} + +func TestDifferentMessageAggregation(t *testing.T) { + require := require.New(t) + sk1, pk1 := NewKeyPair(require) + sk2, pk2 := NewKeyPair(require) + sk3, pk3 := NewKeyPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestDifferentMessagesAggregation local signer") + differentMsg := []byte("TestDifferentMessagesAggregation local signer with different message") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(differentMsg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestOneIncorrectPubKeyAggregation(t *testing.T) { + require := require.New(t) + sk1, pk1 := NewKeyPair(require) + sk2, pk2 := NewKeyPair(require) + sk3, _ := NewKeyPair(require) + _, wrongPk := NewKeyPair(require) + + pks := []*bls.PublicKey{pk1, pk2, wrongPk} + + msg := []byte("TestOneIncorrectPubKeyAggregation local signer") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { + require := require.New(t) + sk1, pk1 := NewKeyPair(require) + sk2, pk2 := NewKeyPair(require) + _, pk3 := NewKeyPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestMorePubkeysThanSignatures local signer") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { + require := require.New(t) + sk1, pk1 := NewKeyPair(require) + sk2, pk2 := NewKeyPair(require) + sk3, _ := NewKeyPair(require) + + pks := []*bls.PublicKey{pk1, pk2} + + msg := []byte("TestMoreSignaturesThanPubkeys local signer") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + require.NoError(err) + require.False(isValid) +} + +func TestNoPubkeysAggregation(t *testing.T) { + require := require.New(t) + sk1, _ := NewKeyPair(require) + sk2, _ := NewKeyPair(require) + sk3, _ := NewKeyPair(require) + + msg := []byte("TestNoPubkeysAggregation local signer") + + signatures := []*bls.Signature{ + sk1.Sign(msg), + sk2.Sign(msg), + sk3.Sign(msg), + } + + isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) + require.ErrorIs(err, bls.ErrNoPublicKeys) + require.False(isValid) +} + +func TestNoSignaturesAggregation(t *testing.T) { + require := require.New(t) + _, pk1 := NewKeyPair(require) + _, pk2 := NewKeyPair(require) + _, pk3 := NewKeyPair(require) + + pks := []*bls.PublicKey{pk1, pk2, pk3} + + msg := []byte("TestNoSignaturesAggregation local signer") + + isValid, err := blstest.AggregateAndVerify(pks, nil, msg) + require.ErrorIs(err, bls.ErrNoSignatures) + require.False(isValid) +} + +func TestVerifyValidProofOfPossession(t *testing.T) { + require := require.New(t) + signer, pk := NewKeyPair(require) + + msg := []byte("TestVerifyValidProofOfPossession local signer") + + sig := signer.SignProofOfPossession(msg) + + isValid := bls.VerifyProofOfPossession(pk, sig, msg) + require.True(isValid) +} + +func TestVerifyWrongMessageProofOfPossession(t *testing.T) { + require := require.New(t) + signer, pk := NewKeyPair(require) + + msg := []byte("TestVerifyWrongMessageProofOfPossession local signer") + wrongMsg := []byte("TestVerifyWrongMessageProofOfPossession local signer with wrong message") + + sig := signer.SignProofOfPossession(msg) + + isValid := bls.VerifyProofOfPossession(pk, sig, wrongMsg) + require.False(isValid) +} + +func TestVerifyWrongPubkeyProofOfPossession(t *testing.T) { + require := require.New(t) + signer, _ := NewKeyPair(require) + _, wrongPk := NewKeyPair(require) + + msg := []byte("TestVerifyWrongPubkeyProofOfPossession local signer") + + sig := signer.SignProofOfPossession(msg) + + isValid := bls.VerifyProofOfPossession(wrongPk, sig, msg) + require.False(isValid) +} + +func TestVerifyWrongMessageSignedProofOfPossession(t *testing.T) { + require := require.New(t) + signer, pk := NewKeyPair(require) + + msg := []byte("TestVerifyWrongMessageSignedProofOfPossession local signer") + wrongMsg := []byte("TestVerifyWrongMessageSignedProofOfPossession local signer with wrong signature") + + wrongSig := signer.SignProofOfPossession(wrongMsg) + + isValid := bls.VerifyProofOfPossession(pk, wrongSig, msg) + require.False(isValid) +} diff --git a/utils/crypto/bls/blstest/signer_test.go b/utils/crypto/bls/signers/localsigner/serialization_test.go similarity index 67% rename from utils/crypto/bls/blstest/signer_test.go rename to utils/crypto/bls/signers/localsigner/serialization_test.go index ce7ac5cdd1f1..74b8497a4017 100644 --- a/utils/crypto/bls/blstest/signer_test.go +++ b/utils/crypto/bls/signers/localsigner/serialization_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package bls_test +package localsigner import ( "testing" @@ -10,7 +10,6 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) func TestSecretKeyFromBytesZero(t *testing.T) { @@ -18,16 +17,16 @@ func TestSecretKeyFromBytesZero(t *testing.T) { var skArr [bls.SecretKeyLen]byte skBytes := skArr[:] - _, err := localsigner.SecretKeyFromBytes(skBytes) - require.ErrorIs(err, localsigner.ErrFailedSecretKeyDeserialize) + _, err := SecretKeyFromBytes(skBytes) + require.ErrorIs(err, ErrFailedSecretKeyDeserialize) } func TestSecretKeyFromBytesWrongSize(t *testing.T) { require := require.New(t) skBytes := utils.RandomBytes(bls.SecretKeyLen + 1) - _, err := localsigner.SecretKeyFromBytes(skBytes) - require.ErrorIs(err, localsigner.ErrFailedSecretKeyDeserialize) + _, err := SecretKeyFromBytes(skBytes) + require.ErrorIs(err, ErrFailedSecretKeyDeserialize) } func TestSecretKeyBytes(t *testing.T) { @@ -35,12 +34,12 @@ func TestSecretKeyBytes(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := localsigner.NewSigner() + sk, err := NewSigner() require.NoError(err) sig := sk.Sign(msg) skBytes := sk.ToBytes() - sk2, err := localsigner.SecretKeyFromBytes(skBytes) + sk2, err := SecretKeyFromBytes(skBytes) require.NoError(err) sig2 := sk2.Sign(msg) sk2Bytes := sk2.ToBytes() From 3c1ce6c2410b9364b91e4d50f7cb851b8b49e51d Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 14 Jan 2025 13:10:01 -0500 Subject: [PATCH 31/56] Move bls public_test.go back into the bls package --- utils/crypto/bls/{blstest => }/public_test.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) rename utils/crypto/bls/{blstest => }/public_test.go (65%) diff --git a/utils/crypto/bls/blstest/public_test.go b/utils/crypto/bls/public_test.go similarity index 65% rename from utils/crypto/bls/blstest/public_test.go rename to utils/crypto/bls/public_test.go index 3f21bbbfb543..5778e236f5b8 100644 --- a/utils/crypto/bls/blstest/public_test.go +++ b/utils/crypto/bls/public_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package blstest +package bls import ( "encoding/base64" @@ -10,15 +10,14 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" ) func TestPublicKeyFromCompressedBytesWrongSize(t *testing.T) { require := require.New(t) - pkBytes := utils.RandomBytes(bls.PublicKeyLen + 1) - _, err := bls.PublicKeyFromCompressedBytes(pkBytes) - require.ErrorIs(err, bls.ErrFailedPublicKeyDecompress) + pkBytes := utils.RandomBytes(PublicKeyLen + 1) + _, err := PublicKeyFromCompressedBytes(pkBytes) + require.ErrorIs(err, ErrFailedPublicKeyDecompress) } func TestPublicKeyBytes(t *testing.T) { @@ -27,10 +26,10 @@ func TestPublicKeyBytes(t *testing.T) { pkBytes, err := base64.StdEncoding.DecodeString("h5qt9SPxaCo+vOx6sn+QkkpP7Y40Yja7SEAs2MGb/mZT7oKTWgLogjy5c4/wWIGC") require.NoError(err) - pk, err := bls.PublicKeyFromCompressedBytes(pkBytes) + pk, err := PublicKeyFromCompressedBytes(pkBytes) require.NoError(err) - pk2Bytes := bls.PublicKeyToCompressedBytes(pk) + pk2Bytes := PublicKeyToCompressedBytes(pk) require.Equal(pkBytes, pk2Bytes) } @@ -41,13 +40,13 @@ func TestAggregatePublicKeysNoop(t *testing.T) { pkBytes, err := base64.StdEncoding.DecodeString("h5qt9SPxaCo+vOx6sn+QkkpP7Y40Yja7SEAs2MGb/mZT7oKTWgLogjy5c4/wWIGC") require.NoError(err) - pk, err := bls.PublicKeyFromCompressedBytes(pkBytes) + pk, err := PublicKeyFromCompressedBytes(pkBytes) require.NoError(err) - aggPK, err := bls.AggregatePublicKeys([]*bls.PublicKey{pk}) + aggPK, err := AggregatePublicKeys([]*PublicKey{pk}) require.NoError(err) - aggPKBytes := bls.PublicKeyToCompressedBytes(aggPK) + aggPKBytes := PublicKeyToCompressedBytes(aggPK) require.NoError(err) require.Equal(pk, aggPK) From ad10cb2a585fb059382e3fc456fd9e091ed9099e Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 14 Jan 2025 13:31:05 -0500 Subject: [PATCH 32/56] Move bls-tests back to bls package --- .../bls/{blstest => }/bls_benchmark_test.go | 51 ++++++------------- utils/crypto/bls/bls_test.go | 13 ----- utils/crypto/bls/blstest/blstest.go | 21 -------- utils/crypto/bls/signature.go | 13 +++++ .../bls/{blstest => }/signature_test.go | 15 +++--- utils/crypto/bls/signers/json-rpc/bls_test.go | 19 ++++--- .../bls/signers/localsigner/bls_test.go | 19 ++++--- 7 files changed, 53 insertions(+), 98 deletions(-) rename utils/crypto/bls/{blstest => }/bls_benchmark_test.go (57%) delete mode 100644 utils/crypto/bls/blstest/blstest.go rename utils/crypto/bls/{blstest => }/signature_test.go (67%) diff --git a/utils/crypto/bls/blstest/bls_benchmark_test.go b/utils/crypto/bls/bls_benchmark_test.go similarity index 57% rename from utils/crypto/bls/blstest/bls_benchmark_test.go rename to utils/crypto/bls/bls_benchmark_test.go index 751403b71a68..33caa49eeb59 100644 --- a/utils/crypto/bls/blstest/bls_benchmark_test.go +++ b/utils/crypto/bls/bls_benchmark_test.go @@ -1,44 +1,23 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package blstest +package bls import ( - "crypto/rand" "strconv" "testing" "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" - - blst "github.com/supranational/blst/bindings/go" + "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" ) -func newKey(require *require.Assertions) *blst.SecretKey { - var ikm [32]byte - _, err := rand.Read(ikm[:]) - require.NoError(err) - sk := blst.KeyGen(ikm[:]) - ikm = [32]byte{} // zero out the ikm - - return sk -} - -func sign(sk *blst.SecretKey, msg []byte) *bls.Signature { - return new(bls.Signature).Sign(sk, msg, bls.CiphersuiteSignature) -} - -func publicKey(sk *blst.SecretKey) *bls.PublicKey { - return new(bls.PublicKey).From(sk) -} - func BenchmarkVerify(b *testing.B) { privateKey := newKey(require.New(b)) publicKey := publicKey(privateKey) - for _, messageSize := range BenchmarkSizes { + for _, messageSize := range blstest.BenchmarkSizes { b.Run(strconv.Itoa(messageSize), func(b *testing.B) { message := utils.RandomBytes(messageSize) @@ -47,14 +26,14 @@ func BenchmarkVerify(b *testing.B) { b.ResetTimer() for n := 0; n < b.N; n++ { - require.True(b, bls.Verify(publicKey, signature, message)) + require.True(b, Verify(publicKey, signature, message)) } }) } } func BenchmarkAggregatePublicKeys(b *testing.B) { - keys := make([]*bls.PublicKey, BiggestBenchmarkSize) + keys := make([]*PublicKey, blstest.BiggestBenchmarkSize) for i := range keys { privateKey := newKey(require.New(b)) @@ -62,10 +41,10 @@ func BenchmarkAggregatePublicKeys(b *testing.B) { keys[i] = publicKey(privateKey) } - for _, size := range BenchmarkSizes { + for _, size := range blstest.BenchmarkSizes { b.Run(strconv.Itoa(size), func(b *testing.B) { for n := 0; n < b.N; n++ { - _, err := bls.AggregatePublicKeys(keys[:size]) + _, err := AggregatePublicKeys(keys[:size]) require.NoError(b, err) } }) @@ -79,7 +58,7 @@ func BenchmarkPublicKeyToCompressedBytes(b *testing.B) { b.ResetTimer() for range b.N { - bls.PublicKeyToCompressedBytes(pk) + PublicKeyToCompressedBytes(pk) } } @@ -87,11 +66,11 @@ func BenchmarkPublicKeyFromCompressedBytes(b *testing.B) { sk := newKey(require.New(b)) pk := publicKey(sk) - pkBytes := bls.PublicKeyToCompressedBytes(pk) + pkBytes := PublicKeyToCompressedBytes(pk) b.ResetTimer() for range b.N { - _, _ = bls.PublicKeyFromCompressedBytes(pkBytes) + _, _ = PublicKeyFromCompressedBytes(pkBytes) } } @@ -102,7 +81,7 @@ func BenchmarkPublicKeyToUncompressedBytes(b *testing.B) { b.ResetTimer() for range b.N { - bls.PublicKeyToUncompressedBytes(pk) + PublicKeyToUncompressedBytes(pk) } } @@ -110,11 +89,11 @@ func BenchmarkPublicKeyFromValidUncompressedBytes(b *testing.B) { sk := newKey(require.New(b)) pk := publicKey(sk) - pkBytes := bls.PublicKeyToUncompressedBytes(pk) + pkBytes := PublicKeyToUncompressedBytes(pk) b.ResetTimer() for range b.N { - _ = bls.PublicKeyFromValidUncompressedBytes(pkBytes) + _ = PublicKeyFromValidUncompressedBytes(pkBytes) } } @@ -123,10 +102,10 @@ func BenchmarkSignatureFromBytes(b *testing.B) { message := utils.RandomBytes(32) signature := sign(sk, message) - signatureBytes := bls.SignatureToBytes(signature) + signatureBytes := SignatureToBytes(signature) b.ResetTimer() for range b.N { - _, _ = bls.SignatureFromBytes(signatureBytes) + _, _ = SignatureFromBytes(signatureBytes) } } diff --git a/utils/crypto/bls/bls_test.go b/utils/crypto/bls/bls_test.go index 4365d0d87407..8ab0b50ad175 100644 --- a/utils/crypto/bls/bls_test.go +++ b/utils/crypto/bls/bls_test.go @@ -32,19 +32,6 @@ func sign(sk *blst.SecretKey, msg []byte) *Signature { return new(Signature).Sign(sk, msg, CiphersuiteSignature) } -func AggregateAndVerify(publicKeys []*PublicKey, signatures []*Signature, message []byte) (bool, error) { - aggSig, err := AggregateSignatures(signatures) - if err != nil { - return false, err - } - aggPK, err := AggregatePublicKeys(publicKeys) - if err != nil { - return false, err - } - - return Verify(aggPK, aggSig, message), nil -} - func TestAggregationThreshold(t *testing.T) { require := require.New(t) diff --git a/utils/crypto/bls/blstest/blstest.go b/utils/crypto/bls/blstest/blstest.go deleted file mode 100644 index 88bc20c4bc99..000000000000 --- a/utils/crypto/bls/blstest/blstest.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package blstest - -import ( - "github.com/ava-labs/avalanchego/utils/crypto/bls" -) - -func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature, message []byte) (bool, error) { - aggSig, err := bls.AggregateSignatures(signatures) - if err != nil { - return false, err - } - aggPK, err := bls.AggregatePublicKeys(publicKeys) - if err != nil { - return false, err - } - - return bls.Verify(aggPK, aggSig, message), nil -} diff --git a/utils/crypto/bls/signature.go b/utils/crypto/bls/signature.go index 51a3c11f0da6..dd75e9df5078 100644 --- a/utils/crypto/bls/signature.go +++ b/utils/crypto/bls/signature.go @@ -55,3 +55,16 @@ func AggregateSignatures(sigs []*Signature) (*Signature, error) { } return agg.ToAffine(), nil } + +func AggregateAndVerify(publicKeys []*PublicKey, signatures []*Signature, message []byte) (bool, error) { + aggSig, err := AggregateSignatures(signatures) + if err != nil { + return false, err + } + aggPK, err := AggregatePublicKeys(publicKeys) + if err != nil { + return false, err + } + + return Verify(aggPK, aggSig, message), nil +} diff --git a/utils/crypto/bls/blstest/signature_test.go b/utils/crypto/bls/signature_test.go similarity index 67% rename from utils/crypto/bls/blstest/signature_test.go rename to utils/crypto/bls/signature_test.go index 843f38844515..74847dfdc436 100644 --- a/utils/crypto/bls/blstest/signature_test.go +++ b/utils/crypto/bls/signature_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package blstest +package bls import ( "testing" @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" ) func TestSignatureBytes(t *testing.T) { @@ -19,11 +18,11 @@ func TestSignatureBytes(t *testing.T) { sk := newKey(require) sig := sign(sk, msg) - sigBytes := bls.SignatureToBytes(sig) + sigBytes := SignatureToBytes(sig) - sig2, err := bls.SignatureFromBytes(sigBytes) + sig2, err := SignatureFromBytes(sigBytes) require.NoError(err) - sig2Bytes := bls.SignatureToBytes(sig2) + sig2Bytes := SignatureToBytes(sig2) require.Equal(sig, sig2) require.Equal(sigBytes, sig2Bytes) @@ -36,12 +35,12 @@ func TestAggregateSignaturesNoop(t *testing.T) { sk := newKey(require) sig := sign(sk, msg) - sigBytes := bls.SignatureToBytes(sig) + sigBytes := SignatureToBytes(sig) - aggSig, err := bls.AggregateSignatures([]*bls.Signature{sig}) + aggSig, err := AggregateSignatures([]*Signature{sig}) require.NoError(err) - aggSigBytes := bls.SignatureToBytes(aggSig) + aggSigBytes := SignatureToBytes(aggSig) require.NoError(err) require.Equal(sig, aggSig) diff --git a/utils/crypto/bls/signers/json-rpc/bls_test.go b/utils/crypto/bls/signers/json-rpc/bls_test.go index 4cac9a714e24..05540cd71d39 100644 --- a/utils/crypto/bls/signers/json-rpc/bls_test.go +++ b/utils/crypto/bls/signers/json-rpc/bls_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) @@ -106,7 +105,7 @@ func TestValidAggregation(t *testing.T) { signer3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) + isValid, err := bls.AggregateAndVerify(pks, sigs, msg) require.NoError(err) require.True(isValid) } @@ -122,7 +121,7 @@ func TestSingleKeyAggregation(t *testing.T) { sig := signer.Sign(msg) - isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + isValid, err := bls.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) require.NoError(err) require.True(isValid) } @@ -145,7 +144,7 @@ func TestIncorrectMessageAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) + isValid, err := bls.AggregateAndVerify(pks, signatures, []byte("a different message")) require.NoError(err) require.False(isValid) } @@ -169,7 +168,7 @@ func TestOneDifferentMessageAggregation(t *testing.T) { sk3.Sign(differentMsg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -193,7 +192,7 @@ func TestOneIncorrectPubKeyAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -214,7 +213,7 @@ func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { sk2.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -236,7 +235,7 @@ func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -256,7 +255,7 @@ func TestNoPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) + isValid, err := bls.AggregateAndVerify(nil, signatures, msg) require.ErrorIs(err, bls.ErrNoPublicKeys) require.False(isValid) } @@ -272,7 +271,7 @@ func TestNoSignaturesAggregation(t *testing.T) { msg := []byte("TestNoSignaturesAggregation json-rpc") - isValid, err := blstest.AggregateAndVerify(pks, nil, msg) + isValid, err := bls.AggregateAndVerify(pks, nil, msg) require.ErrorIs(err, bls.ErrNoSignatures) require.False(isValid) } diff --git a/utils/crypto/bls/signers/localsigner/bls_test.go b/utils/crypto/bls/signers/localsigner/bls_test.go index 7602e7683d03..a02071b23601 100644 --- a/utils/crypto/bls/signers/localsigner/bls_test.go +++ b/utils/crypto/bls/signers/localsigner/bls_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" ) func NewKeyPair(require *require.Assertions) (*LocalSigner, *bls.PublicKey) { @@ -86,7 +85,7 @@ func TestValidAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) + isValid, err := bls.AggregateAndVerify(pks, sigs, msg) require.NoError(err) require.True(isValid) } @@ -101,7 +100,7 @@ func TestSingleKeyAggregation(t *testing.T) { sig := signer.Sign(msg) - isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + isValid, err := bls.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) require.NoError(err) require.True(isValid) } @@ -121,7 +120,7 @@ func TestIncorrectMessageAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) + isValid, err := bls.AggregateAndVerify(pks, signatures, []byte("a different message")) require.NoError(err) require.False(isValid) } @@ -143,7 +142,7 @@ func TestDifferentMessageAggregation(t *testing.T) { sk3.Sign(differentMsg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -165,7 +164,7 @@ func TestOneIncorrectPubKeyAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -185,7 +184,7 @@ func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { sk2.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -206,7 +205,7 @@ func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := bls.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -225,7 +224,7 @@ func TestNoPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) + isValid, err := bls.AggregateAndVerify(nil, signatures, msg) require.ErrorIs(err, bls.ErrNoPublicKeys) require.False(isValid) } @@ -240,7 +239,7 @@ func TestNoSignaturesAggregation(t *testing.T) { msg := []byte("TestNoSignaturesAggregation local signer") - isValid, err := blstest.AggregateAndVerify(pks, nil, msg) + isValid, err := bls.AggregateAndVerify(pks, nil, msg) require.ErrorIs(err, bls.ErrNoSignatures) require.False(isValid) } From 0533b151552397b016d52f9a0988f9a365fc7ed2 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 14 Jan 2025 17:58:01 -0500 Subject: [PATCH 33/56] Fix linting --- utils/crypto/bls/bls_benchmark_test.go | 1 - utils/crypto/bls/signers/json-rpc/bls_test.go | 1 + utils/crypto/bls/signers/localsigner/bls_test.go | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/crypto/bls/bls_benchmark_test.go b/utils/crypto/bls/bls_benchmark_test.go index 33caa49eeb59..0f5ea8ce3bf5 100644 --- a/utils/crypto/bls/bls_benchmark_test.go +++ b/utils/crypto/bls/bls_benchmark_test.go @@ -19,7 +19,6 @@ func BenchmarkVerify(b *testing.B) { for _, messageSize := range blstest.BenchmarkSizes { b.Run(strconv.Itoa(messageSize), func(b *testing.B) { - message := utils.RandomBytes(messageSize) signature := sign(privateKey, message) diff --git a/utils/crypto/bls/signers/json-rpc/bls_test.go b/utils/crypto/bls/signers/json-rpc/bls_test.go index 05540cd71d39..ebeecc62ac21 100644 --- a/utils/crypto/bls/signers/json-rpc/bls_test.go +++ b/utils/crypto/bls/signers/json-rpc/bls_test.go @@ -87,6 +87,7 @@ func TestVerifyWrongMessageSignedSignature(t *testing.T) { isValid := bls.Verify(pk, wrongSig, msg) require.False(isValid) } + func TestValidAggregation(t *testing.T) { require := require.New(t) server, signer1, pk1 := NewSigner(require) diff --git a/utils/crypto/bls/signers/localsigner/bls_test.go b/utils/crypto/bls/signers/localsigner/bls_test.go index a02071b23601..48930210babe 100644 --- a/utils/crypto/bls/signers/localsigner/bls_test.go +++ b/utils/crypto/bls/signers/localsigner/bls_test.go @@ -104,6 +104,7 @@ func TestSingleKeyAggregation(t *testing.T) { require.NoError(err) require.True(isValid) } + func TestIncorrectMessageAggregation(t *testing.T) { require := require.New(t) sk1, pk1 := NewKeyPair(require) From a429a32911afafb5010e36121bd345513758c50d Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 14 Jan 2025 18:09:33 -0500 Subject: [PATCH 34/56] Add missing license headers --- utils/crypto/bls/blstest/benchmark.go | 3 +++ utils/crypto/bls/signers/json-rpc/benchmark_test.go | 3 +++ utils/crypto/bls/signers/json-rpc/bls_test.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/utils/crypto/bls/blstest/benchmark.go b/utils/crypto/bls/blstest/benchmark.go index c317972e85b0..c1f8df452b83 100644 --- a/utils/crypto/bls/blstest/benchmark.go +++ b/utils/crypto/bls/blstest/benchmark.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package blstest var ( diff --git a/utils/crypto/bls/signers/json-rpc/benchmark_test.go b/utils/crypto/bls/signers/json-rpc/benchmark_test.go index 84699517492c..35bfb480c512 100644 --- a/utils/crypto/bls/signers/json-rpc/benchmark_test.go +++ b/utils/crypto/bls/signers/json-rpc/benchmark_test.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package jsonrpc import ( diff --git a/utils/crypto/bls/signers/json-rpc/bls_test.go b/utils/crypto/bls/signers/json-rpc/bls_test.go index ebeecc62ac21..ba1884be1d56 100644 --- a/utils/crypto/bls/signers/json-rpc/bls_test.go +++ b/utils/crypto/bls/signers/json-rpc/bls_test.go @@ -1,3 +1,6 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + package jsonrpc import ( From 6d14ee67a8c075b2b00d72e14b3c4a74a3f4aaa0 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 15:48:35 -0500 Subject: [PATCH 35/56] Move AggregateAndVerify function to blstest package --- utils/crypto/bls/blstest/blstest.go | 16 ++++++++++++++++ utils/crypto/bls/signature.go | 13 ------------- utils/crypto/bls/signers/json-rpc/bls_test.go | 19 ++++++++++--------- .../bls/signers/localsigner/bls_test.go | 19 ++++++++++--------- 4 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 utils/crypto/bls/blstest/blstest.go diff --git a/utils/crypto/bls/blstest/blstest.go b/utils/crypto/bls/blstest/blstest.go new file mode 100644 index 000000000000..79577b544c02 --- /dev/null +++ b/utils/crypto/bls/blstest/blstest.go @@ -0,0 +1,16 @@ +package blstest + +import "github.com/ava-labs/avalanchego/utils/crypto/bls" + +func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature, message []byte) (bool, error) { + aggSig, err := bls.AggregateSignatures(signatures) + if err != nil { + return false, err + } + aggPK, err := bls.AggregatePublicKeys(publicKeys) + if err != nil { + return false, err + } + + return bls.Verify(aggPK, aggSig, message), nil +} diff --git a/utils/crypto/bls/signature.go b/utils/crypto/bls/signature.go index dd75e9df5078..51a3c11f0da6 100644 --- a/utils/crypto/bls/signature.go +++ b/utils/crypto/bls/signature.go @@ -55,16 +55,3 @@ func AggregateSignatures(sigs []*Signature) (*Signature, error) { } return agg.ToAffine(), nil } - -func AggregateAndVerify(publicKeys []*PublicKey, signatures []*Signature, message []byte) (bool, error) { - aggSig, err := AggregateSignatures(signatures) - if err != nil { - return false, err - } - aggPK, err := AggregatePublicKeys(publicKeys) - if err != nil { - return false, err - } - - return Verify(aggPK, aggSig, message), nil -} diff --git a/utils/crypto/bls/signers/json-rpc/bls_test.go b/utils/crypto/bls/signers/json-rpc/bls_test.go index ba1884be1d56..6ea757830eff 100644 --- a/utils/crypto/bls/signers/json-rpc/bls_test.go +++ b/utils/crypto/bls/signers/json-rpc/bls_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" ) @@ -109,7 +110,7 @@ func TestValidAggregation(t *testing.T) { signer3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, sigs, msg) + isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) require.NoError(err) require.True(isValid) } @@ -125,7 +126,7 @@ func TestSingleKeyAggregation(t *testing.T) { sig := signer.Sign(msg) - isValid, err := bls.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) require.NoError(err) require.True(isValid) } @@ -148,7 +149,7 @@ func TestIncorrectMessageAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, []byte("a different message")) + isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) require.NoError(err) require.False(isValid) } @@ -172,7 +173,7 @@ func TestOneDifferentMessageAggregation(t *testing.T) { sk3.Sign(differentMsg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -196,7 +197,7 @@ func TestOneIncorrectPubKeyAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -217,7 +218,7 @@ func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { sk2.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -239,7 +240,7 @@ func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -259,7 +260,7 @@ func TestNoPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(nil, signatures, msg) + isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) require.ErrorIs(err, bls.ErrNoPublicKeys) require.False(isValid) } @@ -275,7 +276,7 @@ func TestNoSignaturesAggregation(t *testing.T) { msg := []byte("TestNoSignaturesAggregation json-rpc") - isValid, err := bls.AggregateAndVerify(pks, nil, msg) + isValid, err := blstest.AggregateAndVerify(pks, nil, msg) require.ErrorIs(err, bls.ErrNoSignatures) require.False(isValid) } diff --git a/utils/crypto/bls/signers/localsigner/bls_test.go b/utils/crypto/bls/signers/localsigner/bls_test.go index 48930210babe..19e96541107b 100644 --- a/utils/crypto/bls/signers/localsigner/bls_test.go +++ b/utils/crypto/bls/signers/localsigner/bls_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" + "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" ) func NewKeyPair(require *require.Assertions) (*LocalSigner, *bls.PublicKey) { @@ -85,7 +86,7 @@ func TestValidAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, sigs, msg) + isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) require.NoError(err) require.True(isValid) } @@ -100,7 +101,7 @@ func TestSingleKeyAggregation(t *testing.T) { sig := signer.Sign(msg) - isValid, err := bls.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) require.NoError(err) require.True(isValid) } @@ -121,7 +122,7 @@ func TestIncorrectMessageAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, []byte("a different message")) + isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) require.NoError(err) require.False(isValid) } @@ -143,7 +144,7 @@ func TestDifferentMessageAggregation(t *testing.T) { sk3.Sign(differentMsg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -165,7 +166,7 @@ func TestOneIncorrectPubKeyAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -185,7 +186,7 @@ func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { sk2.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -206,7 +207,7 @@ func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(pks, signatures, msg) + isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -225,7 +226,7 @@ func TestNoPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := bls.AggregateAndVerify(nil, signatures, msg) + isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) require.ErrorIs(err, bls.ErrNoPublicKeys) require.False(isValid) } @@ -240,7 +241,7 @@ func TestNoSignaturesAggregation(t *testing.T) { msg := []byte("TestNoSignaturesAggregation local signer") - isValid, err := bls.AggregateAndVerify(pks, nil, msg) + isValid, err := blstest.AggregateAndVerify(pks, nil, msg) require.ErrorIs(err, bls.ErrNoSignatures) require.False(isValid) } From bb67f2562fb1b753e2b304ffed5a9949de64a42e Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 15:50:08 -0500 Subject: [PATCH 36/56] Make signers directory singular --- config/config.go | 2 +- network/network_test.go | 2 +- network/p2p/acp118/handler_test.go | 2 +- network/peer/ip_signer_test.go | 2 +- network/peer/ip_test.go | 2 +- network/peer/peer_test.go | 2 +- network/peer/test_peer.go | 2 +- network/test_network.go | 2 +- snow/snowtest/context.go | 2 +- snow/validators/gvalidators/validator_state_test.go | 2 +- snow/validators/manager_test.go | 2 +- snow/validators/set_test.go | 2 +- tests/e2e/p/workflow.go | 2 +- tests/fixture/tmpnet/node.go | 2 +- utils/crypto/bls/{signers => signer}/json-rpc/benchmark_test.go | 0 utils/crypto/bls/{signers => signer}/json-rpc/bls_test.go | 2 +- utils/crypto/bls/{signers => signer}/json-rpc/client.go | 0 utils/crypto/bls/{signers => signer}/json-rpc/messages.go | 0 utils/crypto/bls/{signers => signer}/json-rpc/server.go | 2 +- .../bls/{signers => signer}/localsigner/benchmark_test.go | 0 utils/crypto/bls/{signers => signer}/localsigner/bls_test.go | 0 utils/crypto/bls/{signers => signer}/localsigner/localsigner.go | 0 .../bls/{signers => signer}/localsigner/serialization_test.go | 0 vms/platformvm/block/builder/builder_test.go | 2 +- vms/platformvm/block/executor/proposal_block_test.go | 2 +- vms/platformvm/block/executor/verifier_test.go | 2 +- vms/platformvm/network/warp_test.go | 2 +- vms/platformvm/service_test.go | 2 +- vms/platformvm/signer/proof_of_possession_test.go | 2 +- vms/platformvm/state/staker_test.go | 2 +- vms/platformvm/state/state_test.go | 2 +- vms/platformvm/txs/add_permissionless_validator_tx_test.go | 2 +- vms/platformvm/txs/convert_subnet_to_l1_tx_test.go | 2 +- vms/platformvm/txs/executor/standard_tx_executor_test.go | 2 +- vms/platformvm/txs/executor/state_changes_test.go | 2 +- vms/platformvm/txs/executor/warp_verifier_test.go | 2 +- vms/platformvm/txs/register_l1_validator_tx_test.go | 2 +- vms/platformvm/validator_set_property_test.go | 2 +- vms/platformvm/validators/manager_benchmark_test.go | 2 +- vms/platformvm/validators/manager_test.go | 2 +- vms/platformvm/vm_regression_test.go | 2 +- vms/platformvm/vm_test.go | 2 +- vms/platformvm/warp/gwarp/signer_test.go | 2 +- vms/platformvm/warp/message/register_l1_validator_test.go | 2 +- vms/platformvm/warp/signature_test.go | 2 +- vms/platformvm/warp/signer_test.go | 2 +- vms/platformvm/warp/validator_test.go | 2 +- wallet/chain/p/builder_test.go | 2 +- wallet/subnet/primary/examples/register-l1-validator/main.go | 2 +- wallet/subnet/primary/examples/set-l1-validator-weight/main.go | 2 +- 50 files changed, 43 insertions(+), 43 deletions(-) rename utils/crypto/bls/{signers => signer}/json-rpc/benchmark_test.go (100%) rename utils/crypto/bls/{signers => signer}/json-rpc/bls_test.go (99%) rename utils/crypto/bls/{signers => signer}/json-rpc/client.go (100%) rename utils/crypto/bls/{signers => signer}/json-rpc/messages.go (100%) rename utils/crypto/bls/{signers => signer}/json-rpc/server.go (97%) rename utils/crypto/bls/{signers => signer}/localsigner/benchmark_test.go (100%) rename utils/crypto/bls/{signers => signer}/localsigner/bls_test.go (100%) rename utils/crypto/bls/{signers => signer}/localsigner/localsigner.go (100%) rename utils/crypto/bls/{signers => signer}/localsigner/serialization_test.go (100%) diff --git a/config/config.go b/config/config.go index 00a29b0ec749..c47e379508c6 100644 --- a/config/config.go +++ b/config/config.go @@ -37,7 +37,7 @@ import ( "github.com/ava-labs/avalanchego/utils/compression" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/ips" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/perms" diff --git a/network/network_test.go b/network/network_test.go index a8a194e4e890..0fb495369e27 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -30,7 +30,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/bloom" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/ips" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" diff --git a/network/p2p/acp118/handler_test.go b/network/p2p/acp118/handler_test.go index b179c00efb91..3065490d589e 100644 --- a/network/p2p/acp118/handler_test.go +++ b/network/p2p/acp118/handler_test.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/proto/pb/sdk" "github.com/ava-labs/avalanchego/snow/engine/common" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" ) diff --git a/network/peer/ip_signer_test.go b/network/peer/ip_signer_test.go index b1430748a3ee..b45ae5f10404 100644 --- a/network/peer/ip_signer_test.go +++ b/network/peer/ip_signer_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/staking" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" ) func TestIPSigner(t *testing.T) { diff --git a/network/peer/ip_test.go b/network/peer/ip_test.go index 6613fe6a48d7..3711afa0d832 100644 --- a/network/peer/ip_test.go +++ b/network/peer/ip_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/staking" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" ) func TestSignedIpVerify(t *testing.T) { diff --git a/network/peer/peer_test.go b/network/peer/peer_test.go index 5ec43bf33f2d..b5f02c1fe1ca 100644 --- a/network/peer/peer_test.go +++ b/network/peer/peer_test.go @@ -25,7 +25,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" diff --git a/network/peer/test_peer.go b/network/peer/test_peer.go index 86b66f66c244..ce775a452e92 100644 --- a/network/peer/test_peer.go +++ b/network/peer/test_peer.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" diff --git a/network/test_network.go b/network/test_network.go index df62eb961de8..4fd3ae712fcf 100644 --- a/network/test_network.go +++ b/network/test_network.go @@ -28,7 +28,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" "github.com/ava-labs/avalanchego/utils/resource" diff --git a/snow/snowtest/context.go b/snow/snowtest/context.go index b36eaa7435e5..8ec187e75126 100644 --- a/snow/snowtest/context.go +++ b/snow/snowtest/context.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/logging" ) diff --git a/snow/validators/gvalidators/validator_state_test.go b/snow/validators/gvalidators/validator_state_test.go index 516ddd4d46c6..5fc1384d0163 100644 --- a/snow/validators/gvalidators/validator_state_test.go +++ b/snow/validators/gvalidators/validator_state_test.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/snow/validators/validatorsmock" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils" pb "github.com/ava-labs/avalanchego/proto/pb/validatorstate" diff --git a/snow/validators/manager_test.go b/snow/validators/manager_test.go index 50a5c871a6d0..4208dc9bbc45 100644 --- a/snow/validators/manager_test.go +++ b/snow/validators/manager_test.go @@ -11,7 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" safemath "github.com/ava-labs/avalanchego/utils/math" diff --git a/snow/validators/set_test.go b/snow/validators/set_test.go index 59597eab644d..dc2efcde720f 100644 --- a/snow/validators/set_test.go +++ b/snow/validators/set_test.go @@ -11,7 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" safemath "github.com/ava-labs/avalanchego/utils/math" diff --git a/tests/e2e/p/workflow.go b/tests/e2e/p/workflow.go index 1a542ccadc37..0ca615ea9fb1 100644 --- a/tests/e2e/p/workflow.go +++ b/tests/e2e/p/workflow.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/tests/fixture/e2e" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm" diff --git a/tests/fixture/tmpnet/node.go b/tests/fixture/tmpnet/node.go index ca696ebde160..8d32d33efc31 100644 --- a/tests/fixture/tmpnet/node.go +++ b/tests/fixture/tmpnet/node.go @@ -22,7 +22,7 @@ import ( "github.com/ava-labs/avalanchego/config" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/staking" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/vms/platformvm/signer" ) diff --git a/utils/crypto/bls/signers/json-rpc/benchmark_test.go b/utils/crypto/bls/signer/json-rpc/benchmark_test.go similarity index 100% rename from utils/crypto/bls/signers/json-rpc/benchmark_test.go rename to utils/crypto/bls/signer/json-rpc/benchmark_test.go diff --git a/utils/crypto/bls/signers/json-rpc/bls_test.go b/utils/crypto/bls/signer/json-rpc/bls_test.go similarity index 99% rename from utils/crypto/bls/signers/json-rpc/bls_test.go rename to utils/crypto/bls/signer/json-rpc/bls_test.go index 6ea757830eff..a58c7eac1ede 100644 --- a/utils/crypto/bls/signers/json-rpc/bls_test.go +++ b/utils/crypto/bls/signer/json-rpc/bls_test.go @@ -11,7 +11,7 @@ import ( "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" ) func NewLocalPair(require *require.Assertions) (*localsigner.LocalSigner, *bls.PublicKey) { diff --git a/utils/crypto/bls/signers/json-rpc/client.go b/utils/crypto/bls/signer/json-rpc/client.go similarity index 100% rename from utils/crypto/bls/signers/json-rpc/client.go rename to utils/crypto/bls/signer/json-rpc/client.go diff --git a/utils/crypto/bls/signers/json-rpc/messages.go b/utils/crypto/bls/signer/json-rpc/messages.go similarity index 100% rename from utils/crypto/bls/signers/json-rpc/messages.go rename to utils/crypto/bls/signer/json-rpc/messages.go diff --git a/utils/crypto/bls/signers/json-rpc/server.go b/utils/crypto/bls/signer/json-rpc/server.go similarity index 97% rename from utils/crypto/bls/signers/json-rpc/server.go rename to utils/crypto/bls/signer/json-rpc/server.go index 02f6b79d3a9c..2b68d9e84fad 100644 --- a/utils/crypto/bls/signers/json-rpc/server.go +++ b/utils/crypto/bls/signer/json-rpc/server.go @@ -14,7 +14,7 @@ import ( "github.com/gorilla/rpc/v2/json" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" ) type signerService struct { diff --git a/utils/crypto/bls/signers/localsigner/benchmark_test.go b/utils/crypto/bls/signer/localsigner/benchmark_test.go similarity index 100% rename from utils/crypto/bls/signers/localsigner/benchmark_test.go rename to utils/crypto/bls/signer/localsigner/benchmark_test.go diff --git a/utils/crypto/bls/signers/localsigner/bls_test.go b/utils/crypto/bls/signer/localsigner/bls_test.go similarity index 100% rename from utils/crypto/bls/signers/localsigner/bls_test.go rename to utils/crypto/bls/signer/localsigner/bls_test.go diff --git a/utils/crypto/bls/signers/localsigner/localsigner.go b/utils/crypto/bls/signer/localsigner/localsigner.go similarity index 100% rename from utils/crypto/bls/signers/localsigner/localsigner.go rename to utils/crypto/bls/signer/localsigner/localsigner.go diff --git a/utils/crypto/bls/signers/localsigner/serialization_test.go b/utils/crypto/bls/signer/localsigner/serialization_test.go similarity index 100% rename from utils/crypto/bls/signers/localsigner/serialization_test.go rename to utils/crypto/bls/signer/localsigner/serialization_test.go diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 32e831d854d5..9c2156faee0f 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/snow/consensus/snowman" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 97d6e16e6770..38045e79fd17 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -18,7 +18,7 @@ import ( "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/timer/mockable" diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index 35e806e8ffde..37c5c48376d4 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -25,7 +25,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" diff --git a/vms/platformvm/network/warp_test.go b/vms/platformvm/network/warp_test.go index 7813548fcc68..d8b20925f26c 100644 --- a/vms/platformvm/network/warp_test.go +++ b/vms/platformvm/network/warp_test.go @@ -21,7 +21,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/genesis/genesistest" "github.com/ava-labs/avalanchego/vms/platformvm/state" "github.com/ava-labs/avalanchego/vms/platformvm/state/statetest" diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 423d698c9d6d..2332ff56fba4 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -30,7 +30,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" "github.com/ava-labs/avalanchego/utils/formatting/address" diff --git a/vms/platformvm/signer/proof_of_possession_test.go b/vms/platformvm/signer/proof_of_possession_test.go index fac9744e9eda..0b567d5f4378 100644 --- a/vms/platformvm/signer/proof_of_possession_test.go +++ b/vms/platformvm/signer/proof_of_possession_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" ) func TestProofOfPossession(t *testing.T) { diff --git a/vms/platformvm/state/staker_test.go b/vms/platformvm/state/staker_test.go index 78eab52cceff..23846fc1a13e 100644 --- a/vms/platformvm/state/staker_test.go +++ b/vms/platformvm/state/staker_test.go @@ -12,7 +12,7 @@ import ( "go.uber.org/mock/gomock" "github.com/ava-labs/avalanchego/ids" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/signer" "github.com/ava-labs/avalanchego/vms/platformvm/signer/signermock" "github.com/ava-labs/avalanchego/vms/platformvm/txs" diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index 3ebc1bf75f24..bdb68bba15ea 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -28,7 +28,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/set" diff --git a/vms/platformvm/txs/add_permissionless_validator_tx_test.go b/vms/platformvm/txs/add_permissionless_validator_tx_test.go index e1f7e90b1140..cdcb518491a7 100644 --- a/vms/platformvm/txs/add_permissionless_validator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_validator_tx_test.go @@ -15,7 +15,7 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/components/avax/avaxmock" diff --git a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go index fe80ae65d174..81d231bf721f 100644 --- a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index c7bbcc69e7ec..a789888ea206 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -23,7 +23,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/hashing" "github.com/ava-labs/avalanchego/utils/logging" diff --git a/vms/platformvm/txs/executor/state_changes_test.go b/vms/platformvm/txs/executor/state_changes_test.go index b8554a3aa350..04831b452b3b 100644 --- a/vms/platformvm/txs/executor/state_changes_test.go +++ b/vms/platformvm/txs/executor/state_changes_test.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/iterator" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" diff --git a/vms/platformvm/txs/executor/warp_verifier_test.go b/vms/platformvm/txs/executor/warp_verifier_test.go index f6ca17312ec5..fe7f898caac6 100644 --- a/vms/platformvm/txs/executor/warp_verifier_test.go +++ b/vms/platformvm/txs/executor/warp_verifier_test.go @@ -15,7 +15,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/txs" "github.com/ava-labs/avalanchego/vms/platformvm/warp" diff --git a/vms/platformvm/txs/register_l1_validator_tx_test.go b/vms/platformvm/txs/register_l1_validator_tx_test.go index ec7b5ac91902..fcf8787d723b 100644 --- a/vms/platformvm/txs/register_l1_validator_tx_test.go +++ b/vms/platformvm/txs/register_l1_validator_tx_test.go @@ -15,7 +15,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/snowtest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/components/avax" "github.com/ava-labs/avalanchego/vms/platformvm/signer" diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index d670a7f08b46..dd3c310c254d 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -33,7 +33,7 @@ import ( "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/platformvm/block" "github.com/ava-labs/avalanchego/vms/platformvm/config" diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 130a14f24ca3..27dc488b7dbf 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -16,7 +16,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/utils/units" diff --git a/vms/platformvm/validators/manager_test.go b/vms/platformvm/validators/manager_test.go index dd4f32f9460d..981aa1451e15 100644 --- a/vms/platformvm/validators/manager_test.go +++ b/vms/platformvm/validators/manager_test.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/timer/mockable" "github.com/ava-labs/avalanchego/vms/platformvm/block" diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index eff4a31d4f00..89a56147d495 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -31,7 +31,7 @@ import ( "github.com/ava-labs/avalanchego/utils/bloom" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/version" diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 3823979bcb4e..a6c2fd8fb298 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -38,7 +38,7 @@ import ( "github.com/ava-labs/avalanchego/subnets" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/logging" "github.com/ava-labs/avalanchego/utils/math/meter" diff --git a/vms/platformvm/warp/gwarp/signer_test.go b/vms/platformvm/warp/gwarp/signer_test.go index 012d5436a9ba..47d4ed79c308 100644 --- a/vms/platformvm/warp/gwarp/signer_test.go +++ b/vms/platformvm/warp/gwarp/signer_test.go @@ -11,7 +11,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/signertest" "github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils" diff --git a/vms/platformvm/warp/message/register_l1_validator_test.go b/vms/platformvm/warp/message/register_l1_validator_test.go index 81e5bb6d8fd9..22cec55ebe1f 100644 --- a/vms/platformvm/warp/message/register_l1_validator_test.go +++ b/vms/platformvm/warp/message/register_l1_validator_test.go @@ -12,7 +12,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/hashing" ) diff --git a/vms/platformvm/warp/signature_test.go b/vms/platformvm/warp/signature_test.go index 18af48027ec7..9e31f1efaae8 100644 --- a/vms/platformvm/warp/signature_test.go +++ b/vms/platformvm/warp/signature_test.go @@ -18,7 +18,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" ) diff --git a/vms/platformvm/warp/signer_test.go b/vms/platformvm/warp/signer_test.go index 2ea7e572db15..d1daca487d72 100644 --- a/vms/platformvm/warp/signer_test.go +++ b/vms/platformvm/warp/signer_test.go @@ -10,7 +10,7 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/constants" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/signertest" ) diff --git a/vms/platformvm/warp/validator_test.go b/vms/platformvm/warp/validator_test.go index 00a54b7fd0e7..8cd5f7f57769 100644 --- a/vms/platformvm/warp/validator_test.go +++ b/vms/platformvm/warp/validator_test.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators/validatorsmock" "github.com/ava-labs/avalanchego/snow/validators/validatorstest" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" ) diff --git a/wallet/chain/p/builder_test.go b/wallet/chain/p/builder_test.go index 90b024841fce..aa27b99e3594 100644 --- a/wallet/chain/p/builder_test.go +++ b/wallet/chain/p/builder_test.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/utils" "github.com/ava-labs/avalanchego/utils/constants" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/units" diff --git a/wallet/subnet/primary/examples/register-l1-validator/main.go b/wallet/subnet/primary/examples/register-l1-validator/main.go index 333b21076ef2..5808cc8aad0a 100644 --- a/wallet/subnet/primary/examples/register-l1-validator/main.go +++ b/wallet/subnet/primary/examples/register-l1-validator/main.go @@ -14,7 +14,7 @@ import ( "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/utils/units" "github.com/ava-labs/avalanchego/vms/platformvm/warp" diff --git a/wallet/subnet/primary/examples/set-l1-validator-weight/main.go b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go index 169a22a42f40..3464483515ab 100644 --- a/wallet/subnet/primary/examples/set-l1-validator-weight/main.go +++ b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go @@ -13,7 +13,7 @@ import ( "github.com/ava-labs/avalanchego/genesis" "github.com/ava-labs/avalanchego/ids" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signers/localsigner" + "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/set" "github.com/ava-labs/avalanchego/vms/platformvm/warp" "github.com/ava-labs/avalanchego/vms/platformvm/warp/message" From 7c78147a7307a1304d02f673b754f9d7e57889fb Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 15:51:31 -0500 Subject: [PATCH 37/56] Remove unnecessary comment --- utils/crypto/bls/signer/localsigner/localsigner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/crypto/bls/signer/localsigner/localsigner.go b/utils/crypto/bls/signer/localsigner/localsigner.go index c467f71dcba1..2b77c9768976 100644 --- a/utils/crypto/bls/signer/localsigner/localsigner.go +++ b/utils/crypto/bls/signer/localsigner/localsigner.go @@ -8,7 +8,7 @@ import ( "errors" "runtime" - "github.com/ava-labs/avalanchego/utils/crypto/bls" // Import the parent package + "github.com/ava-labs/avalanchego/utils/crypto/bls" blst "github.com/supranational/blst/bindings/go" ) From 008b72c7f9663827ebab372e10b51743e2eaa35e Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 15:57:05 -0500 Subject: [PATCH 38/56] Remove unnecessary comments --- utils/crypto/bls/signer/json-rpc/client.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/utils/crypto/bls/signer/json-rpc/client.go b/utils/crypto/bls/signer/json-rpc/client.go index 7f9a1197fde5..64ebf20ffd9f 100644 --- a/utils/crypto/bls/signer/json-rpc/client.go +++ b/utils/crypto/bls/signer/json-rpc/client.go @@ -18,7 +18,6 @@ import ( var _ bls.Signer = (*Client)(nil) type Client struct { - // http client http *http.Client url url.URL } @@ -37,7 +36,7 @@ func (c *Client) call(method string, params []interface{}, result interface{}) e } ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() // Ensure the context is canceled to release resources + defer cancel() req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url.String(), bytes.NewBuffer(requestBody)) if err != nil { @@ -68,9 +67,7 @@ func (c *Client) PublicKey() *bls.PublicKey { return pk } -// Sign [msg] to authorize this message func (c *Client) Sign(msg []byte) *bls.Signature { - // request the public key from the json-rpc server reply := new(SignReply) err := c.call("Signer.Sign", []interface{}{SignArgs{msg}}, reply) // TODO: handle this @@ -78,17 +75,13 @@ func (c *Client) Sign(msg []byte) *bls.Signature { panic(err) } - // deserialize the public key sig := new(bls.Signature) sig = sig.Deserialize(reply.Signature) - // can be nil if the public key is invalid return sig } -// Sign [msg] to prove the ownership func (c *Client) SignProofOfPossession(msg []byte) *bls.Signature { - // request the public key from the json-rpc server reply := new(SignReply) err := c.call("Signer.SignProofOfPossession", []interface{}{SignArgs{msg}}, reply) // TODO: handle this @@ -96,10 +89,8 @@ func (c *Client) SignProofOfPossession(msg []byte) *bls.Signature { panic(err) } - // deserialize the public key sig := new(bls.Signature) sig = sig.Deserialize(reply.Signature) - // can be nil if the public key is invalid return sig } From 42cda67737fb65ba90041d710ace68d82972d6c0 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 15:58:06 -0500 Subject: [PATCH 39/56] Remove the `-` from `jsonrpc` package directory --- utils/crypto/bls/signer/{json-rpc => jsonrpc}/benchmark_test.go | 0 utils/crypto/bls/signer/{json-rpc => jsonrpc}/bls_test.go | 0 utils/crypto/bls/signer/{json-rpc => jsonrpc}/client.go | 0 utils/crypto/bls/signer/{json-rpc => jsonrpc}/messages.go | 0 utils/crypto/bls/signer/{json-rpc => jsonrpc}/server.go | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/signer/{json-rpc => jsonrpc}/benchmark_test.go (100%) rename utils/crypto/bls/signer/{json-rpc => jsonrpc}/bls_test.go (100%) rename utils/crypto/bls/signer/{json-rpc => jsonrpc}/client.go (100%) rename utils/crypto/bls/signer/{json-rpc => jsonrpc}/messages.go (100%) rename utils/crypto/bls/signer/{json-rpc => jsonrpc}/server.go (100%) diff --git a/utils/crypto/bls/signer/json-rpc/benchmark_test.go b/utils/crypto/bls/signer/jsonrpc/benchmark_test.go similarity index 100% rename from utils/crypto/bls/signer/json-rpc/benchmark_test.go rename to utils/crypto/bls/signer/jsonrpc/benchmark_test.go diff --git a/utils/crypto/bls/signer/json-rpc/bls_test.go b/utils/crypto/bls/signer/jsonrpc/bls_test.go similarity index 100% rename from utils/crypto/bls/signer/json-rpc/bls_test.go rename to utils/crypto/bls/signer/jsonrpc/bls_test.go diff --git a/utils/crypto/bls/signer/json-rpc/client.go b/utils/crypto/bls/signer/jsonrpc/client.go similarity index 100% rename from utils/crypto/bls/signer/json-rpc/client.go rename to utils/crypto/bls/signer/jsonrpc/client.go diff --git a/utils/crypto/bls/signer/json-rpc/messages.go b/utils/crypto/bls/signer/jsonrpc/messages.go similarity index 100% rename from utils/crypto/bls/signer/json-rpc/messages.go rename to utils/crypto/bls/signer/jsonrpc/messages.go diff --git a/utils/crypto/bls/signer/json-rpc/server.go b/utils/crypto/bls/signer/jsonrpc/server.go similarity index 100% rename from utils/crypto/bls/signer/json-rpc/server.go rename to utils/crypto/bls/signer/jsonrpc/server.go From ae7cc4bc59e5d39632b0c6e5e86e4553b357e364 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 16:00:34 -0500 Subject: [PATCH 40/56] Use `any` keyword instead of `interfacei{}` --- utils/crypto/bls/signer/jsonrpc/client.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/crypto/bls/signer/jsonrpc/client.go b/utils/crypto/bls/signer/jsonrpc/client.go index 64ebf20ffd9f..06e313d9b2a5 100644 --- a/utils/crypto/bls/signer/jsonrpc/client.go +++ b/utils/crypto/bls/signer/jsonrpc/client.go @@ -29,7 +29,7 @@ func NewClient(url url.URL) *Client { } } -func (c *Client) call(method string, params []interface{}, result interface{}) error { +func (c *Client) call(method string, params []any, result any) error { requestBody, err := json2.EncodeClientRequest(method, params) if err != nil { return err @@ -56,7 +56,7 @@ func (c *Client) call(method string, params []interface{}, result interface{}) e func (c *Client) PublicKey() *bls.PublicKey { reply := new(PublicKeyReply) - err := c.call("Signer.PublicKey", []interface{}{PublicKeyArgs{}}, reply) + err := c.call("Signer.PublicKey", []any{PublicKeyArgs{}}, reply) if err != nil { panic(err) } @@ -69,7 +69,7 @@ func (c *Client) PublicKey() *bls.PublicKey { func (c *Client) Sign(msg []byte) *bls.Signature { reply := new(SignReply) - err := c.call("Signer.Sign", []interface{}{SignArgs{msg}}, reply) + err := c.call("Signer.Sign", []any{SignArgs{msg}}, reply) // TODO: handle this if err != nil { panic(err) @@ -83,7 +83,7 @@ func (c *Client) Sign(msg []byte) *bls.Signature { func (c *Client) SignProofOfPossession(msg []byte) *bls.Signature { reply := new(SignReply) - err := c.call("Signer.SignProofOfPossession", []interface{}{SignArgs{msg}}, reply) + err := c.call("Signer.SignProofOfPossession", []any{SignArgs{msg}}, reply) // TODO: handle this if err != nil { panic(err) From 9290db9043e453033829c6dbf84dce94deba83d1 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 16:10:43 -0500 Subject: [PATCH 41/56] Move `jsonrpc/messages.go` to `jsonrpc/message.go` --- utils/crypto/bls/signer/jsonrpc/{messages.go => message.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename utils/crypto/bls/signer/jsonrpc/{messages.go => message.go} (100%) diff --git a/utils/crypto/bls/signer/jsonrpc/messages.go b/utils/crypto/bls/signer/jsonrpc/message.go similarity index 100% rename from utils/crypto/bls/signer/jsonrpc/messages.go rename to utils/crypto/bls/signer/jsonrpc/message.go From cb56999f8b2547a1c2deb5ef43ed023e1e4c3353 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 16:15:37 -0500 Subject: [PATCH 42/56] Export the jsonrpc signer service type --- utils/crypto/bls/signer/jsonrpc/server.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/crypto/bls/signer/jsonrpc/server.go b/utils/crypto/bls/signer/jsonrpc/server.go index 2b68d9e84fad..126b047c9910 100644 --- a/utils/crypto/bls/signer/jsonrpc/server.go +++ b/utils/crypto/bls/signer/jsonrpc/server.go @@ -17,7 +17,7 @@ import ( "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" ) -type signerService struct { +type SignerService struct { signer *localsigner.LocalSigner } @@ -26,16 +26,16 @@ type Server struct { listener net.Listener } -func NewSignerService() *signerService { +func NewSignerService() *SignerService { signer, err := localsigner.NewSigner() if err != nil { panic(err) } - return &signerService{signer: signer} + return &SignerService{signer: signer} } -func Serve(service *signerService) (*Server, error) { +func Serve(service *SignerService) (*Server, error) { server := rpc.NewServer() server.RegisterCodec(json.NewCodec(), "application/json") @@ -84,17 +84,17 @@ func (s *Server) Close() error { return s.listener.Close() } -func (s *signerService) PublicKey(_ *http.Request, _ *PublicKeyArgs, reply *PublicKeyReply) error { +func (s *SignerService) PublicKey(_ *http.Request, _ *PublicKeyArgs, reply *PublicKeyReply) error { *reply = toPkReply(s.signer.PublicKey()) return nil } -func (s *signerService) Sign(_ *http.Request, args *struct{ Msg []byte }, reply *SignReply) error { +func (s *SignerService) Sign(_ *http.Request, args *struct{ Msg []byte }, reply *SignReply) error { *reply = toSignReply(s.signer.Sign(args.Msg)) return nil } -func (s *signerService) SignProofOfPossession(_ *http.Request, args *struct{ Msg []byte }, reply *SignProofOfPossessionReply) error { +func (s *SignerService) SignProofOfPossession(_ *http.Request, args *struct{ Msg []byte }, reply *SignProofOfPossessionReply) error { *reply = toSignProofOfPossessionReply(s.signer.SignProofOfPossession(args.Msg)) return nil } From d80464807fce3ccd2894f0e3377f7419668b3683 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 16:25:05 -0500 Subject: [PATCH 43/56] Bubble up the signer/jsonrpc server-error --- utils/crypto/bls/signer/jsonrpc/bls_test.go | 3 ++- utils/crypto/bls/signer/jsonrpc/server.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/crypto/bls/signer/jsonrpc/bls_test.go b/utils/crypto/bls/signer/jsonrpc/bls_test.go index a58c7eac1ede..e373adbba394 100644 --- a/utils/crypto/bls/signer/jsonrpc/bls_test.go +++ b/utils/crypto/bls/signer/jsonrpc/bls_test.go @@ -22,7 +22,8 @@ func NewLocalPair(require *require.Assertions) (*localsigner.LocalSigner, *bls.P } func NewSigner(require *require.Assertions) (*Server, *Client, *bls.PublicKey) { - service := NewSignerService() + service, err := NewSignerService() + require.NoError(err) server, err := Serve(service) require.NoError(err) diff --git a/utils/crypto/bls/signer/jsonrpc/server.go b/utils/crypto/bls/signer/jsonrpc/server.go index 126b047c9910..1ac6e71bbd6c 100644 --- a/utils/crypto/bls/signer/jsonrpc/server.go +++ b/utils/crypto/bls/signer/jsonrpc/server.go @@ -26,13 +26,13 @@ type Server struct { listener net.Listener } -func NewSignerService() *SignerService { +func NewSignerService() (*SignerService, error) { signer, err := localsigner.NewSigner() if err != nil { - panic(err) + return nil, err } - return &SignerService{signer: signer} + return &SignerService{signer: signer}, nil } func Serve(service *SignerService) (*Server, error) { From 55b6a3fa9082ec202b1d2a002baf73b11c1217c5 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 16:31:31 -0500 Subject: [PATCH 44/56] Rename `jsonrpc` package to `jsonrpcsigner` --- utils/crypto/bls/signer/jsonrpc/benchmark_test.go | 2 +- utils/crypto/bls/signer/jsonrpc/bls_test.go | 2 +- utils/crypto/bls/signer/jsonrpc/client.go | 2 +- utils/crypto/bls/signer/jsonrpc/message.go | 2 +- utils/crypto/bls/signer/jsonrpc/server.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/crypto/bls/signer/jsonrpc/benchmark_test.go b/utils/crypto/bls/signer/jsonrpc/benchmark_test.go index 35bfb480c512..540a53809374 100644 --- a/utils/crypto/bls/signer/jsonrpc/benchmark_test.go +++ b/utils/crypto/bls/signer/jsonrpc/benchmark_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package jsonrpc +package jsonrpcsigner import ( "strconv" diff --git a/utils/crypto/bls/signer/jsonrpc/bls_test.go b/utils/crypto/bls/signer/jsonrpc/bls_test.go index e373adbba394..cdcb2e640ff5 100644 --- a/utils/crypto/bls/signer/jsonrpc/bls_test.go +++ b/utils/crypto/bls/signer/jsonrpc/bls_test.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package jsonrpc +package jsonrpcsigner import ( "net/url" diff --git a/utils/crypto/bls/signer/jsonrpc/client.go b/utils/crypto/bls/signer/jsonrpc/client.go index 06e313d9b2a5..0f3943b86e9d 100644 --- a/utils/crypto/bls/signer/jsonrpc/client.go +++ b/utils/crypto/bls/signer/jsonrpc/client.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package jsonrpc +package jsonrpcsigner import ( "bytes" diff --git a/utils/crypto/bls/signer/jsonrpc/message.go b/utils/crypto/bls/signer/jsonrpc/message.go index c79d7f293b69..b33f7374d6bb 100644 --- a/utils/crypto/bls/signer/jsonrpc/message.go +++ b/utils/crypto/bls/signer/jsonrpc/message.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package jsonrpc +package jsonrpcsigner type PublicKeyArgs struct{} diff --git a/utils/crypto/bls/signer/jsonrpc/server.go b/utils/crypto/bls/signer/jsonrpc/server.go index 1ac6e71bbd6c..03c60d95cd4a 100644 --- a/utils/crypto/bls/signer/jsonrpc/server.go +++ b/utils/crypto/bls/signer/jsonrpc/server.go @@ -1,7 +1,7 @@ // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. -package jsonrpc +package jsonrpcsigner import ( "context" From e17122dad173e97898d1ff558f42333a41a17f43 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 22:54:50 -0500 Subject: [PATCH 45/56] Update coreth --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 29ab7ec85e46..5b77a5323aa5 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.14.1-0.20250106222550-c575b84e58f7 + github.com/ava-labs/coreth v0.14.1-rc.0.0.20250121034325-4cd690e2055a github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 diff --git a/go.sum b/go.sum index 393134fdff3b..d2861deff75e 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/coreth v0.14.1-0.20250106222550-c575b84e58f7 h1:aAgV8u1Qnv3kev4cnV1PdwSL8rv1ic53sw6nmm0/ngs= -github.com/ava-labs/coreth v0.14.1-0.20250106222550-c575b84e58f7/go.mod h1:mzAii2r+iq2zCYTxk7obnOQ004BahdX26O8Lp0Ftpgc= +github.com/ava-labs/coreth v0.14.1-rc.0.0.20250121034325-4cd690e2055a h1:1fNibfxmkKUfVOIgh4hnDqtWRj2mZZAPASpakpi8e0A= +github.com/ava-labs/coreth v0.14.1-rc.0.0.20250121034325-4cd690e2055a/go.mod h1:/smuOWlKNaHl3T/6aVgclEDtwvK8cUGUd7DN44EQaTg= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= From 1b8f739beeecf4211df3630e233ed2d11cf10d24 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 20 Jan 2025 23:29:01 -0500 Subject: [PATCH 46/56] Remove circular package dependency --- utils/crypto/bls/blstest/blstest.go | 16 ---------- utils/crypto/bls/signer/jsonrpc/bls_test.go | 32 +++++++++++++------ .../crypto/bls/signer/localsigner/bls_test.go | 32 +++++++++++++------ 3 files changed, 44 insertions(+), 36 deletions(-) delete mode 100644 utils/crypto/bls/blstest/blstest.go diff --git a/utils/crypto/bls/blstest/blstest.go b/utils/crypto/bls/blstest/blstest.go deleted file mode 100644 index 79577b544c02..000000000000 --- a/utils/crypto/bls/blstest/blstest.go +++ /dev/null @@ -1,16 +0,0 @@ -package blstest - -import "github.com/ava-labs/avalanchego/utils/crypto/bls" - -func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature, message []byte) (bool, error) { - aggSig, err := bls.AggregateSignatures(signatures) - if err != nil { - return false, err - } - aggPK, err := bls.AggregatePublicKeys(publicKeys) - if err != nil { - return false, err - } - - return bls.Verify(aggPK, aggSig, message), nil -} diff --git a/utils/crypto/bls/signer/jsonrpc/bls_test.go b/utils/crypto/bls/signer/jsonrpc/bls_test.go index cdcb2e640ff5..4a52e44883da 100644 --- a/utils/crypto/bls/signer/jsonrpc/bls_test.go +++ b/utils/crypto/bls/signer/jsonrpc/bls_test.go @@ -10,10 +10,22 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" ) +func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature, message []byte) (bool, error) { + aggSig, err := bls.AggregateSignatures(signatures) + if err != nil { + return false, err + } + aggPK, err := bls.AggregatePublicKeys(publicKeys) + if err != nil { + return false, err + } + + return bls.Verify(aggPK, aggSig, message), nil +} + func NewLocalPair(require *require.Assertions) (*localsigner.LocalSigner, *bls.PublicKey) { sk, err := localsigner.NewSigner() require.NoError(err) @@ -111,7 +123,7 @@ func TestValidAggregation(t *testing.T) { signer3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) + isValid, err := AggregateAndVerify(pks, sigs, msg) require.NoError(err) require.True(isValid) } @@ -127,7 +139,7 @@ func TestSingleKeyAggregation(t *testing.T) { sig := signer.Sign(msg) - isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + isValid, err := AggregateAndVerify(pks, []*bls.Signature{sig}, msg) require.NoError(err) require.True(isValid) } @@ -150,7 +162,7 @@ func TestIncorrectMessageAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) + isValid, err := AggregateAndVerify(pks, signatures, []byte("a different message")) require.NoError(err) require.False(isValid) } @@ -174,7 +186,7 @@ func TestOneDifferentMessageAggregation(t *testing.T) { sk3.Sign(differentMsg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -198,7 +210,7 @@ func TestOneIncorrectPubKeyAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -219,7 +231,7 @@ func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { sk2.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -241,7 +253,7 @@ func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -261,7 +273,7 @@ func TestNoPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) + isValid, err := AggregateAndVerify(nil, signatures, msg) require.ErrorIs(err, bls.ErrNoPublicKeys) require.False(isValid) } @@ -277,7 +289,7 @@ func TestNoSignaturesAggregation(t *testing.T) { msg := []byte("TestNoSignaturesAggregation json-rpc") - isValid, err := blstest.AggregateAndVerify(pks, nil, msg) + isValid, err := AggregateAndVerify(pks, nil, msg) require.ErrorIs(err, bls.ErrNoSignatures) require.False(isValid) } diff --git a/utils/crypto/bls/signer/localsigner/bls_test.go b/utils/crypto/bls/signer/localsigner/bls_test.go index 19e96541107b..978fea332a51 100644 --- a/utils/crypto/bls/signer/localsigner/bls_test.go +++ b/utils/crypto/bls/signer/localsigner/bls_test.go @@ -9,9 +9,21 @@ import ( "github.com/stretchr/testify/require" "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" ) +func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature, message []byte) (bool, error) { + aggSig, err := bls.AggregateSignatures(signatures) + if err != nil { + return false, err + } + aggPK, err := bls.AggregatePublicKeys(publicKeys) + if err != nil { + return false, err + } + + return bls.Verify(aggPK, aggSig, message), nil +} + func NewKeyPair(require *require.Assertions) (*LocalSigner, *bls.PublicKey) { sk, err := NewSigner() require.NoError(err) @@ -86,7 +98,7 @@ func TestValidAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, sigs, msg) + isValid, err := AggregateAndVerify(pks, sigs, msg) require.NoError(err) require.True(isValid) } @@ -101,7 +113,7 @@ func TestSingleKeyAggregation(t *testing.T) { sig := signer.Sign(msg) - isValid, err := blstest.AggregateAndVerify(pks, []*bls.Signature{sig}, msg) + isValid, err := AggregateAndVerify(pks, []*bls.Signature{sig}, msg) require.NoError(err) require.True(isValid) } @@ -122,7 +134,7 @@ func TestIncorrectMessageAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, []byte("a different message")) + isValid, err := AggregateAndVerify(pks, signatures, []byte("a different message")) require.NoError(err) require.False(isValid) } @@ -144,7 +156,7 @@ func TestDifferentMessageAggregation(t *testing.T) { sk3.Sign(differentMsg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -166,7 +178,7 @@ func TestOneIncorrectPubKeyAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -186,7 +198,7 @@ func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { sk2.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -207,7 +219,7 @@ func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(pks, signatures, msg) + isValid, err := AggregateAndVerify(pks, signatures, msg) require.NoError(err) require.False(isValid) } @@ -226,7 +238,7 @@ func TestNoPubkeysAggregation(t *testing.T) { sk3.Sign(msg), } - isValid, err := blstest.AggregateAndVerify(nil, signatures, msg) + isValid, err := AggregateAndVerify(nil, signatures, msg) require.ErrorIs(err, bls.ErrNoPublicKeys) require.False(isValid) } @@ -241,7 +253,7 @@ func TestNoSignaturesAggregation(t *testing.T) { msg := []byte("TestNoSignaturesAggregation local signer") - isValid, err := blstest.AggregateAndVerify(pks, nil, msg) + isValid, err := AggregateAndVerify(pks, nil, msg) require.ErrorIs(err, bls.ErrNoSignatures) require.False(isValid) } From 89ce1bcb67127065ebcfb214c56138afef563638 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 27 Jan 2025 12:34:33 -0500 Subject: [PATCH 47/56] Remove jsonrpc signer implementation --- .../bls/signer/jsonrpc/benchmark_test.go | 31 -- utils/crypto/bls/signer/jsonrpc/bls_test.go | 350 ------------------ utils/crypto/bls/signer/jsonrpc/client.go | 96 ----- utils/crypto/bls/signer/jsonrpc/message.go | 26 -- utils/crypto/bls/signer/jsonrpc/server.go | 112 ------ 5 files changed, 615 deletions(-) delete mode 100644 utils/crypto/bls/signer/jsonrpc/benchmark_test.go delete mode 100644 utils/crypto/bls/signer/jsonrpc/bls_test.go delete mode 100644 utils/crypto/bls/signer/jsonrpc/client.go delete mode 100644 utils/crypto/bls/signer/jsonrpc/message.go delete mode 100644 utils/crypto/bls/signer/jsonrpc/server.go diff --git a/utils/crypto/bls/signer/jsonrpc/benchmark_test.go b/utils/crypto/bls/signer/jsonrpc/benchmark_test.go deleted file mode 100644 index 540a53809374..000000000000 --- a/utils/crypto/bls/signer/jsonrpc/benchmark_test.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package jsonrpcsigner - -import ( - "strconv" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls/blstest" -) - -func BenchmarkSign(b *testing.B) { - server, privateKey, _ := NewSigner(require.New(b)) - defer server.Close() - - for _, messageSize := range blstest.BenchmarkSizes { - b.Run(strconv.Itoa(messageSize), func(b *testing.B) { - message := utils.RandomBytes(messageSize) - - b.ResetTimer() - - for n := 0; n < b.N; n++ { - _ = privateKey.Sign(message) - } - }) - } -} diff --git a/utils/crypto/bls/signer/jsonrpc/bls_test.go b/utils/crypto/bls/signer/jsonrpc/bls_test.go deleted file mode 100644 index 4a52e44883da..000000000000 --- a/utils/crypto/bls/signer/jsonrpc/bls_test.go +++ /dev/null @@ -1,350 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package jsonrpcsigner - -import ( - "net/url" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" -) - -func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature, message []byte) (bool, error) { - aggSig, err := bls.AggregateSignatures(signatures) - if err != nil { - return false, err - } - aggPK, err := bls.AggregatePublicKeys(publicKeys) - if err != nil { - return false, err - } - - return bls.Verify(aggPK, aggSig, message), nil -} - -func NewLocalPair(require *require.Assertions) (*localsigner.LocalSigner, *bls.PublicKey) { - sk, err := localsigner.NewSigner() - require.NoError(err) - pk := sk.PublicKey() - return sk, pk -} - -func NewSigner(require *require.Assertions) (*Server, *Client, *bls.PublicKey) { - service, err := NewSignerService() - require.NoError(err) - server, err := Serve(service) - require.NoError(err) - - url := url.URL{ - Scheme: "http", - Host: server.Addr().String(), - } - - client := NewClient(url) - pk := client.PublicKey() - - return server, client, pk -} - -func TestVerifyValidSignature(t *testing.T) { - require := require.New(t) - server, signer, pk := NewSigner(require) - defer server.Close() - - msg := []byte("TestVerifyValidSignature json-rpc") - - sig := signer.Sign(msg) - - isValid := bls.Verify(pk, sig, msg) - require.True(isValid) -} - -func TestVerifyWrongMessageSignature(t *testing.T) { - require := require.New(t) - server, signer, pk := NewSigner(require) - defer server.Close() - - msg := []byte("TestVerifyWrongMessageSignature json-rpc") - wrongMsg := []byte("TestVerifyWrongMessageSignature json-rpc with wrong message") - - sig := signer.Sign(msg) - - isValid := bls.Verify(pk, sig, wrongMsg) - require.False(isValid) -} - -func TestVerifyWrongPubkeySignature(t *testing.T) { - require := require.New(t) - server, signer, _ := NewSigner(require) - defer server.Close() - _, wrongPk := NewLocalPair(require) - - msg := []byte("TestVerifyWrongPubkeySignature json-rpc") - - sig := signer.Sign(msg) - - isValid := bls.Verify(wrongPk, sig, msg) - require.False(isValid) -} - -func TestVerifyWrongMessageSignedSignature(t *testing.T) { - require := require.New(t) - server, signer, pk := NewSigner(require) - defer server.Close() - - msg := []byte("TestVerifyWrongMessageSignedSignature json-rpc") - wrongMsg := []byte("TestVerifyWrongMessageSignedSignaturelocal json-rpc with wrong signature") - - wrongSig := signer.Sign(wrongMsg) - - isValid := bls.Verify(pk, wrongSig, msg) - require.False(isValid) -} - -func TestValidAggregation(t *testing.T) { - require := require.New(t) - server, signer1, pk1 := NewSigner(require) - defer server.Close() - - signer2, pk2 := NewLocalPair(require) - signer3, pk3 := NewLocalPair(require) - - pks := []*bls.PublicKey{pk1, pk2, pk3} - - msg := []byte("TestValidAggregation json-rpc") - - sigs := []*bls.Signature{ - signer1.Sign(msg), - signer2.Sign(msg), - signer3.Sign(msg), - } - - isValid, err := AggregateAndVerify(pks, sigs, msg) - require.NoError(err) - require.True(isValid) -} - -func TestSingleKeyAggregation(t *testing.T) { - require := require.New(t) - server, signer, pk := NewSigner(require) - defer server.Close() - - pks := []*bls.PublicKey{pk} - - msg := []byte("TestSingleKeyAggregation json-rpc") - - sig := signer.Sign(msg) - - isValid, err := AggregateAndVerify(pks, []*bls.Signature{sig}, msg) - require.NoError(err) - require.True(isValid) -} - -func TestIncorrectMessageAggregation(t *testing.T) { - require := require.New(t) - server, sk1, pk1 := NewSigner(require) - defer server.Close() - - sk2, pk2 := NewLocalPair(require) - sk3, pk3 := NewLocalPair(require) - - pks := []*bls.PublicKey{pk1, pk2, pk3} - - msg := []byte("TestIncorrectMessageAggregation json-rpc") - - signatures := []*bls.Signature{ - sk1.Sign(msg), - sk2.Sign(msg), - sk3.Sign(msg), - } - - isValid, err := AggregateAndVerify(pks, signatures, []byte("a different message")) - require.NoError(err) - require.False(isValid) -} - -func TestOneDifferentMessageAggregation(t *testing.T) { - require := require.New(t) - server, sk1, pk1 := NewSigner(require) - defer server.Close() - - sk2, pk2 := NewLocalPair(require) - sk3, pk3 := NewLocalPair(require) - - pks := []*bls.PublicKey{pk1, pk2, pk3} - - msg := []byte("TestDifferentMessagesAggregation json-rpc") - differentMsg := []byte("TestDifferentMessagesAggregation json-rpc with different message") - - signatures := []*bls.Signature{ - sk1.Sign(msg), - sk2.Sign(msg), - sk3.Sign(differentMsg), - } - - isValid, err := AggregateAndVerify(pks, signatures, msg) - require.NoError(err) - require.False(isValid) -} - -func TestOneIncorrectPubKeyAggregation(t *testing.T) { - require := require.New(t) - server, sk1, pk1 := NewSigner(require) - defer server.Close() - - sk2, pk2 := NewLocalPair(require) - sk3, _ := NewLocalPair(require) - _, wrongPk := NewLocalPair(require) - - pks := []*bls.PublicKey{pk1, pk2, wrongPk} - - msg := []byte("TestOneIncorrectPubKeyAggregation json-rpc") - - signatures := []*bls.Signature{ - sk1.Sign(msg), - sk2.Sign(msg), - sk3.Sign(msg), - } - - isValid, err := AggregateAndVerify(pks, signatures, msg) - require.NoError(err) - require.False(isValid) -} - -func TestMorePubkeysThanSignaturesAggregation(t *testing.T) { - require := require.New(t) - server, sk1, pk1 := NewSigner(require) - defer server.Close() - sk2, pk2 := NewLocalPair(require) - _, pk3 := NewLocalPair(require) - - pks := []*bls.PublicKey{pk1, pk2, pk3} - - msg := []byte("TestMorePubkeysThanSignatures json-rpc") - - signatures := []*bls.Signature{ - sk1.Sign(msg), - sk2.Sign(msg), - } - - isValid, err := AggregateAndVerify(pks, signatures, msg) - require.NoError(err) - require.False(isValid) -} - -func TestMoreSignaturesThanPubkeysAggregation(t *testing.T) { - require := require.New(t) - server, sk1, pk1 := NewSigner(require) - defer server.Close() - sk2, pk2 := NewLocalPair(require) - sk3, _ := NewLocalPair(require) - - pks := []*bls.PublicKey{pk1, pk2} - - msg := []byte("TestMoreSignaturesThanPubkeys json-rpc") - - signatures := []*bls.Signature{ - sk1.Sign(msg), - sk2.Sign(msg), - sk3.Sign(msg), - } - - isValid, err := AggregateAndVerify(pks, signatures, msg) - require.NoError(err) - require.False(isValid) -} - -func TestNoPubkeysAggregation(t *testing.T) { - require := require.New(t) - server, sk1, _ := NewSigner(require) - defer server.Close() - sk2, _ := NewLocalPair(require) - sk3, _ := NewLocalPair(require) - - msg := []byte("TestNoPubkeysAggregation json-rpc") - - signatures := []*bls.Signature{ - sk1.Sign(msg), - sk2.Sign(msg), - sk3.Sign(msg), - } - - isValid, err := AggregateAndVerify(nil, signatures, msg) - require.ErrorIs(err, bls.ErrNoPublicKeys) - require.False(isValid) -} - -func TestNoSignaturesAggregation(t *testing.T) { - require := require.New(t) - server, _, pk1 := NewSigner(require) - defer server.Close() - _, pk2 := NewLocalPair(require) - _, pk3 := NewLocalPair(require) - - pks := []*bls.PublicKey{pk1, pk2, pk3} - - msg := []byte("TestNoSignaturesAggregation json-rpc") - - isValid, err := AggregateAndVerify(pks, nil, msg) - require.ErrorIs(err, bls.ErrNoSignatures) - require.False(isValid) -} - -func TestVerifyValidProofOfPossession(t *testing.T) { - require := require.New(t) - server, signer, pk := NewSigner(require) - defer server.Close() - - msg := []byte("TestVerifyValidProofOfPossession json-rpc") - - sig := signer.SignProofOfPossession(msg) - - isValid := bls.VerifyProofOfPossession(pk, sig, msg) - require.True(isValid) -} - -func TestVerifyWrongMessageProofOfPossession(t *testing.T) { - require := require.New(t) - server, signer, pk := NewSigner(require) - defer server.Close() - - msg := []byte("TestVerifyWrongMessageProofOfPossession json-rpc") - wrongMsg := []byte("TestVerifyWrongMessageProofOfPossession json-rpc with wrong message") - - sig := signer.SignProofOfPossession(msg) - - isValid := bls.VerifyProofOfPossession(pk, sig, wrongMsg) - require.False(isValid) -} - -func TestVerifyWrongPubkeyProofOfPossession(t *testing.T) { - require := require.New(t) - server, signer, _ := NewSigner(require) - defer server.Close() - _, wrongPk := NewLocalPair(require) - - msg := []byte("TestVerifyWrongPubkeyProofOfPossession json-rpc") - - sig := signer.SignProofOfPossession(msg) - - isValid := bls.VerifyProofOfPossession(wrongPk, sig, msg) - require.False(isValid) -} - -func TestVerifyWrongMessageSignedProofOfPossession(t *testing.T) { - require := require.New(t) - server, signer, pk := NewSigner(require) - defer server.Close() - - msg := []byte("TestVerifyWrongMessageSignedProofOfPossession json-rpc") - wrongMsg := []byte("TestVerifyWrongMessageSignedProofOfPossession json-rpc with wrong signature") - - wrongSig := signer.SignProofOfPossession(wrongMsg) - - isValid := bls.VerifyProofOfPossession(pk, wrongSig, msg) - require.False(isValid) -} diff --git a/utils/crypto/bls/signer/jsonrpc/client.go b/utils/crypto/bls/signer/jsonrpc/client.go deleted file mode 100644 index 0f3943b86e9d..000000000000 --- a/utils/crypto/bls/signer/jsonrpc/client.go +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package jsonrpcsigner - -import ( - "bytes" - "context" - "net/http" - "net/url" - "time" - - "github.com/gorilla/rpc/v2/json2" - - "github.com/ava-labs/avalanchego/utils/crypto/bls" -) - -var _ bls.Signer = (*Client)(nil) - -type Client struct { - http *http.Client - url url.URL -} - -func NewClient(url url.URL) *Client { - return &Client{ - http: &http.Client{}, - url: url, - } -} - -func (c *Client) call(method string, params []any, result any) error { - requestBody, err := json2.EncodeClientRequest(method, params) - if err != nil { - return err - } - - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - - req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.url.String(), bytes.NewBuffer(requestBody)) - if err != nil { - return err - } - req.Header.Set("Content-Type", "application/json") - - resp, err := c.http.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - return json2.DecodeClientResponse(resp.Body, result) -} - -func (c *Client) PublicKey() *bls.PublicKey { - reply := new(PublicKeyReply) - - err := c.call("Signer.PublicKey", []any{PublicKeyArgs{}}, reply) - if err != nil { - panic(err) - } - - pk := new(bls.PublicKey) - pk = pk.Deserialize(reply.PublicKey) - - return pk -} - -func (c *Client) Sign(msg []byte) *bls.Signature { - reply := new(SignReply) - err := c.call("Signer.Sign", []any{SignArgs{msg}}, reply) - // TODO: handle this - if err != nil { - panic(err) - } - - sig := new(bls.Signature) - sig = sig.Deserialize(reply.Signature) - - return sig -} - -func (c *Client) SignProofOfPossession(msg []byte) *bls.Signature { - reply := new(SignReply) - err := c.call("Signer.SignProofOfPossession", []any{SignArgs{msg}}, reply) - // TODO: handle this - if err != nil { - panic(err) - } - - sig := new(bls.Signature) - sig = sig.Deserialize(reply.Signature) - - return sig -} diff --git a/utils/crypto/bls/signer/jsonrpc/message.go b/utils/crypto/bls/signer/jsonrpc/message.go deleted file mode 100644 index b33f7374d6bb..000000000000 --- a/utils/crypto/bls/signer/jsonrpc/message.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package jsonrpcsigner - -type PublicKeyArgs struct{} - -type SignArgs struct { - Msg []byte -} - -type SignProofOfPossessionArgs struct { - Msg []byte -} - -type PublicKeyReply struct { - PublicKey []byte -} - -type SignReply struct { - Signature []byte -} - -type SignProofOfPossessionReply struct { - Signature []byte -} diff --git a/utils/crypto/bls/signer/jsonrpc/server.go b/utils/crypto/bls/signer/jsonrpc/server.go deleted file mode 100644 index 03c60d95cd4a..000000000000 --- a/utils/crypto/bls/signer/jsonrpc/server.go +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package jsonrpcsigner - -import ( - "context" - "log" - "net" - "net/http" - "time" - - "github.com/gorilla/rpc/v2" - "github.com/gorilla/rpc/v2/json" - - "github.com/ava-labs/avalanchego/utils/crypto/bls" - "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" -) - -type SignerService struct { - signer *localsigner.LocalSigner -} - -type Server struct { - httpServer *http.Server - listener net.Listener -} - -func NewSignerService() (*SignerService, error) { - signer, err := localsigner.NewSigner() - if err != nil { - return nil, err - } - - return &SignerService{signer: signer}, nil -} - -func Serve(service *SignerService) (*Server, error) { - server := rpc.NewServer() - server.RegisterCodec(json.NewCodec(), "application/json") - - err := server.RegisterService(service, "Signer") - if err != nil { - return nil, err - } - - httpServer := &http.Server{ - Handler: server, - ReadHeaderTimeout: 1 * time.Second, - } - - listener, err := net.Listen("tcp", "") - if err != nil { - return nil, err - } - - go func() { - if err := httpServer.Serve(listener); err != nil && err != http.ErrServerClosed { - log.Fatal(err) - } - }() - - return &Server{ - httpServer: httpServer, - listener: listener, - }, nil -} - -func (s *Server) Addr() net.Addr { - return s.listener.Addr() -} - -func (s *Server) Close() error { - // Create a context with a timeout to allow for graceful shutdown - ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) - defer cancel() - - // Shutdown the HTTP server - if err := s.httpServer.Shutdown(ctx); err != nil { - return err - } - - // Close the listener - return s.listener.Close() -} - -func (s *SignerService) PublicKey(_ *http.Request, _ *PublicKeyArgs, reply *PublicKeyReply) error { - *reply = toPkReply(s.signer.PublicKey()) - return nil -} - -func (s *SignerService) Sign(_ *http.Request, args *struct{ Msg []byte }, reply *SignReply) error { - *reply = toSignReply(s.signer.Sign(args.Msg)) - return nil -} - -func (s *SignerService) SignProofOfPossession(_ *http.Request, args *struct{ Msg []byte }, reply *SignProofOfPossessionReply) error { - *reply = toSignProofOfPossessionReply(s.signer.SignProofOfPossession(args.Msg)) - return nil -} - -func toPkReply(pk *bls.PublicKey) PublicKeyReply { - return PublicKeyReply{PublicKey: pk.Serialize()} -} - -func toSignReply(sig *bls.Signature) SignReply { - return SignReply{Signature: sig.Serialize()} -} - -func toSignProofOfPossessionReply(sig *bls.Signature) SignProofOfPossessionReply { - return SignProofOfPossessionReply{Signature: sig.Serialize()} -} From 0658a9f93cacbab9cc6f03a8a9ae4753e227d6d6 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Mon, 27 Jan 2025 13:17:55 -0500 Subject: [PATCH 48/56] Add lint fix from merging master changes --- vms/platformvm/service_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 3a1b691cf4b7..1d7c584403af 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -29,6 +29,7 @@ import ( "github.com/ava-labs/avalanchego/snow/validators" "github.com/ava-labs/avalanchego/upgrade/upgradetest" "github.com/ava-labs/avalanchego/utils/constants" + "github.com/ava-labs/avalanchego/utils/crypto/bls" "github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner" "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" "github.com/ava-labs/avalanchego/utils/formatting" @@ -1330,12 +1331,12 @@ func FuzzGetFeeState(f *testing.F) { func TestGetCurrentValidatorsForL1(t *testing.T) { subnetID := ids.GenerateTestID() - sk, err := bls.NewSigner() + sk, err := localsigner.NewSigner() require.NoError(t, err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) - otherSK, err := bls.NewSigner() + otherSK, err := localsigner.NewSigner() require.NoError(t, err) otherPK := otherSK.PublicKey() otherPKBytes := bls.PublicKeyToUncompressedBytes(otherPK) From d27a6d580612dd287d2d40c70a2c890eff667178 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 12:55:39 -0500 Subject: [PATCH 49/56] Define bls-ciphersuite constants with iota --- utils/crypto/bls/ciphersuite.go | 29 +++++++++++++++---- utils/crypto/bls/public.go | 4 +-- .../bls/signer/localsigner/localsigner.go | 4 +-- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/utils/crypto/bls/ciphersuite.go b/utils/crypto/bls/ciphersuite.go index 7eb0e27eb263..466d959c194a 100644 --- a/utils/crypto/bls/ciphersuite.go +++ b/utils/crypto/bls/ciphersuite.go @@ -3,10 +3,27 @@ package bls -var ( - // The ciphersuite is more commonly known as G2ProofOfPossession. - // There are two digests to ensure that message space for normal - // signatures and the proof of possession are distinct. - CiphersuiteSignature = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") - CiphersuiteProofOfPossession = []byte("BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_") +type Ciphersuite int + +const ( + CiphersuiteSignature Ciphersuite = iota + CiphersuiteProofOfPossession ) + +var ciphersuiteStrings = [...]string{ + "BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_", + "BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_", +} + +var ciphersuiteBytes = [...][]byte{ + []byte(ciphersuiteStrings[0]), + []byte(ciphersuiteStrings[1]), +} + +func (c Ciphersuite) String() string { + return ciphersuiteStrings[c] +} + +func (c Ciphersuite) Bytes() []byte { + return ciphersuiteBytes[c] +} diff --git a/utils/crypto/bls/public.go b/utils/crypto/bls/public.go index 0d3dbaf9559b..5ac5bd214730 100644 --- a/utils/crypto/bls/public.go +++ b/utils/crypto/bls/public.go @@ -77,7 +77,7 @@ func AggregatePublicKeys(pks []*PublicKey) (*PublicKey, error) { // The [sig] and [pk] may have been an aggregation of other signatures and keys. // Invariant: [pk] and [sig] have both been validated. func Verify(pk *PublicKey, sig *Signature, msg []byte) bool { - return sig.Verify(false, pk, false, msg, CiphersuiteSignature) + return sig.Verify(false, pk, false, msg, CiphersuiteSignature.Bytes()) } // Verify the possession of the secret pre-image of [sk] by verifying a [sig] of @@ -85,5 +85,5 @@ func Verify(pk *PublicKey, sig *Signature, msg []byte) bool { // The [sig] and [pk] may have been an aggregation of other signatures and keys. // Invariant: [pk] and [sig] have both been validated. func VerifyProofOfPossession(pk *PublicKey, sig *Signature, msg []byte) bool { - return sig.Verify(false, pk, false, msg, CiphersuiteProofOfPossession) + return sig.Verify(false, pk, false, msg, CiphersuiteProofOfPossession.Bytes()) } diff --git a/utils/crypto/bls/signer/localsigner/localsigner.go b/utils/crypto/bls/signer/localsigner/localsigner.go index 2b77c9768976..ac6ac987a897 100644 --- a/utils/crypto/bls/signer/localsigner/localsigner.go +++ b/utils/crypto/bls/signer/localsigner/localsigner.go @@ -64,10 +64,10 @@ func (s *LocalSigner) PublicKey() *bls.PublicKey { // Sign [msg] to authorize this message func (s *LocalSigner) Sign(msg []byte) *bls.Signature { - return new(bls.Signature).Sign(s.sk, msg, bls.CiphersuiteSignature) + return new(bls.Signature).Sign(s.sk, msg, bls.CiphersuiteSignature.Bytes()) } // Sign [msg] to prove the ownership func (s *LocalSigner) SignProofOfPossession(msg []byte) *bls.Signature { - return new(bls.Signature).Sign(s.sk, msg, bls.CiphersuiteProofOfPossession) + return new(bls.Signature).Sign(s.sk, msg, bls.CiphersuiteProofOfPossession.Bytes()) } From 139f59f16743ae3778e569b9c577c13aa4530378 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 13:07:02 -0500 Subject: [PATCH 50/56] Move secret-key length to local implementation --- utils/crypto/bls/public.go | 1 - utils/crypto/bls/signer/localsigner/serialization_test.go | 8 +++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/crypto/bls/public.go b/utils/crypto/bls/public.go index 5ac5bd214730..0ba5ea800f70 100644 --- a/utils/crypto/bls/public.go +++ b/utils/crypto/bls/public.go @@ -10,7 +10,6 @@ import ( ) const ( - SecretKeyLen = blst.BLST_SCALAR_BYTES PublicKeyLen = blst.BLST_P1_COMPRESS_BYTES ) diff --git a/utils/crypto/bls/signer/localsigner/serialization_test.go b/utils/crypto/bls/signer/localsigner/serialization_test.go index 74b8497a4017..e0636272dff1 100644 --- a/utils/crypto/bls/signer/localsigner/serialization_test.go +++ b/utils/crypto/bls/signer/localsigner/serialization_test.go @@ -7,15 +7,17 @@ import ( "testing" "github.com/stretchr/testify/require" + blst "github.com/supranational/blst/bindings/go" "github.com/ava-labs/avalanchego/utils" - "github.com/ava-labs/avalanchego/utils/crypto/bls" ) +const SecretKeyLen = blst.BLST_SCALAR_BYTES + func TestSecretKeyFromBytesZero(t *testing.T) { require := require.New(t) - var skArr [bls.SecretKeyLen]byte + var skArr [SecretKeyLen]byte skBytes := skArr[:] _, err := SecretKeyFromBytes(skBytes) require.ErrorIs(err, ErrFailedSecretKeyDeserialize) @@ -24,7 +26,7 @@ func TestSecretKeyFromBytesZero(t *testing.T) { func TestSecretKeyFromBytesWrongSize(t *testing.T) { require := require.New(t) - skBytes := utils.RandomBytes(bls.SecretKeyLen + 1) + skBytes := utils.RandomBytes(SecretKeyLen + 1) _, err := SecretKeyFromBytes(skBytes) require.ErrorIs(err, ErrFailedSecretKeyDeserialize) } From 62b26c5e8b514773589148548279ff050e4520ea Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 13:13:53 -0500 Subject: [PATCH 51/56] Remove stutter from localsigner constructor --- config/config.go | 4 ++-- network/network_test.go | 2 +- network/p2p/acp118/handler_test.go | 2 +- network/peer/ip_signer_test.go | 2 +- network/peer/ip_test.go | 2 +- network/peer/peer_test.go | 6 +++--- network/peer/test_peer.go | 2 +- network/test_network.go | 2 +- snow/snowtest/context.go | 2 +- .../validators/gvalidators/validator_state_test.go | 8 ++++---- snow/validators/manager_test.go | 14 +++++++------- snow/validators/set_test.go | 8 ++++---- tests/e2e/p/workflow.go | 2 +- tests/fixture/tmpnet/node.go | 2 +- utils/crypto/bls/signer/localsigner/bls_test.go | 2 +- utils/crypto/bls/signer/localsigner/localsigner.go | 2 +- .../bls/signer/localsigner/serialization_test.go | 2 +- vms/platformvm/block/builder/builder_test.go | 6 +++--- .../block/executor/proposal_block_test.go | 4 ++-- vms/platformvm/block/executor/verifier_test.go | 2 +- vms/platformvm/network/warp_test.go | 4 ++-- vms/platformvm/service_test.go | 10 +++++----- vms/platformvm/signer/proof_of_possession_test.go | 4 ++-- vms/platformvm/state/staker_test.go | 2 +- vms/platformvm/state/state_test.go | 14 +++++++------- .../txs/add_permissionless_validator_tx_test.go | 2 +- vms/platformvm/txs/convert_subnet_to_l1_tx_test.go | 2 +- .../txs/executor/standard_tx_executor_test.go | 14 +++++++------- vms/platformvm/txs/executor/state_changes_test.go | 2 +- vms/platformvm/txs/executor/warp_verifier_test.go | 2 +- vms/platformvm/validator_set_property_test.go | 6 +++--- .../validators/manager_benchmark_test.go | 2 +- vms/platformvm/validators/manager_test.go | 2 +- vms/platformvm/vm_regression_test.go | 8 ++++---- vms/platformvm/vm_test.go | 8 ++++---- vms/platformvm/warp/gwarp/signer_test.go | 2 +- .../warp/message/register_l1_validator_test.go | 2 +- vms/platformvm/warp/signature_test.go | 2 +- vms/platformvm/warp/signer_test.go | 2 +- vms/platformvm/warp/validator_test.go | 6 +++--- wallet/chain/p/builder_test.go | 10 +++++----- 41 files changed, 91 insertions(+), 91 deletions(-) diff --git a/config/config.go b/config/config.go index 91dfc4b608b3..be15e8a6f8fd 100644 --- a/config/config.go +++ b/config/config.go @@ -641,7 +641,7 @@ func getStakingTLSCert(v *viper.Viper) (tls.Certificate, error) { func getStakingSigner(v *viper.Viper) (bls.Signer, error) { if v.GetBool(StakingEphemeralSignerEnabledKey) { - key, err := localsigner.NewSigner() + key, err := localsigner.New() if err != nil { return nil, fmt.Errorf("couldn't generate ephemeral signing key: %w", err) } @@ -679,7 +679,7 @@ func getStakingSigner(v *viper.Viper) (bls.Signer, error) { return nil, errMissingStakingSigningKeyFile } - key, err := localsigner.NewSigner() + key, err := localsigner.New() if err != nil { return nil, fmt.Errorf("couldn't generate new signing key: %w", err) } diff --git a/network/network_test.go b/network/network_test.go index 0fb495369e27..771b351270b6 100644 --- a/network/network_test.go +++ b/network/network_test.go @@ -175,7 +175,7 @@ func newTestNetwork(t *testing.T, count int) (*testDialer, []*testListener, []id require.NoError(t, err) nodeID := ids.NodeIDFromCert(cert) - blsKey, err := localsigner.NewSigner() + blsKey, err := localsigner.New() require.NoError(t, err) config := defaultConfig diff --git a/network/p2p/acp118/handler_test.go b/network/p2p/acp118/handler_test.go index 3065490d589e..aed5b6df78b7 100644 --- a/network/p2p/acp118/handler_test.go +++ b/network/p2p/acp118/handler_test.go @@ -73,7 +73,7 @@ func TestHandler(t *testing.T) { require := require.New(t) ctx := context.Background() - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pk := sk.PublicKey() networkID := uint32(123) diff --git a/network/peer/ip_signer_test.go b/network/peer/ip_signer_test.go index b45ae5f10404..5d0a3b172022 100644 --- a/network/peer/ip_signer_test.go +++ b/network/peer/ip_signer_test.go @@ -28,7 +28,7 @@ func TestIPSigner(t *testing.T) { require.NoError(err) tlsKey := tlsCert.PrivateKey.(crypto.Signer) - blsKey, err := localsigner.NewSigner() + blsKey, err := localsigner.New() require.NoError(err) s := NewIPSigner(dynIP, tlsKey, blsKey) diff --git a/network/peer/ip_test.go b/network/peer/ip_test.go index 3711afa0d832..ccaa2804d67c 100644 --- a/network/peer/ip_test.go +++ b/network/peer/ip_test.go @@ -22,7 +22,7 @@ func TestSignedIpVerify(t *testing.T) { cert1, err := staking.ParseCertificate(tlsCert1.Leaf.Raw) require.NoError(t, err) tlsKey1 := tlsCert1.PrivateKey.(crypto.Signer) - blsKey1, err := localsigner.NewSigner() + blsKey1, err := localsigner.New() require.NoError(t, err) tlsCert2, err := staking.NewTLSCert() diff --git a/network/peer/peer_test.go b/network/peer/peer_test.go index b5f02c1fe1ca..b039b870f35f 100644 --- a/network/peer/peer_test.go +++ b/network/peer/peer_test.go @@ -111,7 +111,7 @@ func newRawTestPeer(t *testing.T, config Config) *rawTestPeer { 1, )) tls := tlsCert.PrivateKey.(crypto.Signer) - bls, err := localsigner.NewSigner() + bls, err := localsigner.New() require.NoError(err) config.IPSigner = NewIPSigner(ip, tls, bls) @@ -327,7 +327,7 @@ func TestInvalidBLSKeyDisconnects(t *testing.T) { 1, )) - bogusBLSKey, err := localsigner.NewSigner() + bogusBLSKey, err := localsigner.New() require.NoError(err) require.NoError(rawPeer1.config.Validators.AddStaker( constants.PrimaryNetworkID, @@ -348,7 +348,7 @@ func TestInvalidBLSKeyDisconnects(t *testing.T) { func TestShouldDisconnect(t *testing.T) { peerID := ids.GenerateTestNodeID() txID := ids.GenerateTestID() - blsKey, err := localsigner.NewSigner() + blsKey, err := localsigner.New() require.NoError(t, err) tests := []struct { diff --git a/network/peer/test_peer.go b/network/peer/test_peer.go index ce775a452e92..20396ad942aa 100644 --- a/network/peer/test_peer.go +++ b/network/peer/test_peer.go @@ -101,7 +101,7 @@ func StartTestPeer( } tlsKey := tlsCert.PrivateKey.(crypto.Signer) - blsKey, err := localsigner.NewSigner() + blsKey, err := localsigner.New() if err != nil { return nil, err } diff --git a/network/test_network.go b/network/test_network.go index 4fd3ae712fcf..e8ae032cd5a9 100644 --- a/network/test_network.go +++ b/network/test_network.go @@ -84,7 +84,7 @@ func NewTestNetworkConfig( return nil, err } - blsKey, err := localsigner.NewSigner() + blsKey, err := localsigner.New() if err != nil { return nil, err } diff --git a/snow/snowtest/context.go b/snow/snowtest/context.go index 8ec187e75126..68a04491db36 100644 --- a/snow/snowtest/context.go +++ b/snow/snowtest/context.go @@ -52,7 +52,7 @@ func ConsensusContext(ctx *snow.Context) *snow.ConsensusContext { func Context(tb testing.TB, chainID ids.ID) *snow.Context { require := require.New(tb) - secretKey, err := localsigner.NewSigner() + secretKey, err := localsigner.New() require.NoError(err) publicKey := secretKey.PublicKey() diff --git a/snow/validators/gvalidators/validator_state_test.go b/snow/validators/gvalidators/validator_state_test.go index 5fc1384d0163..ee55ef8568e0 100644 --- a/snow/validators/gvalidators/validator_state_test.go +++ b/snow/validators/gvalidators/validator_state_test.go @@ -136,7 +136,7 @@ func TestGetValidatorSet(t *testing.T) { state := setupState(t, ctrl) // Happy path - sk0, err := localsigner.NewSigner() + sk0, err := localsigner.New() require.NoError(err) vdr0 := &validators.GetValidatorOutput{ NodeID: ids.GenerateTestNodeID(), @@ -144,7 +144,7 @@ func TestGetValidatorSet(t *testing.T) { Weight: 1, } - sk1, err := localsigner.NewSigner() + sk1, err := localsigner.New() require.NoError(err) vdr1 := &validators.GetValidatorOutput{ NodeID: ids.GenerateTestNodeID(), @@ -182,7 +182,7 @@ func TestGetValidatorSet(t *testing.T) { func TestPublicKeyDeserialize(t *testing.T) { require := require.New(t) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pk := sk.PublicKey() @@ -223,7 +223,7 @@ func setupValidatorSet(b *testing.B, size int) map[ids.NodeID]*validators.GetVal b.Helper() set := make(map[ids.NodeID]*validators.GetValidatorOutput, size) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(b, err) pk := sk.PublicKey() for i := 0; i < size; i++ { diff --git a/snow/validators/manager_test.go b/snow/validators/manager_test.go index 4208dc9bbc45..36ef4b4fff16 100644 --- a/snow/validators/manager_test.go +++ b/snow/validators/manager_test.go @@ -215,7 +215,7 @@ func TestGet(t *testing.T) { _, ok := m.GetValidator(subnetID, nodeID) require.False(ok) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pk := sk.PublicKey() @@ -305,7 +305,7 @@ func TestGetMap(t *testing.T) { mp := m.GetMap(subnetID) require.Empty(mp) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pk := sk.PublicKey() @@ -405,7 +405,7 @@ func TestSample(t *testing.T) { require.NoError(err) require.Empty(sampled) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) nodeID0 := ids.GenerateTestNodeID() @@ -465,7 +465,7 @@ func TestString(t *testing.T) { func TestAddCallback(t *testing.T) { require := require.New(t) - expectedSK, err := localsigner.NewSigner() + expectedSK, err := localsigner.New() require.NoError(err) var ( @@ -513,7 +513,7 @@ func TestAddCallback(t *testing.T) { func TestAddWeightCallback(t *testing.T) { require := require.New(t) - expectedSK, err := localsigner.NewSigner() + expectedSK, err := localsigner.New() require.NoError(err) var ( @@ -596,7 +596,7 @@ func TestAddWeightCallback(t *testing.T) { func TestRemoveWeightCallback(t *testing.T) { require := require.New(t) - expectedSK, err := localsigner.NewSigner() + expectedSK, err := localsigner.New() require.NoError(err) var ( @@ -679,7 +679,7 @@ func TestRemoveWeightCallback(t *testing.T) { func TestRemoveCallback(t *testing.T) { require := require.New(t) - expectedSK, err := localsigner.NewSigner() + expectedSK, err := localsigner.New() require.NoError(err) var ( diff --git a/snow/validators/set_test.go b/snow/validators/set_test.go index dc2efcde720f..4ede0239dabc 100644 --- a/snow/validators/set_test.go +++ b/snow/validators/set_test.go @@ -166,7 +166,7 @@ func TestSetGet(t *testing.T) { _, ok := s.Get(nodeID) require.False(ok) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pk := sk.PublicKey() @@ -233,7 +233,7 @@ func TestSetMap(t *testing.T) { m := s.Map() require.Empty(m) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pk := sk.PublicKey() @@ -331,7 +331,7 @@ func TestSetSample(t *testing.T) { require.NoError(err) require.Empty(sampled) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) nodeID0 := ids.GenerateTestNodeID() @@ -386,7 +386,7 @@ func TestSetAddCallback(t *testing.T) { require := require.New(t) nodeID0 := ids.BuildTestNodeID([]byte{1}) - sk0, err := localsigner.NewSigner() + sk0, err := localsigner.New() require.NoError(err) pk0 := sk0.PublicKey() txID0 := ids.GenerateTestID() diff --git a/tests/e2e/p/workflow.go b/tests/e2e/p/workflow.go index 0ca615ea9fb1..d6f01e6ddda2 100644 --- a/tests/e2e/p/workflow.go +++ b/tests/e2e/p/workflow.go @@ -115,7 +115,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() { } tc.By("issuing an AddPermissionlessValidatorTx", func() { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pop := signer.NewProofOfPossession(sk) diff --git a/tests/fixture/tmpnet/node.go b/tests/fixture/tmpnet/node.go index 93e7826c50ba..bfc6acad7610 100644 --- a/tests/fixture/tmpnet/node.go +++ b/tests/fixture/tmpnet/node.go @@ -266,7 +266,7 @@ func (n *Node) EnsureBLSSigningKey() error { } // Generate a new signing key - newKey, err := localsigner.NewSigner() + newKey, err := localsigner.New() if err != nil { return fmt.Errorf("failed to generate staking signer key: %w", err) } diff --git a/utils/crypto/bls/signer/localsigner/bls_test.go b/utils/crypto/bls/signer/localsigner/bls_test.go index 978fea332a51..3969529dde38 100644 --- a/utils/crypto/bls/signer/localsigner/bls_test.go +++ b/utils/crypto/bls/signer/localsigner/bls_test.go @@ -25,7 +25,7 @@ func AggregateAndVerify(publicKeys []*bls.PublicKey, signatures []*bls.Signature } func NewKeyPair(require *require.Assertions) (*LocalSigner, *bls.PublicKey) { - sk, err := NewSigner() + sk, err := New() require.NoError(err) pk := sk.PublicKey() return sk, pk diff --git a/utils/crypto/bls/signer/localsigner/localsigner.go b/utils/crypto/bls/signer/localsigner/localsigner.go index ac6ac987a897..5959e1b7d097 100644 --- a/utils/crypto/bls/signer/localsigner/localsigner.go +++ b/utils/crypto/bls/signer/localsigner/localsigner.go @@ -26,7 +26,7 @@ type LocalSigner struct { // NewSecretKey generates a new secret key from the local source of // cryptographically secure randomness. -func NewSigner() (*LocalSigner, error) { +func New() (*LocalSigner, error) { var ikm [32]byte _, err := rand.Read(ikm[:]) if err != nil { diff --git a/utils/crypto/bls/signer/localsigner/serialization_test.go b/utils/crypto/bls/signer/localsigner/serialization_test.go index e0636272dff1..eb9ca0ad6a9c 100644 --- a/utils/crypto/bls/signer/localsigner/serialization_test.go +++ b/utils/crypto/bls/signer/localsigner/serialization_test.go @@ -36,7 +36,7 @@ func TestSecretKeyBytes(t *testing.T) { msg := utils.RandomBytes(1234) - sk, err := NewSigner() + sk, err := New() require.NoError(err) sig := sk.Sign(msg) skBytes := sk.ToBytes() diff --git a/vms/platformvm/block/builder/builder_test.go b/vms/platformvm/block/builder/builder_test.go index 9c2156faee0f..d61de89dcece 100644 --- a/vms/platformvm/block/builder/builder_test.go +++ b/vms/platformvm/block/builder/builder_test.go @@ -112,7 +112,7 @@ func TestBuildBlockShouldReward(t *testing.T) { validatorEndTime = validatorStartTime.Add(360 * 24 * time.Hour) ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) rewardOwners := &secp256k1fx.OutputOwners{ @@ -320,7 +320,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { validatorEndTime = now.Add(env.config.MaxStakeDuration) ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -353,7 +353,7 @@ func TestBuildBlockInvalidStakingDurations(t *testing.T) { // Add a validator ending past [MaxStakeDuration] validator2EndTime := now.Add(env.config.MaxStakeDuration + time.Second) - sk, err = localsigner.NewSigner() + sk, err = localsigner.New() require.NoError(err) tx2, err := wallet.IssueAddPermissionlessValidatorTx( diff --git a/vms/platformvm/block/executor/proposal_block_test.go b/vms/platformvm/block/executor/proposal_block_test.go index 38045e79fd17..17720c4511a7 100644 --- a/vms/platformvm/block/executor/proposal_block_test.go +++ b/vms/platformvm/block/executor/proposal_block_test.go @@ -1329,7 +1329,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { nodeID = ids.GenerateTestNodeID() ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -1414,7 +1414,7 @@ func TestAddValidatorProposalBlock(t *testing.T) { validatorEndTime = validatorStartTime.Add(env.config.MinStakeDuration) nodeID = ids.GenerateTestNodeID() - sk, err = localsigner.NewSigner() + sk, err = localsigner.New() require.NoError(err) addValidatorTx2, err := wallet.IssueAddPermissionlessValidatorTx( diff --git a/vms/platformvm/block/executor/verifier_test.go b/vms/platformvm/block/executor/verifier_test.go index 37c5c48376d4..b278a5845a49 100644 --- a/vms/platformvm/block/executor/verifier_test.go +++ b/vms/platformvm/block/executor/verifier_test.go @@ -1217,7 +1217,7 @@ func TestBlockExecutionWithComplexity(t *testing.T) { } func TestDeactivateLowBalanceL1Validators(t *testing.T) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) var ( diff --git a/vms/platformvm/network/warp_test.go b/vms/platformvm/network/warp_test.go index d8b20925f26c..8e3413f1d6c8 100644 --- a/vms/platformvm/network/warp_test.go +++ b/vms/platformvm/network/warp_test.go @@ -178,7 +178,7 @@ func TestSignatureRequestVerifySubnetToL1Conversion(t *testing.T) { } func TestSignatureRequestVerifyL1ValidatorRegistrationRegistered(t *testing.T) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) var ( @@ -545,7 +545,7 @@ func TestSignatureRequestVerifyL1ValidatorRegistrationNotRegistered(t *testing.T } func TestSignatureRequestVerifyL1ValidatorWeight(t *testing.T) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) const ( diff --git a/vms/platformvm/service_test.go b/vms/platformvm/service_test.go index 1d7c584403af..51b6efcdb907 100644 --- a/vms/platformvm/service_test.go +++ b/vms/platformvm/service_test.go @@ -264,7 +264,7 @@ func TestGetTx(t *testing.T) { func(t testing.TB, s *Service) *txs.Tx { wallet := newWallet(t, s.vm, walletConfig{}) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -800,7 +800,7 @@ func TestGetValidatorsAt(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) tx, err := wallet.IssueAddPermissionlessValidatorTx( @@ -1023,7 +1023,7 @@ func TestGetValidatorsAtReplyMarshalling(t *testing.T) { } { nodeID := ids.GenerateTestNodeID() - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) reply.Validators[nodeID] = &validators.GetValidatorOutput{ NodeID: nodeID, @@ -1331,12 +1331,12 @@ func FuzzGetFeeState(f *testing.F) { func TestGetCurrentValidatorsForL1(t *testing.T) { subnetID := ids.GenerateTestID() - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) - otherSK, err := localsigner.NewSigner() + otherSK, err := localsigner.New() require.NoError(t, err) otherPK := otherSK.PublicKey() otherPKBytes := bls.PublicKeyToUncompressedBytes(otherPK) diff --git a/vms/platformvm/signer/proof_of_possession_test.go b/vms/platformvm/signer/proof_of_possession_test.go index 0b567d5f4378..a30d5dac093a 100644 --- a/vms/platformvm/signer/proof_of_possession_test.go +++ b/vms/platformvm/signer/proof_of_possession_test.go @@ -42,7 +42,7 @@ func TestProofOfPossession(t *testing.T) { func TestNewProofOfPossessionDeterministic(t *testing.T) { require := require.New(t) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) blsPOP0 := NewProofOfPossession(sk) @@ -61,7 +61,7 @@ func BenchmarkProofOfPossessionVerify(b *testing.B) { } func newProofOfPossession() (*ProofOfPossession, error) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() if err != nil { return nil, err } diff --git a/vms/platformvm/state/staker_test.go b/vms/platformvm/state/staker_test.go index 23846fc1a13e..5495868e6f15 100644 --- a/vms/platformvm/state/staker_test.go +++ b/vms/platformvm/state/staker_test.go @@ -202,7 +202,7 @@ func TestNewPendingStaker(t *testing.T) { func generateStakerTx(require *require.Assertions) *txs.AddPermissionlessValidatorTx { nodeID := ids.GenerateTestNodeID() - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pop := signer.NewProofOfPossession(sk) subnetID := ids.GenerateTestID() diff --git a/vms/platformvm/state/state_test.go b/vms/platformvm/state/state_test.go index fa2e3d49770d..46c5939f7afa 100644 --- a/vms/platformvm/state/state_test.go +++ b/vms/platformvm/state/state_test.go @@ -546,7 +546,7 @@ func TestState_writeStakers(t *testing.T) { func createPermissionlessValidatorTx(t testing.TB, subnetID ids.ID, validatorsData txs.Validator) *txs.AddPermissionlessValidatorTx { var sig signer.Signer = &signer.Empty{} if subnetID == constants.PrimaryNetworkID { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) sig = signer.NewProofOfPossession(sk) } @@ -786,7 +786,7 @@ func TestState_ApplyValidatorDiffs(t *testing.T) { subnetStakers = make([]Staker, numNodes) ) for i := range primaryStakers { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) timeOffset := time.Duration(i) * time.Second @@ -1515,12 +1515,12 @@ func TestL1Validators(t *testing.T) { NodeID: ids.GenerateTestNodeID(), } - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) - otherSK, err := localsigner.NewSigner() + otherSK, err := localsigner.New() require.NoError(t, err) otherPK := otherSK.PublicKey() otherPKBytes := bls.PublicKeyToUncompressedBytes(otherPK) @@ -2017,7 +2017,7 @@ func TestLoadL1ValidatorAndLegacy(t *testing.T) { } require.NoError(state.PutCurrentValidator(legacyStaker)) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) @@ -2095,12 +2095,12 @@ func TestGetCurrentValidators(t *testing.T) { subnetID2 := ids.GenerateTestID() subnetIDs := []ids.ID{subnetID1, subnetID2} - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) pk := sk.PublicKey() pkBytes := bls.PublicKeyToUncompressedBytes(pk) - otherSK, err := localsigner.NewSigner() + otherSK, err := localsigner.New() require.NoError(t, err) otherPK := otherSK.PublicKey() otherPKBytes := bls.PublicKeyToUncompressedBytes(otherPK) diff --git a/vms/platformvm/txs/add_permissionless_validator_tx_test.go b/vms/platformvm/txs/add_permissionless_validator_tx_test.go index cdcb518491a7..73c6b9c0c505 100644 --- a/vms/platformvm/txs/add_permissionless_validator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_validator_tx_test.go @@ -1397,7 +1397,7 @@ func TestAddPermissionlessValidatorTxSyntacticVerify(t *testing.T) { }, } - blsSK, err := localsigner.NewSigner() + blsSK, err := localsigner.New() require.NoError(t, err) blsPOP := signer.NewProofOfPossession(blsSK) diff --git a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go index 81d231bf721f..deef28852d10 100644 --- a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go @@ -546,7 +546,7 @@ func TestConvertSubnetToL1TxSerialization(t *testing.T) { } func TestConvertSubnetToL1TxSyntacticVerify(t *testing.T) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) var ( diff --git a/vms/platformvm/txs/executor/standard_tx_executor_test.go b/vms/platformvm/txs/executor/standard_tx_executor_test.go index a789888ea206..0c5f90c9bc46 100644 --- a/vms/platformvm/txs/executor/standard_tx_executor_test.go +++ b/vms/platformvm/txs/executor/standard_tx_executor_test.go @@ -1451,7 +1451,7 @@ func TestDurangoMemoField(t *testing.T) { chainTime = env.state.GetTimestamp() endTime = chainTime.Add(defaultMaxStakingDuration) ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) wallet := newWallet(t, env, walletConfig{}) @@ -2540,7 +2540,7 @@ func TestStandardExecutorConvertSubnetToL1Tx(t *testing.T) { t.Run(test.name, func(t *testing.T) { require := require.New(t) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) // Create the ConvertSubnetToL1Tx @@ -2741,7 +2741,7 @@ func TestStandardExecutorRegisterL1ValidatorTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - initialSK, err := localsigner.NewSigner() + initialSK, err := localsigner.New() require.NoError(t, err) const ( @@ -2794,7 +2794,7 @@ func TestStandardExecutorRegisterL1ValidatorTx(t *testing.T) { const weight = 1 // Create the Warp message - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) pop := signer.NewProofOfPossession(sk) pk := sk.PublicKey() @@ -3263,7 +3263,7 @@ func TestStandardExecutorSetL1ValidatorWeightTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) const ( @@ -3758,7 +3758,7 @@ func TestStandardExecutorIncreaseL1ValidatorBalanceTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) const ( @@ -4046,7 +4046,7 @@ func TestStandardExecutorDisableL1ValidatorTx(t *testing.T) { require.NoError(t, err) // Create the subnet conversion - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) const ( diff --git a/vms/platformvm/txs/executor/state_changes_test.go b/vms/platformvm/txs/executor/state_changes_test.go index 04831b452b3b..b85043ca0099 100644 --- a/vms/platformvm/txs/executor/state_changes_test.go +++ b/vms/platformvm/txs/executor/state_changes_test.go @@ -229,7 +229,7 @@ func TestAdvanceTimeTo_RemovesStaleExpiries(t *testing.T) { } func TestAdvanceTimeTo_UpdateL1Validators(t *testing.T) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) const ( diff --git a/vms/platformvm/txs/executor/warp_verifier_test.go b/vms/platformvm/txs/executor/warp_verifier_test.go index fe7f898caac6..cca492344911 100644 --- a/vms/platformvm/txs/executor/warp_verifier_test.go +++ b/vms/platformvm/txs/executor/warp_verifier_test.go @@ -26,7 +26,7 @@ func TestVerifyWarpMessages(t *testing.T) { subnetID = ids.GenerateTestID() chainID = ids.GenerateTestID() newValidator = func() (bls.Signer, *validators.GetValidatorOutput) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) return sk, &validators.GetValidatorOutput{ diff --git a/vms/platformvm/validator_set_property_test.go b/vms/platformvm/validator_set_property_test.go index dd3c310c254d..8a1333353b2e 100644 --- a/vms/platformvm/validator_set_property_test.go +++ b/vms/platformvm/validator_set_property_test.go @@ -276,7 +276,7 @@ func addPrimaryValidatorWithBLSKey(t testing.TB, vm *VM, data *validatorInputDat wallet := newWallet(t, vm, walletConfig{}) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -414,7 +414,7 @@ func buildTimestampsList(events []uint8, currentTime time.Time, nodeID ids.NodeI currentTime = currentTime.Add(txexecutor.SyncBound) switch endTime := currentTime.Add(defaultMinStakingDuration); events[0] { case startPrimaryWithBLS: - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() if err != nil { return nil, fmt.Errorf("could not make private key: %w", err) } @@ -452,7 +452,7 @@ func buildTimestampsList(events []uint8, currentTime time.Time, nodeID ids.NodeI case startPrimaryWithBLS: currentTime = currentPrimaryVal.endTime.Add(txexecutor.SyncBound) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() if err != nil { return nil, fmt.Errorf("could not make private key: %w", err) } diff --git a/vms/platformvm/validators/manager_benchmark_test.go b/vms/platformvm/validators/manager_benchmark_test.go index 27dc488b7dbf..a58074ec43d1 100644 --- a/vms/platformvm/validators/manager_benchmark_test.go +++ b/vms/platformvm/validators/manager_benchmark_test.go @@ -109,7 +109,7 @@ func addPrimaryValidator( endTime time.Time, height uint64, ) (ids.NodeID, error) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() if err != nil { return ids.EmptyNodeID, err } diff --git a/vms/platformvm/validators/manager_test.go b/vms/platformvm/validators/manager_test.go index 981aa1451e15..677daa5af952 100644 --- a/vms/platformvm/validators/manager_test.go +++ b/vms/platformvm/validators/manager_test.go @@ -39,7 +39,7 @@ func TestGetValidatorSet_AfterEtna(t *testing.T) { Upgrades: upgrades, }) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) var ( subnetID = ids.GenerateTestID() diff --git a/vms/platformvm/vm_regression_test.go b/vms/platformvm/vm_regression_test.go index 89a56147d495..d63ab5f712ac 100644 --- a/vms/platformvm/vm_regression_test.go +++ b/vms/platformvm/vm_regression_test.go @@ -1478,7 +1478,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { Addrs: []ids.ShortID{ids.GenerateTestShortID()}, } ) - sk1, err := localsigner.NewSigner() + sk1, err := localsigner.New() require.NoError(t, err) pk1 := sk1.PublicKey() @@ -1584,7 +1584,7 @@ func TestSubnetValidatorBLSKeyDiffAfterExpiry(t *testing.T) { t.Logf("primaryEndHeight: %d", primaryEndHeight) // reinsert primary validator with a different BLS key - sk2, err := localsigner.NewSigner() + sk2, err := localsigner.New() require.NoError(t, err) pk2 := sk2.PublicKey() @@ -1750,7 +1750,7 @@ func TestPrimaryNetworkValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // reinsert primary validator with a different BLS key - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) primaryRestartTx, err := wallet.IssueAddPermissionlessValidatorTx( @@ -1919,7 +1919,7 @@ func TestSubnetValidatorPopulatedToEmptyBLSKeyDiff(t *testing.T) { require.NoError(err) // reinsert primary validator with a different BLS key - sk2, err := localsigner.NewSigner() + sk2, err := localsigner.New() require.NoError(err) primaryRestartTx, err := wallet.IssueAddPermissionlessValidatorTx( diff --git a/vms/platformvm/vm_test.go b/vms/platformvm/vm_test.go index 62bab34ba315..3e0f69ee8e90 100644 --- a/vms/platformvm/vm_test.go +++ b/vms/platformvm/vm_test.go @@ -317,7 +317,7 @@ func TestAddValidatorCommit(t *testing.T) { } ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) // create valid tx @@ -473,7 +473,7 @@ func TestAddValidatorInvalidNotReissued(t *testing.T) { startTime := latestForkTime.Add(txexecutor.SyncBound).Add(1 * time.Second) endTime := startTime.Add(defaultMinStakingDuration) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ @@ -1908,7 +1908,7 @@ func TestRemovePermissionedValidatorDuringAddPending(t *testing.T) { wallet := newWallet(t, vm, walletConfig{}) nodeID := ids.GenerateTestNodeID() - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ Threshold: 1, @@ -2124,7 +2124,7 @@ func TestPruneMempool(t *testing.T) { endTime = startTime.Add(vm.MinStakeDuration) ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) rewardsOwner := &secp256k1fx.OutputOwners{ diff --git a/vms/platformvm/warp/gwarp/signer_test.go b/vms/platformvm/warp/gwarp/signer_test.go index 47d4ed79c308..46f88ce5537b 100644 --- a/vms/platformvm/warp/gwarp/signer_test.go +++ b/vms/platformvm/warp/gwarp/signer_test.go @@ -30,7 +30,7 @@ type testSigner struct { func setupSigner(t testing.TB) *testSigner { require := require.New(t) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(err) chainID := ids.GenerateTestID() diff --git a/vms/platformvm/warp/message/register_l1_validator_test.go b/vms/platformvm/warp/message/register_l1_validator_test.go index 22cec55ebe1f..970bd8dfaabf 100644 --- a/vms/platformvm/warp/message/register_l1_validator_test.go +++ b/vms/platformvm/warp/message/register_l1_validator_test.go @@ -17,7 +17,7 @@ import ( ) func newBLSPublicKey(t *testing.T) [bls.PublicKeyLen]byte { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) pk := sk.PublicKey() diff --git a/vms/platformvm/warp/signature_test.go b/vms/platformvm/warp/signature_test.go index 9e31f1efaae8..5149d701bb6f 100644 --- a/vms/platformvm/warp/signature_test.go +++ b/vms/platformvm/warp/signature_test.go @@ -45,7 +45,7 @@ func (v *testValidator) Compare(o *testValidator) int { } func newTestValidator() *testValidator { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() if err != nil { panic(err) } diff --git a/vms/platformvm/warp/signer_test.go b/vms/platformvm/warp/signer_test.go index d1daca487d72..b6ee92f62075 100644 --- a/vms/platformvm/warp/signer_test.go +++ b/vms/platformvm/warp/signer_test.go @@ -18,7 +18,7 @@ import ( func TestSigner(t *testing.T) { for name, test := range signertest.SignerTests { t.Run(name, func(t *testing.T) { - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) chainID := ids.GenerateTestID() diff --git a/vms/platformvm/warp/validator_test.go b/vms/platformvm/warp/validator_test.go index 8cd5f7f57769..ffded4cf2a9a 100644 --- a/vms/platformvm/warp/validator_test.go +++ b/vms/platformvm/warp/validator_test.go @@ -163,7 +163,7 @@ func TestGetCanonicalValidatorSet(t *testing.T) { } func TestFilterValidators(t *testing.T) { - sk0, err := localsigner.NewSigner() + sk0, err := localsigner.New() require.NoError(t, err) pk0 := sk0.PublicKey() vdr0 := &Validator{ @@ -172,7 +172,7 @@ func TestFilterValidators(t *testing.T) { Weight: 1, } - sk1, err := localsigner.NewSigner() + sk1, err := localsigner.New() require.NoError(t, err) pk1 := sk1.PublicKey() vdr1 := &Validator{ @@ -316,7 +316,7 @@ func BenchmarkGetCanonicalValidatorSet(b *testing.B) { getValidatorOutputs := make([]*validators.GetValidatorOutput, 0, numNodes) for i := 0; i < numNodes; i++ { nodeID := ids.GenerateTestNodeID() - blsPrivateKey, err := localsigner.NewSigner() + blsPrivateKey, err := localsigner.New() require.NoError(b, err) blsPublicKey := blsPrivateKey.PublicKey() getValidatorOutputs = append(getValidatorOutputs, &validators.GetValidatorOutput{ diff --git a/wallet/chain/p/builder_test.go b/wallet/chain/p/builder_test.go index aa27b99e3594..3880fe14b9b4 100644 --- a/wallet/chain/p/builder_test.go +++ b/wallet/chain/p/builder_test.go @@ -470,7 +470,7 @@ func TestAddPermissionlessValidatorTx(t *testing.T) { delegationShares uint32 = reward.PercentDenominator ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) pop := signer.NewProofOfPossession(sk) @@ -571,9 +571,9 @@ func TestAddPermissionlessDelegatorTx(t *testing.T) { } func TestConvertSubnetToL1Tx(t *testing.T) { - sk0, err := localsigner.NewSigner() + sk0, err := localsigner.New() require.NoError(t, err) - sk1, err := localsigner.NewSigner() + sk1, err := localsigner.New() require.NoError(t, err) var ( @@ -656,7 +656,7 @@ func TestRegisterL1ValidatorTx(t *testing.T) { balance = units.Avax ) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) pop := signer.NewProofOfPossession(sk) @@ -779,7 +779,7 @@ func TestSetL1ValidatorWeightTx(t *testing.T) { ) require.NoError(t, err) - sk, err := localsigner.NewSigner() + sk, err := localsigner.New() require.NoError(t, err) warp, err := warp.NewMessage( From 5beb31191ab3a9b91242678879b8b63148d3ce0a Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 13:24:21 -0500 Subject: [PATCH 52/56] Update coreth --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 5b77a5323aa5..4f2e34e16a79 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/DataDog/zstd v1.5.2 github.com/NYTimes/gziphandler v1.1.1 github.com/antithesishq/antithesis-sdk-go v0.3.8 - github.com/ava-labs/coreth v0.14.1-rc.0.0.20250121034325-4cd690e2055a + github.com/ava-labs/coreth v0.14.1-rc.1.0.20250128181907-9ccd7981f68f github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 diff --git a/go.sum b/go.sum index d2861deff75e..b19731269ec2 100644 --- a/go.sum +++ b/go.sum @@ -64,8 +64,8 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/ava-labs/coreth v0.14.1-rc.0.0.20250121034325-4cd690e2055a h1:1fNibfxmkKUfVOIgh4hnDqtWRj2mZZAPASpakpi8e0A= -github.com/ava-labs/coreth v0.14.1-rc.0.0.20250121034325-4cd690e2055a/go.mod h1:/smuOWlKNaHl3T/6aVgclEDtwvK8cUGUd7DN44EQaTg= +github.com/ava-labs/coreth v0.14.1-rc.1.0.20250128181907-9ccd7981f68f h1:kOr+Y6I0y/qpBFBCtXrLctK/GjtwCYOu0IXUjzR8Yzk= +github.com/ava-labs/coreth v0.14.1-rc.1.0.20250128181907-9ccd7981f68f/go.mod h1:5zXT1GRH+NT9UFs3m3Ks6a8NH0AUmGlz/xWEVlUCUwk= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60 h1:EL66gtXOAwR/4KYBjOV03LTWgkEXvLePribLlJNu4g0= github.com/ava-labs/ledger-avalanche/go v0.0.0-20241009183145-e6f90a8a1a60/go.mod h1:/7qKobTfbzBu7eSTVaXMTr56yTYk4j2Px6/8G+idxHo= github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g= From 7d2fd6ad37f4c9e0da52a446bc86bcda15d01398 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 13:34:16 -0500 Subject: [PATCH 53/56] fixup! Define bls-ciphersuite constants with iota --- utils/crypto/bls/bls_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/crypto/bls/bls_test.go b/utils/crypto/bls/bls_test.go index 8ab0b50ad175..6e3bf4a1ba2f 100644 --- a/utils/crypto/bls/bls_test.go +++ b/utils/crypto/bls/bls_test.go @@ -29,7 +29,7 @@ func publicKey(sk *blst.SecretKey) *PublicKey { } func sign(sk *blst.SecretKey, msg []byte) *Signature { - return new(Signature).Sign(sk, msg, CiphersuiteSignature) + return new(Signature).Sign(sk, msg, CiphersuiteSignature.Bytes()) } func TestAggregationThreshold(t *testing.T) { From 2e8fa1070a85cafcfbf1298f39269a9eda3fad83 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 13:47:42 -0500 Subject: [PATCH 54/56] Lint fix --- utils/crypto/bls/signer/localsigner/serialization_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/crypto/bls/signer/localsigner/serialization_test.go b/utils/crypto/bls/signer/localsigner/serialization_test.go index eb9ca0ad6a9c..11480f9f0fc9 100644 --- a/utils/crypto/bls/signer/localsigner/serialization_test.go +++ b/utils/crypto/bls/signer/localsigner/serialization_test.go @@ -7,9 +7,10 @@ import ( "testing" "github.com/stretchr/testify/require" - blst "github.com/supranational/blst/bindings/go" "github.com/ava-labs/avalanchego/utils" + + blst "github.com/supranational/blst/bindings/go" ) const SecretKeyLen = blst.BLST_SCALAR_BYTES From 5b57b4715a81e7c0053a94ba7ba5f1eec7c3de12 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 14:27:52 -0500 Subject: [PATCH 55/56] Update utils/crypto/bls/public.go Co-authored-by: Stephen Buttolph Signed-off-by: Richard Pringle --- utils/crypto/bls/public.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/utils/crypto/bls/public.go b/utils/crypto/bls/public.go index 0ba5ea800f70..ed8868a01ae2 100644 --- a/utils/crypto/bls/public.go +++ b/utils/crypto/bls/public.go @@ -9,9 +9,7 @@ import ( blst "github.com/supranational/blst/bindings/go" ) -const ( - PublicKeyLen = blst.BLST_P1_COMPRESS_BYTES -) +const PublicKeyLen = blst.BLST_P1_COMPRESS_BYTES var ( ErrNoPublicKeys = errors.New("no public keys") From 72113daa9bf9649b2438051c528d3fb084ca9e58 Mon Sep 17 00:00:00 2001 From: Richard Pringle Date: Tue, 28 Jan 2025 17:08:56 -0500 Subject: [PATCH 56/56] Rename constructor to FromBytes --- config/config.go | 4 ++-- tests/fixture/tmpnet/node.go | 2 +- utils/crypto/bls/signer/localsigner/localsigner.go | 4 ++-- utils/crypto/bls/signer/localsigner/serialization_test.go | 6 +++--- vms/platformvm/network/warp_test.go | 2 +- vms/platformvm/txs/add_permissionless_validator_tx_test.go | 2 +- vms/platformvm/txs/convert_subnet_to_l1_tx_test.go | 2 +- vms/platformvm/txs/register_l1_validator_tx_test.go | 2 +- .../subnet/primary/examples/register-l1-validator/main.go | 2 +- .../subnet/primary/examples/set-l1-validator-weight/main.go | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config/config.go b/config/config.go index be15e8a6f8fd..d3c3a136f11a 100644 --- a/config/config.go +++ b/config/config.go @@ -654,7 +654,7 @@ func getStakingSigner(v *viper.Viper) (bls.Signer, error) { if err != nil { return nil, fmt.Errorf("unable to decode base64 content: %w", err) } - key, err := localsigner.SecretKeyFromBytes(signerKeyContent) + key, err := localsigner.FromBytes(signerKeyContent) if err != nil { return nil, fmt.Errorf("couldn't parse signing key: %w", err) } @@ -668,7 +668,7 @@ func getStakingSigner(v *viper.Viper) (bls.Signer, error) { if err != nil { return nil, err } - key, err := localsigner.SecretKeyFromBytes(signingKeyBytes) + key, err := localsigner.FromBytes(signingKeyBytes) if err != nil { return nil, fmt.Errorf("couldn't parse signing key: %w", err) } diff --git a/tests/fixture/tmpnet/node.go b/tests/fixture/tmpnet/node.go index bfc6acad7610..b4d55eb46a45 100644 --- a/tests/fixture/tmpnet/node.go +++ b/tests/fixture/tmpnet/node.go @@ -316,7 +316,7 @@ func (n *Node) GetProofOfPossession() (*signer.ProofOfPossession, error) { if err != nil { return nil, err } - secretKey, err := localsigner.SecretKeyFromBytes(signingKeyBytes) + secretKey, err := localsigner.FromBytes(signingKeyBytes) if err != nil { return nil, err } diff --git a/utils/crypto/bls/signer/localsigner/localsigner.go b/utils/crypto/bls/signer/localsigner/localsigner.go index 5959e1b7d097..965b77fbe697 100644 --- a/utils/crypto/bls/signer/localsigner/localsigner.go +++ b/utils/crypto/bls/signer/localsigner/localsigner.go @@ -43,9 +43,9 @@ func (s *LocalSigner) ToBytes() []byte { return s.sk.Serialize() } -// SecretKeyFromBytes parses the big-endian format of the secret key into a +// FromBytes parses the big-endian format of the secret key into a // secret key. -func SecretKeyFromBytes(skBytes []byte) (*LocalSigner, error) { +func FromBytes(skBytes []byte) (*LocalSigner, error) { sk := new(secretKey).Deserialize(skBytes) if sk == nil { return nil, ErrFailedSecretKeyDeserialize diff --git a/utils/crypto/bls/signer/localsigner/serialization_test.go b/utils/crypto/bls/signer/localsigner/serialization_test.go index 11480f9f0fc9..34009ff99752 100644 --- a/utils/crypto/bls/signer/localsigner/serialization_test.go +++ b/utils/crypto/bls/signer/localsigner/serialization_test.go @@ -20,7 +20,7 @@ func TestSecretKeyFromBytesZero(t *testing.T) { var skArr [SecretKeyLen]byte skBytes := skArr[:] - _, err := SecretKeyFromBytes(skBytes) + _, err := FromBytes(skBytes) require.ErrorIs(err, ErrFailedSecretKeyDeserialize) } @@ -28,7 +28,7 @@ func TestSecretKeyFromBytesWrongSize(t *testing.T) { require := require.New(t) skBytes := utils.RandomBytes(SecretKeyLen + 1) - _, err := SecretKeyFromBytes(skBytes) + _, err := FromBytes(skBytes) require.ErrorIs(err, ErrFailedSecretKeyDeserialize) } @@ -42,7 +42,7 @@ func TestSecretKeyBytes(t *testing.T) { sig := sk.Sign(msg) skBytes := sk.ToBytes() - sk2, err := SecretKeyFromBytes(skBytes) + sk2, err := FromBytes(skBytes) require.NoError(err) sig2 := sk2.Sign(msg) sk2Bytes := sk2.ToBytes() diff --git a/vms/platformvm/network/warp_test.go b/vms/platformvm/network/warp_test.go index 8e3413f1d6c8..7b6975840a43 100644 --- a/vms/platformvm/network/warp_test.go +++ b/vms/platformvm/network/warp_test.go @@ -241,7 +241,7 @@ func TestSignatureRequestVerifyL1ValidatorRegistrationNotRegistered(t *testing.T skBytes, err := hex.DecodeString("36a33c536d283dfa599d0a70839c67ded6c954e346c5e8e5b4794e2299907887") require.NoError(t, err) - sk, err := localsigner.SecretKeyFromBytes(skBytes) + sk, err := localsigner.FromBytes(skBytes) require.NoError(t, err) var ( diff --git a/vms/platformvm/txs/add_permissionless_validator_tx_test.go b/vms/platformvm/txs/add_permissionless_validator_tx_test.go index 73c6b9c0c505..007b08c2c9d9 100644 --- a/vms/platformvm/txs/add_permissionless_validator_tx_test.go +++ b/vms/platformvm/txs/add_permissionless_validator_tx_test.go @@ -41,7 +41,7 @@ func TestAddPermissionlessPrimaryValidator(t *testing.T) { skBytes, err := hex.DecodeString("6668fecd4595b81e4d568398c820bbf3f073cb222902279fa55ebb84764ed2e3") require.NoError(err) - sk, err := localsigner.SecretKeyFromBytes(skBytes) + sk, err := localsigner.FromBytes(skBytes) require.NoError(err) avaxAssetID, err := ids.FromString("FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z") diff --git a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go index deef28852d10..01387dd8df26 100644 --- a/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go +++ b/vms/platformvm/txs/convert_subnet_to_l1_tx_test.go @@ -38,7 +38,7 @@ var ( func TestConvertSubnetToL1TxSerialization(t *testing.T) { skBytes, err := hex.DecodeString("6668fecd4595b81e4d568398c820bbf3f073cb222902279fa55ebb84764ed2e3") require.NoError(t, err) - sk, err := localsigner.SecretKeyFromBytes(skBytes) + sk, err := localsigner.FromBytes(skBytes) require.NoError(t, err) var ( diff --git a/vms/platformvm/txs/register_l1_validator_tx_test.go b/vms/platformvm/txs/register_l1_validator_tx_test.go index fcf8787d723b..0d0c83819aeb 100644 --- a/vms/platformvm/txs/register_l1_validator_tx_test.go +++ b/vms/platformvm/txs/register_l1_validator_tx_test.go @@ -34,7 +34,7 @@ func TestRegisterL1ValidatorTxSerialization(t *testing.T) { skBytes, err := hex.DecodeString("6668fecd4595b81e4d568398c820bbf3f073cb222902279fa55ebb84764ed2e3") require.NoError(err) - sk, err := localsigner.SecretKeyFromBytes(skBytes) + sk, err := localsigner.FromBytes(skBytes) require.NoError(err) var ( diff --git a/wallet/subnet/primary/examples/register-l1-validator/main.go b/wallet/subnet/primary/examples/register-l1-validator/main.go index 5808cc8aad0a..2281b6d1c718 100644 --- a/wallet/subnet/primary/examples/register-l1-validator/main.go +++ b/wallet/subnet/primary/examples/register-l1-validator/main.go @@ -39,7 +39,7 @@ func main() { log.Fatalf("failed to decode secret key: %s\n", err) } - sk, err := localsigner.SecretKeyFromBytes(blsSKBytes) + sk, err := localsigner.FromBytes(blsSKBytes) if err != nil { log.Fatalf("failed to parse secret key: %s\n", err) } diff --git a/wallet/subnet/primary/examples/set-l1-validator-weight/main.go b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go index 3464483515ab..af9af5d8b6e1 100644 --- a/wallet/subnet/primary/examples/set-l1-validator-weight/main.go +++ b/wallet/subnet/primary/examples/set-l1-validator-weight/main.go @@ -38,7 +38,7 @@ func main() { log.Fatalf("failed to decode secret key: %s\n", err) } - sk, err := localsigner.SecretKeyFromBytes(blsSKBytes) + sk, err := localsigner.FromBytes(blsSKBytes) if err != nil { log.Fatalf("failed to parse secret key: %s\n", err) }