Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate Signer #693

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22.8

require (
github.com/VictoriaMetrics/fastcache v1.12.1
github.com/ava-labs/avalanchego v1.11.13-rc.0
github.com/ava-labs/avalanchego v1.12.0-initial-poc.9.0.20241129153017-3f46a5a4a084
github.com/cespare/cp v0.1.0
github.com/crate-crypto/go-ipa v0.0.0-20231025140028-3c0104f4b233
github.com/davecgh/go-spew v1.1.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanchego v1.11.13-rc.0 h1:yxhZbLlZ+29wR6W29rz0QryZxk35iyMNr1IhX9NPFCU=
github.com/ava-labs/avalanchego v1.11.13-rc.0/go.mod h1:86tO6F1FT8emclUwdQ2WCwAtAerqjm5A4IbV6XxNUyM=
github.com/ava-labs/avalanchego v1.12.0-initial-poc.9.0.20241129153017-3f46a5a4a084 h1:sZcRy4DXLquvwj/GBr9jE4NkQN3Vy+UK1eENbefxQ0w=
github.com/ava-labs/avalanchego v1.12.0-initial-poc.9.0.20241129153017-3f46a5a4a084/go.mod h1:8f6zzG+5CDDw8+Lxkz5ODe94I8ZH8kT4BTroCNtTATo=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,12 @@ func NewContext() *snow.Context {
return subnetID, nil
},
}
blsSecretKey, err := bls.NewSecretKey()
blsSecretKey, err := bls.NewSigner()
if err != nil {
panic(err)
}
ctx.WarpSigner = avalancheWarp.NewSigner(blsSecretKey, ctx.NetworkID, ctx.ChainID)
ctx.PublicKey = bls.PublicFromSecretKey(blsSecretKey)
ctx.PublicKey = blsSecretKey.PublicKey()
return ctx
}

