Skip to content

Commit ce59646

Browse files
committed
loopout: reject unsupported address formats
This commit adds a check to reject unsupported address formats such as P2PK or P2TR addresses
1 parent 1741896 commit ce59646

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

loopd/swapclient_server.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ var (
5555
errBalanceTooLow = errors.New(
5656
"channel balance too low for loop out amount",
5757
)
58+
59+
// errInvalidAddress is returned when the destination address is of
60+
// an unsupported format such as P2PK or P2TR addresses.
61+
errInvalidAddress = errors.New(
62+
"invalid or unsupported address",
63+
)
5864
)
5965

6066
// swapClientServer implements the grpc service exposed by loopd.
@@ -1154,6 +1160,18 @@ func validateLoopOutRequest(ctx context.Context, lnd lndclient.LightningClient,
11541160
errIncorrectChain, chainParams.Name)
11551161
}
11561162

1163+
// Check that the provided destination address is a supported
1164+
// address format.
1165+
switch sweepAddr.(type) {
1166+
case *btcutil.AddressWitnessScriptHash,
1167+
*btcutil.AddressWitnessPubKeyHash,
1168+
*btcutil.AddressScriptHash,
1169+
*btcutil.AddressPubKeyHash:
1170+
1171+
default:
1172+
return 0, errInvalidAddress
1173+
}
1174+
11571175
// Check that the label is valid.
11581176
if err := labels.Validate(req.Label); err != nil {
11591177
return 0, err

loopd/swapclient_server_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ var (
2626
[]byte{123}, &chaincfg.MainNetParams,
2727
)
2828

29+
nodepubkeyAddr, _ = btcutil.DecodeAddress(
30+
mock_lnd.NewMockLnd().NodePubkey, &chaincfg.MainNetParams,
31+
)
32+
2933
chanID1 = lnwire.NewShortChanIDFromInt(1)
3034
chanID2 = lnwire.NewShortChanIDFromInt(2)
3135
chanID3 = lnwire.NewShortChanIDFromInt(3)
@@ -445,6 +449,13 @@ func TestValidateLoopOutRequest(t *testing.T) {
445449
err: errBalanceTooLow,
446450
expectedTarget: 0,
447451
},
452+
{
453+
name: "node pubkey as dest addr",
454+
chain: chaincfg.MainNetParams,
455+
destAddr: nodepubkeyAddr,
456+
err: errInvalidAddress,
457+
expectedTarget: 0,
458+
},
448459
}
449460

450461
for _, test := range tests {

0 commit comments

Comments
 (0)