Bitcoin get block counting
No one person or computer has responsibility for these block chain updates; no miner has special status. The updates, like the authentication of new blocks, are provided by the network of bitcoin miners at large. Bitcoin also relies on cryptography. The computational problem is different for every block in the chain, and it involves a particular kind of algorithm called a hash function. Like any function, a cryptographic hash function takes an input—a string of numbers and letters—and produces an output.
But there are three things that set cryptographic hash functions apart:. The hash function that bitcoin relies on—called SHA, and developed by the US National Security Agency—always produces a string that is 64 characters long. You could run your name through that hash function, or the entire King James Bible.
Think of it like mixing paint. If you substitute light pink paint for regular pink paint in the example above, the result is still going to be pretty much the same purple , just a little lighter. But with hashes, a slight variation in the input results in a completely different output:. The proof-of-work problem that miners have to solve involves taking a hash of the contents of the block that they are working on—all of the transactions, some meta-data like a timestamp , and the reference to the previous block—plus a random number called a nonce.
Their goal is to find a hash that has at least a certain number of leading zeroes. That constraint is what makes the problem more or less difficult. More leading zeroes means fewer possible solutions, and more time required to solve the problem. Every 2, blocks roughly two weeks , that difficulty is reset. If it took miners less than 10 minutes on average to solve those 2, blocks, then the difficulty is automatically increased.
If it took longer, then the difficulty is decreased. Miners search for an acceptable hash by choosing a nonce, running the hash function, and checking. When a miner is finally lucky enough to find a nonce that works, and wins the block, that nonce gets appended to the end of the block, along with the resulting hash. Her first step would be to go in and change the record for that transaction.
Then, because she had modified the block, she would have to solve a new proof-of-work problem—find a new nonce—and do all of that computational work, all over again.
Again, due to the unpredictable nature of hash functions, making the slightest change to the original block means starting the proof of work from scratch. But unless the hacker has more computing power at her disposal than all other bitcoin miners combined, she could never catch up.
She would always be at least six blocks behind, and her alternative chain would obviously be a counterfeit. She has to find a new one. The code that makes bitcoin mining possible is completely open-source, and developed by volunteers. But the force that really makes the entire machine go is pure capitalistic competition. Every miner right now is racing to solve the same block simultaneously, but only the winner will get the prize. In a sense, everybody else was just burning electricity. Yet their presence in the network is critical.
But it also solves another problem. It distributes new bitcoins in a relatively fair way—only those people who dedicate some effort to making bitcoin work get to enjoy the coins as they are created. But because mining is a competitive enterprise, miners have come up with ways to gain an edge. One obvious way is by pooling resources. Your machine, right now, is actually working as part of a bitcoin mining collective that shares out the computational load.
Your computer is not trying to solve the block, at least not immediately. It is chipping away at a cryptographic problem, using the input at the top of the screen and combining it with a nonce, then taking the hash to try to find a solution.
Solving that problem is a lot easier than solving the block itself, but doing so gets the pool closer to finding a winning nonce for the block. And the pool pays its members in bitcoins for every one of these easier problems they solve. If you did find a solution, then your bounty would go to Quartz, not you. This whole time you have been mining for us!
We just wanted to make the strange and complex world of bitcoin a little easier to understand. An earlier version of this article incorrectly stated that the long pink string of numbers and letters in the interactive at the top is the target output hash your computer is trying to find by running the mining script. Note that ownership of succesive blocks is not a good sign of selfish mining. This is partly because a miner can mine selfishly, and profitably, without mining two blocks in a row.
It's also partly because it's too easy to hide the true owner of a block. Concerned Bitcoin enthusiasts were worried about selfish mining when the BTC Guild mined 4 blocks in succession recently. If you examine the blockchain carefully around the time of this occurrence, it looks like these blocks were released within minutes of each other, too far apart in time to indicate selfish behavior, and without any evidence of a corresponding orphan.
This kind of successive mining by a given pool is kind of like tossing a coin and getting 6 heads in a row; it's rare, but it's bound to happen every so often in a long sequence. Timing, not ownership, of succesive blocks is the better indicator, ideally coupled with detected orphans at the same time.
As a result of the increased awareness of our findings, it is now inconceivable that someone could engage in selfish mining without facing some kind of backlash. So, any good selfish miner worth her salt will want to do so clandestinely.
To stay one step ahead of the attacker, it's worth thinking about what she might do:. If the detectors examine block ownership, the attacker can easily cover her tracks and cloak her identity.
She'd use different Bitcoin and IP addresses, she'd tumble her payouts before using them, and generally masquerade as N separate pools. Each of the N separate pools would look like they are competing with one another, and they would each look like they are too small to matter, and too small to successfully launch a selfish mining attack.
But behind the scenes, and unknown to the public, these pools would be coordinated by the same single entity. Outing such collusion is difficult, and this is one of the main reasons why block ownership is a bad indicator. If the detectors examine block timing, they are in effect detecting just a subset of the behaviors of a selfish miner. As shown in the state diagram in our paper, a selfish miner makes money by various different schemes, corresponding to different transitions of the state machine: A selfish miner determined to hide her activities might forego the former behavior to remain below the radar.
She would make less money, but she'd remain undetected. If the detectors examine abandoned orphaned blocks, the attacker is aided by the current behavior of the network where abadoned blocks are silently pruned and discarded, which makes accurately counting orphans impossible.
In essence, the Bitcoin network is helping the attacker to destroy the evidence of her activities. If the protocol were to be modified to propagate every solved block, this countermeasure would be mitigated. Such propagation of all viable block solutions would not pose any denial of service or excess load, as block solutions are quite rare and, by design, very difficult to compute.
All of this shows that detecting selfish mining is possible, but difficult to perform accurately. So, no one can definitively claim that selfish mining is or is not taking place. That said, both we and others have been looking for suggestive evidence of selfish mining. In particular, Matt Springer has done a fascinating timing gap analysis. You should read his analysis, but since he reveals the punchline in his first sentence, I'll mention it rihgt now: Luckily, the evidence so far indicates that selfish mining is not taking place in Bitcoin.
Let's hope that things remain this way for the foreseeable future. We originally described the Selfish Mining attack on Bitcoin , where an attacker can game Bitcoin and mine more than his fair share of coins. Some members of the Bitcoin community, in a frenzy to the moon, did not want to acknowledge that the Bitcoin protocol could be game-able and funded the development of an independent simulator whose subtext was to show the error of our ways.