8

I understand that a transaction is a record of 1+ Bitcoins being given from one party to another.

I understand that a block is a collection of unverified (pending) transactions that gets verified every ~10 mins or so.

I understand that mining is the act of running specialized software that will solve some cryptographic problem, and as a result, allows a block of pending transactions to be added to the block chain (history of all transactions, ever).

So first off, if anything I have said so far is not true or misleading, please begin by correcting me!

Assuming I'm more or less correct, I'm still not seeing why mining is crucial to the system, and am (obviously) not seeing the forest through the trees here.

If I send 10 BTC to someone, why does someone else (a "miner") need to verify this? Shouldn't this transaction be stored in a DB somewhere, and verifiable by querying that DB?

1
  • 1
    I don't think it is a duplicate of that question, @StephenGornick. This is more than solely about what the mining problem is about but also about how miners contribute to the security and fairness of the network. Commented Apr 28, 2013 at 20:22

4 Answers 4

7

You should start here: http://www.youtube.com/watch?v=GmOzih6I1zs

As the video mentions, mining is needed to ensure fairness and for keeping th network stable, safe and secure.

Now, let's see what that means. But first a very brief explanation of the principle of mining.

Mining

The Bitcoin network consists of nodes that all store a database with all transactions, called the block chain. This database consists of a long chain of blocks, each holding one or more transactions. What miners basically do is bundling all unconfirmed transaction into a block. The form of the block must satisfy certain conditions before the block is considered valid. This condition is called proof of work and is not trivial to understand. When a miner finds a block that is valid, it can send its block to the network and others will verify it. When it is indeed valid, all clients will add it to their block chain. Every time a miner finds a valid block, it has the right to assign a certain amount of bitcoins to himself, called the block reward. They also get all transaction fees of all transactions included in his block. This way, new bitcoins are added to the network and it can be ensured that transactions can be confirmed.

Fairness

Since Bitcoin is peer-to-peer and there is no central authority to control it, every one can send any kind of transaction to the network, whether or not it is valid. You could simply send a transaction that sends someone else's coins to yourself.

Luckily no one in the network will accept your transaction. When you want to spend bitcoins from a certain address, you will need to sign the transaction with the private key of that address. Other clients in the network can verify that you own that private key because they have the public key. This method is based on public-key cryptography.

So when miners try to bundle unconfirmed transactions into a block, they first need to confirm every transaction to make sure that all transactions in its block are valid. When they are not, other clients will not accept the block they mined when they send it to the network.

This way, miners ensure that people can only spend bitcoins they own.

Stability

This is the least difficult one to understand. The Bitcoin protocol sets the difficulty of the mining problem so that averagely every 10 minutes a new block can be found by some miner. This way, a transaction takes 10 minutes to be confirmed on average.

However, after a transaction has been included in a block, it still is not irreversible. This is not easy to understand, but when a miners try to mine a new block, they include in that block the number and the ID of the previous one. So let's say someone mined block 100, which follows number 99. It can happen that someone else didn't notice that someone found a valid block to follow on 99 and makes a valid number 100 itself as well, let's call it 100'. In this case, most clients will only accept the first block they received. But it can happen that another miner received 100' first and will find a block following on 100' and not on 100. Then we have following situation:

98 - 99 - 100
      \ _ 100' - 101'

When clients notice such a situation, they will always choose the longest existing chain (that only consists of block they think are valid). This means that block 100 will be discarded and that 100' and 101' or now the two last block of the main chain. This means that a transaction that was confirmed by block 100 is now possibly no longer confirmed. Luckily, the miners who found block 100' or 101' probably also knew of the transaction and most probably they also included it in one of those blocks. But it can happen that they did not and so a transaction can be undone.

For this reason, most clients and merchants require a transaction to be confirmed by at least 6 blocks. This means it must be included in a block that has at least 5 blocks after it.

The fact that a transaction will be able to be considered confirmed after averagely 1 hour, makes it a stable situation. It happens rarely that transactions confirmed for more than 1 hour will ever be reversed again.

Safety and security

The previous part about stability already included some security aspects of mining. It is clear that miners make the Bitcoin block chain trustworthy. When a transaction is included in a block and 5 or more other blocks have passed, you can be sure it is irreversible and safe to accept it as a payment.

It is also clear that the safety and security of Bitcoin as a payment system is in the hands of the miners and that every time one of them solves a block, he has the power to decide what transactions he accepted to the block chain.

Mostly, all miners are fair and they will include as much valid transactions as possible. Whenever a miner is not fair and it selectively excludes some transactions, some other miner will likely include it in the next block.

