Nonce and Previous Hash Construction For Bitcoin Mining
Nonce and Previous Hash Construction For Bitcoin Mining
Nonce and Previous Hash 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)
*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.