What bitcoin mining really is...

in #bitcoin7 years ago

In the spirit of plagiarism and all things counterfeit, I have copy and pasted a portion of my gitbook that discusses cryptocurrency mining. Although this is specific to bitcoin, the fundamentals are the same for all cryptos. I've gone and done this because I'm tired of people being satisfied with "It is solving complex math problems" when asking where bitcoin comes from. For more detailed explanations, visit the link.

To understand mining, one must first understand the process of encryption and hash algorithms. In a sentence, bitcoin mining is accomplished by constructing a block of transactions and then creating a hash output that meets a certain requirement using the SHA256 hash algorithm. The steps to mine bitcoin are basically the following:

  • Construct a block of transactions from the mempool

  • Create a block header

  • Find a hash that meets the target/difficulty requirement using the transaction block and header as inputs

If you aren't a computer wizard, keep these facts in your mind for the time being as they will profoundly matter at the end.

  1. Hashes are mathematical functions that are generated from input and change if a single 1 or 0 is changed. For example, the md5 hash of the word "encrypted" is 5031e9989ae1ab3ba509b7d4220c0ddf. It changes to 2d9c15833082cac34d9dc214b7694068 if the 'd' is capitalized so it is "encrypteD".
  2. Hexadecimal notation is a base 16 numerical scheme, often displayed with a leading zero and 'x'. Here, one byte is equal to two characters. 0x00 = 0.

Here's an example. Let's take a look at block 320654. If we head over to chain query we can get a hex encoded block.

Miners verify transactions and by getting a handful from the mempool, and proving the have done the work to verify them by constructing a block header that consists of the following:

  1. 4 bytes: Bitcoin-core version (versionHex)
  2. 32 bytes: Previous block header hash (previous blockhash)
  3. 32 bytes: A merkle tree hash of all the transactions (merkle root)
  4. 4 bytes: Creation time of block in seconds from Unix Epoch (time)
  5. 4 bytes: Difficulty target for block (bits)
  6. 4 bytes: Value used to meet hash requirement (nonce)

These first 80 bytes can be found from the block. Here they are in bold.

0200000047c6b5a235e15103c0f3a4bc14c4404e22a5a0c80d95fe040000000000000000d1f659ff0ab35a8321ed9cf5f8a5108b8dacae710a1e797bcc741b6f76372e24d8861554e9db241882134bb0a501000000010000000000000000000000000000000000000000000000000000000000000000ffffffff48038ee404062f503253482f04da8615540827d5df4173c700002e522cfabe6d6d4f795fa04a50546a2cef73a1b478fcc8807fe10efee6947c46bc5632ee37095f04000000000000000000000001ddd03f95................ and on it goes

Now allocated to our 6 categories above:

  1. Version: 02000000
  2. Previous Block Hash:47c6b5a235e15103c0f3a4bc14c4404e22a5a0c80d95fe040000000000000000
  3. Merkle Root Hash: d1f659ff0ab35a8321ed9cf5f8a5108b8dacae710a1e797bcc741b6f76372e24
  4. Timestamp: d8861554
  5. Difficulty: e9db2418
  6. Nonce: 82134bb0

version/version hex: Pretty self explanatory. In older blocks you will see this in little-endian format (least significant bytes first). This is used to track software upgrades.+

time: For a quick conversion of epoch time to gregorian. The gregorian time of the above example is Sunday September 14, 2014 12:15:20 PM (GMT). The Unix Epoch Time is the number of seconds that have elapsed since 1 january, 1970 (midnight UTC).

previousblockhash: In order to make this a chain, the latest block must be connected. This is done by using the previous block hash as an input.

merkleroot: A merkle tree/root is a type of data structure commonly used in computer science. In the case of the blockchain, it works by hashing all transactions in a "bottom and up" approach and then pairing them, and then repeating this process until we are left with one hash. A merkle tree data structure is more easily imagined by a tree root system, with the root branches being data points and the tree stump being the final merkle root hash. Illustration.

difficulty: The difficulty requirement is encoded in hexadecimal notation. The last byte is the exponent value (exponent) and the remaining bytes are the coefficient value (hex_coefficient). The difficulty can be derived from the following formula:
difficulty = hex_coefficient * 2**(8 * (exponent - 3))
The last byte in the difficulty value tells us that an accepted hash should be less than 24 bytes long because 0x18 = 24 in decimal. Given that the header hash is 32 bytes long, this means that an acceptable hash must have at least 8 bytes of zeros in the front. You will commonly here and read on the internet that mining bitcoin is akin to solving complex mathematical problems. This is not technically correct. It is more akin to sampling through a lot of lottery tickets before finding a winning hash.

nonce: This is an integral part of the proof-of-work concept. The best way to think of the nonce is the number of attempts the miner had before finding an appropriate hash that meets the difficulty target, or how many lottery tickets the miner had to buy before finding a hash that would satisfy the difficulty requirement.

That is the surface of the rabbit hole. Hopefully you have more questions now than you did when you started. Just remember that bitcoin mining isn't trying to solve an extremely complex math problem. By reiterating that we are going to cause unnecessary confusion to newcomers. We are instead cycling through A LOT of values, changing our block header one value at a time and hoping it makes a hash that meets the bitcoin network target difficulty requirements. When that value is found, it is broadcast to the other nodes on the network and they can check the work by using the same values. If they match, the work from the miner is accepted by the network and another block is added to the chain.

Sort:  

Congratulations @bx0rr! You received a personal award!

1 Year on Steemit

Click here to view your Board

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @bx0rr! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.16
TRX 0.16
JST 0.031
BTC 59605.87
ETH 2518.81
USDT 1.00
SBD 2.44