Bitcoin Forum
December 10, 2016, 01:36:39 AM *
News: To be able to use the next phase of the beta forum software, please ensure that your email address is correct/functional.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: verifying hashes using sha256sum  (Read 4312 times)
genjix
Legendary
*
expert
Offline Offline

Activity: 1232


View Profile
February 15, 2011, 01:27:37 AM
 #1

http://blockexplorer.com/rawblock/00000000000271de9d8b94afff543366e290e995f3e3e337bb86a0b7bf02e8d1

Take this as an example.

Bitcoin is little endian, right?

So we need:
4 bytes - version
32 bytes - previous block hash
32 bytes - merkle root number
4 bytes - 4 second periodic timestamp (is it unix time?)
4 bytes - bits for difficulty
4 bytes - random nonce
1 byte - 0

From blockexplorer what values would I need to pickle into the file?
version - 1
prev hash - 00000000000148c04e58dca8e1a2df251339c81e2dfe1ff0e9d655b7b4ca428d
merkle root - 72febc107470c4f83e224f9683a5c7fb24c4dece8412b9d95db277c8dd75451d
timestamp - 1297566305
"bits" - 1b028552
nonce - 329961997
0

So I would write these to a file in binary little endian format then run:

sha256sum -b block_header > output
sha256sum -b output

and that should give 000000000001b85fa1709c6824d19d5c7d20736b0b2ea5fd470705a9513c42ae

right?

and how is 'version' decided? do new bitcoin versions up that number and fork the blockchain while accepting version 1 from before a certain point?
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
theymos
Administrator
Legendary
*
expert
Offline Offline

Activity: 2506


View Profile
February 15, 2011, 01:29:01 AM
 #2

I believe all the hashes need to be reversed in some way.

The correct version and timestamp values are shown in rawblock:
http://blockexplorer.com/rawblock/00000000000271de9d8b94afff543366e290e995f3e3e337bb86a0b7bf02e8d1

Version is always 1, and timestamp is the Unix timestamp.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
dirtyfilthy
Member
**
Offline Offline

Activity: 75


View Profile
February 15, 2011, 01:44:24 AM
 #3

I've already said this on irc, but for anybody else reading along don't include the transaction count when hashing i.e. no zero at the end, just finish on the nonce

Address: 1EkSP5Uqf5Fhs8Gg4XJG2b3hrFS7Vm8WFz
pla
Member
**
Offline Offline

Activity: 65


View Profile
February 20, 2011, 11:26:31 PM
 #4

From blockexplorer what values would I need to pickle into the file?

Did you ever find a solution to this?

I tried the following:

Code:
#include<stdio.h>
#include<stdlib.h>

unsigned char Forward[80]=
{
  0x00, 0x00, 0x00, 0x01,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x48, 0xc0, 0x4e, 0x58, 0xdc, 0xa8, 0xe1, 0xa2, 0xdf, 0x25, 0x13, 0x39, 0xc8, 0x1e, 0x2d, 0xfe, 0x1f, 0xf0, 0xe9, 0xd6, 0x55, 0xb7, 0xb4, 0xca, 0x42, 0x8d,
  0x72, 0xfe, 0xbc, 0x10, 0x74, 0x70, 0xc4, 0xf8, 0x3e, 0x22, 0x4f, 0x96, 0x83, 0xa5, 0xc7, 0xfb, 0x24, 0xc4, 0xde, 0xce, 0x84, 0x12, 0xb9, 0xd9, 0x5d, 0xb2, 0x77, 0xc8, 0xdd, 0x75, 0x45, 0x1d,
  0x4D, 0x57, 0x4A, 0x61,
  0x1B, 0x02, 0x85, 0x52,
  0x13, 0xAA, 0xD2, 0x0D
};
unsigned char Reversed[80]=
{
  0x01, 0x00, 0x00, 0x00,
  0x8d, 0x42, 0xca, 0xb4, 0xb7, 0x55, 0xd6, 0xe9, 0xf0, 0x1f, 0xfe, 0x2d, 0x1e, 0xc8, 0x39, 0x13, 0x25, 0xdf, 0xa2, 0xe1, 0xa8, 0xdc, 0x58, 0x4e, 0xc0, 0x48, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x1d, 0x45, 0x75, 0xdd, 0xc8, 0x77, 0xb2, 0x5d, 0xd9, 0xb9, 0x12, 0x84, 0xce, 0xde, 0xc4, 0x24, 0xfb, 0xc7, 0xa5, 0x83, 0x96, 0x4f, 0x22, 0x3e, 0xf8, 0xc4, 0x70, 0x74, 0x10, 0xbc, 0xfe, 0x72,
  0x61, 0x4A, 0x57, 0x4D,
  0x52, 0x85, 0x02, 0x1B,
  0x0D, 0xD2, 0xAA, 0x13
};

int main(void)
{
    FILE *fout;
    fout=fopen("manual.txt", "wb");
    fwrite(Reversed, 1, 80, fout);
    fflush(fout);
    fclose(fout);
    return(0);
}

(Dat1 has the values as they appear from blockexplorer, Dat2 has them bytewise-reversed - And spare me the comments about error handling  Wink ).

Neither produces the "right" hash via sha256sum.

Perhaps relevant, I notice that the "data" field from running "bitcoind getwork" has another 12 dwords worth of crap after the nonce, all zeros except for the 1st and 12th.  That pads it to 128 bytes (not coincidentally, the value of that first dword after the nonce), but I see no particular reason why it contains anything after the nonce.

I don't beg - If I do something to deserve your BTC, you can find my address on the invoice.  Wink
Hal
VIP
Sr. Member
*
expert
Offline Offline

Activity: 314



View Profile
February 21, 2011, 01:30:52 AM
 #5

sha256sum produces hex output, you need to convert to binary with xxd:

sha256sum -b manual.txt | colrm 65 99 | xxd -r -p | sha256sum -b
d1e802bfb7a086bb37e3e3f395e990e2663354ffaf948b9dde71020000000000

Hal Finney
Lis
Sr. Member
****
Offline Offline

Activity: 303


Spice must flow!


View Profile
April 28, 2011, 06:29:54 AM
 #6

sha256sum produces hex output, you need to convert to binary with xxd:

sha256sum -b manual.txt | colrm 65 99 | xxd -r -p | sha256sum -b
d1e802bfb7a086bb37e3e3f395e990e2663354ffaf948b9dde71020000000000
please show the contents of the file manual.txt

You would like to thank?
btc: 14tAPpwzrfZqBeFVvfBZHiBdByYhsoFofn
riX
Sr. Member
****
Offline Offline

Activity: 327



View Profile
May 01, 2011, 02:18:42 AM
 #7

please show the contents of the file manual.txt

Code:
echo 010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13 | xxd -r -p> manual.txt
sha256sum -b manual.txt | xxd -r -p | sha256sum -b

Lis
Sr. Member
****
Offline Offline

Activity: 303


Spice must flow!


View Profile
May 04, 2011, 07:24:44 AM
 #8

please show the contents of the file manual.txt

Code:
echo 010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13 | xxd -r -p> manual.txt
sha256sum -b manual.txt | xxd -r -p | sha256sum -b
Thank you very much

You would like to thank?
btc: 14tAPpwzrfZqBeFVvfBZHiBdByYhsoFofn
Bablos
Newbie
*
Offline Offline

Activity: 24


View Profile
July 29, 2011, 02:00:40 PM
 #9

My simple program for bitcoins getwork checking responce (based on sha256sum source code):

rescheck.zip (7.59kB).

To build use:
Code:
$ gcc -O3 -o rescheck sha256.c rescheck.c

Facility:
  • Auto detect of big/little endian
  • Compare hash of block with target embedded in responce and with difficulty 1


For example:
Code:
./rescheck 010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13

010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13
010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13
bits: 1b/028552
0000000000028552000000000000000000000000000000000000000000000000
00000000000271de9d8b94afff543366e290e995f3e3e337bb86a0b7bf02e8d1
Ok, this solution fine!

Code:
$./rescheck 010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13 \
0000000000026666000000000000000000000000000000000000000000000000

010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13
010000008d42cab4b755d6e9f01ffe2d1ec8391325dfa2e1a8dc584ec0480100000000001d4575ddc877b25dd9b91284cedec424fbc7a583964f223ef8c4707410bcfe72614a574d5285021b0dd2aa13
0000000000026666000000000000000000000000000000000000000000000000
00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
00000000000271de9d8b94afff543366e290e995f3e3e337bb86a0b7bf02e8d1
Bad! Hash of this solution >= target (but < target of difficulty 1)

Code:
$./rescheck 0000000133d3ca51635c3df04ed4420695184cc3b15a418c1d38e0af004644840000000048b034d304884865b81968d57620cf223b1000f91294b1bcab895dc0ab43a7a84e0896081b6f24bb64f3f0fe00000080000

0000000133d3ca51635c3df04ed4420695184cc3b15a418c1d38e0af004644840000000048b034d304884865b81968d57620cf223b1000f91294b1bcab895dc0ab43a7a84e0896081b6f24bb64f3f0fe00000080000
... reverse endian ...
0100000051cad333f03d5c630642d44ec34c18958c415ab1afe0381d8444460000000000d334b04865488804d56819b822cf2076f900103bbcb19412c05d89aba8a743ab0896084ebb246f1bfef0f364
bits: 1b/6f24bb
00000000006f24bb000000000000000000000000000000000000000000000000
00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
00000000bae52400491c6d205d1dbaca9bd6e319af3ac29fe5100dced2cff935
Bad! Hash of this solution >= target (but < target of difficulty 1)

1M1FUrd5wuYufT8LJ8F5fqzR2rbAkoUBpD    N6oe2N3ZsrvTqwRaAosD79c4ED8g1xjgeh
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!