A gentle introduction to bitcoin

Important note: If you own more than $1,000 worth of cryptocurrency then you should definitely be using a hardware wallet instead of keeping coins on exchanges.  I recommend a Trezor which you can buy for €89 directly from their website.


This article is a gentle introduction to bitcoin and assumes minimal technical knowledge.

Shorter companion pieces to this are:

In the popular media, you will often read comments like “Bitcoins are stored in a digital wallet”, or “You can send money using blockchain technology”.  These comments can be misleading and can confuse.  By the end of this you should understand enough to participate in a dinnertime conversation about bitcoin, and not be mystified by the topic.

Bitcoin

Although people refer to bitcoin as a decentralised digital currency, I prefer to think of it as an electronic asset, to sidestep questions around which government backs it and who sets the interest rate, which are often a mental block in understanding bitcoin.

As an electronic asset, you can buy bitcoins, own them, and send them to someone else.  Currently (Sep 2015) there are around 14 million bitcoins that have been created, increasing by 25 bitcoins every 10 minutes or so, with an agreed limit of 21 million, the last of which should be created a little before the year 2140.

Cumulative BTC in circulation

Transactions of bitcoins from account to account are recognised globally in a matter of seconds, and can be considered securely settled within an hour, usually.  They have a price (usually in USD, but can be against any currency, as with anything else), and the price is set by normal supply and demand market forces in marketplaces where traders come to trade, just like with oil or gold.


What is bitcoin designed for?

A 2008 whitepaper written by the pseudonymous Satoshi Nakamoto introduced the concept of bitcoin, and the design principle behind bitcoin is:

A purely peer-to-peer version of electronic cash [which] would allow online payments to be sent directly from one party to another without going through a financial institution.

So, there is the concept of electronic cashcash being a bearer asset, like the cash in your pocket which you can spend at will without asking permission from a third party.

Before Bitcoin there was never electronic cash; we had numbers being stored in the database of a financial institution like a bank or Paypal, whose rules you had to comply with in order to open an account and use, and whose permission you had to seek before being able to move the money.


Why use Bitcoin?

I think of bitcoin like just another international currency whose ‘home ground’ is the internet, as opposed to any geographical location.  Put another way: if the internet were a country, bitcoin would be its currency.  For the first time we have an entirely digital asset which can be controlled by the end user, without requiring signup with an institution.

Bitcoin payments.  Payments of bitcoins can be made from one person to another, irrespective of geographical location or jurisdiction.  Payments are relatively fast – the initial notification is within seconds, and it ‘settles’ in about an hour.  In situations where the normal financial system is inadequate, it can be a useful way of transferring value to anyone who has access to the internet.

Potential users.  Some communities are underserved by banks due to the cost/benefit of the brick & mortar banking model and regulatory cost; some international transfers are unreliable, or can take many days, with manual processes and faxes being used as part of the plumbing; some people may want to accept digital money for selling digital goods; there may be use cases where small payments, in the order of pennies, may be useful, which is currently difficult with existing fee structures with credit cards.  There may be other uses which we haven’t discovered yet…

Price volatility.  Just like other currencies, bitcoin’s price fluctuates.  Bitcoin’s price is more volatile than a lot of currencies (though the volatility is decreasing), so if you account for your wealth in your local currency, then owning bitcoin is essentially a bet on bitcoin’s future exchange rate price.  You can see historical price volatility on Tradeblock’s website.

Conversion.  Just like other currencies, if you have one currency (say, Pound Sterling), and you want to convert it to bitcoin, you need to find someone to exchange it with.  This necessarily has some friction and fees: either dressed up as commissions; or built into the spreads (the conversion price).  With time, conversion is getting easier and cheaper as more exchanges are springing up in more countries.

Maintain cynicism.  You may hear of bitcoin being ‘fast’ and ‘free’ or ‘low cost’.  While that is true when you are strictly in bitcoin, it’s worth maintaining some cynicism and thinking about the costs involved in the ‘on’ and ‘off’ ramp getting from sovereign currencies into bitcoin and back.

