Skip to content

Commit 763d774

Browse files
committed
lnwallet: return structured error from VerifyCommitSig
1 parent 6ec341f commit 763d774

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

lnwallet/musig_session.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,23 @@ func WithLocalCounterNonce(targetHeight uint64,
408408
}
409409
}
410410

411+
// invalidPartialSigError is used to return additional debug information to a
412+
// caller that encounters an invalid partial sig.
413+
type invalidPartialSigError struct {
414+
partialSig []byte
415+
sigHash []byte
416+
signingNonce [musig2.PubNonceSize]byte
417+
verificationNonce [musig2.PubNonceSize]byte
418+
}
419+
420+
// Error returns the error string for the partial sig error.
421+
func (i invalidPartialSigError) Error() string {
422+
return fmt.Sprintf("invalid partial sig: partial_sig=%x, "+
423+
"sig_hash=%x, signing_nonce=%x, verification_nonce=%x",
424+
i.partialSig, i.sigHash, i.signingNonce[:],
425+
i.verificationNonce[:])
426+
}
427+
411428
// VerifyCommitSig attempts to verify the passed partial signature against the
412429
// passed commitment transaction. A keyspend sighash is assumed to generate the
413430
// signed message. As we never re-use nonces, a new verification nonce (our
@@ -450,8 +467,17 @@ func (m *MusigSession) VerifyCommitSig(commitTx *wire.MsgTx,
450467
walletLog.Infof("Verifying new musig2 sig for session=%x, nonce=%s",
451468
m.session.SessionID[:], m.nonces.String())
452469

470+
if partialSig == nil {
471+
return nil, fmt.Errorf("partial sig not set")
472+
}
473+
453474
if !partialSig.Verify(sigHash, m.remoteKey.PubKey) {
454-
return nil, fmt.Errorf("invalid partial commit sig")
475+
return nil, &invalidPartialSigError{
476+
partialSig: partialSig.Serialize(),
477+
sigHash: sigHash,
478+
verificationNonce: m.nonces.VerificationNonce.PubNonce,
479+
signingNonce: m.nonces.SigningNonce.PubNonce,
480+
}
455481
}
456482

457483
nonceOpts := []musig2.NonceGenOption{

0 commit comments

Comments
 (0)