From da5d6dbdf8252d5597fd3c6eb6e61b615a737599 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Wed, 28 Aug 2024 12:55:16 +0200 Subject: [PATCH 1/4] Enable storing and retrieveing multiple frost keyshares --- chains/btc/executor/executor.go | 2 ++ chains/btc/listener/deposit-handler_test.go | 14 ++++++-------- .../evm/listener/eventHandlers/event-handler.go | 2 +- go.mod | 2 +- go.sum | 2 -- keyshare/frost.go | 15 +++++++++++---- keyshare/frost_test.go | 10 ++++++---- tss/frost/keygen/keygen.go | 2 +- tss/frost/resharing/resharing.go | 5 +++-- tss/frost/resharing/resharing_test.go | 15 ++------------- tss/frost/signing/signing.go | 5 +++-- tss/frost/signing/signing_test.go | 12 ++++++------ tss/mock/frost.go | 8 ++++---- 13 files changed, 46 insertions(+), 48 deletions(-) diff --git a/chains/btc/executor/executor.go b/chains/btc/executor/executor.go index 10378d3b..6607fed8 100644 --- a/chains/btc/executor/executor.go +++ b/chains/btc/executor/executor.go @@ -172,6 +172,8 @@ func (e *Executor) executeResourceProps(props []*BtcTransferProposal, resource c } signing, err := signing.NewSigning( i, + // TODO + "", signingHash, resource.Tweak, messageID, diff --git a/chains/btc/listener/deposit-handler_test.go b/chains/btc/listener/deposit-handler_test.go index fca05717..d22a76dc 100644 --- a/chains/btc/listener/deposit-handler_test.go +++ b/chains/btc/listener/deposit-handler_test.go @@ -28,10 +28,9 @@ func TestRunErc20HandlerTestSuite(t *testing.T) { func (s *Erc20HandlerTestSuite) Test_Erc20HandleEvent() { deposit := &listener.Deposit{ - SenderAddress: "senderAddress", - ResourceID: [32]byte{0}, - Amount: big.NewInt(100), - Data: "0x1c3A03D04c026b1f4B4208D2ce053c5686E6FB8d_1", + ResourceID: [32]byte{0}, + Amount: big.NewInt(100), + Data: "0x1c3A03D04c026b1f4B4208D2ce053c5686E6FB8d_1", } sourceID := uint8(1) @@ -70,10 +69,9 @@ func (s *Erc20HandlerTestSuite) Test_Erc20HandleEvent() { func (s *Erc20HandlerTestSuite) Test_Erc20HandleEvent_InvalidDestinationDomainID() { deposit := &listener.Deposit{ - SenderAddress: "senderAddress", - ResourceID: [32]byte{0}, - Amount: big.NewInt(100), - Data: "0x1c3A03D04c026b1f4B4208D2ce053c5686E6FB8d_InvalidDestinationDomainID", + ResourceID: [32]byte{0}, + Amount: big.NewInt(100), + Data: "0x1c3A03D04c026b1f4B4208D2ce053c5686E6FB8d_InvalidDestinationDomainID", } sourceID := uint8(1) diff --git a/chains/evm/listener/eventHandlers/event-handler.go b/chains/evm/listener/eventHandlers/event-handler.go index e1ee2e92..2533c379 100644 --- a/chains/evm/listener/eventHandlers/event-handler.go +++ b/chains/evm/listener/eventHandlers/event-handler.go @@ -390,7 +390,7 @@ func (eh *RefreshEventHandler) HandleEvents( return nil } frostResharing := frostResharing.NewResharing( - eh.sessionID(startBlock), topology.Threshold, eh.host, eh.communication, eh.frostStorer, + eh.sessionID(startBlock), "", topology.Threshold, eh.host, eh.communication, eh.frostStorer, ) err = eh.coordinator.Execute(context.Background(), []tss.TssProcess{frostResharing}, make(chan interface{}, 1)) if err != nil { diff --git a/go.mod b/go.mod index 0f2db091..db7489d9 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/binance-chain/tss-lib v0.0.0-00010101000000-000000000000 github.com/btcsuite/btcd/btcutil v1.1.5 github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 + github.com/cenkalti/backoff/v4 v4.3.0 github.com/centrifuge/go-substrate-rpc-client/v4 v4.2.1 github.com/creasty/defaults v1.6.0 github.com/deckarep/golang-set/v2 v2.1.0 @@ -34,7 +35,6 @@ require ( github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect - github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/consensys/bavard v0.1.13 // indirect github.com/consensys/gnark-crypto v0.12.1 // indirect github.com/crate-crypto/go-kzg-4844 v0.3.0 // indirect diff --git a/go.sum b/go.sum index 8863740c..b2fbe246 100644 --- a/go.sum +++ b/go.sum @@ -121,8 +121,6 @@ github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3 github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= -github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= -github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/keyshare/frost.go b/keyshare/frost.go index 60ac6e79..c626d1a8 100644 --- a/keyshare/frost.go +++ b/keyshare/frost.go @@ -4,6 +4,7 @@ package keyshare import ( + "encoding/hex" "encoding/json" "fmt" "os" @@ -71,7 +72,7 @@ func (ks *FrostKeyshareStore) UnlockKeyshare() { // StoreFrostKeyshare stores frost keyshare generated by keygen or reshare into file and truncates // old keyshare. func (ks *FrostKeyshareStore) StoreKeyshare(keyshare FrostKeyshare) error { - f, err := os.OpenFile(ks.path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) + f, err := os.OpenFile(fmt.Sprintf("%s.%s", ks.path, hex.EncodeToString(keyshare.Key.PublicKey)), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) if err != nil { return err } @@ -111,13 +112,19 @@ func (ks *FrostKeyshareStore) StoreKeyshare(keyshare FrostKeyshare) error { return err } -// GetFrostKeyshare fetches current keyshare from file. +// GetFrostKeyshare fetches keyshare from file by public key. // Can be a blocking call if keygen or resharing are pending. -func (ks *FrostKeyshareStore) GetKeyshare() (FrostKeyshare, error) { +func (ks *FrostKeyshareStore) GetKeyshare(publicKey string) (FrostKeyshare, error) { fStore := frostKeyshareStore{} k := FrostKeyshare{} - kb, err := os.ReadFile(ks.path) + // used for backwards compatibility with keys before public key was stored + path := ks.path + if len(publicKey) > 0 { + path = fmt.Sprintf("%s.%s", ks.path, publicKey) + } + + kb, err := os.ReadFile(path) if err != nil { return k, fmt.Errorf("error on reading keyshare file: %s", err) } diff --git a/keyshare/frost_test.go b/keyshare/frost_test.go index da944bef..96b804fe 100644 --- a/keyshare/frost_test.go +++ b/keyshare/frost_test.go @@ -5,6 +5,8 @@ package keyshare_test import ( "encoding/base64" + "encoding/hex" + "fmt" "os" "testing" @@ -32,11 +34,10 @@ func (s *FrostKeyshareStoreTestSuite) SetupTest() { s.keyshareStore = keyshare.NewFrostKeyshareStore(s.path) } func (s *FrostKeyshareStoreTestSuite) TearDownTest() { - os.Remove(s.path) } func (s *FrostKeyshareStoreTestSuite) Test_RetrieveInvalidFile() { - _, err := s.keyshareStore.GetKeyshare() + _, err := s.keyshareStore.GetKeyshare("") s.NotNil(err) } @@ -61,15 +62,16 @@ func (s *FrostKeyshareStoreTestSuite) Test_StoreAndRetrieveShare() { Threshold: 1, PrivateShare: privateShare, VerificationShares: verificationShares, - PublicKey: taproot.PublicKey{}, + PublicKey: taproot.PublicKey{1}, ChainKey: []byte{}, }, threshold, peers) err := s.keyshareStore.StoreKeyshare(keyshare) s.Nil(err) - storedKeyshare, err := s.keyshareStore.GetKeyshare() + storedKeyshare, err := s.keyshareStore.GetKeyshare(hex.EncodeToString(keyshare.Key.PublicKey)) s.Nil(err) s.Equal(keyshare, storedKeyshare) + os.Remove(fmt.Sprintf("%s.%s", s.path, hex.EncodeToString(keyshare.Key.PublicKey))) } diff --git a/tss/frost/keygen/keygen.go b/tss/frost/keygen/keygen.go index fbd9801d..ea1bb57e 100644 --- a/tss/frost/keygen/keygen.go +++ b/tss/frost/keygen/keygen.go @@ -25,7 +25,7 @@ type FrostKeyshareStorer interface { StoreKeyshare(keyshare keyshare.FrostKeyshare) error LockKeyshare() UnlockKeyshare() - GetKeyshare() (keyshare.FrostKeyshare, error) + GetKeyshare(publicKey string) (keyshare.FrostKeyshare, error) } type Keygen struct { diff --git a/tss/frost/resharing/resharing.go b/tss/frost/resharing/resharing.go index 2eae4e20..51e9a009 100644 --- a/tss/frost/resharing/resharing.go +++ b/tss/frost/resharing/resharing.go @@ -27,7 +27,7 @@ type startParams struct { VerificationShares map[party.ID]*curve.Secp256k1Point } type FrostKeyshareStorer interface { - GetKeyshare() (keyshare.FrostKeyshare, error) + GetKeyshare(publicKey string) (keyshare.FrostKeyshare, error) StoreKeyshare(keyshare keyshare.FrostKeyshare) error LockKeyshare() UnlockKeyshare() @@ -43,6 +43,7 @@ type Resharing struct { func NewResharing( sessionID string, + publicKey string, threshold int, host host.Host, comm comm.Communication, @@ -50,7 +51,7 @@ func NewResharing( ) *Resharing { storer.LockKeyshare() var key keyshare.FrostKeyshare - key, err := storer.GetKeyshare() + key, err := storer.GetKeyshare(publicKey) if err != nil { // empty key for parties that don't have one key = keyshare.FrostKeyshare{ diff --git a/tss/frost/resharing/resharing_test.go b/tss/frost/resharing/resharing_test.go index 177b3896..ac41dc1a 100644 --- a/tss/frost/resharing/resharing_test.go +++ b/tss/frost/resharing/resharing_test.go @@ -14,7 +14,6 @@ import ( "github.com/ChainSafe/sygma-relayer/tss" "github.com/ChainSafe/sygma-relayer/tss/frost/resharing" tsstest "github.com/ChainSafe/sygma-relayer/tss/test" - "github.com/golang/mock/gomock" "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peerstore" @@ -53,12 +52,7 @@ func (s *ResharingTestSuite) Test_ValidResharingProcess_OldAndNewSubset() { } communicationMap[host.ID()] = &communication storer := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", i)) - share, err := storer.GetKeyshare() - s.MockFrostStorer.EXPECT().LockKeyshare() - s.MockFrostStorer.EXPECT().UnlockKeyshare() - s.MockFrostStorer.EXPECT().GetKeyshare().Return(share, err) - s.MockFrostStorer.EXPECT().StoreKeyshare(gomock.Any()).Return(nil) - resharing := resharing.NewResharing("resharing2", 1, host, &communication, s.MockFrostStorer) + resharing := resharing.NewResharing("resharing2", "", 1, host, &communication, storer) electorFactory := elector.NewCoordinatorElectorFactory(host, s.BullyConfig) coordinators = append(coordinators, tss.NewCoordinator(host, &communication, electorFactory)) processes = append(processes, resharing) @@ -100,12 +94,7 @@ func (s *ResharingTestSuite) Test_ValidResharingProcess_RemovePeer() { } communicationMap[host.ID()] = &communication storer := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", i)) - share, err := storer.GetKeyshare() - s.MockFrostStorer.EXPECT().LockKeyshare() - s.MockFrostStorer.EXPECT().UnlockKeyshare() - s.MockFrostStorer.EXPECT().GetKeyshare().Return(share, err) - s.MockFrostStorer.EXPECT().StoreKeyshare(gomock.Any()).Return(nil) - resharing := resharing.NewResharing("resharing2", 1, host, &communication, s.MockFrostStorer) + resharing := resharing.NewResharing("resharing2", "", 1, host, &communication, storer) electorFactory := elector.NewCoordinatorElectorFactory(host, s.BullyConfig) coordinators = append(coordinators, tss.NewCoordinator(host, &communication, electorFactory)) processes = append(processes, resharing) diff --git a/tss/frost/signing/signing.go b/tss/frost/signing/signing.go index 1395efa4..944c777d 100644 --- a/tss/frost/signing/signing.go +++ b/tss/frost/signing/signing.go @@ -32,7 +32,7 @@ type Signature struct { } type SaveDataFetcher interface { - GetKeyshare() (keyshare.FrostKeyshare, error) + GetKeyshare(publicKey string) (keyshare.FrostKeyshare, error) LockKeyshare() UnlockKeyshare() } @@ -49,6 +49,7 @@ type Signing struct { func NewSigning( id int, + publicKey string, msg []byte, tweak string, messageID string, @@ -59,7 +60,7 @@ func NewSigning( ) (*Signing, error) { fetcher.LockKeyshare() defer fetcher.UnlockKeyshare() - key, err := fetcher.GetKeyshare() + key, err := fetcher.GetKeyshare(publicKey) if err != nil { return nil, err } diff --git a/tss/frost/signing/signing_test.go b/tss/frost/signing/signing_test.go index d90178fc..1d7cd1a7 100644 --- a/tss/frost/signing/signing_test.go +++ b/tss/frost/signing/signing_test.go @@ -43,7 +43,7 @@ func (s *SigningTestSuite) Test_ValidSigningProcess() { s.Nil(err) fetcher := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", 0)) - testKeyshare, err := fetcher.GetKeyshare() + testKeyshare, err := fetcher.GetKeyshare("") s.Nil(err) tweakedKeyshare, err := testKeyshare.Key.Derive(h, nil) s.Nil(err) @@ -57,7 +57,7 @@ func (s *SigningTestSuite) Test_ValidSigningProcess() { communicationMap[host.ID()] = &communication fetcher := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", i)) - signing, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) + signing, err := signing.NewSigning(1, "", msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) if err != nil { panic(err) } @@ -110,15 +110,15 @@ func (s *SigningTestSuite) Test_MultipleProcesses() { communicationMap[host.ID()] = &communication fetcher := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", i)) - signing1, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) + signing1, err := signing.NewSigning(1, "", msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) if err != nil { panic(err) } - signing2, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing2", host, &communication, fetcher) + signing2, err := signing.NewSigning(1, "", msgBytes, tweak, "signing1", "signing2", host, &communication, fetcher) if err != nil { panic(err) } - signing3, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing3", host, &communication, fetcher) + signing3, err := signing.NewSigning(1, "", msgBytes, tweak, "signing1", "signing3", host, &communication, fetcher) if err != nil { panic(err) } @@ -176,7 +176,7 @@ func (s *SigningTestSuite) Test_ProcessTimeout() { communicationMap[host.ID()] = &communication fetcher := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", i)) - signing, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) + signing, err := signing.NewSigning(1, "", msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) if err != nil { panic(err) } diff --git a/tss/mock/frost.go b/tss/mock/frost.go index db796900..5191d04b 100644 --- a/tss/mock/frost.go +++ b/tss/mock/frost.go @@ -35,18 +35,18 @@ func (m *MockFrostKeyshareStorer) EXPECT() *MockFrostKeyshareStorerMockRecorder } // GetKeyshare mocks base method. -func (m *MockFrostKeyshareStorer) GetKeyshare() (keyshare.FrostKeyshare, error) { +func (m *MockFrostKeyshareStorer) GetKeyshare(publicKey string) (keyshare.FrostKeyshare, error) { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetKeyshare") + ret := m.ctrl.Call(m, "GetKeyshare", publicKey) ret0, _ := ret[0].(keyshare.FrostKeyshare) ret1, _ := ret[1].(error) return ret0, ret1 } // GetKeyshare indicates an expected call of GetKeyshare. -func (mr *MockFrostKeyshareStorerMockRecorder) GetKeyshare() *gomock.Call { +func (mr *MockFrostKeyshareStorerMockRecorder) GetKeyshare(publicKey interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKeyshare", reflect.TypeOf((*MockFrostKeyshareStorer)(nil).GetKeyshare)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetKeyshare", reflect.TypeOf((*MockFrostKeyshareStorer)(nil).GetKeyshare), publicKey) } // LockKeyshare mocks base method. From 5b99ef89c91c40f18c5bcb6ff13ed488ec688969 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Wed, 28 Aug 2024 14:58:44 +0200 Subject: [PATCH 2/4] Add public key to frost key configuration --- chains/btc/config/config.go | 3 +++ chains/btc/config/config_test.go | 19 +++++++++++++++++++ chains/btc/executor/executor.go | 3 +-- .../listener/eventHandlers/event-handler.go | 8 -------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/chains/btc/config/config.go b/chains/btc/config/config.go index 6131a06c..609f812c 100644 --- a/chains/btc/config/config.go +++ b/chains/btc/config/config.go @@ -22,6 +22,7 @@ type RawResource struct { FeeAmount string Tweak string Script string + PublicKey []byte } type Resource struct { @@ -30,6 +31,7 @@ type Resource struct { ResourceID [32]byte Tweak string Script []byte + PublicKey string } type RawBtcConfig struct { @@ -136,6 +138,7 @@ func NewBtcConfig(chainConfig map[string]interface{}) (*BtcConfig, error) { Script: scriptBytes, Tweak: r.Tweak, FeeAmount: feeAmount, + PublicKey: hex.EncodeToString(r.PublicKey), } } diff --git a/chains/btc/config/config_test.go b/chains/btc/config/config_test.go index 78512453..d25cbd36 100644 --- a/chains/btc/config/config_test.go +++ b/chains/btc/config/config_test.go @@ -96,6 +96,8 @@ func (s *NewBtcConfigTestSuite) Test_ValidConfig() { feeAddress, _ := btcutil.DecodeAddress("mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt", &chaincfg.TestNet3Params) expectedScript, _ := hex.DecodeString("51206a698882348433b57d549d6344f74500fcd13ad8d2200cdf89f8e39e5cafa7d5") + expectedPublicKey := "36c62696a3869cb46b2e6c93be73d039e6ab341853d824efadecd3dcee332c1a" + publicKeyBytes, _ := hex.DecodeString(expectedPublicKey) rawConfig := map[string]interface{}{ "id": 1, "endpoint": "ws://domain.com", @@ -112,6 +114,14 @@ func (s *NewBtcConfigTestSuite) Test_ValidConfig() { Script: "51206a698882348433b57d549d6344f74500fcd13ad8d2200cdf89f8e39e5cafa7d5", Tweak: "tweak", }, + config.RawResource{ + Address: "tb1qln69zuhdunc9stwfh6t7adexxrcr04ppy6thgm", + FeeAmount: "10000000", + ResourceID: "0x0000000000000000000000000000000000000000000000000000000000000300", + Script: "51206a698882348433b57d549d6344f74500fcd13ad8d2200cdf89f8e39e5cafa7d5", + Tweak: "tweak", + PublicKey: publicKeyBytes, + }, }, } @@ -141,6 +151,15 @@ func (s *NewBtcConfigTestSuite) Test_ValidConfig() { Script: expectedScript, Tweak: "tweak", FeeAmount: big.NewInt(10000000), + PublicKey: "", + }, + { + Address: expectedAddress, + ResourceID: expectedResource, + Script: expectedScript, + Tweak: "tweak", + FeeAmount: big.NewInt(10000000), + PublicKey: expectedPublicKey, }, }, }) diff --git a/chains/btc/executor/executor.go b/chains/btc/executor/executor.go index 6607fed8..e5d87660 100644 --- a/chains/btc/executor/executor.go +++ b/chains/btc/executor/executor.go @@ -172,8 +172,7 @@ func (e *Executor) executeResourceProps(props []*BtcTransferProposal, resource c } signing, err := signing.NewSigning( i, - // TODO - "", + resource.PublicKey, signingHash, resource.Tweak, messageID, diff --git a/chains/evm/listener/eventHandlers/event-handler.go b/chains/evm/listener/eventHandlers/event-handler.go index 2533c379..d3c155f6 100644 --- a/chains/evm/listener/eventHandlers/event-handler.go +++ b/chains/evm/listener/eventHandlers/event-handler.go @@ -389,14 +389,6 @@ func (eh *RefreshEventHandler) HandleEvents( log.Err(err).Msgf("Failed executing ecdsa key refresh") return nil } - frostResharing := frostResharing.NewResharing( - eh.sessionID(startBlock), "", topology.Threshold, eh.host, eh.communication, eh.frostStorer, - ) - err = eh.coordinator.Execute(context.Background(), []tss.TssProcess{frostResharing}, make(chan interface{}, 1)) - if err != nil { - log.Err(err).Msgf("Failed executing frost key refresh") - return nil - } return nil } From 61231211014441d46e30d9f7c8b90fdf825a7b1e Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Wed, 28 Aug 2024 15:42:33 +0200 Subject: [PATCH 3/4] Revert resharing_test changes --- tss/frost/resharing/resharing_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tss/frost/resharing/resharing_test.go b/tss/frost/resharing/resharing_test.go index ac41dc1a..58e82d74 100644 --- a/tss/frost/resharing/resharing_test.go +++ b/tss/frost/resharing/resharing_test.go @@ -19,6 +19,7 @@ import ( "github.com/libp2p/go-libp2p/core/peerstore" "github.com/sourcegraph/conc/pool" "github.com/stretchr/testify/suite" + "go.uber.org/mock/gomock" ) type ResharingTestSuite struct { @@ -52,7 +53,12 @@ func (s *ResharingTestSuite) Test_ValidResharingProcess_OldAndNewSubset() { } communicationMap[host.ID()] = &communication storer := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", i)) - resharing := resharing.NewResharing("resharing2", "", 1, host, &communication, storer) + share, err := storer.GetKeyshare("") + s.MockFrostStorer.EXPECT().LockKeyshare() + s.MockFrostStorer.EXPECT().UnlockKeyshare() + s.MockFrostStorer.EXPECT().GetKeyshare("").Return(share, err) + s.MockFrostStorer.EXPECT().StoreKeyshare(gomock.Any()).Return(nil) + resharing := resharing.NewResharing("resharing2", "", 1, host, &communication, s.MockFrostStorer) electorFactory := elector.NewCoordinatorElectorFactory(host, s.BullyConfig) coordinators = append(coordinators, tss.NewCoordinator(host, &communication, electorFactory)) processes = append(processes, resharing) @@ -94,7 +100,12 @@ func (s *ResharingTestSuite) Test_ValidResharingProcess_RemovePeer() { } communicationMap[host.ID()] = &communication storer := keyshare.NewFrostKeyshareStore(fmt.Sprintf("../../test/keyshares/%d-frost.keyshare", i)) - resharing := resharing.NewResharing("resharing2", "", 1, host, &communication, storer) + share, err := storer.GetKeyshare("") + s.MockFrostStorer.EXPECT().LockKeyshare() + s.MockFrostStorer.EXPECT().UnlockKeyshare() + s.MockFrostStorer.EXPECT().GetKeyshare("").Return(share, err) + s.MockFrostStorer.EXPECT().StoreKeyshare(gomock.Any()).Return(nil) + resharing := resharing.NewResharing("resharing2", "", 1, host, &communication, s.MockFrostStorer) electorFactory := elector.NewCoordinatorElectorFactory(host, s.BullyConfig) coordinators = append(coordinators, tss.NewCoordinator(host, &communication, electorFactory)) processes = append(processes, resharing) From 3e72180d24197bbcc933c82725ddaa311cf6e4e7 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Mon, 2 Sep 2024 17:44:40 +0200 Subject: [PATCH 4/4] Remove frost keyshare storer from refresh event handler --- app/app.go | 2 +- chains/evm/listener/eventHandlers/event-handler.go | 4 ---- example/app/app.go | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/app.go b/app/app.go index ac7e8612..9aad7af6 100644 --- a/app/app.go +++ b/app/app.go @@ -225,7 +225,7 @@ func Run() error { eventHandlers = append(eventHandlers, hubEventHandlers.NewDepositEventHandler(depositListener, depositHandler, bridgeAddress, *config.GeneralChainConfig.Id, msgChan)) eventHandlers = append(eventHandlers, hubEventHandlers.NewKeygenEventHandler(l, tssListener, coordinator, host, communication, keyshareStore, bridgeAddress, networkTopology.Threshold)) eventHandlers = append(eventHandlers, hubEventHandlers.NewFrostKeygenEventHandler(l, tssListener, coordinator, host, communication, frostKeyshareStore, frostAddress, networkTopology.Threshold)) - eventHandlers = append(eventHandlers, hubEventHandlers.NewRefreshEventHandler(l, topologyProvider, topologyStore, tssListener, coordinator, host, communication, connectionGate, keyshareStore, frostKeyshareStore, bridgeAddress)) + eventHandlers = append(eventHandlers, hubEventHandlers.NewRefreshEventHandler(l, topologyProvider, topologyStore, tssListener, coordinator, host, communication, connectionGate, keyshareStore, bridgeAddress)) eventHandlers = append(eventHandlers, hubEventHandlers.NewRetryEventHandler(l, tssListener, depositHandler, propStore, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations, msgChan)) evmListener := listener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval) executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64()) diff --git a/chains/evm/listener/eventHandlers/event-handler.go b/chains/evm/listener/eventHandlers/event-handler.go index d3c155f6..0af8a2fd 100644 --- a/chains/evm/listener/eventHandlers/event-handler.go +++ b/chains/evm/listener/eventHandlers/event-handler.go @@ -26,7 +26,6 @@ import ( "github.com/ChainSafe/sygma-relayer/tss/ecdsa/keygen" "github.com/ChainSafe/sygma-relayer/tss/ecdsa/resharing" frostKeygen "github.com/ChainSafe/sygma-relayer/tss/frost/keygen" - frostResharing "github.com/ChainSafe/sygma-relayer/tss/frost/resharing" "github.com/ethereum/go-ethereum/common" ethTypes "github.com/ethereum/go-ethereum/core/types" "github.com/libp2p/go-libp2p/core/host" @@ -311,7 +310,6 @@ type RefreshEventHandler struct { communication comm.Communication connectionGate *p2p.ConnectionGate ecdsaStorer resharing.SaveDataStorer - frostStorer frostResharing.FrostKeyshareStorer } func NewRefreshEventHandler( @@ -324,7 +322,6 @@ func NewRefreshEventHandler( communication comm.Communication, connectionGate *p2p.ConnectionGate, ecdsaStorer resharing.SaveDataStorer, - frostStorer frostResharing.FrostKeyshareStorer, bridgeAddress common.Address, ) *RefreshEventHandler { return &RefreshEventHandler{ @@ -336,7 +333,6 @@ func NewRefreshEventHandler( host: host, communication: communication, ecdsaStorer: ecdsaStorer, - frostStorer: frostStorer, connectionGate: connectionGate, bridgeAddress: bridgeAddress, } diff --git a/example/app/app.go b/example/app/app.go index 9e5568a3..31b76cd1 100644 --- a/example/app/app.go +++ b/example/app/app.go @@ -197,7 +197,7 @@ func Run() error { eventHandlers = append(eventHandlers, hubEventHandlers.NewDepositEventHandler(depositListener, depositHandler, bridgeAddress, *config.GeneralChainConfig.Id, msgChan)) eventHandlers = append(eventHandlers, hubEventHandlers.NewKeygenEventHandler(l, tssListener, coordinator, host, communication, keyshareStore, bridgeAddress, networkTopology.Threshold)) eventHandlers = append(eventHandlers, hubEventHandlers.NewFrostKeygenEventHandler(l, tssListener, coordinator, host, communication, frostKeyshareStore, frostAddress, networkTopology.Threshold)) - eventHandlers = append(eventHandlers, hubEventHandlers.NewRefreshEventHandler(l, nil, nil, tssListener, coordinator, host, communication, connectionGate, keyshareStore, frostKeyshareStore, bridgeAddress)) + eventHandlers = append(eventHandlers, hubEventHandlers.NewRefreshEventHandler(l, nil, nil, tssListener, coordinator, host, communication, connectionGate, keyshareStore, bridgeAddress)) eventHandlers = append(eventHandlers, hubEventHandlers.NewRetryEventHandler(l, tssListener, depositHandler, propStore, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations, msgChan)) evmListener := listener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval) executor := executor.NewExecutor(host, communication, coordinator, bridgeContract, keyshareStore, exitLock, config.GasLimit.Uint64())