Skip to content

Commit 06b1283

Browse files
committed
tapchannel: no passive assets in funding proofs
Previously, anchorVPackets included all "TypeSimple" outputs in the funding proofs sent to a responder. Passive assets (viz. those located in the same UTXO, but not selected for funding) also have default output type TypeSimple, which caused them to be included incorrectly. The fix is to also check that AnchorOutputIndex == 0, since passive assets are always assigned to anchor outputs at index >= 1.
1 parent da2106d commit 06b1283

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

tapchannel/aux_funding_controller.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ const (
8686
// message is 64k bytes, we leave some breathing room for the chunk
8787
// metadata.
8888
proofChunkSize = 60_000
89+
90+
// FundingOutputIndex is the anchor output index for channel funding.
91+
// Funding outputs are always at index 0; passive assets use index >= 1.
92+
FundingOutputIndex uint32 = 0
8993
)
9094

9195
// ErrorReporter is used to report an error back to the caller and/or peer that
@@ -1114,6 +1118,13 @@ func (f *FundingController) signAllVPackets(ctx context.Context,
11141118
return allPackets, activePackets, passivePkts, nil
11151119
}
11161120

1121+
// isFundingOutput returns true if the output should be included in channel
1122+
// funding proofs.
1123+
func isFundingOutput(vOut *tappsbt.VOutput) bool {
1124+
return vOut.Type == tappsbt.TypeSimple &&
1125+
vOut.AnchorOutputIndex == FundingOutputIndex
1126+
}
1127+
11171128
// anchorVPackets anchors the vPackets to the funding PSBT, creating a
11181129
// complete, but unsigned PSBT packet that can be used to create out asset
11191130
// channel.
@@ -1178,13 +1189,10 @@ func (f *FundingController) anchorVPackets(fundedPkt *tapsend.FundedPsbt,
11781189

11791190
vPkt.Outputs[vOutIdx].ProofSuffix = proofSuffix
11801191

1181-
// Any output that isn't a split root output is a
1182-
// channel funding output, so we'll store the proofs
1183-
// for those outputs. If there is change, that will be
1184-
// the split root output. And if there is no change,
1185-
// there is no split root output, as it's an interactive
1186-
// transfer.
1187-
if vPkt.Outputs[vOutIdx].Type == tappsbt.TypeSimple {
1192+
// Only include outputs destined for the funding output
1193+
// (index 0). Passive assets go to separate anchor
1194+
// outputs and should not be included in funding proofs.
1195+
if isFundingOutput(vPkt.Outputs[vOutIdx]) {
11881196
fundingProofs = append(
11891197
fundingProofs, proofSuffix,
11901198
)

0 commit comments

Comments
 (0)