loopout: add unit test for the MuSig2 sweep case

This commit is contained in:
Andras Banki-Horvath 2022-06-24 13:57:42 +02:00
parent 82b58e5c0e
commit 5d7b0abdf5
No known key found for this signature in database
GPG key ID: 80E5375C094198D8
6 changed files with 244 additions and 37 deletions

View file

@ -10,7 +10,7 @@ import (
"sync"
"time"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@ -96,6 +96,7 @@ type executeConfig struct {
totalPaymentTimout time.Duration
maxPaymentRetries int
cancelSwap func(context.Context, *outCancelDetails) error
verifySchnorrSig func(pubKey *btcec.PublicKey, hash, sig []byte) error
}
// loopOutInitResult contains information about a just-initiated loop out swap.
@ -1437,15 +1438,13 @@ func (s *loopOutSwap) createMuSig2SweepTxn(
// To be sure that we're good, parse and validate that the combined
// signature is indeed valid for the sig hash and the internal pubkey.
sig, err := schnorr.ParseSignature(finalSig)
err = s.executeConfig.verifySchnorrSig(
htlc.TaprootKey, sigHash, finalSig,
)
if err != nil {
return nil, err
}
if !sig.Verify(sigHash, htlc.TaprootKey) {
return nil, fmt.Errorf("invalid combined signature")
}
// Now that we know the signature is correct, we can fill it in to our
// witness.
sweepTx.TxIn[0].Witness = wire.TxWitness{