Skip to content

Commit

Permalink
update signer type
Browse files Browse the repository at this point in the history
  • Loading branch information
darioush authored and richardpringle committed Nov 29, 2024
1 parent a857e7c commit 7b5b48b
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 54 deletions.
4 changes: 1 addition & 3 deletions 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 Expand Up @@ -131,5 +131,3 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ava-labs/avalanchego v1.11.13-rc.0 => github.com/ava-labs/avalanchego v1.12.0-initial-poc.9.0.20241129153017-3f46a5a4a084
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'}
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

0 comments on commit 7b5b48b

Please sign in to comment.