1

How does it become harder for miners to extract bitcoin as time passes (excluding increasing computer capabilities and the competition between miners accordingly)? Is related to the amount of bitcoins that could be extracted at that timestamp?

2 Answers 2

1

The Bitcoin blockchain has a property called the "difficulty" or "target", which is expressed as a 32-byte number. For a new block to be valid (among many other things) it's hash (another 32-byte number) must be arithmetically less than the target. This target value is adjusted after every 2,016 block period by a deterministic algorithm performed by all full nodes on the network.

Imagine if I asked you to flip a coin and if you got 3 "heads" in a row you win. How many attempts would you need to win? Once you win, I change the difficulty: now you must get 4 "heads" in a row... that will be harder for you and require more "computation" (attempts).

In Bitcoin, the difficulty adjustment algorithm looks at the time stamp of the block at the start and end of the 2,016-block period. If that time is greater than two weeks, the new difficulty target becomes "easier". If the blocks are being mined too fast, the difficulty becomes "harder".

further reading: Where exactly is the "off-by-one" difficulty bug?

3
  • Thank you for the detailed answer, I have some questions though. Firstly, isn't bitcoin blockchain using SHA-256 hashing algorithm which produces 64-bit results? Secondly, what do you specifically mean by "arithmetically less" since hash is a combination of letters and numbers? Also, could you elaborate on the last paragraph more? @pinhead Apr 21, 2020 at 19:20
  • SHA-256 digests are 256 bits (32 bytes) hence the name. While hashes are commonly displayed as hexadecimal digits (0-9, A-F) they aren't strings, they are a set of 32 bytes that can be interpreted or compared as numbers just like 1-byte numbers. Since the target is just a number, it can go up or down based on how fast the last 2,016 blocks were. The formula targets 1 block every 10 minutes.
    – pinhead
    Apr 21, 2020 at 19:52
  • Alright, now I understand it completely! Thank you! @pinhead Apr 21, 2020 at 20:34
0

The easiest way I can think of to explain this is to give you a die (dice) and say "If you roll less than a 6, i'll give you $100". It'll be pretty easy to get the money, right? The only way you can lose is if you roll a 6

Now if I change the game to be "roll less than a 2", it's harder (less likely) that you'll get it on your first go, because you have to roll a 1.

So lets say I am aiming for you to win $100 a minute, and you're fast enough to roll about 3 times a minute. You start rolling and I notice with the difficulty set at 5, you're winning a lot more often than once a minute, so I dial the difficulty number down (make it harder). Say we reach a point where with the difficulty set at "below 3" you are, on average, winning once a minute. Then you have a real streak of bad luck and it takes you 4 minutes to roll less than 3 - you just kept rolling 6's for the first 3 minutes. I figure I'll go easy on you, and I raise the difficulty number again because you're having a bad streak so I'll make it easier to win. Then you start doing really well, so i start reducing the number again.

On a regular basis, i'll look back over the average time it took you to win recent games and decide whether to adjust the difficulty or not, and tweak it up or down to try and keep you to winning once a minute. If you get faster at rolling, i'll make the game harder. If you get your buddy to roll with you, I'll make it harder still. If you put the die away for a day then roll a win it'll massively affect the average time for a win, and I'll probably adjust thing so it's easier.


This uses a 6 sided dice; the numbers involved in bitcoin are much much higher - at the time of writing the difficulty is about 15,000,000,000,000 and hashes can be between 0 and 2^224 (about 270,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000) but the premise remains the same - it's a dice with 27000 vigintillion sides and you have to roll less than about 15 trillion. And you can buy devices that roll up to 16 trillion times a second. With your big rewards you can buy loads of these devices and fill a warehouse with them, increasing your odds of being the one to roll the win, if you can afford the power bill

The rolling of the dice is the generating of the hash code for the transactions the miner has decided to pack into a block.

In essence the miner packs a block with transactions, calculates the hash, it's greater than the difficulty, they change one number in the block header (rather than go to the effort of packing another block of transactions - a lot more computationally expensive to do but would have the desired effect of changing the hashcode, which is the overall goal) called the nonce. So we change the nonce, re-do the hash, is it less than the difficulty? No. Change the nonce, redo the hash. Check the difficulty/change the nonce/hash/check/change/hash/check/change..

Eventually something happens:

  • we find a hash less than the current difficulty - quick! announce it to the network and get the world to verify the work, accept it and we get the reward
  • someone else finds a block of transactions that has a hash less than the difficulty, they get the reward, all the transactions they packed are completed/paid - we need to start over with a new block of transactions
  • we run out of nonces (there are only 4 billion) because we're hashing so fast (transaction blocks have a timestamp that increments, which also changes the hashcode, but even then coupled with the 4 billion nonces means if we hash faster than >4ghash/second we'll run out of nonces before the time ticks up by a second, so we then go and modify one of the transactions slightly, or swap it out for another) - whatever is needed to bring about even a valid single byte change in the block will produce a different hashcode, so we make that change and carry on (probably back with the nonce changing method)

So who is the authority on what the difficulty should be? Same as anything else with bitcoin - everyone. The network decides on the difficulty, and because all (or most) of the network are good actors, you can't cheat, you can't write a program that claims a win with some hash, because everyone else proof checks the work and they don't accept it if you cheated the hashcode, or lied about getting lower than the difficulty. It's like everyone else in the casino watched you roll, and if you rolled a 6 but shouted "i rolled a 1!" they ignore you

2
  • Thank you for the detailed answer! I appreciate it! @Caius Jard Apr 22, 2020 at 8:54
  • No probs! I made a couple of edits since you've read it, but likely stuff you knew already..
    – Caius Jard
    Apr 22, 2020 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.