What is Bitcoin Mining and How Does it Work?

BITCOIN MINING

so welcome back to the course on blockchain in the last discussion we have discussed this Bitcoin mining presidio and we have looked into the consensus protocol in permissioned blockchain environment with a focus on the proof of work base system in Bitcoin network and we have looked into that how this proof of work-based mining procedure generates a consensus mechanism among the different miners who are proposing new blocks and make a tamper-proof architecture of the entire blockchain so in today’s discussion, we will explore that further and we look into the different tasks of the miner and what are the incentives to the miner to participate in this mining procedure and that mining procedure how to motivate them to employ some kind of economical properties or economical feature in the environment to control the entire mining procedure.

MINING BITCOINS

  • Join the network and listen for transactions – validate the proposed
  • Listen for new blocks – validate and re-broadcast a new block when it is proposed
  • Collect transactions for a predefined time and construct a new block

 so let us look into the details of the Bitcoin miners so the life of a miner of something like this though their task is to validate the transaction and then construct a new block once they have constructed a new block then employed here hash power to vote on consensus vote on consensus in the sense like to find out that who is going to complete the work first and then accordingly propose that block as a new block and commit the transactions in that new block and add that new block to the existing blockchain and then stored and broadcast that new blockchain to the peers that entire blockchain gets propagate in the network

 so this mining Bitcoin the entire procedure has six different steps so the first step is that – if you want to be a miner you have to join in the Bitcoin network and listen for the transactions then validate the proposed transactions which are coming from the client so the next step is to listen for the new blocks validate those new blocks and rebroadcast a new block when it is proposed so if you are getting a new block from one of your peers then you validate that new block and we broadcast it in the network then collect the transactions for a predefined time and construct a new block with that transactions the transactions which are not already included in the blockchain so as a miner you take those transactions and construct a new block.

  • Find a nonce to make the new block valid
  • Broadcast the new block – everybody accepts it if it is a part of the main chain
  • Earn the reward for participating in the mining procedure

then your task is to participate in the mining procedure or where your task is to find out a nonce to make the block valid by utilizing the predefined difficulty function for that means having a certain minimum number of zeros at the prefix of the obtain hash value so you have to generate the nonce according to that which is the mining procedure

so once you have got a new block you broadcast that new block to your peers and everybody in your peering system they will accept that block if it is part of the main chain so this concept we have discussed earlier because in a typical blockchain environment it may happen that multiple blocks are generated together so you had a block earlier 

so assume that this is the blockchain this is the longest chain every block is pointing to the previous block by the nonce and then at this so this is at time instance t1 this is a time instant T – this is a time instant T 3 and then at time instants T 4 – 2 miners have found out as same block if 2 – have found out the same block and both are the valid blocks then they proposed those blocks to the peers and if both are valid block they get propagated

so the idea is there here I am just trying to draw a Bitcoin network where you have multiple peers now assume that this is one miner and this is another minor so this minor has a found out block I am naming this block as b1 b2 b3 b4 and b5 say this miner has found out block b4 this miner has found out block b5 so this miner will broadcast this B4 block to its peers then this peer will again rebroadcast this b4 block

similarly this particular miner it will start broadcasting B5 block and this intermediate node it will get a certain number of b4 blocks and a certain number of b5 blocks so it will accept the block which it has received from more number of peers so it has to say 1 2 3 4 5 different peers so if it receives B5 from saying it has received b5 from 3 peers and it has received b4 from 2 peers then this miner it will accept the block that it has received from the maximum number of peers and rebroadcast that block

so that way this the next block say which is getting generated say B 6 it says B 5 is now getting propagated and this miner it has to say this minor it has received this miner it has received the block B 5 it has accepted Block B 5 and after accepting Block B5 if it is it has got successful in generating block b6 now it adds up this block b6 will b5 so now at instance t5 so now this becomes B 1 B 2 B 3 B 5 B 6 this becomes the longest chain in the network and this particular blockchain is utilized and the additional block that we had earlier we call this is a fork and this particular block it is not getting added further so these blocks have not become the part of the main chain so this chain is termed as the main chain in the blockchain network and this block before it the block before it doesn’t become part of this main chain so we call this block as the orphan block so that way the entire blockchain gets propagated in the network 

 so this way the block get broadcasted in the network and whenever the miner has found out a new block by participating in the mining procedure they aren’t a certain reward for participating in the mining procedure and this individual team runs in different rounds so at every time instance you are generating new blocks one after another 