Expand Down
20 changes: 10 additions & 10 deletions plugin/evm/vm_warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,16 @@ func testWarpVMTransaction(t *testing.T, unsignedMessage *avalancheWarp.Unsigned
defer logsSub.Unsubscribe()

nodeID1 := ids.GenerateTestNodeID()
blsSecretKey1, err := bls.NewSecretKey()
blsSecretKey1, err := bls.NewSigner()
require.NoError(err)
blsPublicKey1 := bls.PublicFromSecretKey(blsSecretKey1)
blsSignature1 := bls.Sign(blsSecretKey1, unsignedMessage.Bytes())
blsPublicKey1 := blsSecretKey1.PublicKey()
blsSignature1 := blsSecretKey1.Sign(unsignedMessage.Bytes())

nodeID2 := ids.GenerateTestNodeID()
blsSecretKey2, err := bls.NewSecretKey()
blsSecretKey2, err := bls.NewSigner()
require.NoError(err)
blsPublicKey2 := bls.PublicFromSecretKey(blsSecretKey2)
blsSignature2 := bls.Sign(blsSecretKey2, unsignedMessage.Bytes())
blsPublicKey2 := blsSecretKey2.PublicKey()
blsSignature2 := blsSecretKey2.Sign(unsignedMessage.Bytes())

blsAggregatedSignature, err := bls.AggregateSignatures([]*bls.Signature{blsSignature1, blsSignature2})
require.NoError(err)
Expand Down Expand Up @@ -523,18 +523,18 @@ func testReceiveWarpMessage(
type signer struct {
networkID ids.ID
nodeID ids.NodeID
secret *bls.SecretKey
secret bls.Signer
signature *bls.Signature
weight uint64
}
newSigner := func(networkID ids.ID, weight uint64) signer {
secret, err := bls.NewSecretKey()
secret, err := bls.NewSigner()
require.NoError(err)
return signer{
networkID: networkID,
nodeID: ids.GenerateTestNodeID(),
secret: secret,
signature: bls.Sign(secret, unsignedMessage.Bytes()),
signature: secret.Sign(unsignedMessage.Bytes()),
weight: weight,
}
}
Expand Down Expand Up @@ -582,7 +582,7 @@ func testReceiveWarpMessage(
for _, s := range signers {
vdrOutput[s.nodeID] = &validators.GetValidatorOutput{
NodeID: s.nodeID,
PublicKey: bls.PublicFromSecretKey(s.secret),
PublicKey: s.secret.PublicKey(),
Weight: s.weight,
}
}
Expand Down
10 changes: 5 additions & 5 deletions precompile/contracts/warp/predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func init() {
}

for _, testVdr := range testVdrs {
blsSignature := bls.Sign(testVdr.sk, unsignedMsg.Bytes())
blsSignature := testVdr.sk.Sign(unsignedMsg.Bytes())
blsSignatures = append(blsSignatures, blsSignature)
}

Expand All @@ -102,7 +102,7 @@ func init() {

type testValidator struct {
nodeID ids.NodeID
sk *bls.SecretKey
sk bls.Signer
vdr *avalancheWarp.Validator
}

Expand All @@ -111,13 +111,13 @@ func (v *testValidator) Compare(o *testValidator) int {
}

func newTestValidator() *testValidator {
sk, err := bls.NewSecretKey()
sk, err := bls.NewSigner()
if err != nil {
panic(err)
}

nodeID := ids.GenerateTestNodeID()
pk := bls.PublicFromSecretKey(sk)
pk := sk.PublicKey()
return &testValidator{
nodeID: nodeID,
sk: sk,
Expand Down Expand Up @@ -240,7 +240,7 @@ func testWarpMessageFromPrimaryNetwork(t *testing.T, requirePrimaryNetworkSigner
PublicKey: testVdrs[i].vdr.PublicKey,
}
getValidatorsOutput[testVdrs[i].nodeID] = validatorOutput
blsSignatures = append(blsSignatures, bls.Sign(testVdrs[i].sk, unsignedMsg.Bytes()))
blsSignatures = append(blsSignatures, testVdrs[i].sk.Sign(unsignedMsg.Bytes()))
}
aggregateSignature, err := bls.AggregateSignatures(blsSignatures)
require.NoError(err)
Expand Down
32 changes: 16 additions & 16 deletions precompile/contracts/warp/signature_verification_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ func TestSignatureVerification(t *testing.T) {
signers.Add(1)

unsignedBytes := unsignedMsg.Bytes()
vdr0Sig := bls.Sign(testVdrs[0].sk, unsignedBytes)
vdr1Sig := bls.Sign(testVdrs[1].sk, unsignedBytes)
vdr0Sig := testVdrs[0].sk.Sign(unsignedBytes)
vdr1Sig := testVdrs[1].sk.Sign(unsignedBytes)
aggSig, err := bls.AggregateSignatures([]*bls.Signature{vdr0Sig, vdr1Sig})
require.NoError(err)
aggSigBytes := [bls.SignatureLen]byte{}
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestSignatureVerification(t *testing.T) {
require.NoError(err)

unsignedBytes := unsignedMsg.Bytes()
vdr0Sig := bls.Sign(testVdrs[0].sk, unsignedBytes)
vdr0Sig := testVdrs[0].sk.Sign(unsignedBytes)
aggSigBytes := [bls.SignatureLen]byte{}
copy(aggSigBytes[:], bls.SignatureToBytes(vdr0Sig))

Expand Down Expand Up @@ -323,10 +323,10 @@ func TestSignatureVerification(t *testing.T) {
signers.Add(1)

unsignedBytes := unsignedMsg.Bytes()
vdr0Sig := bls.Sign(testVdrs[0].sk, unsignedBytes)
vdr0Sig := testVdrs[0].sk.Sign(unsignedBytes)
// Give sig from vdr[2] even though the bit vector says it
// should be from vdr[1]
vdr2Sig := bls.Sign(testVdrs[2].sk, unsignedBytes)
vdr2Sig := testVdrs[2].sk.Sign(unsignedBytes)
aggSig, err := bls.AggregateSignatures([]*bls.Signature{vdr0Sig, vdr2Sig})
require.NoError(err)
aggSigBytes := [bls.SignatureLen]byte{}
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestSignatureVerification(t *testing.T) {
signers.Add(1)

unsignedBytes := unsignedMsg.Bytes()
vdr0Sig := bls.Sign(testVdrs[0].sk, unsignedBytes)
vdr0Sig := testVdrs[0].sk.Sign(unsignedBytes)
// Don't give the sig from vdr[1]
aggSigBytes := [bls.SignatureLen]byte{}
copy(aggSigBytes[:], bls.SignatureToBytes(vdr0Sig))
Expand Down Expand Up @@ -407,11 +407,11 @@ func TestSignatureVerification(t *testing.T) {
signers.Add(1)

unsignedBytes := unsignedMsg.Bytes()
vdr0Sig := bls.Sign(testVdrs[0].sk, unsignedBytes)
vdr1Sig := bls.Sign(testVdrs[1].sk, unsignedBytes)
vdr0Sig := testVdrs[0].sk.Sign(unsignedBytes)
vdr1Sig := testVdrs[1].sk.Sign(unsignedBytes)
// Give sig from vdr[2] even though the bit vector doesn't have
// it
vdr2Sig := bls.Sign(testVdrs[2].sk, unsignedBytes)
vdr2Sig := testVdrs[2].sk.Sign(unsignedBytes)
aggSig, err := bls.AggregateSignatures([]*bls.Signature{vdr0Sig, vdr1Sig, vdr2Sig})
require.NoError(err)
aggSigBytes := [bls.SignatureLen]byte{}
Expand Down Expand Up @@ -454,8 +454,8 @@ func TestSignatureVerification(t *testing.T) {
signers.Add(2)

unsignedBytes := unsignedMsg.Bytes()
vdr1Sig := bls.Sign(testVdrs[1].sk, unsignedBytes)
vdr2Sig := bls.Sign(testVdrs[2].sk, unsignedBytes)
vdr1Sig := testVdrs[1].sk.Sign(unsignedBytes)
vdr2Sig := testVdrs[2].sk.Sign(unsignedBytes)
aggSig, err := bls.AggregateSignatures([]*bls.Signature{vdr1Sig, vdr2Sig})
require.NoError(err)
aggSigBytes := [bls.SignatureLen]byte{}
Expand Down Expand Up @@ -498,8 +498,8 @@ func TestSignatureVerification(t *testing.T) {
signers.Add(2)

unsignedBytes := unsignedMsg.Bytes()
vdr1Sig := bls.Sign(testVdrs[1].sk, unsignedBytes)
vdr2Sig := bls.Sign(testVdrs[2].sk, unsignedBytes)
vdr1Sig := testVdrs[1].sk.Sign(unsignedBytes)
vdr2Sig := testVdrs[2].sk.Sign(unsignedBytes)
aggSig, err := bls.AggregateSignatures([]*bls.Signature{vdr1Sig, vdr2Sig})
require.NoError(err)
aggSigBytes := [bls.SignatureLen]byte{}
Expand Down Expand Up @@ -559,8 +559,8 @@ func TestSignatureVerification(t *testing.T) {
signers.Add(1) // vdr[2]

unsignedBytes := unsignedMsg.Bytes()
vdr1Sig := bls.Sign(testVdrs[1].sk, unsignedBytes)
vdr2Sig := bls.Sign(testVdrs[2].sk, unsignedBytes)
vdr1Sig := testVdrs[1].sk.Sign(unsignedBytes)
vdr2Sig := testVdrs[2].sk.Sign(unsignedBytes)
aggSig, err := bls.AggregateSignatures([]*bls.Signature{vdr1Sig, vdr2Sig})
require.NoError(err)
aggSigBytes := [bls.SignatureLen]byte{}
Expand Down Expand Up @@ -621,7 +621,7 @@ func TestSignatureVerification(t *testing.T) {

unsignedBytes := unsignedMsg.Bytes()
// Because vdr[1] and vdr[2] share a key, only one of them sign.
vdr2Sig := bls.Sign(testVdrs[2].sk, unsignedBytes)
vdr2Sig := testVdrs[2].sk.Sign(unsignedBytes)
aggSigBytes := [bls.SignatureLen]byte{}
copy(aggSigBytes[:], bls.SignatureToBytes(vdr2Sig))

Expand Down
2 changes: 1 addition & 1 deletion scripts/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
set -euo pipefail

# Don't export them as they're used in the context of other calls
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.11.13-rc.0'}
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'3f46a5a4a084'}
4 changes: 2 additions & 2 deletions utils/snow.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ var (
)

func TestSnowContext() *snow.Context {
sk, err := bls.NewSecretKey()
sk, err := bls.NewSigner()
if err != nil {
panic(err)
}
pk := bls.PublicFromSecretKey(sk)
pk := sk.PublicKey()
networkID := constants.UnitTestID
chainID := testChainID

Expand Down
16 changes: 8 additions & 8 deletions warp/aggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
)

func newValidator(t testing.TB, weight uint64) (*bls.SecretKey, *avalancheWarp.Validator) {
sk, err := bls.NewSecretKey()
func newValidator(t testing.TB, weight uint64) (bls.Signer, *avalancheWarp.Validator) {
sk, err := bls.NewSigner()
require.NoError(t, err)
pk := bls.PublicFromSecretKey(sk)
pk := sk.PublicKey()
return sk, &avalancheWarp.Validator{
PublicKey: pk,
PublicKeyBytes: bls.PublicKeyToCompressedBytes(pk),
Expand All @@ -43,17 +43,17 @@ func TestAggregateSignatures(t *testing.T) {
vdr1sk, vdr1 := newValidator(t, vdrWeight)
vdr2sk, vdr2 := newValidator(t, vdrWeight+1)
vdr3sk, vdr3 := newValidator(t, vdrWeight-1)
sig1 := bls.Sign(vdr1sk, unsignedMsg.Bytes())
sig2 := bls.Sign(vdr2sk, unsignedMsg.Bytes())
sig3 := bls.Sign(vdr3sk, unsignedMsg.Bytes())
sig1 := vdr1sk.Sign(unsignedMsg.Bytes())
sig2 := vdr2sk.Sign(unsignedMsg.Bytes())
sig3 := vdr3sk.Sign(unsignedMsg.Bytes())
vdrToSig := map[*avalancheWarp.Validator]*bls.Signature{
vdr1: sig1,
vdr2: sig2,
vdr3: sig3,
}
nonVdrSk, err := bls.NewSecretKey()
nonVdrSk, err := bls.NewSigner()
require.NoError(t, err)
nonVdrSig := bls.Sign(nonVdrSk, unsignedMsg.Bytes())
nonVdrSig := nonVdrSk.Sign(unsignedMsg.Bytes())
vdrs := []*avalancheWarp.Validator{
{
PublicKey: vdr1.PublicKey,
Expand Down
10 changes: 5 additions & 5 deletions warp/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func init() {
func TestAddAndGetValidMessage(t *testing.T) {
db := memdb.New()

sk, err := bls.NewSecretKey()
sk, err := bls.NewSigner()
require.NoError(t, err)
warpSigner := avalancheWarp.NewSigner(sk, networkID, sourceChainID)
messageSignatureCache := &cache.LRU[ids.ID, []byte]{Size: 500}
Expand All @@ -63,7 +63,7 @@ func TestAddAndGetValidMessage(t *testing.T) {
func TestAddAndGetUnknownMessage(t *testing.T) {
db := memdb.New()

sk, err := bls.NewSecretKey()
sk, err := bls.NewSigner()
require.NoError(t, err)
warpSigner := avalancheWarp.NewSigner(sk, networkID, sourceChainID)
messageSignatureCache := &cache.LRU[ids.ID, []byte]{Size: 500}
Expand All @@ -82,7 +82,7 @@ func TestGetBlockSignature(t *testing.T) {
blockClient := warptest.MakeBlockClient(blkID)
db := memdb.New()

sk, err := bls.NewSecretKey()
sk, err := bls.NewSigner()
require.NoError(err)
warpSigner := avalancheWarp.NewSigner(sk, networkID, sourceChainID)
messageSignatureCache := &cache.LRU[ids.ID, []byte]{Size: 500}
Expand All @@ -107,7 +107,7 @@ func TestGetBlockSignature(t *testing.T) {
func TestZeroSizedCache(t *testing.T) {
db := memdb.New()

sk, err := bls.NewSecretKey()
sk, err := bls.NewSigner()
require.NoError(t, err)
warpSigner := avalancheWarp.NewSigner(sk, networkID, sourceChainID)

Expand Down Expand Up @@ -135,7 +135,7 @@ func TestOffChainMessages(t *testing.T) {
check func(require *require.Assertions, b Backend)
err error
}
sk, err := bls.NewSecretKey()
sk, err := bls.NewSigner()
require.NoError(t, err)
warpSigner := avalancheWarp.NewSigner(sk, networkID, sourceChainID)

Expand Down
4 changes: 2 additions & 2 deletions warp/handlers/signature_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
func TestMessageSignatureHandler(t *testing.T) {
database := memdb.New()
snowCtx := utils.TestSnowContext()
blsSecretKey, err := bls.NewSecretKey()
blsSecretKey, err := bls.NewSigner()
require.NoError(t, err)
warpSigner := avalancheWarp.NewSigner(blsSecretKey, snowCtx.NetworkID, snowCtx.ChainID)

Expand Down Expand Up @@ -127,7 +127,7 @@ func TestMessageSignatureHandler(t *testing.T) {
func TestBlockSignatureHandler(t *testing.T) {
database := memdb.New()
snowCtx := utils.TestSnowContext()
blsSecretKey, err := bls.NewSecretKey()
blsSecretKey, err := bls.NewSigner()
require.NoError(t, err)

warpSigner := avalancheWarp.NewSigner(blsSecretKey, snowCtx.NetworkID, snowCtx.ChainID)
Expand Down
4 changes: 2 additions & 2 deletions warp/verifier_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
func TestAddressedCallSignatures(t *testing.T) {
database := memdb.New()
snowCtx := utils.TestSnowContext()
blsSecretKey, err := bls.NewSecretKey()
blsSecretKey, err := bls.NewSigner()
require.NoError(t, err)
warpSigner := avalancheWarp.NewSigner(blsSecretKey, snowCtx.NetworkID, snowCtx.ChainID)

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestAddressedCallSignatures(t *testing.T) {
func TestBlockSignatures(t *testing.T) {
database := memdb.New()
snowCtx := utils.TestSnowContext()
blsSecretKey, err := bls.NewSecretKey()
blsSecretKey, err := bls.NewSigner()
require.NoError(t, err)

warpSigner := avalancheWarp.NewSigner(blsSecretKey, snowCtx.NetworkID, snowCtx.ChainID)
Expand Down
Loading