Bitcoin Forum
May 25, 2024, 11:00:01 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Finding correct coding values  (Read 179 times)
Sarchio (OP)
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
October 15, 2019, 09:31:29 AM
 #1

Hello everyone! I am writing a school essay about mathematics in cryptocurrency. I would want to show the SHA-256 coding,(something familiar to this: http://www.righto.com/2014/09/mining-bitcoin-with-pencil-and-paper.html) however I am not sure about the input data. As I know I need:
*Version - which, as for now, is a constant 02000000
*Hash of the previous block in little endian
*timestamp - seconds from 1 January 1970 with accuracy to two hours (Idk which Timezone is correct)
*Current target
*nonce
*Merkle root - If I do not mine in a bitcoin client, how can I know the correct current merkle root?(I read that each client has a different merkle root)
Then, as I understand, I should divide the sum of those into 8 parts, which will be mine a,b,c,d,e,f,g,h; then 128 round of coding and I will receive my hash.
Also, theoretically, if I would get a correct hash, how can I attach it to the blockchain and receive the coins? Would the bitcoin client be needed?
Sorry for all the mistakes, I am a total newbie. So, could you tell me what parts are wrong? Thanks in advance.
HeRetiK
Legendary
*
Offline Offline

Activity: 2940
Merit: 2092



View Profile
October 15, 2019, 10:06:12 AM
Merited by ABCbits (1), Coding Enthusiast (1)
 #2

*timestamp - seconds from 1 January 1970 with accuracy to two hours (Idk which Timezone is correct)

UTC, which is identical to Zulu Time (UTC+0)

https://en.bitcoin.it/wiki/Block_timestamp


*Merkle root - If I do not mine in a bitcoin client, how can I know the correct current merkle root?(I read that each client has a different merkle root)

The merkle root is derived from the transaction ids to be included in the block you are trying to mine.

Here's a code-based example, I hope this clarifies a bit what is happening:

https://bitcoindev.network/calculating-the-merkle-root-for-a-block/
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
October 15, 2019, 10:17:16 AM
Merited by suchmoon (4), ABCbits (1), hugeblack (1)
 #3

Then, as I understand, I should divide the sum of those into 8 parts, which will be mine a,b,c,d,e,f,g,h; then 128 round of coding and I will receive my hash.
It is not a "sum" it is "concatenation". You concatenate all those parts (version, prev_hash,...) together to get a 80 byte long result and hash it twice with SHA256 (meaning SHA256(SHA256(80_bytes))).
To perform SHA256 you first split your "message" into blockSize parts. Since SHA256 is using 64 byte blocks you need 2 blocks (1x 64 + 1x 16(+pad)). Then you perform block compression/permutation on each of these blocks. 'a' to 'h' are the 8 parts of those blocks that split it into and then perform the permutation. Read https://tools.ietf.org/html/rfc6234 for details.

Also, theoretically, if I would get a correct hash, how can I attach it to the blockchain and receive the coins? Would the bitcoin client be needed?
Initially before you even start mining the block, you create a special transaction known as Coinbase Transaction. In that transaction you pay yourself the block reward + sum of transaction fees and place it at index 0 of the transaction array inside the block. Then calculate the merkle root and start going through hashes. When you found the correct block hash you simply broadcast it to other nodes so that they can know you found a new block and other miners could start working on the next block and stop working on the block you just mined.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
aliashraf
Legendary
*
Offline Offline

Activity: 1456
Merit: 1174

Always remember the cause!


View Profile WWW
October 15, 2019, 11:39:43 AM
 #4

op,
For you to do both your school assignment and mining bitcoin, you need to follow a minimum of bitcoin consensus rules in addition to sha256 implementation:

1- You need to keep the data you hash compatible with bitcoin format for a block header.

2- You need to be sure about the integrity and consistency of the block referred by  prev_block_hash you include in the block header under consideration otherwise you may found yourself mining on an obsolete fork.

2- You need to include a hash value for the Merkle Root part of the block header such that it commits to a correct block.

3- A minimum block has to include at least one txn, the coinbase.

4- You need to put your wallet address in the output script of the coinbase to receive 12.5 btc (in current halving status) again compatible with bitcoin transaction format.

So, as of your latest question, whether you need a bitcoin full client software to do this job or not, my answer would be both yes and no. You don't need it as a MUST but you need it as a SHOULD if you are actually thinking about mining as a resource-consuming activity that has to compensate for its costs, because without a full node:

1- You may be mining on top of an invalid block (like in spy mining) because you won't be able to properly validate the last block.

2- You won't be able to include any transaction in the block, other than your locally generated coinbase. So you won't have the chance to grind transaction fees.

That being said, please note that you need at least a minimized version of networking modules of the client software to communicate with other peers properly, no matter what.
odolvlobo
Legendary
*
Offline Offline

Activity: 4326
Merit: 3235



View Profile
October 16, 2019, 09:08:01 AM
 #5

Hello everyone! I am writing a school essay about mathematics in cryptocurrency. I would want to show the SHA-256 coding,... however I am not sure about the input data. As I know I need:
...

SHA-256 can be used on any data. I suggest that you avoid the details of the block header. Otherwise, your essay could get out of control.

...Then, as I understand, I should divide the sum of those into 8 parts, which will be mine a,b,c,d,e,f,g,h; then 128 round of coding and I will receive my hash.
Also, theoretically, if I would get a correct hash, how can I attach it to the blockchain and receive the coins?

It is much more complicated than that.


Another suggestion: narrow your topic down to how a hash such as SHA-256 can be used to prove something, and just mention its uses in Bitcoin as examples.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
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!