in3rsha / bitcoin-utxo-dump

Get a list of UTXOs (unspent transaction outputs) from your Bitcoin Core client.
MIT License
241 stars 103 forks source link

Incorrect script for P2PK (uncompressed pubkey) #32

Closed ottosch closed 2 years ago

ottosch commented 2 years ago

Hi @in3rsha,

I've noticed the program is not outputting the correct script for P2PK when the public key is uncompressed. Example: output of txid 050a20f455b8e98b7a374fd00c810b7c5102ef260b69bea89dd5792e55235fd8 has script 050766aa8462489f7957d5ae8dc499fa580f45f7f143d94eb7e461e2597416005d instead of 040766aa8462489f7957d5ae8dc499fa580f45f7f143d94eb7e461e2597416005db647f4a78c534057fc887667c5c332b287cc5ade652d319cc6942649f20dafdb.

I see 2 issues: 1- The pubkey is only decompressed if address field is selected and flag p2pkaddresses is used. I think it should also be decompressed if script field is selected.

2- Even if those conditions are met, output["script"] is not updated.

Is this a bug? Can I fix it?

in3rsha commented 2 years ago

With the "script" field I've basically just returned how it has been stored in the database without doing anything else to it.

Do you want the script field to show the full original script (including opcodes)? Like this:

41040766aa8462489f7957d5ae8dc499fa580f45f7f143d94eb7e461e2597416005db647f4a78c534057fc887667c5c332b287cc5ade652d319cc6942649f20dafdbac

(0x41 at the start is a indicates how many upcoming bytes, and 0xac is OP_CHECKSIG).

Or do you just want it to show the uncompressed public key only?

040766aa8462489f7957d5ae8dc499fa580f45f7f143d94eb7e461e2597416005db647f4a78c534057fc887667c5c332b287cc5ade652d319cc6942649f20dafdb
ottosch commented 2 years ago

I think it's fine to display the public key only (compressed or uncompressed, whichever is in the UTXO).

in3rsha commented 2 years ago

The tool now shows the full uncompressed public keys if that's how they appear in the locking script.

Thanks for bringing this up.