Skip to content

multi: check destination address types and networks - #1280

Merged
hieblmi merged 3 commits into
lightninglabs:masterfrom
starius:fixes3
Nov 10, 2026
Merged

hieblmi merged 3 commits into
lightninglabs:masterfrom
starius:fixes3

Conversation

@starius

@starius starius commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Factored out of #1199 (btcd v2 migration), where these are the first three commits. They fix destination address bugs that master has today and don't depend on the migration. #1199 builds on this PR.

Loop Out accepts only P2PKH, P2SH, P2WPKH, P2WSH and P2TR destination addresses, and only for the active network. The other paths that take a destination address check less:

  • Setting the autoloop destination to a P2PKH or P2SH address or a raw public key crashes loopd. RpcToParameters decodes the address with nil chain parameters, and the decoder dereferences them for base58 addresses and raw public keys. loopd doesn't recover from panics in RPC handlers, so the SetLiquidityParams call takes the daemon down.
  • Instant Out accepts every type the decoder returns, including raw public keys, which Loop Out rejects.
  • Autoloop, Instant Out, static address withdrawals and manual HTLC sweeps accept bech32 addresses of other networks. The decoder accepts bech32 addresses of all known networks (base58 addresses of other networks fail to decode), and the output script doesn't depend on the network, so a mainnet node pays to the witness program of a testnet address.

The first commit moves the Loop Out type check into utils.IsSupportedDestAddr and applies it to Instant Out before the swap starts and to the autoloop parameters when they are validated. Static address withdrawals and manual HTLC sweeps already reject other types when they estimate the transaction weight. In #1199 the check also keeps the btcd v2 address decoder from widening the accepted types: that decoder also accepts pay-to-anchor addresses, which anyone can spend.

The second commit decodes the autoloop destination for the active network. P2PKH and P2SH destinations now work, and a raw public key fails the type check from the first commit. RpcToParameters now takes the chain parameters as an argument.

The third commit adds utils.CheckAddrNetwork and calls it in the four paths above. Earlier versions saved the autoloop destination without this check, and loopd applies the saved parameters at startup, where an error stops the daemon. The parameters can only be changed while loopd runs, so if the saved destination belongs to another network, loopd removes it at startup with a warning, and autoloop pays to wallet addresses.

Pull Request Checklist

  • Add an entry to docs/release-notes/release-notes-next.md, or apply the no-changelog label.

@starius starius mentioned this pull request Nov 8, 2026
1 task done
@hieblmi
hieblmi self-requested a review November 10, 2026 13:26

@hieblmi hieblmi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Loop Out accepts only P2PKH, P2SH, P2WPKH, P2WSH and P2TR destination
addresses. Instant Out and the autoloop destination accepted any type
that the address decoder returns, which for Instant Out included raw
public keys. The btcd v2 address package also decodes pay-to-anchor
addresses, which anyone can spend.

Move the Loop Out check into utils.IsSupportedDestAddr. Apply it to
Instant Out before the swap starts and to the autoloop parameters when
they are validated, so that a decoder change can't widen the accepted
destination types.
RpcToParameters decoded the autoloop destination address with nil chain
parameters. For P2PKH and P2SH addresses and raw public keys, the
decoder dereferences the parameters, so a SetLiquidityParams call with
such an address panicked. loopd does not recover from panics in RPC
handlers, so the daemon crashed.

Pass the chain parameters of the active network to RpcToParameters and
decode the address with them. A raw public key now decodes and fails
the destination type check.
Loop Out rejects a destination address that does not belong to the
active network. Autoloop, Instant Out, static address withdrawals and
manual HTLC sweeps did not. The decoder accepts bech32 addresses of all
known networks, and their output scripts don't depend on the network,
so these paths paid to the same witness program on the active network.

Add utils.CheckAddrNetwork and call it after each of these decodes.
Earlier versions saved the autoloop destination without the check. If
the saved destination belongs to another network, loopd removes it at
startup and autoloop pays to wallet addresses, because failing to start
would leave no way to change the parameters.
@hieblmi
hieblmi merged commit 69ac8b1 into lightninglabs:master Nov 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants