Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ var (
errBalanceTooLow = errors.New(
"channel balance too low for loop out amount",
)

// errInvalidAddress is returned when the destination address is of
// an unsupported format such as P2PK or P2TR addresses.
errInvalidAddress = errors.New(
"invalid or unsupported address",
)
)

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

// Check that the provided destination address is a supported
// address format.
switch sweepAddr.(type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean!

case *btcutil.AddressWitnessScriptHash,
*btcutil.AddressWitnessPubKeyHash,
*btcutil.AddressScriptHash,
*btcutil.AddressPubKeyHash:

default:
return 0, errInvalidAddress
}

// Check that the label is valid.
if err := labels.Validate(req.Label); err != nil {
return 0, err
Expand Down
11 changes: 11 additions & 0 deletions loopd/swapclient_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ var (
[]byte{123}, &chaincfg.MainNetParams,
)

nodepubkeyAddr, _ = btcutil.DecodeAddress(
mock_lnd.NewMockLnd().NodePubkey, &chaincfg.MainNetParams,
)

chanID1 = lnwire.NewShortChanIDFromInt(1)
chanID2 = lnwire.NewShortChanIDFromInt(2)
chanID3 = lnwire.NewShortChanIDFromInt(3)
Expand Down Expand Up @@ -445,6 +449,13 @@ func TestValidateLoopOutRequest(t *testing.T) {
err: errBalanceTooLow,
expectedTarget: 0,
},
{
name: "node pubkey as dest addr",
chain: chaincfg.MainNetParams,
destAddr: nodepubkeyAddr,
err: errInvalidAddress,
expectedTarget: 0,
},
}

for _, test := range tests {
Expand Down