Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: schnorr signature hash missing leading zeroes #341

Merged
merged 1 commit into from
Jul 24, 2024
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
7 changes: 2 additions & 5 deletions chains/btc/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/hex"
"fmt"
"math/big"
"sync"
"time"

Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions tss/frost/signing/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}

Expand Down
21 changes: 7 additions & 14 deletions tss/frost/signing/signing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"context"
"encoding/hex"
"fmt"
"math/big"
"testing"
"time"

Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down
Loading