Repository navigation
multi: check destination address types and networks - #1280
Merged
Merged
Conversation
1 task done
hieblmi
self-requested a review
November 10, 2026 13:26
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
RpcToParametersdecodes 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 theSetLiquidityParamscall takes the daemon down.The first commit moves the Loop Out type check into
utils.IsSupportedDestAddrand 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.
RpcToParametersnow takes the chain parameters as an argument.The third commit adds
utils.CheckAddrNetworkand 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
docs/release-notes/release-notes-next.md, or apply theno-changeloglabel.