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:
1 parent
4ea24c0820
commit
681e3ceede
4 files changed
+31
-3
No files matched your search
@@ -72,6 +72,9 @@ package](https://github.com/lightningnetwork/lnd/pull/7356)
|
|||||||
`grpc.keepalive_time_ms=5100` is recommended on the client side (adding 100ms
|
`grpc.keepalive_time_ms=5100` is recommended on the client side (adding 100ms
|
||||||
to account for slightly different clock speeds).
|
to account for slightly different clock speeds).
|
||||||
|
|
||||||
|
* [Fixed a bug where we didn't check for correct networks when submitting
|
||||||
|
onchain transactions](https://github.com/lightningnetwork/lnd/pull/6448).
|
||||||
|
|
||||||
## Misc
|
## Misc
|
||||||
|
|
||||||
* [Generate default macaroons
|
* [Generate default macaroons
|
||||||
|
|||||||
@@ -292,12 +292,19 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
|
|||||||
|
|
||||||
// If specified, add a fallback address to the payment request.
|
// If specified, add a fallback address to the payment request.
|
||||||
if len(invoice.FallbackAddr) > 0 {
|
if len(invoice.FallbackAddr) > 0 {
|
||||||
addr, err := btcutil.DecodeAddress(invoice.FallbackAddr,
|
addr, err := btcutil.DecodeAddress(
|
||||||
cfg.ChainParams)
|
invoice.FallbackAddr, cfg.ChainParams,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("invalid fallback "+
|
return nil, nil, fmt.Errorf("invalid fallback "+
|
||||||
"address: %v", err)
|
"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))
|
options = append(options, zpay32.FallbackAddr(addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1104,6 +1104,12 @@ func (w *WalletKit) FundPsbt(_ context.Context,
|
|||||||
"%s for network %s: %v", addrStr,
|
"%s for network %s: %v", addrStr,
|
||||||
w.cfg.ChainParams.Name, err)
|
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)
|
pkScript, err := txscript.PayToAddrScript(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error getting pk "+
|
return nil, fmt.Errorf("error getting pk "+
|
||||||
|
|||||||
+13
-1
@@ -970,6 +970,11 @@ func addrPairsToOutputs(addrPairs map[string]int64,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !addr.IsForNet(params) {
|
||||||
|
return nil, fmt.Errorf("address is not for %s",
|
||||||
|
params.Name)
|
||||||
|
}
|
||||||
|
|
||||||
pkscript, err := txscript.PayToAddrScript(addr)
|
pkscript, err := txscript.PayToAddrScript(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -2579,7 +2584,14 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
|
|||||||
in.DeliveryAddress, r.cfg.ActiveNetParams.Params,
|
in.DeliveryAddress, r.cfg.ActiveNetParams.Params,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid delivery address: %v", err)
|
return fmt.Errorf("invalid delivery address: "+
|
||||||
|
"%v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !addr.IsForNet(r.cfg.ActiveNetParams.Params) {
|
||||||
|
return fmt.Errorf("delivery address is not "+
|
||||||
|
"for %s",
|
||||||
|
r.cfg.ActiveNetParams.Params.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a script to pay out to the address provided.
|
// Create a script to pay out to the address provided.
|
||||||
|
|||||||
Reference in new issue
Block a user