# Tag Info

39

if in the coming years the difficulty increases so much that mining is no longer profitable That's not really possible. The mining power is set so that the miners need 10 minutes in average to mine a block. If 50% of the miners would disappear because it's not profitable any more, the difficulty would decrease so that it's profitable again. Can the ...

22

The explanations on the web are all very vague and mystical, on purpose maybe. Here is my take in simple words, just reading the megacoin source code from the above comment. The goal is to have a more adaptive way of adjusting the difficulty instead of just averaging the last 2016 blocks like bitcoin. This is needed because of multipools which might switch ...

18

Meni's answer is good. I just want to give some practical detail method about difficulty calculation, perhaps helpful for future views of this question's answer. Let's take a look at Satoshi's genesis block header (part of related info): \$ bitcoin-cli getblockhash 0 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f \$ bitcoin-cli ...

18

The target section of the block header is called nBits in the code. nBits is a 32-bit compact encoding of a 256-bit target threshold. It works like scientific notation, except that it uses base-256 instead of base-10. For example, if nBits is equal to 0x181b8330, you would calculate it like this: Or, more simply, you'd use the same shorthand you use with ...

16

(If I may repeat myself a bit...) Mining is like having a lot of people throwing weighted coins (such that 1 millionth of the time it comes up heads) and telling you when they hit a heads. If one such "heads" is reported every 10 minutes (600 seconds), you can make a very accurate estimation of how many times per second the coins are being flipped. In this ...

16

Contrary to popular belief, the target is not actually based on the number of leading zeroes. This is a major simplification that is used to get the general idea across, but is not actually how the code works. Instead, the target is just a number that is adjusted by the ratio between the actual time between blocks and the expected time between blocks (with ...

15

How to calculate the target from bits Let's start with a block-header, always 80-bytes that looks like this: 04000000b9e2784a84e5d2468cee60ad14e08d0fee5dda49a37148040000000000000000e9dd2b13157508891880ef68729a1e5ecdde58062ebfa214a89f0141e5a4717faefd2b577627061880564bec From the 80-bytes, the bits are actually the 72nd to 76th byte: ...

14

As Andrew's answer points out, the 'number of leading zeros' is just a simplification, so I thought I would give an example to more concretely illustrate this: Block hashes are usually represented in hex format, which utilizes the character set [0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f]. But for simplicity, we can just use a base 10 number set [0,1,2,3,4,5,6,7,8,9], ...

13

A supercomputer is way slower than mining with ASICs. A supercomputer only has much CPU power, not even GPU power and ASICs are way more powerfull than GPUs. ASICs represent the hashing algorithm as hardware which means they can't do anything else, that's why they are so fast. At http://bitcoinwatch.com/ you can see the current network hashrate in PetaFLOPS,...

13

A hash is 256 bits long, so there are 2^256 possible hashes in the hash space. But if you assert that the hash has to begin with a 0, that halves the number of hashes that are allowed (and thus doubles the average number of hashes you need to test), and if you say it must start with two 0's, that's now only quarter of the hash space that is valid. The ...

11

I'm not sure it was. When the network started operating (and Satoshi was pretty much the only one mining), blocks weren't found every 10 minutes. For example, the first 2016 blocks were found in 24 days rather than 2 weeks. Normally this would cause the target to go up but it can't go above the hardcoded max target, so only in block 32256 in December 30 2009 ...

11

Because blocks were not being mined in less than 10 minutes on average during this time (so the difficulty would only decrease and not increase), and the difficulty cannot go lower than 1.

10

Mining is a self-adjusting system. The difficulty only rises in accordance to the available mining power. Hence, it can neither go to a difficulty where it will take months for a block to be found, nor can it become prohibitely expensive to mine. Also see How is difficulty calculated?.

10

17 judging by the latest blocks published on blockchain.info: https://blockchain.info/block/0000000000000000057fcc708cf0130d95e27c5819203e9f967ac56e4df598ee

10

They aren't really necessary. The reason that they are included can only be known by Satoshi, and AFAIK, he did not state why he chose to include nBits in the block header (or many other things that are just arbitrary). This is one of the many things that Satoshi chose to do and no one really knows why. It remains in the block header today because removing ...

9

The Bitcoin reward schedule follows a predetermined pattern, see Controlled supply from the Bitcoin wiki. The next reward drop will happen at block number 420000. The current block number at the time of writing this answer is 318662. There are about 101338 blocks remaining. At approximately 10 minutes per block, there are approximately 1008 blocks per week, ...

9

You're presenting it as a choice between either allowing miners to choose the difficulty, or having it be implied by previous history. In fact, neither is true. The target is determined by history (for the reasons you bring up), and the target stored inside the block header has to match the value determined by history. At this point, there is no good ...

8

TL;DR. Bitcoin profitability is about choosing between buying BTC outright (Coinbase, or Bitstamp) or buying hardware ASIC miners and paying the ongoing electrical fees. Edit: To keep mining expenses low, you will need the cheapest form of electricity. This usually means coal in most regions. "Clean coal" doesn't exist. 10 years from now is a long time, ...

8

To understand this we should first explain that a block with a high difficulty, let's say D, is also a share of low difficulty d < D, therefore if we find such a block for difficulty D we automatically have a block of difficulty d. This also means that if I as a miner am looking for a share with difficulty d I might by chance find a block of difficulty D (...

8

No, there is no consensus until the next block is found. The network is experiencing a blockchain-fork. It will only mend once one of the tips pulls ahead by adding another block. Then all nodes will reorganize to the longest chain and consensus is reestablished. The losing chain becomes an extinct branch – valid but not part of the longest chain. There can'...

8

Testnet has a built in functionality that changes the difficulty to 1 if the mining process takes 20 minutes or longer. This question explains the dropping of difficulty to 1. So while the difficulty is 1, the blocks are being formed rapidly until the difficulty reaches to a value which takes 10 minutes.

8

TL;DR The formula comes from turning an algorithm into a mathematical formula. nBits encodes the target with the first bytes as the size of the final target, followed by the 3 most significant bytes of that target. This can be converted into that crazy formula. The formula is the mathematical representation of the actual algorithm that was used for the ...

7

The mining difficulty is going up very fast. You are correct. But the mining industry is also stimulating the Bitcoin economy significantly. See this news story, for instance: KnCminer sells \$3M of bitcoin mining equipment in 4 days My best answer to your chart is another chart: From: https://blockchain.info/charts/miners-revenue Even with the bitcoin ...

7

No, the SHA2 hashing function is not vulnerable to any known attack that significantly reduces the difficulty of finding a block, but it is a highly random process. Randomness is funny sometimes. Statistically it it works out to be even over a longer time period or larger population, but if you focus in on a small set of samples sometimes you see a cluster ...

7

Miners task is to find a hash below a target T. Obviously if T is smaller, its more difficult to find the hash number. Difficulty D is defined by: D = Tmax/T where Tmax is: 2^224 The probability of finding the hash is: P = T/2^256 which is equal to 1/D2^32 So if you can make h number of hashes in t time, the probability of finding the target hash is: P =...

7

Take the difference (in days) between the current date and the date you are trying to estimate the block height for. Then multiple that difference by 24 hours and by 6 (6 blocks per hour) Current block height + (difference in days) (144) = new estimated block height Difficulty changes upon release of new ASICs or halving are temporary (average block time ...

7

I admit that I don't know for sure, but I have a guess. Since Satoshi was mining by himself for the first blocks, he probably set the initial target to whatever would take approximately 10 minutes to mine a block on his CPU. Had he set it to the maximum value for a 256 bit number, he would have mined the first 2,016 blocks almost instantly, and then ...

7

It looks like the format was designed for other purposes than Bitcoin's target, and used unmodified in the code. If you want a rationale for why a compact representation in the first place: not to waste space in block headers, presumably. We now know that there is little need for having the target stored in block headers at all (header-first sync does not ...

7

The "leading zeros" are a simplification. The difficulty is encoded as a target which is essentially a 256 bit number. Since block hashes are produced by SHA-256, they're also a string of 256 bits. If a block candidate's hash interpreted as a number is numerically smaller than the target, the block candidate is a valid block.

7

It's not trivial a) to agree on the time in a distributed system, especially how much time has passed between two events, b) to establish when exactly a block candidate was found. Further, when a node is catching up with the chaintip after being offline, it has no means whatsoever to determine whether a block was actually found within the allocated timeframe....

Only top voted, non community-wiki answers of a minimum length are eligible