While I can’t imagine “mass consumer adoption” of bitcoin, I can imagine a group of freelancer developers or graphic designers in an emerging economy, who may not have access to banks or Paypal.  With bitcoin, for the first time, they can do ‘digital’ work and be paid digitally.  Of course, there is still the question of how they can convert bitcoin back into local currency, but that’s an easier problem to solve then receiving the money in the first place.

It’s worth noting that while bitcoin has spawned many other similar cryptocurrencies such as litecoin, dogecoin, bitcoin is still the most widely used and traded due to its network effect and relatively higher levels of security and robustness.


How does it work?

A network of computers validates and keeps track of bitcoin payments, and ensures that they are recorded by being added to an ever-growing list of all the bitcoin payments that have been made.

Keeping track of payments: The Bitcoin Blockchain

There is a file (well, split into several files) called “The Bitcoin Blockchain”, sitting on thousands of computers across the world, including my laptop at home.  When you read the word “blockchain”, think “database” or even “list” and you have the right kind of idea.  For a primer on blockchain please see A gentle introduction to blockchain technology.

Bitcoin Blockchain file on my computer

A screenshot of The Bitcoin Blockchain files on my computer.  Here you can see The Bitcoin Blockchain split into files, each 134MB big, and the total is about 50GB at time of writing.

This file contains data about all the bitcoin transactions, that is payments of bitcoins from one account to another, that have ever happened.  This is often called a ledger, similar to a bank’s ledger which keeps a record of payments between bank accounts.

Ledgers

Simplified bank ledger vs bitcoin ledger: they are similar.

The bitcoin network.  The computers which store this file also run software that connects them over the internet to the other computers running the same software.  This forms a network of computers that can talk to each other, relaying information about

  1. new payments (at time of writing there is about one new bitcoin payment per second, but this comes in fits and starts)
  2. updates to The Bitcoin Blockchain (every 10 mins or so, a new “page” or block of valid transactions is confirmed and is distributed to all of the computers on the network)

When you make a bitcoin payment, a payment instruction is sent to the network.  The computers on the network validate the instruction and relay it to the other computers.  After some time has passed, the payment gets included in one of the block updates, and is added to The Bitcoin Blockchain file on all the computers across the network.

Peer-to-peer.  The distribution of data works on a peer-to-peer basis, rather than client-server.  Peer-to-peer is like a gossip network where everyone tells a few other people the news (about new transactions and new blocks), and eventually the message gets to everyone in the network.  This is as opposed to client-server is more like a conventional organisation where a boss tells subordinates the news, and the boss is a central point of reference, and potential failure.

Client server vs Peer to peer

Client-server vs Peer-to-peer data distribution models

One benefit of peer-to-peer (p2p) over client-server is that with p2p, the network doesn’t rely on one central point of control which can fail.


How are bitcoins stored?

Bitcoin ownership is tracked on The Bitcoin Blockchain, and bitcoins are associated with “bitcoin addresses”.  Bitcoins themselves are not stored; but rather the keys or passwords needed to make payments are stored, in “wallets” which are apps that manage the addresses, keys, balances, and payments.

Bitcoin accounts: addresses

In banking you have accounts which keep pots of money separate; in bitcoin you have addresses.  A bitcoin address is similar to a bank account number, with a few differences.

Here’s an example of a bitcoin address: 1MKe24pNsLmFYk9mJd1dXHkKj9h5YhoEey.  Just like with bank accounts, if you want to receive a bitcoin payment, you need to tell someone your bitcoin address, so they know where to send bitcoins to.  A typical conversation, which could be in person, or online, or on chat (Whatsapp/Skype etc) looks like:

chat

(BTC and XBT mean the same thing and are industry standard abbreviations for bitcoins, like GBP for Pound Sterling)

Bitcoin wallets

