This article has been corrected.
If you clicked the button above, you're currently pulling out bitcoin, the math-based digital currency that has recently passed $ 1,000 on exchanges. Congratulations. (It will do no harm to your computer, we promise it).
The new bitcoins are created approximately every 10 minutes in batches of 25 coins, with each coin valued at approximately $ 730 at current rates. Your computer, in conjunction with anyone else's reading this post that clicked the button above, is running thousands of others to unlock and request the next lot.
As long as the counter above keeps going up, your computer will keep running a bitcoin mining script and will try to get a piece of the action. (But do not worry: it's designed to shut down after 10 minutes if you're on a phone or tablet, so the battery does not drain).
So, what exactly is this script doing?
Let's start with what he is not doing. Your computer does not explore the cavernous depths of the Internet in search of digital minerals that can be modeled in bitcoin ingots. There are no minerals and the bitcoin extraction does not involve the extraction or merging of anything. It's called mining just because the people who do it are the ones that get new bitcoins, and why bitcoin is a limited resource released in small amounts over time, like gold, or anything else that is extracted. (The size of each lot of coins decreases by half to approximately every four years, and around 2140, will be reduced to zero, limiting the total number of bitcoins in circulation to 21 million.) But the analogy ends here.
What the bitcoin miners actually do could be better described as competitive accounting. The miners build and operate a gigantic public ledger containing a record of every bitcoin transaction in history. Whenever someone wants to send bitcoins to someone else, the transfer must be validated by the miners: check the ledger to make sure the sender is not transferring money he does not have. If the transfer is executed, the miners add it to the ledger. Finally, to protect that ledger from hackers, the miners seal it behind layers and layers of computational work – too much for a potential cheater to complete.
And for this service, they are rewarded in bitcoins.
Or rather, some miners are rewarded. The miners are all competing with each other to be the first to approve a new batch of transactions and finish the computational work necessary to seal those transactions in the ledger. With each new game, the winner takes everything.
It's the computational work that really takes time, and this is mainly what your computer is doing right now. He's trying to solve a kind of cryptographic problem that involves guessing and checking billions of times until he finds an answer.
If all this seems rather intoxicating, it is because mining is an elaborate solution to a difficult problem that plagues every double expense.
Double expense and a public ledger
As the name suggests, the double expense is when someone spends money more than once. It is a risk with any currency. Traditional currencies avoid it through a combination of hard-to-imitate physical money and trusted third parties – banks, credit card providers and services like PayPal – who process transactions and update account balances accordingly.
But bitcoin is completely digital and has no third party. The idea of a supervisory body is completely contrary to its ethics. So if you tell me you have 25 bitcoins, how do I know you're telling the truth? The solution is public accounting with records of all transactions, known as a chain of blocks. (We will understand why it is called so soon.) If all your bitcoins can be traced back to when they were created, you can not get away with lying about how many you have.
So every time someone transfers bitcoins to someone else, the miners consult the ledger to make sure the sender does not spend twice. If he actually has the right to send that money, the transfer is approved and entered in the ledger. Simple, is not it?
Well, not really. The use of a public ledger involves some problems. The first is privacy. How can any bitcoin exchange be completely transparent, keeping all bitcoins completely anonymous? The second is security. If the ledger is totally public, how do you prevent people from confusing it for their own profit?
There is no bitcoin account
The Bitcoin ledger deals with the problem of privacy through a bit of accounting deception. The registry keeps track of bitcoin transfers, not account balances. In a very real sense, there is no bitcoin account. And this keeps anonymous users.
Here's how it works: Say Alice wants to transfer a bitcoin to Bob. First Bob puts a digital address for Alice to send money to, along with a key that allows him to access the money once there. It works like an e-mail account and a password, except that Bob sets a new address and a key for each incoming transaction (he does not have to do it, but is highly recommended).
When Alice clicks on a button to send the money to Bob, the transfer is encoded into a piece of text that includes the amount and the address of Mario. Here's how the text actually looks:
And here's a more digestible diagram of this:
This transaction record is sent to every bitcoin miner, for example, every computer on the Internet that runs mining software and, if it is legitimate, is added to the ledger. Suppose you go through.
Now, tell me Bob wants to pay Carol a bitcoin. Carol, of course, sets an address and a key. And then Bob essentially takes the bitcoin that Alice gave him and uses his address and the key from that transfer to sign the bitcoin to Carol:
This transaction is sent to all miners and they will check (using the reference number from Alice to Bob's transfer) to make sure that Bob has not already transferred that bitcoin to someone else. No double shopping. After validating the transfer, each miner will send a message to all the other miners, giving it the blessing.
If Bob's transfer to Carol passes, this will also be added to the ledger.
Here are all the transactions: people who sign bitcoins (or fractions of bitcoins) one above the other. The ledger keeps track of coins, but does not keep track of people, at least not explicitly. Assuming Bob creates a new address and key for each transaction, the ledger will not be able to reveal who it is, or what its addresses are, or how many bitcoins it has in everything. It's just a record of money moving between anonymous hands.
There is no main document
Now for the most complicated problem: keep the ledger secure.
The first thing bitcoin does to protect the registry is to decentralize it. There is not a huge spreadsheet that is stored on a server somewhere. There is no master document at all.
Instead, the ledger is divided into blocks: registers of discrete transactions that contain 10 minutes of bitcoin activity each. Each block includes a reference to the previous block and you can follow the links from the most recent block to the first block, when bitcoin creator Satoshi Nakamoto summoned the first bitcoins.
This lineage of blocks is the chain of blocks and constitutes the public ledger of bitcoins. Every 10 minutes the miners add a new block, making the chain grow like an expanding pearl necklace.
In general, every bitcoin has a copy of the entire chain of blocks on its computer. If you shut down the computer and stop the extraction for a while, when you restart, your machine will send a message to other miners requesting the blocks created in his absence. No person or computer is responsible for these block chain updates; no miner has a special status. Updates, such as the authentication of new blocks, are provided by the bitcoin miners network in general.
Proof of work
Dividing the register into distributed blocks is not sufficient on its own to protect the registry from fraud. Bitcoin is also based on cryptography.
To add a new block to the chain, a miner must end up what is called a cryptographic job trial problem. Such problems are impossible to solve without applying a ton of brute computing force, so if you have a solution in hand, it's proof that you've done a certain amount of computational work. The computational problem is different for each block in the chain and implies a particular type of algorithm called a hash function.
Like any function, a cryptographic hash function accepts an input (a string of numbers and letters) and produces an output. But there are three things that separate cryptographic hash functions:
1. The output is a predetermined length, independently of the input.
The hash function that the bitcoin is based on the so-called SHA-256 and developed by the US National Security Agency always produces a string 64 characters long. For example:
You could use your name through that hash function or the entire King James Bible. In both cases, you will get 64 characters from the other side. And, for a given input, you will always get the same result.
2. It is impossible to perform a cryptographic hash function in reverse.
If you have the output of a cryptographic hash function (called a hash in short), there is no way to know what the input is. It is a one-way street. And that's what makes it cryptographic: you can use a hash function to scramble the text in a way that is impossible to decode.
Think about how to mix painting. It's easy to mix pink paint, blue paint, is gray paint. But it is difficult to get the result Violet and do not mix it.
3. Changing input even slightly changes the output
Painting mixing is a good way to think about the unidirectional nature of hash functions, but it does not capture their unpredictability. If you replace light pink paint for regular pink paint in the example above, the result will still be more or less the same Violet, just a little lighter. But with hashes, a slight variation in input generates a completely different output:
The proof-of-work problem that miners have to solve is to take a hash of the content of the block they are working on: all transactions, some meta-data (like a timestamp) and the reference to the previous block -more a number random called a there is not.
Their goal is to find a hash that has at least a number of main zeros. Something like this:
This constraint is what makes the problem more or less difficult. More initial zeroes mean less possible solutions and more time needed to solve the problem. Every 2,016 blocks (about two weeks), this difficulty is restored. If to solve those 2.016 blocks it took less than 10 minutes in less than 10 minutes, the difficulty increases automatically. If it takes more time, the difficulty decreases.
Miners search for an acceptable hash by choosing a nonce, executing the hash function and checking. If the hash does not have the correct number of leading zeros, it changes the nonce, executes the hash function and checks again.
Because of the unidirectional nature of hash functions, it is not possible to go back to find a suitable nonce. And because of the unpredictability of the hash function, trying different nonces never brings you closer to the right one. It's all a process of elimination.
When a miner is finally lucky enough to find a nonce that works, and wins the block, that nonce is added to the end of the block, along with the resulting hash.
The entire block is then sent to all other miners in the network, each of which can then perform the hash function with the winner's nonce and verify that it works. If the solution is accepted by the majority of miners, the winner receives the reward and a new block is started, using the hash of the previous block as a reference.
So, how do you protect this bitcoin from fraud?
Let's say a hacker wanted to change a transaction that happened 60 minutes, or six blocks, maybe, maybe to remove the proof he had spent some bitcoins, so he could spend them again. His first step would be to enter and change the record for that transaction. So, since he had modified the block, he would have to solve a new problem of proof of work, find a new nonce and do all the work of calculation, all over again. (Again, because of the unpredictable nature of hash functions, making the slightest change to the original block means starting the test of work from scratch.) From there, you should start building an alternative chain going forward, solving a new test – problem of work for each block until it has reached the present.
But unless the hacker has more computing power available to all the other bitcoin miners put together, he could never recover. It would always be at least six blocks behind, and its alternative chain would have obviously been forged.
The key is that if someone changes an accepted block, one that already has a work proof solution blocked at the end of it, can not reuse the same solution. You must find a new one. And that's why proof of work is needed to ensure that you can not only surreptitiously change a block and then bribe the ledger.
Mining is competitive, non-cooperative
The code that makes bitcoin extraction possible is completely open-source and developed by volunteers. But the force that really drives the whole machine is pure capitalist competition. Each miner is currently running to solve the same block at the same time, but only the winner will get the prize. In a sense, everyone else was just burning electricity. Yet their presence in the network is essential.
The ultimate aim of mining is to prevent people from using bitcoins at double expense. But it also solves another problem. Distributes the new bitcoins relatively fair: only people who spend some effort at work on bitcoins enjoy the coins as they are created.
But since mining is a competitive business, the miners have come up with ways to gain an advantage. An obvious way is by pooling resources.
Your machine, right now, is actually working as part of a bitcoin mining collective that shares the computational load. Your computer is not trying to solve the block, at least not immediately. He is cutting away a cryptographic problem, using input at the top of the screen and combining it with a nonce, then taking the hash to try and find a solution. Solving this problem is much simpler than solving the block itself, but by doing so, the pool is approaching in search of a winning nonce for the block. And the pool pays its members in bitcoins for each of these easier problems that they solve.
What are the chances that you really win?
Undoubtedly, you have waited patiently to discover one thing: is there any chance that you could win some bitcoins?
Not at all. If you found a solution, then your size would go to Quartz, not you. For all this time you dug for us!
But the odds of finding a solution and taking advantage of the computing power you provided are essentially zero. The collective of bitcoin quartz miners is not big enough. We are not trying to take advantage of you. We just wanted to make the strange and complex bitcoin world a little easier to understand.
Correction (December 18, 2013): An earlier version of this article erroneously indicated that the long pink string of numbers and letters in the interactive top is the destination output hash that the computer is trying to find by running the mining script. In fact, it's one of the inputs your computer powers into the hash function, not the output it is looking for.