Bitcoin algorithm - A Brief Description

This entry is part 4 of 8 in the series Cryptocurrency Basics

In order to examine its strength, it’s necessary to briefly describe some of the details behind the Bitcoin algorithm.  For a more complete description please see Nakamoto’s original 2008 paper.

Bitcoin Transactions

At the heart of the system is the transaction, a block of data that holds information such as how many bitcoins to send, and the network address to send them to.  This data is digitally signed by the owner of the bitcoins using and encryption method called asymmetric, or public/private key, encryption.

In public/private key encryption one key is held by the owner and kept secret the second is published for all the world to see. Data is encrypted using the public key can only be decrypted using the private key, and vice versa. This can be used to digitally sign a piece of data.

Figure One:  Digitally Signed a transaction


Bitcoin Algorithm - The Blockchain

The publicly held history of all transactions of Bitcoin is held in what is known as the blockchain.  Starting with the creation of each Bitcoin, this shows every transfer of ownership to the present day. The integrity of the blockchain can be proven using another common encryption algorithm used throughout the Internet called SHA256.  Known as a ‘hashing’ algorithm, this is used to detect whether the data has been tampered with.  Changing even a single bit will radically change the output from the hash.

Figure Two: Hashing algorithms prove the unbroken chain of transactions

The output from the hash is a long string of bits. By including this string as part of the next transaction, the two transactions can be chained together.

By combining these two, providing a way to sign a transaction to prove it was created by the owner, then providing a way to chain transactions together to prove they’ve not been tampered with, Bitcoin provides a way to prove ownership similar in main ways to title deeds for property, or ownership records for cars.

The Network

When a transaction is posted publically, a copy is being sent to every server on the Bitcoin network.  This network is extensive and powerful, but was created by individuals the world over donating server time to Bitcoin.  Without this, the system simply wouldn’t function.

But why would anyone donate expensive servers in the first place?

In order to create an incentive for individuals to donate server time, the original design intentionally makes the hashing algorithm more difficult than it needs to be.  Instead of allowing just any output from the algorithm, the design requires that the output contains an exact number of zeros at the start. Not all results have this number of zeros, and so by increasing or decreasing the number of zeros, the algorithm is made harder or easier. Increase the number of zeros and more results had to be thrown away before hitting on the right one, decrease it and fewer have to be far away.

Figure Three: If you stipulate more zeros at the start, hashing gets more difficult.

To get a valid answer, the algorithm needs to be rerun with new random number added to the transaction block each time.  Do this often enough and eventually you’ll stumble upon a random number that’s just right to produce a hash output with exactly the right number of zeros at the start.  However, it’s impossible to calculate in advance which random number will do this. Therefore the calculation of the hash turns into something of a lottery.

It’s being part of this lottery that gives the incentive, as it also includes a prize. The first server solving the puzzle can create an agreed number of the coins and add them to that transaction. These are brand new coins, and can be exchanged for traditional cash or held by the owner.

The probability that any particular server will find a valid output is also set by the design. That calculation looks like this.

Finally, the difficulty of the algorithm is changed to ensure that no matter how many servers are on the network it is likely that a new result will be found every 10 minutes.

Arbitrating between winners

In its simplest form the above would work only if every server was working on the same block and could agree on who found the winning answer first. On a global network this is not possible. Delays in the transmission of data between servers means that no two servers can be guaranteed to have the same data.

This makes the simple case above susceptible to what is known as double accounting. A coin holder could potentially use the same coin to buy services from two different people at the same time. So long as those two people did not share data neither would know that the other transaction existed.

To make this impossible the design calls for a system of consensus between servers. Each server works on the longest blockchain it holds. It also has in reserve every other potentially valid blockchain.  Because each server is working on what it thinks is the longest blockchain, there is a preference across the whole network for longer blockchain. This gives the blockchain which is actually longest an advantage, and it grows fastest.

Figure Four: Agreeing who has the longest blockchain.

Longer blockchain therefore grow faster then shorter ones. Over six or seven iterations one will accelerate away from the others and the network achieves a consensus.  Transactions in that blockchain are confirmed and transactions in losing chains are discarded.

Next, Bitcoin Vulnerabilities

Previous, Introduction to Cryptocurrencies