MINING DIFFICULTY

  • A measure of how difficult it is to fond a hash below a given target
  • Bitcoin network has a global block difficulty
  • Mining pools also have a pool-specific share difficulty
  • The difficulty changes for every 2016 blocks
  • Desired rate – one block each 10 minutes
  • Two weeks to generate 2016 blocks
  • The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find 

now we have a term called mining difficulty so this mining difficulty it is a measure of how difficult it is to find a hash below a given target so it should be fine to find a has below a given target so if you remember the mining procedure the mining procedure says that we are going to generate our 256 bit hash function and we say that there is a mining difficulty the difficulty represented in this way that well out of this 256-bit hash the first 64-bit should be zero so at least first 64-bit would be zero so this says that well you have to generate a hash function

we’re in the final hash result at least the first 64-bit should be 0 and after that, the remaining bits can be zeros and ones so this is the difficulty of the mining procedure, and based on that we define a metric called mining difficulty so we have a concept called mining pool that we will discuss later the mining pools also have a pool-specific share difficulty now this difficulty parameter I am going to discuss the mathematical formulation of this difficulty parameter so this difficulty parameter it changes for every 2016 blocks so our desire rate is that we want to generate one block each at 10 minutes so at every 10 minute my target is to generate a new block

  now if you try to generate a new block at every 10 minutes and if you do the computation in that way you will find out that well to generate 2016 blocks you require exactly two weeks so it in two weeks you can generate 2016 blocks so this difficulty level it is readjusted at every 2 weeks so at every 2 weeks you find out that how many blocks you have generated whether you have generated 2016 blocks in less than 2 weeks time of duration they that means the difficulty is going to be too simple for the miners so you increase the difficulty and if you finding out that well the miners are taking more than 2 weeks of duration to generate 2016 blocks then it means that current difficulty is going to be too hard for the miners so you reduce the difficulty in that way 

  • Compute the following for every two weeks

current _difficulty = previous_difficulty * (2 weeks in milliseconds)/(milliseconds to mine last 2016 blocks)

so with this idea in mind so we define difficulty or we set the difficulty by utilizing this formula so you compute the difficulty at every two weeks or you can just recompute the difficulty after every 2016 block have been generated so you can compute on either every two weeks or after 2016 blocks are generated so our expectation is that within two weeks you want to generate 2016 blocks so that inter block generation time becomes equal to ten minutes so we said the difficulty in this way

so the current difficulty will be a previous difficulty the difficulty that was earlier multiplied by two weeks in milliseconds the total to each duration divided by milliseconds to mind the last 2016 blocks so that means if you are taking less time to mine 2016 blocks compared to two weeks then you are going to increase the current difficulty so if you can generate 2016 block faster that means there are current difficulty is going to be too easy for the minder so you increase the difficulty level if you are taking more time compared to two weeks to generate this 2016 blocks that means this time these milliseconds to mine last 2016 blocks this terminology becomes more than two weeks equivalent in minutes again if you are taking more time than two weeks that means the mining is becoming too hard so you reduce the current difficulty level so that way the Bitcoin network dynamically changes the difficulty level 

HASH – RATE VERSUS DIFFICULTY

  • The hash is a random number between 0 and 2^256 – 1
  • To find  block, the hash must be less than a given target
  • The offset for difficulty 1 is 0 × ffff * 2^208
  • The offset for difficulty D is 0 × ffff * 2^208/D
  • The expected number of hashes we need to calculate to find a block with difficulty D is (D * 2^256) / (0 × ffff * 2^208 )  

now let us look into that how this difficulty level is related to the hash rate that means how many hash you can perform now the hash that we are going to generate as you are using double sha-256 for generating the hash function so this hash is a random number between 0 & 2^256 – 1 so to find a block our objective is the hash must be less than a given target so we offset the difficulty level 1 as 0 at 0 ffff into 2^208 that means out of the 256 blocks we are saying that the initial 48 bits we one touch to 0 and the remaining bit we want as the 1 so that is the offset for difficulty 1 now accordingly we define the offset for difficulty D is all ones into 2^208/D

