Skip to content

Commit

Permalink
lnwallet: return structured error from VerifyCommitSig
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Jul 3, 2023
1 parent 6ec341f commit 763d774
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lnwallet/musig_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,23 @@ func WithLocalCounterNonce(targetHeight uint64,
}
}

// invalidPartialSigError is used to return additional debug information to a
// caller that encounters an invalid partial sig.
type invalidPartialSigError struct {
partialSig []byte
sigHash []byte
signingNonce [musig2.PubNonceSize]byte
verificationNonce [musig2.PubNonceSize]byte
}

// Error returns the error string for the partial sig error.
func (i invalidPartialSigError) Error() string {
return fmt.Sprintf("invalid partial sig: partial_sig=%x, "+
"sig_hash=%x, signing_nonce=%x, verification_nonce=%x",
i.partialSig, i.sigHash, i.signingNonce[:],
i.verificationNonce[:])
}

// VerifyCommitSig attempts to verify the passed partial signature against the
// passed commitment transaction. A keyspend sighash is assumed to generate the
// signed message. As we never re-use nonces, a new verification nonce (our
Expand Down Expand Up @@ -450,8 +467,17 @@ func (m *MusigSession) VerifyCommitSig(commitTx *wire.MsgTx,
walletLog.Infof("Verifying new musig2 sig for session=%x, nonce=%s",
m.session.SessionID[:], m.nonces.String())

if partialSig == nil {
return nil, fmt.Errorf("partial sig not set")
}

if !partialSig.Verify(sigHash, m.remoteKey.PubKey) {
return nil, fmt.Errorf("invalid partial commit sig")
return nil, &invalidPartialSigError{
partialSig: partialSig.Serialize(),
sigHash: sigHash,
verificationNonce: m.nonces.VerificationNonce.PubNonce,
signingNonce: m.nonces.SigningNonce.PubNonce,
}
}

nonceOpts := []musig2.NonceGenOption{
Expand Down

0 comments on commit 763d774

Please sign in to comment.