From 2dd399ca523888b368faf19dd887c464d0dec51d Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Tue, 30 Oct 2018 01:22:30 -0700 Subject: [PATCH] watchtower/blob/justice_kit: return DER signatures This commit fixes an issue with the witness stack construction for to-local and to-remote inputs, that would cause the justice kit to return signatures as fixed-size, 64-byte signatures. The correct behavior is to return DER-encoded signatures so that they will properly verify on the network, since the consensus rules won't be able to understand the fixed-size variant. --- watchtower/blob/justice_kit.go | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/watchtower/blob/justice_kit.go b/watchtower/blob/justice_kit.go index e436fdbb..3030356e 100644 --- a/watchtower/blob/justice_kit.go +++ b/watchtower/blob/justice_kit.go @@ -180,12 +180,18 @@ func (b *JusticeKit) CommitToLocalWitnessScript() ([]byte, error) { // CommitToLocalRevokeWitnessStack constructs a witness stack spending the // revocation clause of the commitment to-local output. // 1 -func (b *JusticeKit) CommitToLocalRevokeWitnessStack() [][]byte { +func (b *JusticeKit) CommitToLocalRevokeWitnessStack() ([][]byte, error) { + toLocalSig, err := b.CommitToLocalSig.ToSignature() + if err != nil { + return nil, err + } + witnessStack := make([][]byte, 2) - witnessStack[0] = append(b.CommitToLocalSig[:], byte(txscript.SigHashAll)) + witnessStack[0] = append(toLocalSig.Serialize(), + byte(txscript.SigHashAll)) witnessStack[1] = []byte{1} - return witnessStack + return witnessStack, nil } // HasCommitToRemoteOutput returns true if the blob contains a to-remote p2wkh @@ -207,11 +213,17 @@ func (b *JusticeKit) CommitToRemoteWitnessScript() ([]byte, error) { // CommitToRemoteWitnessStack returns a witness stack spending the commitment // to-remote output, which is a regular p2wkh. // -func (b *JusticeKit) CommitToRemoteWitnessStack() [][]byte { - witnessStack := make([][]byte, 1) - witnessStack[0] = append(b.CommitToRemoteSig[:], byte(txscript.SigHashAll)) +func (b *JusticeKit) CommitToRemoteWitnessStack() ([][]byte, error) { + toRemoteSig, err := b.CommitToRemoteSig.ToSignature() + if err != nil { + return nil, err + } - return witnessStack + witnessStack := make([][]byte, 1) + witnessStack[0] = append(toRemoteSig.Serialize(), + byte(txscript.SigHashAll)) + + return witnessStack, nil } // Encrypt encodes the blob of justice using encoding version, and then