Nonce and Previous Hash Construction For Bitcoin Mining

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Nonce Construction for Bitcoin Mining

Using a cryptographically secure generator (necessary for our purposes?), create a nonce with at
least 128 bits of entropy (32 hex characters). Obviously, any change to the block data (such as
the nonce) will make the block hash completely different.
The nonce starts initialized to zero.
One problem is that as difficulty increased, miners often cycled through all 4 billion values of the
nonce without finding a block. This was resolved by updating the block timestamp to account for
the elapsed time. Because the timestamp is part of the header, the change would allow miners to
iterate through the values of the nonce again with different results.
1. Theoretically, a block only has 32 bits for the nonce. Why is it that size? Is it possible for
the difficulty to become high enough that there are no nonce solutions?
At the default size, it requires over a quadrillion hashes to solve a block. 2^32 is only 4 billion.
Fewer than one in a billion times will there be any nonce that makes the block valid. Simply put,
it is this size because this size is just “big enough”.
With classical computation methods, even with a difficulty of 1 (standard) there is a 36.7%
chance of not finding any valid hash in the entire nonce range (2^32). At 1 million difficulty
there is a 99.999905% that you will not find a solution in the entire nonce range. Our quantum
version circumvents the issue.
Hash Construction for Bitcoin Mining
Hashing power of the bitcoin network for the first 5 years:
2009 0.5 MH/sec–8 MH/sec (16× growth)
2010 8 MH/sec–116 GH/sec (14,500× growth)
2011 16 GH/sec–9 TH/sec (562× growth)
2012 9 TH/sec–23 TH/sec (2.5× growth)
2013 23 TH/sec–10 PH/sec (450× growth)
2014 10 PH/sec–150 PH/sec in August (15× growth)

2. What is the role of the previous hash in blockchain mining?


Short answer: the new hash is attainted by passing the previous hash, data (the aggregated set of
transactions included in this block, obtained classically), and nonce through SHA-256. Miners
will try to calculate the hash of a block by adding a nonce to the block header repeatedly until the
hash value yielded is less than the target.
The purpose is to connect the blocks through the blockchain. Although a block has just one
parent, it can temporarily have multiple children. Each of the children refers to the same block as
its parent and contains the same (parent) hash in the “previous block hash” field. Multiple
children arise during a blockchain “fork,” a temporary situation that occurs when different blocks
are discovered almost simultaneously by different miners. Forks are generally resolved before
the chain continues.
The “previous block hash” field is inside the block header and thereby affects the current block’s
hash. In a block, the previous has is found in the header (the metadata); the header size is 80
bytes, whereas the average transaction is at least 250 bytes and the average block contains more
than 500 transactions.
Block Header Contents: The nonce, difficulty, and timestamp are used in the mining process
Size (bytes) Field Description
4 Version Version # to track latest updates to software or protocol
32 Previous Hash The hash of the previous (parent) block in the chain
32 Merkle Root A hash of the root of the Merkle tree of this block’s
transactions
4 Timestamp The approximate creation time of this block
4 Difficulty The proof-of-work algorithm difficulty target for this block
4 Nonce A counter used for the proof-of-work algorithm

*Please note that all of this data in the block header is compressed into 80 bytes using a notation
called “little-endian”, making the transfer of block headers between nodes a trivially efficient
process. We are ignoring this compression for now.
The hash is formed by hashing the block header twice through the SHA256 algorithm (result is
32 bytes). As a node receives incoming blocks from the network, it will validate these blocks and
then link them to the existing blockchain. To establish a link, a node will examine the incoming
block header and look for the “previous block hash.”
Defining Merkle Roots:
Each block in the bitcoin blockchain contains a summary of all the transactions in the block,
using a Merkle tree (aka a binary hash tree) which contains cryptographic hashes. Merkle trees
are used in bitcoin to summarize all the transactions in a block, producing an overall digital
fingerprint of the entire set of transactions, providing a very efficient process to verify whether a
transaction is included in a block. A Merkle tree is constructed by recursively hashing pairs of
nodes until there is only one hash, called the root, or Merkle root. The cryptographic hash
algorithm used in bitcoin’s Merkle trees is SHA256 applied twice.
When N data elements are hashed and summarized in a Merkle tree, you can check to see if any
one data element is included in the tree with at most 2*log2(N) calculations. Transactions form
the leaves of the tree. These transactions are not stored in the Merkle tree themselves; rather,
their data is hashed and the resulting hash is stored in each leaf node. Consecutive pairs of leaf
nodes are then summarized in a parent node, by concatenating the two hashes and hashing them
together- two 32-byte hashes of the children are concatenated to create a 64-byte string. That
string is then double-hashed to produce the parent node’s hash. When only one node remains,
that is the Merkle root.
There are 4 processes essential to Bitcoin’s decentralized nature: (1) Independent verification of
each transaction, by every full node, based on a comprehensive list of criteria, (2) Independent
aggregation of those transactions into new blocks by mining nodes, coupled with demonstrated
computation through a proof-of-work algorithm, (3) Independent verification of the new blocks
by every node and assembly into a chain, and (4) Independent selection, by every node, of the
chain with the most cumulative computation demonstrated through proof of work.
Difficulty Rating:
The encoding has a 1-byte exponent, followed by a 3-byte coefficient. Example: the difficulty
bits value is 0x1903a30c, with the first part 0x19 being a hexadecimal exponent, while the next
part, 0x03a30c, is the coefficient.
To decode it, we use:
target = coefficient * 2^(8 * (exponent – 3)), then convert to decimal, then convert to
hexadecimal, then to binary. That will give us the number of leading bits set to 0.

Putting these parts together for mining:


In the simplest terms, mining is the process of hashing the block header repeatedly, changing one
parameter, until the resulting hash matches a specific target. You take the current block’s header,
add the nonce, and calculate its hash.
Traditionally, one would start with nonce 0 and increment the nonce by 1 for each wrong hash,
add it again to the block header, and hash that changed value.

You might also like