2

I know that getting the address from the blk*.dat files is discussed a lot of times. But I don't get it why? When I have the raw scriptSig I can encode it and get the bitcoin address or not?

E.g. the first block the first transation:

input scriptSig (this value is correct, as defined here: https://en.bitcoin.it/wiki/Genesis_block):

04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73

output scriptSig:

4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac

as written in here: https://en.bitcoin.it/wiki/Genesis_block the address of the output is:

1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

now, how to get from the scriptSig 4104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac to the address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa?

If you try it here: http://gobittest.appspot.com/Address the output is NOT the expected address "1A1....."

2

First, note that the scriptSig on the genesis block was before addresses were used. The scriptSig there is called p2pk, or pay-to-pub-key. Addresses (the kind starting with a 1) are actually p2pkh, or pay-to-pub-key-hash. You can convert one to the other fairly easily and that's what's going on here.

The actual scriptSig can be parsed like so:

41 = number of bytes in hex of the element (65 bytes)
04...5f = public key
ac = OP_CHECKSIG

Plug in 04...5f into the Public ECDSA key at http://gobittest.appspot.com/Address and you'll see that the address does indeed match.

  • My fault was, that I took the first and last byte also as part of the pub-key. when I removed it, everything was correct – Erhard Dinhobl May 30 '16 at 6:08
  • But how to convert all the others to an address (beside those in the genesis block)? like: 76a91487bfdc1e986af9671805a902e0b2ca853f587d6288ac – Erhard Dinhobl Jun 10 '16 at 6:16
  • 1
    Take out the 76a914 at the beginning (OP_DUP, OP_HASH160, 20 byte length) and the 88ac at the end (OP_EQUALVERIFY, OP_CHECKSIG) and put that into box 3. – Jimmy Song Jun 10 '16 at 20:07
  • Thanks I will try it! But is there a general approache for that? Because I have some other scripts and I think asking for every case would lead to a huge blowup..... – Erhard Dinhobl Jun 13 '16 at 12:23
  • 1
    The way to get this generally is to take the binary and make it into script form. OP_HASH160 <hash> OP_EQUAL seems to be the form, so if you take out the a914 at the front and 87 at the end, you'll have the hash160 (box 3). Note this means there needs to be no signature, so it's a very dangerous script that shouldn't get used. – Jimmy Song Jun 19 '16 at 2:17
0

Or maybe am I right with the following assumptions: there are three types of scriptSig's

  1. OP_DUP OP_HASH160 .... OP_EQUALVERIFY OP_CHECKSIG
  2. OP_HASH160 ... OP_EQUAL
  3. OP_m ... OP_CHECKMULTISIG

But what to do now with these options? In the 3rd option I only have to take all bytes represented as "..." and decode it. But whats with the others?

E.g.: hot to get it from: 76a91490bb78d00b26139e4d51ceb9655295c2bd98aed688ac

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.