2
$\begingroup$

Alright this is another day of my pursuit to learn about how crypto works. I have several terms that I have found linked together. I was trying to do research on how the Target Hash is determined and how a Nonce is decided. But I think I am getting lost in several terms and need helping making the connections.

I found a post on here that said the hash is "computed by double-SHA256 the block header, including timestamp, nonce, version, Merkle root, nBits which encodes the difficulty, and previous block hash." and "A target computed from the difficulty only".

I am confused what the difference between a block header and a block's hash value is. Confused about the nonce and target value and how they are decided. Merkle root seems like something out of my depth for now. And I am familiar with difficulty as it relates to finding revenue from proof-of-work mining, but I am not familiar with how difficulty is calculate or what nBits is and how it relates to this mess.

I know this is a lot of stuff to walk someone through but honestly a lot of posts are either older and if I wanted any clarity I am not sure if I would get a response and my other options is articles assembled by gurus that oversimplify stuff.

$\endgroup$
0

1 Answer 1

1
$\begingroup$

It really depends on the crytocurrency you are looking at. I will take example on Bitcoin here. Also, Bitcoin has gone through lots of changes which makes it difficult to track everything. For example, the target determination algorithm has changed at least 2 times.

Bitcoin uses SHA-256 as its hashing function. SHA-256 is a very simple algorithm but it is harder to find out and calculate the probabilities of possible attacks against it. The agency responsible for its development (SHA-256) is the NIST agency of the US. You can browse it at http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf. The PDF on the link provided really defines the SHA-2 family of hash functions. It is really easy to implement.

In SHA-256, the program splits the message (the bits of it) into fixed sized blocks adding some padding if necessary. The resulting blocks (each split of the message having nothing to do with the blockchain blocks) are passed through several functions. The hash value of the last block is added to the current hash value. The resulting 256 bits hash is thus dependent on the whole message input. This makes the hash unique with a very high probability.

For Bitcoin, things are quite simple. The algorithm was changed but, early on, the target was simply calculated by the network of nodes with the equation: new target = current target × (minutes to mine the last 2016 blocks / 20160 minutes). 20160 minutes is the time expected to mine 2016 blocks. If the current mining time of 2016 blocks is higher than expected, the new target will become smaller by the equation and vice-versa.

The goal of mining is to get blocks from the network of nodes (which include the transactions) and find a hash of that block that is lower than the value of the target. If the target is very high, the probability of finding that hash increases. I don't have actual probabilities but by logic it is easy to conceive that, the higher the target value, the easier it is to find a hash which is smaller.

This mining process must have a way to make the hash of the block vary which introduces the nonce. The nonce is a 32 bits value which is started at 0 and stored in the header of the block. The hash of the block is made and the nonce incremented by one at every unsuccessful attempt. If the nonce reaches its maximum capacity. The coinbase transaction is used.

The coinbase transaction is used to compensate the miner and to further increase the amount of possible different nonces. The coinbase transaction has special requirements and it is verified to make sure it meets some requirements. For example, the nodes will check if the miner doesn't compensate himself too much based on the current miner subsidy (starting at 50 BTC and halved every 210k blocks) and on the amount of transaction fees included in the transactions of the block.

Transactions are quite complex structures. They have inputs and outputs. The coinbase transaction will thus have lots of unused fields and inputs/outputs will be mostly empty. It is only the miner compensating itself. All those fields can thus be used to change the hash value of the block in order to find a hash smaller than the target.

As to transactions themselves. I don't know a lot about them. I know they rely a lot on assymetric cryptography whereas a public key can be shared and its private counterpart is kept private. It is very hard to find the private key from the public key so you can prove you own a certain address by providing its associated public key and signature.

Merkle root is simply a hash of all the transactions. Transactions are simply arrays of bytes with some added meaning. They are hashed in pairs until a "root" is found.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.