Skip to content

Commit

Permalink
add test and fix owner change
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel committed Nov 7, 2024
1 parent ebe95f8 commit 3097a3b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 13 deletions.
69 changes: 69 additions & 0 deletions integration_test/resign_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,72 @@ func TestInitResignHappyFlows(t *testing.T) {
srv.HttpSrv.Close()
}
}

func TestInitResignChangeOwnerHappyFlows(t *testing.T) {
err := logging.SetGlobalLogger("info", "capital", "console", nil)
require.NoError(t, err)
logger := zap.L().Named("integration-tests")
version := "test.version"
stubClient := &stubs.Client{
CallContractF: func(call ethereum.CallMsg) ([]byte, error) {
return nil, nil
},
}
servers, ops := createOperators(t, version, stubClient)
clnt, err := initiator.New(ops, logger, version, rootCert, false)
require.NoError(t, err)
withdraw := newEthAddress(t)
sk, err := eth_crypto.GenerateKey()
require.NoError(t, err)
owner := eth_crypto.PubkeyToAddress(sk.PublicKey)
skNewOwner, err := eth_crypto.GenerateKey()
require.NoError(t, err)
newOwner := eth_crypto.PubkeyToAddress(skNewOwner.PublicKey)
t.Run("test 4 operators resign happy flow", func(t *testing.T) {
id := spec.NewID()
depositData, ks, proofs, err := clnt.StartDKG(id, withdraw.Bytes(), []uint64{11, 22, 33, 44}, "holesky", owner, 0, uint64(spec_crypto.MIN_ACTIVATION_BALANCE))
require.NoError(t, err)
err = validator.ValidateResults([]*wire.DepositDataCLI{depositData}, ks, [][]*wire.SignedProof{proofs}, 1, owner, 0, withdraw)
require.NoError(t, err)
// re-sign
id = spec.NewID()
require.NoError(t, err)
signedProofs := []*spec.SignedProof{}
for _, p := range proofs {
signedProofs = append(signedProofs, &spec.SignedProof{
Proof: &spec.Proof{
ValidatorPubKey: p.Proof.ValidatorPubKey,
EncryptedShare: p.Proof.EncryptedShare,
SharePubKey: p.Proof.SharePubKey,
Owner: p.Proof.Owner,
},
Signature: p.Signature,
})
}
rMsg, err := clnt.ConstructResignMessage(
[]uint64{11, 22, 33, 44},
signedProofs[0].Proof.ValidatorPubKey,
"mainnet",
withdraw.Bytes(),
newOwner,
10,
uint64(spec_crypto.MIN_ACTIVATION_BALANCE),
signedProofs,
)
require.NoError(t, err)
rMsgs := []*wire.ResignMessage{rMsg}
siganture, err := SignResign(rMsgs, sk)
require.NoError(t, err)
signatureBytes, err := hex.DecodeString(siganture)
require.NoError(t, err)
signedResign := wire.SignedResign{Messages: rMsgs, Signature: signatureBytes}
depositDataArr, ksArr, proofsArr, err := clnt.StartResigning(id, &signedResign)
require.NoError(t, err)
err = validator.ValidateResults(depositDataArr, ksArr[0], proofsArr, 1, newOwner, 10, withdraw)
require.NoError(t, err)
})

for _, srv := range servers {
srv.HttpSrv.Close()
}
}
15 changes: 2 additions & 13 deletions pkgs/operator/instances_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (s *Switch) HandleInstanceOperation(reqID [24]byte, transportMsg *wire.Tran
}
if err := spec_crypto.VerifySignedMessageByOwner(
s.EthClient,
getOwner(signedResign.Messages[0]),
signedResign.Messages[0].Proofs[0].Proof.Owner,
hash,
signedResign.Signature,
); err != nil {
Expand Down Expand Up @@ -234,7 +234,7 @@ func (s *Switch) HandleInstanceOperation(reqID [24]byte, transportMsg *wire.Tran
}
if err := spec_crypto.VerifySignedMessageByOwner(
s.EthClient,
getOwner(signedReshare.Messages[0]),
signedReshare.Messages[0].Proofs[0].Proof.Owner,
hash,
signedReshare.Signature,
); err != nil {
Expand All @@ -261,17 +261,6 @@ func (s *Switch) HandleInstanceOperation(reqID [24]byte, transportMsg *wire.Tran
}

// Helper functions to abstract out common behavior
func getOwner(message interface{}) [20]byte {
var owner [20]byte
switch msg := message.(type) {
case *wire.ResignMessage:
copy(owner[:], msg.Resign.Owner[:])
case *wire.ReshareMessage:
copy(owner[:], msg.Reshare.Owner[:])
}
return owner
}

func (s *Switch) validateInstances(reqID InstanceID) error {
s.Mtx.Lock()
l := len(s.Instances)
Expand Down

0 comments on commit 3097a3b

Please sign in to comment.