There is however one flaw. When a miner has more computation power than all other miners combined, it can always create new blocks at a faster rate than the others. This gives him much power over the block chain, and that is to be avoided at all cost. This flaw is named a 51% attack. This answer sums up the consequences of what could happen if someone would have 51% of the network computation power.

But this is a security flaw, what has this to do with why miners should mine? Well, as more people mine, the total computation power rises and it will be much much harder for someone to perform such a 51% attack. Currently, to own hardware capable of performing such an attack would be so enormously expensive that it is economically unfeasible to do, if not completely impossible. So, every miner who contributes his power to the network ensures that only fair miners will find blocks and that the network will be safe for people to trust upon.

7
  • 2
    Thanks @Steven Roose (+1) - awesome answer. So, to sum, mining is the act of actually reconciling/verifying transactions across the distributed network (instead of a central server doing the reconciliation). And, as a reward for providing the reconciliation, miners get awarded in newly-created bitcoins. Is that a fair assessment? Thanks again! Commented Apr 28, 2013 at 20:57
  • Yes, that sums it up. A question that some people have is whether the transaction fees per block are going to be enough to stimulate miners when the block reward is gone. The block reward halves every 4 years and in December 2012 it changed from 50 to 25 BTC. Some day it will be zero and from then on miners have to make their money of transaction fees. Commented Apr 29, 2013 at 0:54
  • @StevenRoose So miners do the actual signature checking as well? Not "the network", but the miners specifically? So that mining is basically this: "Check signatures in transactions. When done, concatenate a bunch of stuff and append i; increment i until hash(bunchOfStuff+i) < chosenDifficulty"? Commented Dec 2, 2015 at 22:04
  • 1
    @ErikVesterlund Something like that, indeed. But keep in mind that non-mining nodes also do signature verification. When a miner broadcasts a block with invalid signatures, a non-mining node will reject the block and block the miner and just stick to the chain it knows of that does only include valid blocks. Commented Dec 7, 2015 at 14:56
  • If the difficulty level was to remain at 1 like it was when the blockchain started, with today's miners insane hashrates they could rewrite the entire blockchain from scratch within less than a second. Let's say some miner recreates the entire blockchain AND has access to alot of full nodes so he can just copy this "new blockchain" over it. Is there any protection against this kind of an attack? Because if not, then that means mining is completely pointless in defending the system. Commented Dec 8, 2017 at 6:33
2

In order to prevent double spending, signed transactions need to be time-stamped in a well defined order (so that clients can determine the validity of each transaction; i.e. is the source of funds sufficient to support the transaction).

Rather than have a single centralized trusted authority, Bitcoin distributes this function across the network. But how to decide who to trust to do this? The answer is to give the authority to whomever demonstrates the most computing power.

Since a demonstration of computing power cannot be reliably faked, (unlike other measures of individual identity), people can pool their resources to earn the right to timestamp transactions. As long as more computing power is in the hands of non-malicious users, than malicious ones, no malicious user (or collection of users) will be able to subvert the timestamping function.

1

Where would the DB be?

If the DB is stored in some centralized location, then Bitcoin is no longer decentralised.

Basically, the DB must be stored by a distributed network of honest nodes, and shared in the P2P network. However, we need a way for single nodes to be able to verify if a block isn't forged. Enter the nonce/hash: It is something hard to generate (forge), but easy to verify. One needs to pick the correct nonce for the block hash to follow the criteria, and it takes time to find a working nonce. (On the other hand, verifying a hash is a quick job)

Now, of course, we need a way to "legitimately" generate the nonce -- there's no central authority handing out nonces. Enter miners: As long as the almost all of the mining population is working towards generating nonces for "good" blocks (blocks containing all broadcasted transactions with not tampering), we can guarantee that all the generated blocks have come from these miners, and thus these blocks are "legitimate".

While the transactions do get broadcast, there's no way of knowing if a transaction has reached the rest of the world. I can direct a transaction at you and make it look like I've given you money, when I haven't. However, baking a transaction into a block is something nearly impossible for any individual to do as he has to race against the majority of miners.

See also: http://codinginmysleep.com/bitcoin-mining-in-plain-english/

2
  • The nonce is actually just a counter. What's hard to generate is the hash over the block contents, the previous block hash and the nonce. Commented Apr 28, 2013 at 18:52
  • @MichaelBorgwardt: updated. Both really mean the same "generating the nonce" and "generating the hash" in this context, though. Commented Apr 28, 2013 at 19:08
1

The short answer is this: Lacking any central authority, the simple scheme you mentioned wouldn't work for Bitcoin.

Consider if you transferred the same 10 bitcoins to two different accounts with two different transactions. What would stop some people from recognizing the first transaction and some from recognizing the second?

Bitcoin uses proof of work (mining) to solve this "double spend problem".

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