With my bank, under one single username/password, I control a number of accounts (eg incoming salary, monthly savings, tax, etc), each of which have a balance or amount of currency.  Similarly, Bitcoin wallets are apps that display all of your bitcoin addresses, display balances and make it easy to send and receive payments.

For a wallet to provide accurate information, it needs to be online or connected to a Bitcoin Blockchain file, which it uses as its source of information.  The wallet will read the Bitcoin Blockchain file and calculate the balances in each address.

wallet_data

Bitcoin wallets let you create bitcoin addresses to receive incoming transactions and make outgoing payments, plus have other features that make them user friendly.


How are bitcoins sent?

Payments, or bitcoin transactions

Each bitcoin address has its own private key, which is needed to send payments from that address.  You can think of a key as a kind of password, but it’s mathematically linked to its respective address, so it can’t be changed, unlike a conventional password or PIN number.

For the address above (1MKe24pNsLmFYk9mJd1dXHkKj9h5YhoEey), the private key is 5KkKR3VAjjPbHPzi3pWEHVQWrVa3C4fwD4PjR9wWgSV2D3kdmeM.  Whoever knows this private key, including readers of this blog, can now make payments from the address.

To get your own address/private key combination, it is not given to you by some authority like a bank, but rather you pick a random number and apply some maths to it – wallet software will do this for you.

Private keys.  The private key is something you want to keep securely and never expose.  Because you can not change that private key to something more memorable, it can be a pain to remember.  Most wallet apps will encrypt that key with a password that you choose.  Later, when you want to make a payment, you just need to remember your password.

Because bitcoins don’t exist as such, bitcoin wallets don’t store bitcoins but store the keys that let you transfer or ‘spend’ them.  Copying a wallet doesn’t double the number of bitcoins you own, you simply have a copy of the same keys.  If someone manages to copy and read your wallet, they can empty the accounts, just as two people with duplicate keys to a bank’s safe deposit locker can race to unlock the locker, but the contents of the locker do not double.

Bitcoin wallet with private keys

Bitcoin wallets contain private keys, not bitcoins!


What happens when I make a bitcoin payment?

A payment is an instruction to unlink some bitcoins from an address you control, and move them to the control of another address (your recipient).

Your payment instruction includes everything you’d expect, including:

  1. which bitcoins you’re sending
  2. which address you’re sending them from
  3. which address you’re sending them to

Digital cryptographic signatures.  The instruction is then digitally signed with the private key of the address which currently holds the bitcoins.  This digital signing demonstrates that you are owner of the address in question (because only you know the private key).

Payment instructions are sent from the wallet software to any of the computers on the network (called “nodes” or “payment validators”).

Validators.  When the first computer receives the instruction, it checks some technical details, and some business logic details (eg, does my payment attempt to create bitcoins out of nothing?  Have the coins being sent already been sent elsewhere? etc).

checklists

Validators validate at technical and business logic levels.

If these tests pass, then the computer relays it to others on the network, who each run the same validation tests.  Remember on this network, computers can’t trust each other so they have to run the same tests.  Eventually all computers on the network know about this payment, and it appears on screens everywhere in the world as an “unconfirmed transaction”.  It is unconfirmed because although the payment has been verified and passed around, it isn’t entered into the ledger yet.


How are bitcoins tracked?

How do transactions get entered into everyone’s blockchains?

As well as passing information about transactions between each other, specialised nodes (computers who form part of the network) work to add these transactions, in blocks, to the blockchain.  This is known as “mining” bitcoin.  This is often described as “solving complex mathematical puzzles to win bitcoin”.  In fact there is nothing complex about this process, and you can do this by hand without a calculator; it just deliberately takes many computational steps without shortcuts.

Mining.  Mining is a guessing game where your chance of winning is related to the how quickly your machine can perform calculations compared to how quickly other miners are performing similar calculations.  Whoever guesses the right number first wins the right to add a new block of transactions to everyone’s blockchains, and does this by publishing this to the other computers on the network.  Each computer performs a quick validation of the block, and they agree that the block and transactions conform to the rules, then they add the block to their own blockchain.  Why does the miner do this?  Because as part of the block, they get to award themselves with some amount of new bitcoins (currently 25 BTC, and halving roughly every 4 years, the next halving being July 2016). This block-adding happens roughly every 10 minutes on the network.

See a gentle introduction to bitcoin mining for further detail.

2

Due to this reward, bitcoin mining has got very competitive, with companies developing specialised hardware, called ASICs, which are very quick at the guessing game and associated number-crunching.

Bitcoin’s protocol and code ensures that it takes around 10 minutes for the network as a whole to guess correctly.  This is the speed that transactions take to be confirmed onto the blockchain.

Slow for security.  By making it slow (10 minutes is slow compared to how fast it could be down if the guessing game was removed), and by making it computationally and therefore financially expensive to participate in this process, it also makes it financially expensive for miscreants to buy enough processing power to write their own abnormal blocks of transactions into the blockchain.

Bear in mind that even if miscreants were to do this, all the other computers would need to agree with all of the transactions, so they still cannot insert transactions that break the business logic rules, eg conjuring bitcoins out of thin air.


Bitcoin security

There are two parts to this:

  1. Making payments
  2. Block control

Making payments.  As discussed earlier, the only thing you need to make a bitcoin payment is the private key of the address you want to spend from.  You need to balance making it hard for people to steal your keys, and having backups in case you lose your keys – there are stories of people throwing away old laptops containing – not bitcoins – but bitcoin private keys controlling bitcoins worth millions of dollars.

Block control.  There are two parts to this.  Firstly there is block-creation (“mining”), performed by some specialised nodes; secondly there is block validation, which is performed by all nodes. Like an army of independent accountants and auditors all auditing the same ledger, the vision of bitcoin is to have many thousands of independent block validators to be participating in keeping the system honest.  This independence and mutual validation of transaction and blocks is supposed to prevent any one person or entity from adding rogue blocks and dominating the network with their influence.

However, in practice, miners join forces into ‘mining pools’ in order to win blocks more often.  In a mining pool, one participant creates the candidate block, and the others get to work ‘mining’ it.  If any of the participants wins, the spoils are shared with the pool.  This has the effect of each participant getting paid out more often, but less amount, like a lottery syndicate.  This smoothing of cashflow works well for paying back capital needed to buy mining equipment.  As a consequence, the mining pool owners have greater power over the bitcoin network in terms of creating blocks, voting on protocol changes, and potentially re-writing recent ledger entries.

Without going into too much technical detail, if you have ability to re-write a recent block, then you could ‘unwind’ a payment in what is known as a ‘double spend’ attack.  You would make a payment to a vendor, and have it confirmed in a block.  If you can create a couple of blocks without the payment to the vendor, then the network will invoke the ‘longest chain rule’ and ignore / orphan the first block and use your longer chain instead.   You also need to invalidate the original payment, by creating a slightly different transaction, spending the same bitcoins, but paying yourself or your friend, instead of the vendor.  If you can slip this transaction into your new blocks, then the old transaction will be invalid to the network.  Here’s an example. For more on the difficulties of changing the transaction list, read a gentle introduction to immutability of blockchains.

Your ability to do this shuffle increases with ‘mining power’, but it decreases with the age of the block you are trying to replace (the older the block, the harder it is to re-write), as each block ‘costs’ a certain amount of mining power to create, and you are competing against the rest of the network to create blocks.

Scams.  It’s hard to write about bitcoin security without mentioning Mt Gox, an early bitcoin exchange.  Bitcoin exchanges are websites you go to to buy or sell bitcoins.  If you want to buy bitcoins, you first make a bank wire to the exchange’s bank account.  When they sight the funds in their bank, they let you place orders to buy bitcoins from sellers.  Likewise, sellers need to send bitcoins to the exchange’s bitcoin wallets before the exchange will let them sell the bitcoins.  The exchange acts as escrow, holding onto cash and bitcoins and then releasing them once the trade has been made.