so this many number of zeros for different values of B by doing this computation you can find out that how many zeros you want at the beginning that determines the number of zeros that you want at the beginning the example that I have given for difficulty level 1 so for difficulty level 1 we want that the 2 0 8 bits so out of this 256 bit 256 bit hash the 2 0 8 bits should be equal to can be either 1 or 0  so we have a control over this 48 bit we want that this initial 48 bit should be all zeros  so that is for the difficulty level 1 accordingly we defined a difficulty level D the number of initial bits that we want so the expected number of hashes we need to calculate to find a block with difficulty D is something equal to D into 2^256 divided by

this offset so that means it comes to be D × 2^48 divided by this offset value so that is the expected number of hashes that you need to perform so this difficulty level dynamically changes the amount of hash that you want to do so if you if you are provide more difficulty that then so if you increase the value of B if you are providing more difficulty value so you have to generate more number of hashes to get the resultant target 

MINING DIFFICULTY

  • Current difficulty: 3511060552899.72 (as of 2nd april, 2018)

 so this is the current mining difficulty as of 2nd April 2018 so this large number represents the current difficulty level for a Bitcoin network 

so if you look into that how difficulty level has changed over time so this curve gives you that how the difficulty level changes got changed over time so you can see that mostly from January 15 to the current time we have a sharp increase in the difficulty level so later on, we will see that presently more and more miners are coming with higher Hardware or high power hardware’s to mine the blocks so that way the mining has become faster nowadays so to control that the Bitcoin network has gradually increased the difficulty and we can see a certain Sharpe in increasing the difficulty level in the last few months where a large number of miners participate in the mining procedure with specialized mining hardware

MINING HARDWARE

  I mentioned there are multiple specialized mining hardware which are available nowadays in the market so initially people have started doing the mining under standard computer then they have find out that well by participating in the Bitcoin mining procedure you can get more benefit you can get more reward and you can earn Bitcoin so the miners they have started developing hardware’s for that and initially people have moved the CPU based hardware to the graphic processing unit GPU based hardware’s and gradually recently they have moved to the hardware based on FPGA board

so this diagram actually shows you hardware with multiple FPGA boats so then in 2013 so we had this ASIC based mining hardware the full form is of an ASIC application-specific integrated circuit so this ASIC was designed to perform this sha-256 hash in a faster way so if you remember that in Bitcoin mining procedure we apply sha 256-bit hash function so to increase the mining speed what you have to do that you have to generate more number of hashes per unit time so this ASIC and the fastest it was released in 2013 for this first computation of sha 256 based bit hash function and this diagram is for mining hardware corresponds to this ASIC design 

TERRAMINER IV

so here is a use case which we call – the TERRAMINER 4 so this TERRAMINER 4 is an ASIC-based Bitcoin mining rig which has multiple such FPGA boats inbuilt which can perform the fast computation of hash function it can perform – 2 Terahash  per second that many numbers of hash it can perform so you can imagine that how many numbers of such 256-bit sha-256 hash function it can perform and the current cost for this hardware is approximately 3500 US dollar but nowadays even this hardware is not sufficient people have started building up mining pool or combination of multiple hardware’s together to perform these mining operations

MINING POOL

  • Pooling of resources by the miners
  • Share the processing power over a network to mine a new block
  • Split the reward proportionally to the amount of work they contributed

 when the point that I mentioned that the mining pool it is an interesting concept in blockchain  Network and Bitcoin network so the idea of this mining pool is that you combine multiple miners together the resources available from multiple miners together and then you ask the miner to generate the hash in a distributed way so every miner will start to generate the hash for a block and they will basically share their processing power over the network to mine a new block so the broad idea can be explained with an example so let me show you an example of that so you have a pool controller or sometimes we call it as pool organizer

 who is whose task is to construct or propose a new block so the pool organizer say has constructed a new block with multiple transactions and that task could be so this is a new block that has been constructed by the pool organizer and the pool organizer has constructed a new block and the task is to find out the nonce for this block

