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
2022-04-22 22:03:08 -04:00
committed by Oliver Gugger
parent 4ea24c0820
commit 681e3ceede
4 changed files with 31 additions and 3 deletions

View File

@@ -970,6 +970,11 @@ func addrPairsToOutputs(addrPairs map[string]int64,
return nil, err
}
if !addr.IsForNet(params) {
return nil, fmt.Errorf("address is not for %s",
params.Name)
}
pkscript, err := txscript.PayToAddrScript(addr)
if err != nil {
return nil, err
@@ -2579,7 +2584,14 @@ func (r *rpcServer) CloseChannel(in *lnrpc.CloseChannelRequest,
in.DeliveryAddress, r.cfg.ActiveNetParams.Params,
)
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.