diff --git a/lnwallet/script_utils.go b/lnwallet/script_utils.go index 03a60c7ec..b7cc5ed4e 100644 --- a/lnwallet/script_utils.go +++ b/lnwallet/script_utils.go @@ -821,11 +821,12 @@ func lockTimeToSequence(isSeconds bool, locktime uint32) uint32 { // // Output Script: // OP_IF -// OP_CHECKSIG +// // OP_ELSE -// OP_CHECKSIGVERIFY -// OP_CHECKSEQUENCEVERIFY +// OP_CHECKSEQUENCEVERIFY OP_DROP +// // OP_ENDIF +// OP_CHECKSIG func commitScriptToSelf(csvTimeout uint32, selfKey, revokeKey *btcec.PublicKey) ([]byte, error) { // This script is spendable under two conditions: either the // 'csvTimeout' has passed and we can redeem our funds, or they can @@ -841,19 +842,22 @@ func commitScriptToSelf(csvTimeout uint32, selfKey, revokeKey *btcec.PublicKey) // If a valid signature using the revocation key is presented, then // allow an immediate spend provided the proper signature. builder.AddData(revokeKey.SerializeCompressed()) - builder.AddOp(txscript.OP_CHECKSIG) builder.AddOp(txscript.OP_ELSE) // Otherwise, we can re-claim our funds after a CSV delay of // 'csvTimeout' timeout blocks, and a valid signature. - builder.AddData(selfKey.SerializeCompressed()) - builder.AddOp(txscript.OP_CHECKSIGVERIFY) builder.AddInt64(int64(csvTimeout)) builder.AddOp(txscript.OP_CHECKSEQUENCEVERIFY) + builder.AddOp(txscript.OP_DROP) + builder.AddData(selfKey.SerializeCompressed()) builder.AddOp(txscript.OP_ENDIF) + // Finally, we'll validate the signature against the public key that's + // left on the top of the stack. + builder.AddOp(txscript.OP_CHECKSIG) + return builder.Script() }