@@ -11,9 +11,12 @@ import (
11
11
"github.com/lightningnetwork/lnd/lntypes"
12
12
)
13
13
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.
15
18
func GenSuccessPathScript (receiverHtlcKey * btcec.PublicKey ,
16
- swapHash lntypes.Hash ) ([]byte , error ) {
19
+ swapHash lntypes.Hash , csv bool ) ([]byte , error ) {
17
20
18
21
builder := txscript .NewScriptBuilder ()
19
22
@@ -25,8 +28,11 @@ func GenSuccessPathScript(receiverHtlcKey *btcec.PublicKey,
25
28
builder .AddOp (txscript .OP_HASH160 )
26
29
builder .AddData (input .Ripemd160H (swapHash [:]))
27
30
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
+ }
30
36
31
37
return builder .Script ()
32
38
}
@@ -61,7 +67,9 @@ func CreateOpTrueLeaf() (asset.ScriptKey, txscript.TapLeaf,
61
67
tapLeaf := txscript .NewBaseTapLeaf (tapScript )
62
68
tree := txscript .AssembleTaprootScriptTree (tapLeaf )
63
69
rootHash := tree .RootNode .TapHash ()
64
- tapKey := txscript .ComputeTaprootOutputKey (asset .NUMSPubKey , rootHash [:])
70
+ tapKey := txscript .ComputeTaprootOutputKey (
71
+ asset .NUMSPubKey , rootHash [:],
72
+ )
65
73
66
74
merkleRootHash := tree .RootNode .TapHash ()
67
75
0 commit comments