It is unknown what happened at Gox, but rumours include having private keys stolen, poor accounting practices, letting people trade first before sending collateral, etc.  Just as you don’t blame the US Dollar if a Citibank branch gets held up and funds stolen, it wasn’t the security of the bitcoin network that was at fault; it was the security and poor practices of the exchange.


What is this decentralised bit?

Let’s go back to “Bitcoin is a decentralised digital currency”.  We’ve seen that bitcoin is digital, and not really a currency (though it is easy to send, and it has a value that is determined by supply and demand on a number of exchanges).  What about the decentralised bit?

Distributed validators.  Centralised means one point or source of control, and decentralised is where control is shared among participants.  In bitcoin, participants are the validators of the transactions and creators of blocks.  If enough of them decide to play by different rules, then the others will need to follow suit.  The validators have “voting power” proportional to how much computation power they have.  Anyone can be validator, and get more votes, if they are prepared to pay for computing power, the costs of which are hardware, electricity, and support.  So instead of one single authority who can change the rules, the rules can only be changed by consensus of those validators.

The validation logic (what does a valid transaction look like?) is baked into the code which is run by the validators.

Open source code.  This code is open source, meaning that validators can see exactly what code or logic they are running.  The version that is most often used (called the ‘reference implementation’) is stored here: https://github.com/bitcoin/bitcoin.  In theory, anyone can contribute to this reference implementation by uploading changes, though there are gatekeepers, people, who have the final say about what gets included.

In theory, anyone can write versions of this software, so long as they conform to the technical and business protocols of bitcoin.  For example you could write you own version of the software, but with cooler graphics, or a more user-friendly interface.  If you want to change some of the protocol rules, however, you’d need to persuade the majority of the validators (miners) to run your software with the new rules.  Here’s an example version that has some changes to the technical protocols: https://github.com/bitcoinxt/bitcoinxt

Changing the rules.  So the rules can be changed, as long as you achieve majority consensus (another myth is that the limit of 21 million bitcoins cannot be changed.  It can be changed, in one line of code, assuming you can get the majority of network participants to agree to run it).  Getting the miners to agree to run code is the real challenge, as they have invested huge amounts of capital and will not readily agree to change anything which may harm their mining rewards – “The turkeys won’t vote for Christmas”.


Conclusion

You will probably have guessed by now that there is a lot more to bitcoin than I have been able to set out here.  In giving a gentle introduction I have had to present some concepts at a high level, which in practice are complex and highly nuanced.  But as you read and learn more on this blog I hope to be able to take you into a more detailed understanding of bitcoin, miningdigital tokens, and the underlying blockchain technologies

=================================================================

BITCOIN MINING

A gentle introduction to bitcoin mining

Recently over dinner, I was asked to explain bitcoin mining, and I struggled as it is entangled with a number of other concepts.  Here’s my attempt at breaking it down into bite-sized pieces.

What is bitcoin mining?

Mining is the process of writing pages (blocks) of bitcoin transactions into the bitcoin ledger, called ‘The Bitcoin Blockchain’, and getting rewarded with newly created bitcoins.

To understand this in more detail, the rest of the post describes:

  • How do bitcoin transactions work?
  • Why is mining needed in bitcoin?
  • Why do miners mine?
  • What is this ‘computationally expensive’ guessing game?
  • Why pay rewards in BTC instead of USD?
  • Who mines?
  • What can and can’t miscreants do?

If you are new to bitcoin, it might be worth having a quick read of “A gentle introduction to bitcoin”.


How do bitcoin transactions work?

The process is:

  1. Make a payment (a bitcoin transaction)
  2. Wait for it to be mined in a block (average 10 mins)
  3. Wait for more blocks to be mined on top (average 10 mins per block)

1. Make a payment. When you make a bitcoin payment, the transaction message is sent to the network and passed around all the network participants (called ’nodes’), and remains in an ‘unconfirmed’ state.  This means the nodes have seen that the payment has been initiated, and they have validated it according to certain technical and business logic rules, but it isn’t yet written into anyone’s bitcoin blockchain ledger.

