Bitcoin Forum
May 23, 2024, 02:27:31 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: manual block check does not work  (Read 133 times)
Nordok (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
April 08, 2018, 03:36:07 PM
Last edit: April 08, 2018, 04:55:23 PM by achow101
 #1

Hello everybody.
I try to check the blocks manually, but I can not do it. I will give an example with the last block:

Build block header

Version:
0x20000000 = 02000000

Previous block:
00000000000000000015276a6b8f5478950f226c4ec97dbb5928ff574985d508
||
08d5854957ff2859bb7dc94e6c220f9578548f6b6a2715000000000000000000

merkle root:
c06e8990f81cf45774cb34451b746c91980846978734f8389ee919f9dd651566
||
661565ddf919e99e38f8348797460898916c741b4534cb7457f41cf890896ec0

Time
2018-04-07 12:18:45 = 1523092725 = 5AC88CF5 = F58CC85A

Bits
17502ab7 = b72a5017

Nonce
f8493c99 = 993c49f8


Well. Block is:
0200000008d5854957ff2859bb7dc94e6c220f9578548f6b6a2715000000000000000000661565d df919e99e38f8348797460898916c741b4534cb7457f41cf890896ec0F58CC85Ab72a5017993c49 f8
(160 char)
first round sha = 3afa7573e72e3f4e4edd602b7f209292766cc58d130c3b22faaae2176d455e9c
second round sha = e843868f1f0f70ac38971dbae5ddf951584ef3d9f783845968e0430b85cf456d

but it must be 0000000000000000001bfaabb992b104e81c971d0ea394a0b357e637dea8c034

what am I doing wrong? Why do I get another hash?
Xynerise
Sr. Member
****
Offline Offline

Activity: 322
Merit: 363

39twH4PSYgDSzU7sLnRoDfthR6gWYrrPoD


View Profile
April 08, 2018, 04:55:49 PM
Last edit: April 08, 2018, 05:16:33 PM by Xynerise
 #2

Be careful with the byte order.
The byte order of the version is incorrect. It should be
Code:
00000020
instead of
Code:
0200000
So the  version,  previous block hash,  Merkle root,  timestamp in Unix time, difficulty and nonce, when concatenated gives us the byte sequence:
Code:
0000002008d5854957ff2859bb7dc94e6c220f9578548f6b6a2715000000000000000000661565ddf919e99e38f8348797460898916c741b4534cb7457f41cf890896ec0f58cc85ab72a5017993c49f8
The first sha256 hash of it gives
Code:
386fd5f539bac4575fe3451fc969b24c1bd828f7269b0e6d186cba17321b57f9
and the sha256d (the hash of this first digest) gives:
Code:
34c0a8de37e657b3a094a30e1d971ce804b192b9abfa1b000000000000000000
The byte order is reversed and written in little endian given us the block hash:
Code:
0000000000000000001bfaabb992b104e81c971d0ea394a0b357e637dea8c034
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3402
Merit: 6642


Just writing some code


View Profile WWW
April 08, 2018, 05:01:39 PM
 #3

Your version is completely incorrect. How did you get 02000000 from 0x20000000? The 0x does not mean that there is supposed to be a 0 in front of the 2; it means that this the whole thing is a hexadecimal number. And the version also needs to be byte swapped, so it should be 00000020.

Nordok (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
April 08, 2018, 08:27:35 PM
 #4

Oh it's great! Big thanks!!!

I still do not understand the nature of my mistake, because in the instruction it is written exactly such use of the order of bits in the version.
Picture:
http://pp.userapi.com/c845322/v845322932/22ff3/CxHzojhuYj0.jpg
URL: https://bitcoin.org/en/developer-reference#block-headers


And the strangest thing is, it works for many blocks. For example:
https://btc.com/000000000000000009a11b3972c8e532fe964de937c9e0096b43814e67af3728
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3402
Merit: 6642


Just writing some code


View Profile WWW
April 08, 2018, 09:05:04 PM
 #5

Oh it's great! Big thanks!!!

I still do not understand the nature of my mistake, because in the instruction it is written exactly such use of the order of bits in the version.
Picture:

URL: https://bitcoin.org/en/developer-reference#block-headers


And the strangest thing is, it works for many blocks. For example:
https://btc.com/000000000000000009a11b3972c8e532fe964de937c9e0096b43814e67af3728
You are confusing different things. One is block version 2 which is 0x00000002 (byte swapped as 0x02000000). The other is block version 0x20000000 (byte swapped as 0x00000020). These are completely different because 0x20000000 is a hexadecimal number. In decimal, it is 536870912, not 2.

Nordok (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
April 09, 2018, 09:38:18 AM
 #6

Oh, I see...
Big thanks! It works.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!