Complex Puzzle in Bitcoin mining ain’t Complex, NO More!

Image : Reuters

Before we start deciphering the complexity of Bitcoin mining, I feel it is imperative to have a quick understanding of the below mentioned terminologies:

hashing : It is the process of converting an input of any length into a fixed size string or a number using an algorithm

Image : Wikipedia

Proof of Work : It is the original consensus algorithm in Blockchain network. The algorithm is used to confirm the transaction and create a new block to the chain. In this algorithm, minors compete against each other to confirm the transaction on the network

Image : gitconnected

nonce : In cryptography, a nonce is an arbitrary number that can be used just once in a cryptographic communication. It is often a random or pseudo-random number issued in an authentication protocol to ensure that old communications cannot be reused in replay attacks.

SHA 256 : SHA-256 is a patented cryptographic hash function that outputs a value that is 256 bits long.

Bitcoin Core : It is a software used for running the computers/nodes which are managing the Bitcoin blockchain. It has the ability to perform the following tasks which as mentioned below :

  1. Connect with other participants in the Bitcoin network
  2. Download the blockchain from other participants
  3. Store the blockchain
  4. Listen for new transactions
  5. Validate & Store those transactions
  6. Relay valid transactions to other nodes
  7. Listen & validate new blocks
  8. Store those blocks as part of its blockchain
  9. Relay valid blocks
  10. Mine new blocks
  11. Manage addresses
  12. Create & send transactions

Blocks : Blocks are nothing but bundle or batches of transactions which helps in addressing the transaction ordering problem. The block creation slows down the “data entry” process of the bookkeeping system, thus minors/bookkeepers around the world have more time to agree to the ordering of blocks of transactions. Because there is more time to agree on the order of blocks, there are fewer differences in opinion about block ordering, and so a greater chance of network wide consensus.

In Bitcoin, blocks are created evert 10 minutes on average. Different cryptocurrencies have different block creation target times.

Alright, now let’s deep dive and try to understand how Bitcoin actually works. Bitcoin mining is nothing but a game of chance, where the entire network participates for creating the blocks and earning their rewards for the block creation. It ensures that all the block creators get equal chance/opportunity to create the blocks within the below mentioned parameters :

  1. The game must give all block creators equal chance of winning(block creation)
  2. The game must not have shortcuts
  3. The game must have publicly displayable proof so that the winner can prove they have won
  4. The game must not be cheatable

This game of chance is called “Proof-of-work”. Each block creator takes a bunch of transactions that they know about, but which have not been included in any previous blocks, and builds a block out of them, in a specific format. The creator then calculates a cryptographic hash from the block’s data. Remember that hash is just a number.

The rule of Bitcoin’s proof-of-work game of chance says, if the hash of the block is smaller than a target number, then this block is considered a valid block which all bookkeepers should accept.

What if the hash of the block is bigger than this Target number?

It’s simple, the block creator needs to alter the data going in to the hash function and try hashing the block again. They could do this by removing, adding or changing the order of transaction in the block, but these are not elegant and eventually you might run out of permutations. Plus, you don’t really want to mess around with the transactions in block.

The solution to this is that every Bitcoin block has special part that block-creators can populate with an arbitrary number. Its only purpose is to allow block creators to fill it with a number, and change the number if the hash block doesn’t meet the “hash is smaller than a target number” rule. So if the 1st attempt doesn’t result in a winning hash, then they can just change the number in this part of the block. This number is called the “nonce” and is completely separate from the financial transactions in the block. Its only job is to change the input data for the hash function.

Image : IEEE

So each block-creator puts together a block and fills the nonce field with the number and hashes the block. If the result meets the “hash is less than a target number” rule for valid blocks, then they have crated a valid block, and can send it to the bookkeepers, and get to work on the next block. If the result doesn’t fit the rule, then they change the nonce and hash again. They do this repeatedly until they find a valid block. This is a process known as mining.

The authority to create a valid block is not given by a third party but is self-assigned by repeating some tedious mathematical algorithms, which all computers can do. Note that mining is a tedious, repetitive job. Take some transactions with the nonce, hash it, see if the hash is smaller than a certain number, and if not repeat with a different nonce. “It is not solving complex mathematical problems” as is widely described in the media.

That’s all Folks!
Credits : The basics of Bitcoins & Blockchains by Antony Lewis
Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

Complex Puzzle in Bitcoin mining ain’t Complex, NO More! was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.