Unconfirmed transaction = valid, known transaction, but not yet included in the ledger.

2. Wait for it to be mined in a block (average 10 mins). Miners take the list of unconfirmed transactions (specifically, those that they know about), and they bundle them into a block, which is just a list of transactions plus some other data.

They then get to work ‘mining’ the block which means playing a guessing game to find a random number (more later).

If they guess right, then the block is published to the rest of the network.  The computers on the network validate that the block meets the criteria, and then ignore it or store it into their blockchains.  The competition then starts again with the unconfirmed transactions that have accumulated since.

The network adjusts the difficulty of the guessing game to target a block being created every 10 mins or so, irrespective of the amount of computing power in the network.

3. Wait for more blocks to be mined on top (average 10 mins per block). The next block that is mined on top of the one with your transaction will refer to the previous block (hence, ‘blockchain’).  The more blocks that have been built on top of the one with your transaction, the more ‘baked’ into the blockchain it is, and so the harder it is to unwind through block-reorganisation attacks (more later).

Unconfirmed transaction -> Confirmed transaction (1 block) -> Confirmed transaction (many blocks)

The current advice suggests that after 6 blocks, the chances of the transaction being unwound due to a competing longer chain replacing your blocks is very small.  If you are receiving a payment, then the higher the value your payment, the longer you may want to wait to reduce the chance of your payment being unwound.


Why is mining needed in bitcoin?

There are two parts to this. First you need a way to get transactions into the ledger, secondly you need a way to make it expensive for miscreants to add dishonest blocks.

Ledger addition.  Transactions are added to the ledger in blocks so as to create some sort of time order to the transactions.  In bitcoin you can’t trust the timestamp of any particular participant, and there is no ‘master clock’ to trust, so block order is the equivalent of time order.

Financial deterrent.  This is about the guessing game, called “Proof of work”.  You don’t actually need the guessing game to add blocks to a blockchain.  However, the guessing game makes it computationally expensive (therefore financially expensive) to add blocks.  This cost acts as a deterrent to miscreants who would otherwise want to add their dishonest blocks.  So long as most of the network is ‘honest’, then the dishonest parties will have a tough time creating rogue blocks.

“Why proof of work?”, in three acts:

Act 1

  • Anyone can create blocks on an “open” network.
  • As you can’t trust anyone specifically, each individual node has to assume that the ‘majority’ of the rest of the network is right.
  • So to dominate the network, you just need to create many aliases who are all under your control and all agree with each other. This kind of domination-by-numbers is called a ‘Sybil attack’.

Act 2

  • It is cheap and easy to spawn validators who all agree with each other.
  • Therefore it is very cheap to bully the network.
  • So for a network to be secure against this, you need to have a more expensive way to bully the network.

Act 3

  • Computational power is more expensive and requires investment and upkeep.
  • Therefore use majority-by-computational-power instead of majority-by-numbers.
  • So miscreants will need to spend a lot more money to dominate the network.

Finale

  • The name given to a challenge that is computationally expensive for the sake of it, is called a “Proof of work” challenge.

Why do miners mine?

Mining reward = Voluntary transaction fees + Block reward (currently 25 BTC per block)

When you mine a block, get to collect any voluntary transaction fees from the transactions you have included. You also get to write one transaction paying yourself some BTC (currently 25 BTC, and reducing to 12.5 BTC in the middle of 2016).  This is called a ‘block reward’ or ‘coinbase transaction’ (not to be confused with the American company called “Coinbase” which operates under a UK legal entity “Coinbase UK, Ltd”).

This is the ‘minting process’ i.e. how bitcoins are created.  The reward decreases with time, and in theory, transaction fees will replace the block reward.

