rpc: verify address is for correct net

Verify that the addresses we're decoding when sending coins onchain are
for the correct network. Without this check we'll convert the users
addresses to their equivalent on other networks, which is a gross
violation of the principle of least astonishment.
This commit is contained in:
Torkel Rogstad authored and Oliver Gugger committed 2023-06-13 11:58:34 +02:00
1 parent 4ea24c0820
commit 681e3ceede
4 files changed
+31 -3

No files matched your search

+9 -2
View File
@@ -292,12 +292,19 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
// If specified, add a fallback address to the payment request.
if len(invoice.FallbackAddr) > 0 {
addr, err := btcutil.DecodeAddress(invoice.FallbackAddr,
cfg.ChainParams)
addr, err := btcutil.DecodeAddress(
invoice.FallbackAddr, cfg.ChainParams,
)
if err != nil {
return nil, nil, fmt.Errorf("invalid fallback "+
"address: %v", err)
}
if !addr.IsForNet(cfg.ChainParams) {
return nil, nil, fmt.Errorf("fallback address is not "+
"for %s", cfg.ChainParams.Name)
}
options = append(options, zpay32.FallbackAddr(addr))
}
+6
View File
@@ -1104,6 +1104,12 @@ func (w *WalletKit) FundPsbt(_ context.Context,
"%s for network %s: %v", addrStr,
w.cfg.ChainParams.Name, err)
}
if !addr.IsForNet(w.cfg.ChainParams) {
return nil, fmt.Errorf("address is not for %s",
w.cfg.ChainParams.Name)
}
pkScript, err := txscript.PayToAddrScript(addr)
if err != nil {
return nil, fmt.Errorf("error getting pk "+