now there are multiple miners say m1 m2 m3 and m4 so you have multiple miners so the pool organizer informs this new block to all the miners and ask them to find out the hash value corresponds to that now what happens every miner independently tries to find out this nonce value and whenever they are finding out the nonce values they assume that the current difficulty level ask for say 20 leading zeros at the prefix say this is the current mining difficulty if this is the current mining difficulty then what individual miner can do they can try to find out the hash value where there are approximately 20 leading zeros at the prefix so the miners can propose something called a share so what is a share here like whenever the miners are generating the blocks the miners will generate blocks something like say they can generate the block something like to 0000d…

see something like that here I do not have five 20 leading zeros so this is in x so these four zeros signify for sixteen leading zeros so in this case, this is a kind of we call this kind of hashes as a near-optimal hash so these are kind of near-optimal has so this near-optimal has ensured that well this particular block is not the optimal one that is intended for but this particular miner is close to optimal so that way this miner also forwards this near-optimal blocks to the pool organizer as well as the block which is optimal so if the miner can find out a hash one of the miners can find out a hash where you have at least twenty leading zeros I should mention it as at least twenty leading zeros at the prefix then

that is the solution so assume that m2 has been able to find out such a block and m2 is sharing this block with the pool organizer and m3 was able to find out 3 such near-optimal hash values which are closer to the original hash value and M4 for was able to find out 2 such has value so the idea is that the way they have participated in this mining procedure so whenever all these four miners they are trying to collectively find out the nonce value for a single block the probability that one of them will be able to find it out it becomes higher compared to if a single miner tries to find out the highest value for the entire block so that way this mining pool concept it can increase the probability of getting a new block and at the same time this near-optimal solution that every miner is sharing with the pool organizer from

this near-optimal solution the pool organizer can decide that how much work has been done by individual miner so this miner was able to say send to such near-optimal solution so the idea is that whenever you are paying to 1 miner you say pay five say $2 to this miner 2 miners were able to generate one-year optimal solution so you pay $1 to 3 miner this one was able to generate three near-optimal solutions so you pay $3 to this one 4 miner able to generate two near-optimal solution so you create to pay $2 to this miner so that way the total block reward that the pool organizer is getting that particular block reward can be shared by multiple miners who are participating in the mining pool

  so that is the broad concept of the mining pool and here is a distribution of multiple pools that are there in that two days Bitcoin network so this BTC. Com and full BTC .. a day actually takes a huge share of the mining pool and one of the interesting statistics that I can show you

 can see you can the latest blocks which are being generated by multiple miners who have actually generated the block so currently the Bitcoin blockchain has this many numbers of blocks 516279 number of blocks so if I go to see more so you can see all the blocks here so you can find out that most of these blocks are related by some of the mining pools so this block was delayed by BTC.table then btc.com then VA BTC then Wahhabi BTC, so you can see that vie BTC has relayed this one-two three-block b2c dot-com, has relayed this block BTC-com hash relate this block then again this block so that means most of the blocks have been generated by some of the blocks some of the mining pools so they are collectively able to generate the new blocks and share the money among themselves

MINING POOL METHODS

  • Pay per share(PPS)
  • Instant guaranteed payout to a miner
  • Miners are paid from the pool’s balance, the share of a miner is R= B * p
  • Miners get almost equal payment, risk is at the pool operator
  • Contains hundreds of thousands of miners through special protocols
  • B: Block reward minus pool fee
  • P: the probability of finding a block in a shared attempt (p=1/D), D is the block difficulty

so let us look into that how the shears are distributed among different miners in a mining pool so in a mining pool there can be hundreds or thousands of miners who communicate with each other through some special protocols that I have discussed earlier so assume that capital B is the block reward pool free so every pool has whenever you are participating some mining pool you have to give some fee for that and B is the block B reward the pool fee effective reward that you are getting and P is the probability of finding a blocking a shared attempt whenever multiple miners are trying to do that and if D is the block difficulties then you can say that 1/ D is the probability for finding a block

 now we have multiple mechanisms like for distributing share one is called the pay per share and pay per share architecture you have an instant guaranteed payout to a miner so

whenever a miner is joining in the mining pool you pay the miner from the pools existing balance and the share of the miner is calculated as B* P so this constant amount of money is given to every individual miner who is joining in the pool and in this particular architecture pay per share the miners get almost equal and payment but a risk at the pool operator so it may happen that the pool is not able to find out any new block but because this is a kind of instant payment and a guaranteed payment to the participant or to the miners who are participating in this pool it may always happen that the pool is not getting any reward they were not able to mine any new block but still the operator need to pay to the individual miners who are there 

  • Proportional
  • Miners earn share until the pool finds a block (end of mining round)
  • R = B* n/N, where n is the amount of his own share, and N is the amount of all share in the round
  • Payments are made once a pool finds out a block

then there are methods like proportional share in case of proportional share  the miners aren’t here until the pool finds a block so at each of every mining round whenever the pool is finding out a block you find out that what is the total share of the individual miners – so the share by share we mean the near-optimal solution that the miners are able to find out so assume that capital N is the total amount of shares in the round and small n is the amount of the share of a particular miner

so you divide the block reward is proportional to the amount of share that has been generated by the miner in this current Mining round so a mining round means to say at saying this is the time instant at this particular time instance this pool has pool generated a block and again say at T 1 at T 2 the pool has generated new block so within this time duration we compute this shares and in proportion to that share the total mining reward is so the pool is generated a new block means at this time the pool gets some reward to be this reward is distributed among individual miners in the pool

  • Pay per last N share (PPLNS)
  • Similar to proportional
  • Miners reward is calculated on the basis of N last shares
  • Miners get more profit for a short round

 Then we have pay per last ends here PPLNS method it is similar to the proportional shares the only difference is that here in capital N we are considering the amount of all share in the round in case of PP in the next method  we consider only the last N shares so among the last N shares  how much here was obtained by a particular miner and that way the miner get more profit so in that way if your round is small that means if you can quickly find out a new block so you will get more share in  this particular pay per last N share method

  • PROS
  • Small miners can participate
  • Predictable mining
  • CONS
  • Leads to centralization
  • Discourages miners for running complete mining procedure

 so the advantage of a mining pool is that small miners can participate in a mining pool and you have a kind of predictable mining like whenever you have a large number of miners who are participating in the mining procedure you can say that well there is a high probability that the pool will be able to find out a new block but the problem with this kind of architecture is that it leads to centralization 

so if you look into these this blockchain.. info website and if you look into these blocks recent blocks which are being relayed by multiple miners you will find out that the same miners are relaying multiple blocks one after another so this buzzy.com is relaying multiple blocks similarly via BTC is also relaying multiple blocks so all the blocks that are getting relayed they are actually coming from there they are coming from some fixed number of mining pools either by BTC or say VAR b TC or btizzy.com again via BTC so a notion of monopoly you can be seen with this architecture and it also discouraged the miners from running the complete mining procedure

because it may happen that the miner will if they have able to generated some 4 almost complete blocks or almost complete hash on your optimal hash they are happy that well they are going to get some amount Of…share so they may not participate further in the future 

Summary – Permissionless Blockchain and Bitcoin

  • The permissionless or open model of blockchain – any user can join the network and participate in the transaction
  • Bitcoin is developed on this principle
  • The blockchain provides the backbone of the permissionless digital currency
  • Provides a decentralized architecture
  • Tamper-proof through the hash- chain
  • Miners ensure the consensus in the system

well in summary in till now we have looked into the permissionless or the open model for blockchain so you have looked into the permissionless or open model for blockchain where any user can join the network and participate in the transactions and bitcoin is developed based on this principle so the blockchain it provides a backbone of the permissionless digital currency by providing a decentralized architecture and by providing architecture which is tamper-proof with the help of Hash chain based technology and then this mining procedure in a permissionless blockchain it ensures the consensus in the system 

so that is the broad idea of this permissionless blockchain architecture so in the next discussion we will start with another model of blockchain which is called a permission modular blockchain and we will see that how traditional distributed system algorithm becomes more powerful for permission blockchain environment and then from there we look into the different application of blockchain apart from the financial domain 

READ MORE ARTICLE: R3 CORDA

follow us on facebook

Leave a Comment