getting bitcoin address of blk*.dat files

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....."

Erhard Dinhobl

Posted 2016-05-27T07:53:02.130

Reputation: 183

Answers

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.

Jimmy Song

Posted 2016-05-27T07:53:02.130

Reputation: 7 330

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 – 2016-05-30T06:08:03.760

But how to convert all the others to an address (beside those in the genesis block)? like: 76a91487bfdc1e986af9671805a902e0b2ca853f587d6288ac – Erhard Dinhobl – 2016-06-10T06:16:36.877

1Take 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 – 2016-06-10T20:07:05.207

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 – 2016-06-13T12:23:24.947

Should I interpret the script and take the stack? – Erhard Dinhobl – 2016-06-13T13:01:31.533

because "a9149cb09d17e24e9b985a4efccf44ee4debce48ef0b87" is another problem and I tried many paddings left and right – Erhard Dinhobl – 2016-06-13T15:04:26.300

1The 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 – 2016-06-19T02:17:23.033

Ok,. I take

Transaction e99783084c44b670c8206c8b3071878963bcf691812005bb416666ba1f500301

At out1 script sig is: a914564960b6d6eb2d10e4580b1441fd69793a184c0287

and then based on walletexplorer.com, the

address there should be: 39ZFwRH6LrYwSttfWU8Kme7vMpC1jpZVvM

So I take "a914" (begin) and "87" (end) away.

Remaining script sig: 564960b6d6eb2d10e4580b1441fd69793a184c02

Now i tried this in every box on the site http://gobittest.appspot.com/Address but I never got the address: 39ZFwRH6LrYwSttfWU8Kme7vMpC1jpZVvM.

– Erhard Dinhobl – 2016-07-25T11:05:27.330

Maybe someone else has some information. – Erhard Dinhobl – 2016-07-25T11:15:22.190

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

Erhard Dinhobl

Posted 2016-05-27T07:53:02.130

Reputation: 183