Skip to content
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

btcutil: consider adding a new method that verifies address is for the correct net #1846

Open
torkelrogstad opened this issue Apr 23, 2022 · 2 comments · May be fixed by #1852
Open

btcutil: consider adding a new method that verifies address is for the correct net #1846

torkelrogstad opened this issue Apr 23, 2022 · 2 comments · May be fixed by #1852

Comments

@torkelrogstad
Copy link
Contributor

In its current form, btcutil.DecodeAddress has some slightly surprising behavior:

addr, err := btcutil.DecodeAddress("bc1q7cyrfmck2ffu2ud3rn5l5a8yv6f0chkp0zpemf", &chaincfg.TestNet3Params)
if err != nil {
	log.Fatal(err)
}
log.Println("address: ", addr.String())

This doesn't error, but instead decoded just fine. It's explained in the godoc that the net is only used for legacy addresses. However, it looks like this is often overlooked. One example would be the instances of this in lnd found in this PR: lightningnetwork/lnd#6448

Would it be an idea to add a new method that decodes the address, and then verifies it is for the given network? Names could for example be DecodeAddressVerify, or DecodeAddressForNet.

@guggero
Copy link
Collaborator

guggero commented Apr 25, 2022

I like the idea of adding DecodeAddressForNet. Will review a PR. Would be nice to add a positive/negative unit test for both the existing and the new functions.

@Roasbeef
Copy link
Member

Historical context: btcsuite/btcutil#133

@torkelrogstad torkelrogstad linked a pull request Apr 30, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants