-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: verify address is for correct net #6448
rpc: verify address is for correct net #6448
Conversation
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.
9ce3f50
to
e9e770c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix! LGTM 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, while we're at it, we should probably also add the check here:
- https://github.com/lightningnetwork/lnd/blob/master/lnrpc/walletrpc/walletkit_server.go#L1030
- https://github.com/lightningnetwork/lnd/blob/master/lnrpc/invoicesrpc/addinvoice.go#L277
- https://github.com/lightningnetwork/lnd/blob/master/rpcserver.go#L2474
Or, to fix the underlying assumption that (because it takes the net params as the second parameter) DecodeAddress
actually checks that the address belongs to the correct network, we should perhaps add the check there?
Looking at the code, this seems to only be possible with non-Segwit (non-bech32) addresses in the first place.
Do you mean changing |
Yes, maybe it's too big of a change. But maybe it would be worth adding a comment in the |
Found another place, in lnd/lnwallet/chancloser/chancloser.go Lines 710 to 728 in f13399b
For the sake of returning errors that look the same in all places, and ergonomics, would it be an idea to introduce a new wallet in |
Oops, I was wrong there. I read the I like your idea of adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK on the bug to be fixed, agree with all that the fix should be included in DecodeAddressForNet
, that way it can trickle into other projects.
Friend at mitbitcoin actually ran into this same issue, so there is real need for this fix.
@torkelrogstad, remember to re-request review from reviewers when ready |
Replaced by/included in #7689, original commit author credits are preserved. |
Change Description
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.
Steps to Test
Prior to this commit:
sendmany
orsendcoins
RPC, with a mainnet or testnet addressAfter this commit, step 2 fails.
Pull Request Checklist
Testing
There doesn't seem to be any tests for this, at least not based on a quick code search. Would be happy to implement if I'm wrong.
Code Style and Documentation
Any new logging statements use an appropriate subsystem and logging level.[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.