Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/mocks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "^1.23"

- run: go install github.com/golang/mock/mockgen@v1.6.0
- run: go install go.uber.org/mock/mockgen@v0.5.0

- run: make genmocks

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: '1.19'
go-version: '1.23'

- name: Build
run: make build-all
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test:
genmocks:
mockgen -destination=./tss/ecdsa/common/mock/tss.go github.com/binance-chain/tss-lib/tss Message
mockgen -destination=./tss/ecdsa/common/mock/communication.go -source=./tss/ecdsa/common/base.go -package mock_tss
mockgen -destination=./tss/ecdsa/common/mock/fetcher.go -source=./tss/ecdsa/signing/signing.go -package mock_tss
mockgen --package mock_tss -destination=./tss/mock/ecdsa.go -source=./tss/ecdsa/keygen/keygen.go
mockgen -source=./tss/coordinator.go -destination=./tss/mock/coordinator.go
mockgen -source=./comm/communication.go -destination=./comm/mock/communication.go
Expand All @@ -34,6 +35,7 @@ genmocks:
mockgen -destination=./comm/p2p/mock/host/host.go github.com/libp2p/go-libp2p/core/host Host
mockgen -destination=./comm/p2p/mock/conn/conn.go github.com/libp2p/go-libp2p/core/network Conn
mockgen -destination=./comm/p2p/mock/stream/stream.go github.com/libp2p/go-libp2p/core/network Stream,Conn
mockgen -source=./chains/evm/message/across.go -destination=./chains/evm/message/mock/across.go



Expand Down
78 changes: 78 additions & 0 deletions cache/signature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package cache

import (
"context"
"fmt"
"time"

"github.com/jellydator/ttlcache/v3"
"github.com/rs/zerolog/log"
"github.com/sprintertech/sprinter-signing/comm"
"github.com/sprintertech/sprinter-signing/tss/ecdsa/signing"
"github.com/sprintertech/sprinter-signing/tss/message"
)

const (
SIGNATURE_TTL = time.Minute * 10
)

type SignatureCache struct {
sigCache *ttlcache.Cache[string, []byte]
comm comm.Communication
}

func NewSignatureCache(ctx context.Context, c comm.Communication, sigChn chan interface{}) *SignatureCache {
cache := ttlcache.New(
ttlcache.WithTTL[string, []byte](SIGNATURE_TTL),
)

sc := &SignatureCache{
sigCache: cache,
comm: c,
}

go sc.watch(ctx, sigChn)
go cache.Start()
return sc
}

func (s *SignatureCache) Signature(id string) ([]byte, error) {
sig := s.sigCache.Get(id)
if sig == nil {
return []byte{}, fmt.Errorf("no signature found with id %s", id)
}

return sig.Value(), nil
}

func (s *SignatureCache) watch(ctx context.Context, sigChn chan interface{}) {
msgChn := make(chan *comm.WrappedMessage)
subID := s.comm.Subscribe(comm.SignatureSessionID, comm.SignatureMsg, msgChn)

for {
select {
case sig := <-sigChn:
{
sig := sig.(signing.EcdsaSignature)
s.sigCache.Set(sig.ID, sig.Signature, ttlcache.DefaultTTL)
}
case msg := <-msgChn:
{
msg, err := message.UnmarshalSignatureMessage(msg.Payload)
if err != nil {
log.Warn().Msgf("Failed to unmarshal signature message: %s", err)
continue
}

log.Debug().Msgf("Received signature for ID: %s", msg.ID)
s.sigCache.Set(msg.ID, msg.Signature, ttlcache.DefaultTTL)
}
case <-ctx.Done():
{
s.sigCache.Stop()
s.comm.UnSubscribe(subID)
return
}
}
}
}
90 changes: 90 additions & 0 deletions cache/signature_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package cache_test

import (
"context"
"testing"
"time"

"github.com/sprintertech/sprinter-signing/cache"
"github.com/sprintertech/sprinter-signing/comm"
mock_communication "github.com/sprintertech/sprinter-signing/comm/mock"
"github.com/sprintertech/sprinter-signing/tss/ecdsa/signing"
"github.com/sprintertech/sprinter-signing/tss/message"
"github.com/stretchr/testify/suite"
"go.uber.org/mock/gomock"
)

type SignatureCacheTestSuite struct {
suite.Suite

sc *cache.SignatureCache
mockCommunication *mock_communication.MockCommunication
cancel context.CancelFunc
sigChn chan interface{}
msgChn chan *comm.WrappedMessage
}

func TestRunSignatureCacheTestSuite(t *testing.T) {
suite.Run(t, new(SignatureCacheTestSuite))
}

func (s *SignatureCacheTestSuite) SetupTest() {
ctrl := gomock.NewController(s.T())

s.sigChn = make(chan interface{}, 1)

s.mockCommunication = mock_communication.NewMockCommunication(ctrl)
s.mockCommunication.EXPECT().Subscribe(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn(func(sessionID string, msgType comm.MessageType, channel chan *comm.WrappedMessage) comm.SubscriptionID {
s.msgChn = channel
return comm.NewSubscriptionID("ID", comm.SignatureMsg)
})
s.mockCommunication.EXPECT().UnSubscribe(gomock.Any()).AnyTimes()

ctx, cancel := context.WithCancel(context.Background())
s.cancel = cancel

s.sc = cache.NewSignatureCache(ctx, s.mockCommunication, s.sigChn)
time.Sleep(time.Millisecond * 100)
}
func (s *SignatureCacheTestSuite) TearDownTest() {
s.cancel()
}

func (s *SignatureCacheTestSuite) Test_Signature_MissingSignature() {
_, err := s.sc.Signature("invalid")

s.NotNil(err)
}

func (s *SignatureCacheTestSuite) Test_Signature_ValidSignatureResult() {
expectedSig := signing.EcdsaSignature{
Signature: []byte("signature"),
ID: "signatureID",
}
s.sigChn <- expectedSig
time.Sleep(time.Millisecond * 100)

sig, err := s.sc.Signature(expectedSig.ID)

s.Nil(err)
s.Equal(sig, expectedSig.Signature)
}

func (s *SignatureCacheTestSuite) Test_Signature_ValidMessage() {
expectedSig := signing.EcdsaSignature{
Signature: []byte("signature"),
ID: "signatureID",
}
wMsgBytes, _ := message.MarshalSignatureMessage(expectedSig.ID, expectedSig.Signature)
wMsg := &comm.WrappedMessage{
Payload: wMsgBytes,
}

s.msgChn <- wMsg
time.Sleep(time.Millisecond * 100)

sig, err := s.sc.Signature(expectedSig.ID)

s.Nil(err)
s.Equal(sig, expectedSig.Signature)
}
182 changes: 182 additions & 0 deletions chains/evm/calls/consts/across.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package consts

import (
"strings"

"github.com/ethereum/go-ethereum/accounts/abi"
)

var SpokePoolABI, _ = abi.JSON(strings.NewReader(`
[
{
"inputs": [
{
"components": [
{
"internalType": "bytes32",
"name": "depositor",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "recipient",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "exclusiveRelayer",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "inputToken",
"type": "bytes32"
},
{
"internalType": "bytes32",
"name": "outputToken",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "inputAmount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "outputAmount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "originChainId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "depositId",
"type": "uint256"
},
{
"internalType": "uint32",
"name": "fillDeadline",
"type": "uint32"
},
{
"internalType": "uint32",
"name": "exclusivityDeadline",
"type": "uint32"
},
{
"internalType": "bytes",
"name": "message",
"type": "bytes"
}
],
"internalType": "struct V3SpokePoolInterface.V3RelayData",
"name": "relayData",
"type": "tuple"
},
{
"internalType": "uint256",
"name": "repaymentChainId",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "repaymentAddress",
"type": "bytes32"
}
],
"name": "fillRelay",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bytes32",
"name": "inputToken",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "outputToken",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "uint256",
"name": "inputAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "outputAmount",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint256",
"name": "destinationChainId",
"type": "uint256"
},
{
"indexed": true,
"internalType": "uint256",
"name": "depositId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint32",
"name": "quoteTimestamp",
"type": "uint32"
},
{
"indexed": false,
"internalType": "uint32",
"name": "fillDeadline",
"type": "uint32"
},
{
"indexed": false,
"internalType": "uint32",
"name": "exclusivityDeadline",
"type": "uint32"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "depositor",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "recipient",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "exclusiveRelayer",
"type": "bytes32"
},
{
"indexed": false,
"internalType": "bytes",
"name": "message",
"type": "bytes"
}
],
"name": "FundsDeposited",
"type": "event"
}
]
`))
Loading
Loading