From a393362eb86d142be94f3acc1fe5d71773a662e0 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 3 Feb 2017 15:28:13 -0800 Subject: [PATCH] lnwallet: ensure CSV delay witness spend uses a minimal OP_IF This commit fixes a slight scripting related issue as a result of default policy in Bitcoin Core 0.13.1. With this version of Bitcoin Core, nodes will now enforce a policy that ensures the first argument of OP_IF is either an empty vector or a 0x01 value. Our current sent of functions to generate the witness for the delay clause of the commitment transaction instead uses a 0x00 value rather than an empty byte vector. With this commit we fix the issue by ensuring that we use an empty vector rather an 0x00 for forcing the commitment delay script pathway. --- lnwallet/script_utils.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lnwallet/script_utils.go b/lnwallet/script_utils.go index 1dae5348a..dc4f853a4 100644 --- a/lnwallet/script_utils.go +++ b/lnwallet/script_utils.go @@ -554,7 +554,7 @@ func lockTimeToSequence(isSeconds bool, locktime uint32) uint32 { // // Possible Input Scripts: // REVOKE: 1 -// SENDRSWEEP: 0 +// SENDRSWEEP: // // Output Script: // OP_IF @@ -630,11 +630,13 @@ func CommitSpendTimeout(signer Signer, signDesc *SignDescriptor, return nil, err } - // Place a zero as the first item in the evaluated witness stack to - // force script execution to the timeout spend clause. + // Place an empty byte as the first item in the evaluated witness stack + // to force script execution to the timeout spend clause. We need to + // place an empty byte in order to ensure our script is still valid + // from the PoV of nodes that are enforcing minimal OP_IF/OP_NOTIF. witnessStack := wire.TxWitness(make([][]byte, 3)) witnessStack[0] = append(sweepSig, byte(txscript.SigHashAll)) - witnessStack[1] = []byte{0} + witnessStack[1] = nil witnessStack[2] = signDesc.WitnessScript return witnessStack, nil