btcsuite / btcd

An alternative full node bitcoin implementation written in Go (golang)
https://github.com/btcsuite/btcd/blob/master/README.md
ISC License
6.2k stars 2.36k forks source link

DecodeAddress return invalid. #2104

Closed leverwwz closed 8 months ago

leverwwz commented 8 months ago

bc1pzh9s9weq3wl3u84jvyv4qzug44pzqxtu66kt9p6fh8k3qamw0c6grphf

this address is valid but DecodeAddress of btcd return invalid.

please help, thank u so much.

guggero commented 8 months ago

What's the error message you get?

leverwwz commented 8 months ago

What's the error message you get?

yeah, thanks, the error message is 'unsupported witness program length: 31.

but i am not sure whether it is a bug of the btcd or not, and it is normal for bitcoin-core wallet.

thanks again for your time.

guggero commented 8 months ago

Hmm, I see. And it looks like bitcoind actually sees it as a valid address:

bitcoin-cli validateaddress bc1pzh9s9weq3wl3u84jvyv4qzug44pzqxtu66kt9p6fh8k3qamw0c6grphf
{
  "isvalid": true,
  "address": "bc1pzh9s9weq3wl3u84jvyv4qzug44pzqxtu66kt9p6fh8k3qamw0c6grphf",
  "scriptPubKey": "511f15cb02bb208bbf1e1eb26119500b88ad4220197cd6acb28749b9ed10776e7e",
  "iswitness": true,
  "witness_version": 1,
  "witness_program": "15cb02bb208bbf1e1eb26119500b88ad4220197cd6acb28749b9ed10776e7e"
}

But I don't think it's a valid P2TR address. Meaning, you can send funds there (it is "valid" in the sense that any burn address is "valid") but you very likely won't be able to spend those funds again. How was the address created?

If you compare the output with an actual P2TR address, the output is slightly different:

bitcoin-cli validateaddress bc1pyjl950fe4lmcjgy956l3ls4mqy6ekae9errf6r99psdg68csyxlsdzh9wc
{
  "isvalid": true,
  "address": "bc1pyjl950fe4lmcjgy956l3ls4mqy6ekae9errf6r99psdg68csyxlsdzh9wc",
  "scriptPubKey": "512024be5a3d39aff7892085a6bf1fc2bb01359b7725c8c69d0ca50c1a8d1f1021bf",
  "isscript": true,
  "iswitness": true,
  "witness_version": 1,
  "witness_program": "24be5a3d39aff7892085a6bf1fc2bb01359b7725c8c69d0ca50c1a8d1f1021bf"
}

Therefore I think the DecodeAddress code is correct in the sense that it also makes sure it's a known address format/length.

leverwwz commented 8 months ago

length

bitcoind actually sees it as a valid address, but here is the problem, btcd decode address return the err. in other words, btcd thinks it as a invalid address.

so is it a bug of the btcd?

leverwwz commented 8 months ago

![Uploading b0e5f36b-1068-4be7-b89b-7433a9f33a5c.jpeg…]()

guggero commented 8 months ago

Please read my message above again. Just because an address is seen as "valid" doesn't mean it is resulting in a valid output that you can spend again. I'm pretty sure this isn't a bug in btcd, on the contrary: The extra validation in btcd prevents you from sending coins to a potentially un-spendable address.

leverwwz commented 8 months ago

Please read my message above again. Just because an address is seen as "valid" doesn't mean it is resulting in a valid output that you can spend again. I'm pretty sure this isn't a bug in btcd, on the contrary: The extra validation in btcd prevents you from sending coins to a potentially un-spendable address.

thans for time.

leverwwz commented 8 months ago

thanks for your time