From 0f3b0d7176bb58f589b3457741a726c751650047 Mon Sep 17 00:00:00 2001 From: mpetrun5 Date: Tue, 23 Jul 2024 16:37:42 +0200 Subject: [PATCH] fix: schnorr signature hash missing leading zeroes --- chains/btc/executor/executor.go | 7 ++----- tss/frost/signing/signing.go | 9 ++++----- tss/frost/signing/signing_test.go | 21 +++++++-------------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/chains/btc/executor/executor.go b/chains/btc/executor/executor.go index 1f18d875..a1a75e02 100644 --- a/chains/btc/executor/executor.go +++ b/chains/btc/executor/executor.go @@ -4,7 +4,6 @@ import ( "context" "encoding/hex" "fmt" - "math/big" "sync" "time" @@ -163,15 +162,13 @@ func (e *Executor) executeResourceProps(props []*BtcTransferProposal, resource c tssProcesses := make([]tss.TssProcess, len(tx.TxIn)) for i := range tx.TxIn { sessionID := fmt.Sprintf("%s-%d", sessionID, i) - txHash, err := txscript.CalcTaprootSignatureHash(sigHashes, txscript.SigHashDefault, tx, i, prevOutputFetcher) + signingHash, err := txscript.CalcTaprootSignatureHash(sigHashes, txscript.SigHashDefault, tx, i, prevOutputFetcher) if err != nil { return err } - msg := new(big.Int) - msg.SetBytes(txHash[:]) signing, err := signing.NewSigning( i, - msg, + signingHash, resource.Tweak, messageID, sessionID, diff --git a/tss/frost/signing/signing.go b/tss/frost/signing/signing.go index c4f07f46..40699999 100644 --- a/tss/frost/signing/signing.go +++ b/tss/frost/signing/signing.go @@ -7,7 +7,6 @@ import ( "context" "encoding/hex" "encoding/json" - "math/big" errors "github.com/ChainSafe/sygma-relayer/tss" "github.com/binance-chain/tss-lib/tss" @@ -43,14 +42,14 @@ type Signing struct { id int coordinator bool key keyshare.FrostKeyshare - msg *big.Int + msg []byte resultChn chan interface{} subscriptionID comm.SubscriptionID } func NewSigning( id int, - msg *big.Int, + msg []byte, tweak string, messageID string, sessionID string, @@ -123,7 +122,7 @@ func (s *Signing) Run( frost.SignTaproot( s.key.Key, common.PartyIDSFromPeers(peerSubset), - s.msg.Bytes(), + s.msg, ), []byte(s.SessionID())) if err != nil { @@ -136,7 +135,7 @@ func (s *Signing) Run( p.Go(func(ctx context.Context) error { return s.processEndMessage(ctx) }) p.Go(func(ctx context.Context) error { return s.ProcessOutboundMessages(ctx, outChn, comm.TssKeySignMsg) }) - s.Log.Info().Msgf("Started signing process for message %s", s.msg.Text(16)) + s.Log.Info().Msgf("Started signing process for message %s", hex.EncodeToString(s.msg)) return p.Wait() } diff --git a/tss/frost/signing/signing_test.go b/tss/frost/signing/signing_test.go index ae8b3e56..d90178fc 100644 --- a/tss/frost/signing/signing_test.go +++ b/tss/frost/signing/signing_test.go @@ -7,7 +7,6 @@ import ( "context" "encoding/hex" "fmt" - "math/big" "testing" "time" @@ -50,8 +49,6 @@ func (s *SigningTestSuite) Test_ValidSigningProcess() { s.Nil(err) msgBytes := []byte("Message") - msg := big.NewInt(0) - msg.SetBytes(msgBytes) for i, host := range s.Hosts { communication := tsstest.TestCommunication{ Host: host, @@ -60,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, msg, tweak, "signing1", "signing1", host, &communication, fetcher) + signing, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) if err != nil { panic(err) } @@ -85,8 +82,8 @@ func (s *SigningTestSuite) Test_ValidSigningProcess() { sig2 := <-resultChn tSig1 := sig1.(signing.Signature) tSig2 := sig2.(signing.Signature) - s.Equal(tweakedKeyshare.PublicKey.Verify(tSig1.Signature, msg.Bytes()), true) - s.Equal(tweakedKeyshare.PublicKey.Verify(tSig2.Signature, msg.Bytes()), true) + s.Equal(tweakedKeyshare.PublicKey.Verify(tSig1.Signature, msgBytes), true) + s.Equal(tweakedKeyshare.PublicKey.Verify(tSig2.Signature, msgBytes), true) cancel() err = pool.Wait() s.Nil(err) @@ -105,8 +102,6 @@ func (s *SigningTestSuite) Test_MultipleProcesses() { s.Nil(err) msgBytes := []byte("Message") - msg := big.NewInt(0) - msg.SetBytes(msgBytes) for i, host := range s.Hosts { communication := tsstest.TestCommunication{ Host: host, @@ -115,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, msg, 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, msg, 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, msg, tweak, "signing1", "signing3", host, &communication, fetcher) + signing3, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing3", host, &communication, fetcher) if err != nil { panic(err) } @@ -173,8 +168,6 @@ func (s *SigningTestSuite) Test_ProcessTimeout() { s.Nil(err) msgBytes := []byte("Message") - msg := big.NewInt(0) - msg.SetBytes(msgBytes) for i, host := range s.Hosts { communication := tsstest.TestCommunication{ Host: host, @@ -183,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, msg, tweak, "signing1", "signing1", host, &communication, fetcher) + signing, err := signing.NewSigning(1, msgBytes, tweak, "signing1", "signing1", host, &communication, fetcher) if err != nil { panic(err) }