tx_fees_replace_block_rewards
Transaction fees are not mandatory (hence the “bitcoin transactions are free” mantra) but miners will seek out transactions containing fees, and preferentially add them to blocks that they are creating.  If there are more unconfirmed transactions than can fit in a block, rational miners will mine the ones with the highest transaction fees first.


What is this ‘computationally expensive’ guessing game?

Miners spend a lot of computing power trying to guess a number, which when added to a block and put through an algorithm, outputs a ‘hash’ that meets certain criteria.

A hash is a fingerprint of data. It’s easy to make a hash from some data but computationally impossible to create the data from the hash.  Hashes look random compared with the data put in.
You can play with hashing here: Go to http://www.xorbin.com/tools/sha256-hash-calculator and type some data into the big box.  You’ll see the hash in the smaller box.  I typed “What does the hash of this look like?”:

hash1

It’s easy to generate a hash from some text, but impossible to re-generate the text from the hash.

If you change just one part of the data, the hash looks entirely different.  I added a question mark:

hash2

Adding or changing just one characters results in a totally different-looking hash.

By changing the data slightly, try to find a hash starting with 0000000.  Tricky eh?

By adding “-17” to the sentence, I found something that gave a hash starting with one zero:

What does the hash of this look like?-17 = 0fd82107e6e73b6f369853da3b53d4a93e8be1e5b3a4dd7da2b4ea644774bc80

I kept going, and to find something that gave a hash starting with a double zero, it took 272 attempts:

What does the hash of this look like?-272 = 00629a604a7ec6b1f05e7703c57197ed6119a6282e9b5f750e14a1500578d3fd

Bitcoin block mining.  Bitcoin mining is essentially the same game, where you tweak the input data (the block header) so that you get an output hash that matches what is required by the network at that point in time.

A recent bitcoin block #372910 was ‘solved’ because the hash was 000000000000000000b037a61e47df14b035199b5a2d464691b9456394bc07da – this had enough zeroes to satisfy the network at this time*.

