<p>You have the wrong block version number.  Block 300000 is a <a href="https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki" rel="nofollow">version 2</a> block, whereas 125552 was version 1.  So the first word in the block header should be "02000000" not "01000000".</p>

CC BY-SA 3.0
2014-05-14T12:42:43.190Z
Thank you so much - I think I'll update the bitcoin wiki page to reflect that... I spun my wheels for quite some time before posting my question - so I really do appreciate the answer.
Harwood
CC BY-SA 3.0
2014-05-14T05:48:54.057Z
2014-05-14T05:48:54.057Z
Nate Eldredge
<p>This is the header for block #300000</p>

<pre><code>02 00 00 00 7E F0 55 E1 │ 67 4D 2E 65 51 DB A4 1C
D2 14 DE BB EE 34 AE B5 │ 44 C7 EC 67 00 00 00 00
00 00 00 00 D3 99 89 63 │ F8 0C 5B AB 43 FE 8C 26
22 8E 98 D0 30 ED F4 DC │ BE 48 A6 66 F5 C3 9E 2D
7A 88 5C 91 02 C8 6D 53 │ 6C 89 00 19 59 3A 47 0D
</code></pre>

<p>Version number is 2 (the very first digit), but you have hardcoded it to 1 </p>

<blockquote>
  <p>header_hex = ("01000000" +</p>
</blockquote>

CC BY-SA 3.0
2014-05-14T12:44:39.303Z
Thank you - the info is not present in the wiki page.  Much appreciated.
Harwood
CC BY-SA 3.0
2014-05-14T10:40:57.073Z
2014-05-14T10:40:57.073Z
amaclin
<p>I've been experimenting with the php code here: <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow">https://en.bitcoin.it/wiki/Block_hashing_algorithm</a>  (after correcting the small bug of $x=; to $x=""; )</p>

<p>With these blocks 0 and 125552 (for example) it works fine and I get the expected hash.</p>

<p>With blocks 225552 and 300000, I get:</p>

<p>7a7bb195e8bcc8e73205df7906eb68f26144c6fbc577d59dd4e8a0cfdb8b90df (rather than 00000000000001f4f14b09019b23d71c222a2c1245ef3df52875d79ff4488709)</p>

<p>and</p>

<p>178d6fe6cbf696311e7f46263067eeb688797e4c790060c1f6edf6daec76c59e (rather than 000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254)</p>

<p>...respectively - which doesn't match the hash of either block.</p>

<p>What am I missing or doing incorrectly?</p>

<p>Additional note - I confirmed these results using "openssl dgst -sha256 -binary test-input.bin |openssl dgst -sha256"...</p>

<p>Further to this, using the python code from the same page:</p>

<pre><code>&gt;&gt;&gt; import hashlib
&gt;&gt;&gt; header_hex = ("01000000" +
...     "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
...     "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
...     "c7f5d74d" +
...     "f2b9441a" +
...      "42a14695")
&gt;&gt;&gt; header_bin = header_hex.decode('hex')
&gt;&gt;&gt; hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
&gt;&gt;&gt; hash.encode('hex_codec')
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'
&gt;&gt;&gt; hash[::-1].encode('hex_codec')
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'
</code></pre>

<p>...works fine... but:</p>

<pre><code>&gt;&gt;&gt; import hashlib
&gt;&gt;&gt; header_hex = ("01000000" +
...     "7ef055e1674d2e6551dba41cd214debbee34aeb544c7ec670000000000000000" +
...     "d3998963f80c5bab43fe8c26228e98d030edf4dcbe48a666f5c39e2d7a885c91" +
...     "02c86d53" +
...     "6c890019" +
...     "593a470d")
&gt;&gt;&gt; header_bin = header_hex.decode('hex')
&gt;&gt;&gt; hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
&gt;&gt;&gt; hash.encode('hex_codec')
'9ec576ecdaf6edf6c16000794c7e7988b6ee673026467f1e3196f6cbe66f8d17'
&gt;&gt;&gt; hash[::-1].encode('hex_codec')
'178d6fe6cbf696311e7f46263067eeb688797e4c790060c1f6edf6daec76c59e'
</code></pre>

<p>...gets the same erroneous result as the php code.</p>

<blockchain><hash><sha256>
SHA256 * 2 on header - what am I doing wrong?
Harwood
# SHA256 * 2 on header - what am I doing wrong?

(Asked by: username_0 on 2014-05-14)

I've been experimenting with the php code here: https://en.bitcoin.it/wiki/Block_hashing_algorithm  (after correcting the small bug of $x=; to $x=""; )
With these blocks 0 and 125552 (for example) it works fine and I get the expected hash.
With blocks 225552 and 300000, I get:
7a7bb195e8bcc8e73205df7906eb68f26144c6fbc577d59dd4e8a0cfdb8b90df (rather than 00000000000001f4f14b09019b23d71c222a2c1245ef3df52875d79ff4488709)
and
178d6fe6cbf696311e7f46263067eeb688797e4c790060c1f6edf6daec76c59e (rather than 000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254)
...respectively - which doesn't match the hash of either block.
What am I missing or doing incorrectly?
Additional note - I confirmed these results using "openssl dgst -sha256 -binary test-input.bin |openssl dgst -sha256"...
Further to this, using the python code from the same page:
>>> import hashlib
>>> header_hex = ("01000000" +
...     "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
...     "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
...     "c7f5d74d" +
...     "f2b9441a" +
...      "42a14695")
>>> header_bin = header_hex.decode('hex')
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
>>> hash.encode('hex_codec')
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'
>>> hash[::-1].encode('hex_codec')
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'

...works fine... but:
>>> import hashlib
>>> header_hex = ("01000000" +
...     "7ef055e1674d2e6551dba41cd214debbee34aeb544c7ec670000000000000000" +
...     "d3998963f80c5bab43fe8c26228e98d030edf4dcbe48a666f5c39e2d7a885c91" +
...     "02c86d53" +
...     "6c890019" +
...     "593a470d")
>>> header_bin = header_hex.decode('hex')
>>> hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
>>> hash.encode('hex_codec')
'9ec576ecdaf6edf6c16000794c7e7988b6ee673026467f1e3196f6cbe66f8d17'
>>> hash[::-1].encode('hex_codec')
'178d6fe6cbf696311e7f46263067eeb688797e4c790060c1f6edf6daec76c59e'

...gets the same erroneous result as the php code.

**Tags:** blockchain, hash, sha256


---

## 2 answers

### Answer by username_1 on 2014-05-14. Score: 1 | Accepted answer

You have the wrong block version number. Block 300000 is a [version 2](https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki) block, whereas 125552 was version 1. So the first word in the block header should be "02000000" not "01000000".

> **Comments:**
> **username_0**: Thank you so much - I think I'll update the bitcoin wiki page to reflect that... I spun my wheels for quite some time before posting my question - so I really do appreciate the answer.  

---

### Answer by username_2 on 2014-05-14. Score: 0

This is the header for block #300000
02 00 00 00 7E F0 55 E1 │ 67 4D 2E 65 51 DB A4 1C
D2 14 DE BB EE 34 AE B5 │ 44 C7 EC 67 00 00 00 00
00 00 00 00 D3 99 89 63 │ F8 0C 5B AB 43 FE 8C 26
22 8E 98 D0 30 ED F4 DC │ BE 48 A6 66 F5 C3 9E 2D
7A 88 5C 91 02 C8 6D 53 │ 6C 89 00 19 59 3A 47 0D

Version number is 2 (the very first digit), but you have hardcoded it to 1 

header_hex = ("01000000" +

> **Comments:**
> **username_0**: Thank you - the info is not present in the wiki page.  Much appreciated.  

---

