diff --git a/integration_test/resign_integration_test.go b/integration_test/resign_integration_test.go index c2052c6b..5897ac31 100644 --- a/integration_test/resign_integration_test.go +++ b/integration_test/resign_integration_test.go @@ -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() + } +} diff --git a/pkgs/operator/instances_manager.go b/pkgs/operator/instances_manager.go index ee08cf1e..d4eca895 100644 --- a/pkgs/operator/instances_manager.go +++ b/pkgs/operator/instances_manager.go @@ -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 { @@ -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 { @@ -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)