@@ -11,9 +11,12 @@ import (
1111 "github.com/lightningnetwork/lnd/lntypes"
1212)
1313
14- // GenSuccessPathScript constructs an HtlcScript for the success payment path.
14+ // GenSuccessPathScript constructs a script for the success path of the HTLC
15+ // payment. Optionally includes a CHECKSEQUENCEVERIFY (CSV) of 1 if `csv` is
16+ // true, to prevent potential pinning attacks when the HTLC is not part of a
17+ // package relay.
1518func GenSuccessPathScript (receiverHtlcKey * btcec.PublicKey ,
16- swapHash lntypes.Hash ) ([]byte , error ) {
19+ swapHash lntypes.Hash , csv bool ) ([]byte , error ) {
1720
1821 builder := txscript .NewScriptBuilder ()
1922
@@ -25,8 +28,11 @@ func GenSuccessPathScript(receiverHtlcKey *btcec.PublicKey,
2528 builder .AddOp (txscript .OP_HASH160 )
2629 builder .AddData (input .Ripemd160H (swapHash [:]))
2730 builder .AddOp (txscript .OP_EQUALVERIFY )
28- //builder.AddInt64(1)
29- //builder.AddOp(txscript.OP_CHECKSEQUENCEVERIFY)
31+
32+ if csv {
33+ builder .AddInt64 (1 )
34+ builder .AddOp (txscript .OP_CHECKSEQUENCEVERIFY )
35+ }
3036
3137 return builder .Script ()
3238}
@@ -61,7 +67,9 @@ func CreateOpTrueLeaf() (asset.ScriptKey, txscript.TapLeaf,
6167 tapLeaf := txscript .NewBaseTapLeaf (tapScript )
6268 tree := txscript .AssembleTaprootScriptTree (tapLeaf )
6369 rootHash := tree .RootNode .TapHash ()
64- tapKey := txscript .ComputeTaprootOutputKey (asset .NUMSPubKey , rootHash [:])
70+ tapKey := txscript .ComputeTaprootOutputKey (
71+ asset .NUMSPubKey , rootHash [:],
72+ )
6573
6674 merkleRootHash := tree .RootNode .TapHash ()
6775
0 commit comments