Merge pull request #2922 from ccdle12/prevent-sendcoins-pubkey
rpcserver: Prevent SendCoins to Pubkey
This commit is contained in:
commit
6c60caa852
32
lnd_test.go
32
lnd_test.go
@ -13044,6 +13044,36 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
t.Fatalf("unable to send coins to eve: %v", err)
|
t.Fatalf("unable to send coins to eve: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure that we can't send coins to our own Pubkey.
|
||||||
|
info, err := ainz.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to get node info: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sweepReq := &lnrpc.SendCoinsRequest{
|
||||||
|
Addr: info.IdentityPubkey,
|
||||||
|
SendAll: true,
|
||||||
|
}
|
||||||
|
_, err = ainz.SendCoins(ctxt, sweepReq)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected SendCoins to users own pubkey to fail")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that we can't send coins to another users Pubkey.
|
||||||
|
info, err = net.Alice.GetInfo(ctxt, &lnrpc.GetInfoRequest{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unable to get node info: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sweepReq = &lnrpc.SendCoinsRequest{
|
||||||
|
Addr: info.IdentityPubkey,
|
||||||
|
SendAll: true,
|
||||||
|
}
|
||||||
|
_, err = ainz.SendCoins(ctxt, sweepReq)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected SendCoins to Alices pubkey to fail")
|
||||||
|
}
|
||||||
|
|
||||||
// With the two coins above mined, we'll now instruct ainz to sweep all
|
// With the two coins above mined, we'll now instruct ainz to sweep all
|
||||||
// the coins to an external address not under its control.
|
// the coins to an external address not under its control.
|
||||||
// We will first attempt to send the coins to addresses that are not
|
// We will first attempt to send the coins to addresses that are not
|
||||||
@ -13053,7 +13083,7 @@ func testSweepAllCoins(net *lntest.NetworkHarness, t *harnessTest) {
|
|||||||
|
|
||||||
// Send coins to a testnet3 address.
|
// Send coins to a testnet3 address.
|
||||||
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
ctxt, _ = context.WithTimeout(ctxb, defaultTimeout)
|
||||||
sweepReq := &lnrpc.SendCoinsRequest{
|
sweepReq = &lnrpc.SendCoinsRequest{
|
||||||
Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg",
|
Addr: "tb1qfc8fusa98jx8uvnhzavxccqlzvg749tvjw82tg",
|
||||||
SendAll: true,
|
SendAll: true,
|
||||||
}
|
}
|
||||||
|
@ -913,6 +913,15 @@ func (r *rpcServer) SendCoins(ctx context.Context,
|
|||||||
activeNetParams.Params.Name)
|
activeNetParams.Params.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the destination address parses to a valid pubkey, we assume the user
|
||||||
|
// accidently tried to send funds to a bare pubkey address. This check is
|
||||||
|
// here to prevent unintended transfers.
|
||||||
|
decodedAddr, _ := hex.DecodeString(in.Addr)
|
||||||
|
_, err = btcec.ParsePubKey(decodedAddr, btcec.S256())
|
||||||
|
if err == nil {
|
||||||
|
return nil, fmt.Errorf("cannot send coins to pubkeys")
|
||||||
|
}
|
||||||
|
|
||||||
var txid *chainhash.Hash
|
var txid *chainhash.Hash
|
||||||
|
|
||||||
wallet := r.server.cc.wallet
|
wallet := r.server.cc.wallet
|
||||||
|
Loading…
Reference in New Issue
Block a user