Bitcoin Forum
May 05, 2024, 03:55:52 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: I Want To Learn Exact Formula To Get Block's Hash  (Read 193 times)
mutsuz (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 0


View Profile
September 21, 2018, 01:47:30 PM
 #1

Hi, I want to learn exact formula to get blocks hash where nonce is compatible for network's target requirements.

For example, I want to see formula like this.

SHA256 ("Previous Block Hash + Nonce + Merkel Root + Client Version")

Thank you very much. Have a great day  Grin
1714924552
Hero Member
*
Offline Offline

Posts: 1714924552

View Profile Personal Message (Offline)

Ignore
1714924552
Reply with quote  #2

1714924552
Report to moderator
1714924552
Hero Member
*
Offline Offline

Posts: 1714924552

View Profile Personal Message (Offline)

Ignore
1714924552
Reply with quote  #2

1714924552
Report to moderator
1714924552
Hero Member
*
Offline Offline

Posts: 1714924552

View Profile Personal Message (Offline)

Ignore
1714924552
Reply with quote  #2

1714924552
Report to moderator
In order to get the maximum amount of activity points possible, you just need to post once per day on average. Skipping days is OK as long as you maintain the average.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714924552
Hero Member
*
Offline Offline

Posts: 1714924552

View Profile Personal Message (Offline)

Ignore
1714924552
Reply with quote  #2

1714924552
Report to moderator
seoincorporation
Legendary
*
Offline Offline

Activity: 3150
Merit: 2930


Top Crypto Casino


View Profile
September 22, 2018, 02:56:21 PM
Merited by TheArchaeologist (3)
 #2

Hi, I want to learn exact formula to get blocks hash where nonce is compatible for network's target requirements.

For example, I want to see formula like this.

SHA256 ("Previous Block Hash + Nonce + Merkel Root + Client Version")

Thank you very much. Have a great day  Grin

This is what you are looking for:

Quote
A block header contains these fields:
Field    Purpose    Updated when...    Size (Bytes)
Version    Block version number    You upgrade the software and it specifies a new version    4
hashPrevBlock    256-bit hash of the previous block header    A new block comes in    32
hashMerkleRoot    256-bit hash based on all of the transactions in the block    A transaction is accepted    32
Time    Current timestamp as seconds since 1970-01-01T00:00 UTC    Every few seconds    4
Bits    Current target in compact format    The difficulty is adjusted    4
Nonce    32-bit number (starts at 0)    A hash is tried (increments)    4

For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, Block 125552. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:

Code:
>>> 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'

Source: https://en.bitcoin.it/wiki/Block_hashing_algorithm

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
mutsuz (OP)
Newbie
*
Offline Offline

Activity: 9
Merit: 0


View Profile
September 22, 2018, 05:01:59 PM
 #3

Hi, I want to learn exact formula to get blocks hash where nonce is compatible for network's target requirements.

For example, I want to see formula like this.

SHA256 ("Previous Block Hash + Nonce + Merkel Root + Client Version")

Thank you very much. Have a great day  Grin

This is what you are looking for:

Quote
A block header contains these fields:
Field    Purpose    Updated when...    Size (Bytes)
Version    Block version number    You upgrade the software and it specifies a new version    4
hashPrevBlock    256-bit hash of the previous block header    A new block comes in    32
hashMerkleRoot    256-bit hash based on all of the transactions in the block    A transaction is accepted    32
Time    Current timestamp as seconds since 1970-01-01T00:00 UTC    Every few seconds    4
Bits    Current target in compact format    The difficulty is adjusted    4
Nonce    32-bit number (starts at 0)    A hash is tried (increments)    4

For example, this python code will calculate the hash of the block with the smallest hash as of June 2011, Block 125552. The header is built from the six fields described above, concatenated together as little-endian values in hex notation:

Code:
>>> 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'

Source: https://en.bitcoin.it/wiki/Block_hashing_algorithm

You are a legend dude. I would give merit if I had but where is the nonce?
TheArchaeologist
Sr. Member
****
Offline Offline

Activity: 310
Merit: 727


---------> 1231006505


View Profile WWW
September 25, 2018, 09:53:00 AM
 #4

You are a legend dude. I would give merit if I had but where is the nonce?
This is the nonce in the example provided by seoincorporation: 42a14695

Code:
version        = "01000000"
hashPrevBlock  = "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000"
hashMerkleRoot = "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b"
Time       = "c7f5d74d"
Bits       = "f2b9441a"
Nonce       = "42a14695"



Sooner or later you're going to realize, just as I did, that there's a difference between knowing the path and walking the path
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!