* More accurately (for pedants) the block header containing the nonce is hashed twice using the SHA-256 hashing algorithm, and had to meet a number smaller than the target number determined by the network difficulty of 54,256,630,327.89 (at block #372910).

Further fun. If you are up for some light programming, there is an excellent guide to playing the guessing game in Python on Alex Gorale’s blog.


Why pay rewards in BTC instead of USD?

Satoshi Nakamoto, the proposer of bitcoin, recognised that if you want lots of people to spend hardware and energy creating this network, you need to incentivise them: i.e. you need to pay them.  The white paper is here, and well worth a read.

How do you pay anonymous participants, without creating some sort of power structure?  Any source of funding provided by some entity (e.g. if a company or government paid miners) would give that entity censorship rights and some control over who mined, and what gets mined.

Satoshi realised that an intrinsic source of funding, where a payment is paid by the system rather than by any external party, would be the answer.  This is why miners are paid by the system, in tokens which have a value that is related to the size and security of the system.  Theoretically, the more valuable the tokens become, the more money can be spent mining, leading to an increase in security and an increase in the value of the network.


Who mines?

Anyone can “participate” in the mining activity.  You just need to download some software and run it.  Your computer will then start taking transactions that it receives through the bitcoin network, and it will bundle them into blocks, and start mining the block.
Your chance of mining a block is somewhat proportional to the amount of computing power you throw at it, because mining is a guessing game, and faster computers guess more quickly.  It is also related to how fast your internet connection is, because once you have created a valid block, you want to make sure that everyone else incorporates it before someone else with a faster internet connection mines his own block and distributes his block more quickly.

In practice, successful miners form groups, or pools, and combine their processing power.  If they win a block, the reward gets shared between participants. This is similar to forming a lottery syndicate, so you win less, but more often, and your income becomes lumpy.

Currently, the top 10 mining pools consistently create about 90% of the blocks, and China-based pools create more than 60% of the blocks.  Pools are generally controlled by the “pool operator” which is a person or a few people.  So despite the rhetoric of bitcoin being decentralised, it is controlled by a handful of people in China. See this Financial Times article for further reading: Bitcoin OPEC

miner_dist_2

Mining is mainly done by Chinese pools. Source: 4 days worth of mining in early Sep 2015 from http://www.blockchain.info

The decentralisation of bitcoin, although romantic in theory, doesn’t seem to be working properly in practice.


A very brief history of mining

In 2009, at first people could mine successfully on their laptops and home computers, using the CPU (Central Processing Unit) to do the calculations.  There seemed to be a gentleman’s agreement not to use more powerful GPUs (graphics cards, the chips that make screens work) that were more efficient and faster at running this specific calculation, but harder to set up.  However that gentleman’s agreement seems to have had broken down, and GPU mining made CPU mining obsolete and caused drove a large increase in mining difficulty between 2010-12.

Then as the price of bitcoin, and so the value of the reward, increased, people started investing in mining equipment, and began manufacturing chips called ASICs (Application-Specific Integrated Circuits) that were good for nothing except hashing / mining (so take popular comparisons with the world’s supercomputers with a pinch of salt).  This was the next revolution in hashing power, starting in 2013.

I recommend this article which describes the history of mining better than I can: A guide to bitcoin mining by VICE Motherboard.


What can and can’t miscreants do?

A dishonest miner can:

  1. Refuse to relay valid transactions to other nodes.
  2. Attempt to create blocks that include or exclude specific transactions of his choosing.
  3. Attempt to create a ‘longer chain’ of blocks that make previously accepted blocks become ‘orphans’ and not part of the main chain.

He can’t:

  1. Create bitcoins out of thin air.*
  2. Steal bitcoins from your account.
  3. Make payments on your behalf or pretend to be you.

That’s a relief.

*Well, he can, but only his version of the ledger will have this transactions. Other nodes will reject this, which is why it is important to confirm a transaction across a number of nodes.

With transactions, the effect a dishonest can have is very limited.  If the rest of the network is honest, they will reject any invalid transactions coming from the baddie, and they will hear about valid transactions from other honest nodes, even if the miscreant is refusing to pass them on.

With blocks, if the miscreant has sufficient block creation power (and this is what it all hinges on), he can delay your transaction by refusing to include it in his blocks.  However, your transaction will still be known by other honest nodes as an ‘unconfirmed transaction’, and it will eventually be included in one of their blocks.

Worse though, is if the miscreant can create a longer chain of blocks than the rest of the network, and can invoke the “longest chain rule” to kick out the shorter chains.  This lets him unwind a transaction. Here’s how:

  1. Create two payments with the same bitcoins: one to an online retailer, the other to yourself (another address you control).
  2. Only broadcast the payment to the retailer.
  3. When the payment gets added in an honest block, the retailer sends you goods.
  4. Secretly create a longer chain of blocks which swaps out the payment to the retailer, and swaps in the payment to yourself.
  5. Publish the longer chain. If the other nodes are playing by the “longest chain rule” rule, then they will ignore the honest block with the retailer payment, and continue to build on your longer chain. The honest block is said to be ‘orphaned’ and does not exist to all intents and purposes.
  6. The original payment to the retailer will be deemed invalid by the honest nodes because those bitcoins have already been spent (in your longer chain).
double_spend

How to double spend.

This is called a “double spend” because the same bitcoins were spent twice – but the second one was the one that became part of the eventual blockchain.


Conclusion

To conclude, bitcoin mining is the theoretically decentralised process where anyone can add a block of transactions to the bitcoin blockchain, without needing permission from any authority, and get paid in bitcoins for it.  It is made deliberately difficult, using proof of work as a defence against Sybil attacks.  The mining difficulty increases with the network hashing power, so the more processing power of the whole network there is, the the more power someone needs to assert control over the network.

It works well until any entity or coordinated group controls too much of the hashing power, at which point they can control various aspects of the system.  Currently 90% of blocks are mined by known ‘pools’ or syndicates of miners, and if a few pools join together, they could effect changes and assert control over the network.

Comments