diff --git a/input/script_utils.go b/input/script_utils.go index 8a5a0df6..8b47b056 100644 --- a/input/script_utils.go +++ b/input/script_utils.go @@ -902,13 +902,15 @@ func CommitSpendRevoke(signer Signer, signDesc *SignDescriptor, } // CommitSpendNoDelay constructs a valid witness allowing a node to spend their -// settled no-delay output on the counterparty's commitment transaction. +// settled no-delay output on the counterparty's commitment transaction. If the +// tweakless field is true, then we'll omit the set where we tweak the pubkey +// with a random set of bytes, and use it directly in the witness stack. // // NOTE: The passed SignDescriptor should include the raw (untweaked) public // key of the receiver and also the proper single tweak value based on the // current commitment point. func CommitSpendNoDelay(signer Signer, signDesc *SignDescriptor, - sweepTx *wire.MsgTx) (wire.TxWitness, error) { + sweepTx *wire.MsgTx, tweakless bool) (wire.TxWitness, error) { if signDesc.KeyDesc.PubKey == nil { return nil, fmt.Errorf("cannot generate witness with nil " + @@ -923,14 +925,25 @@ func CommitSpendNoDelay(signer Signer, signDesc *SignDescriptor, } // Finally, we'll manually craft the witness. The witness here is the - // exact same as a regular p2wkh witness, but we'll need to ensure that - // we use the tweaked public key as the last item in the witness stack - // which was originally used to created the pkScript we're spending. + // exact same as a regular p2wkh witness, depending on the value of the + // tweakless bool. witness := make([][]byte, 2) witness[0] = append(sweepSig, byte(signDesc.HashType)) - witness[1] = TweakPubKeyWithTweak( - signDesc.KeyDesc.PubKey, signDesc.SingleTweak, - ).SerializeCompressed() + + switch tweakless { + // If we're tweaking the key, then we use the tweaked public key as the + // last item in the witness stack which was originally used to created + // the pkScript we're spending. + case false: + witness[1] = TweakPubKeyWithTweak( + signDesc.KeyDesc.PubKey, signDesc.SingleTweak, + ).SerializeCompressed() + + // Otherwise, we can just use the raw pubkey, since there's no random + // value to be combined. + case true: + witness[1] = signDesc.KeyDesc.PubKey.SerializeCompressed() + } return witness, nil } diff --git a/input/witnessgen.go b/input/witnessgen.go index 32e547c6..28a02d08 100644 --- a/input/witnessgen.go +++ b/input/witnessgen.go @@ -79,6 +79,11 @@ const ( // output that sends to a nested P2SH script that pays to a key solely // under our control. The witness generated needs to include the NestedWitnessKeyHash WitnessType = 11 + + // CommitSpendNoDelayTweakless is similar to the CommitSpendNoDelay + // type, but it omits the tweak that randomizes the key we need to + // spend with a channel peer supplied set of randomness. + CommitSpendNoDelayTweakless = 12 ) // Stirng returns a human readable version of the target WitnessType. @@ -90,6 +95,9 @@ func (wt WitnessType) String() string { case CommitmentNoDelay: return "CommitmentNoDelay" + case CommitSpendNoDelayTweakless: + return "CommitmentNoDelayTweakless" + case CommitmentRevoke: return "CommitmentRevoke" @@ -153,7 +161,17 @@ func (wt WitnessType) GenWitnessFunc(signer Signer, }, nil case CommitmentNoDelay: - witness, err := CommitSpendNoDelay(signer, desc, tx) + witness, err := CommitSpendNoDelay(signer, desc, tx, false) + if err != nil { + return nil, err + } + + return &Script{ + Witness: witness, + }, nil + + case CommitSpendNoDelayTweakless: + witness, err := CommitSpendNoDelay(signer, desc, tx, true) if err != nil { return nil, err } diff --git a/sweep/txgenerator.go b/sweep/txgenerator.go index 26a4503e..a06dad96 100644 --- a/sweep/txgenerator.go +++ b/sweep/txgenerator.go @@ -259,6 +259,8 @@ func getInputWitnessSizeUpperBound(inp input.Input) (int, bool, error) { switch inp.WitnessType() { // Outputs on a remote commitment transaction that pay directly to us. + case input.CommitSpendNoDelayTweakless: + fallthrough case input.WitnessKeyHash: fallthrough case input.CommitmentNoDelay: