Technology

The Mechanics of Bitcoin

2 Oct 2014 11:33pm, by

 

 

Bitcoin is constantly talked about in the media but how it works is not something most people can readily explain. So we decided to explain it ourselves to provide some deeper context and understanding for its various use cases.

What is Bitcoin?

Bitcoin is a decentralized peer-to-peer virtual, or crypto, currency system. There is no central institution like a bank to control the system. But it has very strict rules that are controlled by cryptographic functions.

What’s Important About Cryptography?

In cryptography there are symmetric and asymmetric algorithms.

Here, we’ll stick to asymmetric algorithms since they are used extensively in the Bitcoin system.

With asymmetric algorithms, you generate a pair of keys — public and private. Once  a message is encrypted using a public key, it can only be decrypted using the corresponding private key and vice versa.

You can safely publish your public key to the world and keep the private key secret.

This process achieves two key factors:

  • Non-repudiation — In a message signed by Alice’s private key, the resulting ciphertext will have a unique signature of Alice’s which can be verified by its corresponding public key and conclude that the message has indeed come from Alice. This is the concept of non-repudiation.
  • Confidentiality — Suppose Alice wants to send a message only to Bob. Alice signs the message with Bob’s public key and hence only Bob will be able to decrypt it since only he has his private key. This is the concept of confidentiality.

Bitcoin also incorporates hashing. Hashing is used to check the integrity of information. When hashing a value, you obtain a unique string. If even a minor change is made to the original value, the hash will change completely.

A Bitcoin address is a hashed format of a public key.

Using Bitcoin is Anonymous … Really? How?

Online transactions that involve money will generally have some identity of the users validated with their address. In the Bitcoin Network, users can create as many identities as they want without any proof or documents.

Identity in the Bitcoin Network is a Bitcoin address. With this Bitcoin address, users can proceed with Bitcoin transactions. In order to receive Bitcoins, all users need to do is provide their Bitcoin address to the payer. So to provide anonymity, users simply need to create many accounts and use these accounts for public transactions while keeping the main account’s Bitcoin address private. It’s easy to create accounts and it’s free.

Note that all transactions are tracked in a public ledger known as block chain. And anyone can see which Bitcoin address owns how many Bitcoins.

Going Down the Rabbit Hole

mechanicsbitcoin

A transaction is verified before it gets accepted in the network. This is accomplished by adhering to a contract defined in the script. The script is a function or a sequence of instructions that when followed verifies the owner of the Bitcoin so that the owner can spend it. This script can be custom made.

Users have inputs, which are Bitcoins sent to them previously, as well as outputs, which are Bitcoins that users have spent. Inputs help prove that the unspent Bitcoins belong to the user, which is accomplished with their private key. Outputs have instructions which, when followed, will validate the receiver. So, the receivers have to successfully pass the instructions to own the Bitcoins using their key pair.

The Block Chain

A number of verified transactions are collated into what is known in the Bitcoin world as blocks. These blocks, in order to be accepted and appended to the existing block chain, need to solve a mathematical puzzle, or a proof of work. This work is done by miners.

Miners are participants who provide computational resources to solve the mathematical puzzle. The rules of the puzzle are:

  • Provided a challenge, there should exist a nonce — a random value, 4 bytes in length — which gets appended with the challenge such that it produces hash with several leading zeroes on applying hashing algorithm.
  • A challenge basically is derived from calculating the merkle root of the current block.
  • A merkle tree pairs transaction IDs from a block and outputs single hash, eventually providing a unique hash for all the transactions in the current block yielding a merkle root.

There is no known shortcut to calculate a nonce that would produce a 0 leading hash value, given the random nature of hashing. But on average at least one miner would be able to solve this puzzle in approximately 10 minutes, given the advancement of computing and declining hardware costs.

The difficulty level of the puzzle is calibrated so that in two weeks about 2,016 blocks are generated. If fewer blocks are generated, then the system automatically adjusts to an easier difficulty level and vice versa. The only way to calculate is using brute force by trying all the combination of nonce with the given challenge.

What’s in it for the Miners?

The first miner to solve the puzzle is entitled to be rewarded with Bitcoins. Every generation of a new block will create Bitcoins out of thin air. These Bitcoins are also known as coinbase records. The first transaction record of a block is the coinbase record which miners send to themselves as a reward.

Apart from the coinbase reward, there is another incentive, which is the transaction fee that is associated to every transaction in the current block. This transaction fee can be set by the user or payer.

When Bitcoin started in January 2009, the coinbase amount was 50 bitcoins. Every four years, the coinbase value gets halved. There is a cap on the number of total Bitcoin available — 21 million. That means that some time likely between 2110 and 2140 — depending on how many Bitcoins are generated each year — new Bitcoin generation will halt. The miners will still be rewarded with the transaction fee even though the coinbase record will no longer augment.

Suppose there are 2000 blocks already created in the block chain. A transaction occurs after that, It needs to be mined to feature in the 2001th block in the block chain. Then, it is said to have its 1st confirmation. But the tricky part is, it has to be mined atleast in five more blocks after 2001 block thus making it appear/feature in six block in total to determine that it has been successfully transferred to the sent address of a transaction. Of course the confirmation keeps on increasing but six onfirmation is enough for a transaction to be complete. Till that time, The payer has to wait.

Arun Kumaraswamy is a Java-Oracle Developer. His technical skills span a very wide range of technologies across networks, operating systems and web servers. He specializes in programming, PL/SQL and Linux. He conducts penetration testing for websites.  In short, he is the definition of a geek. He likes watching cricket in his spare time. He has some certifications like C|EH, CDAC-DITISS, SCJP and RHCE.

Feature image via Flickr Creative Commons.

A newsletter digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.