Lesson 15


Bitcoin - Technical Background

VIDEO: Complete detail of how Bitcoin works

How bitcoins are stored

You receive bitcoins when somebody sends them to you. But there is no actual balance in bitcoins of a particular account anywhere. Only information about incoming payments to some account (income transactions, or digital receipts) is stored in the network. Balance of account is obtained by summing up all income transactions for the account that have not been spent yet. It is like receiving cheques in your mailbox and calculating the total amount of money that you have.

 

How bitcoins are generated

Bitcoins are created during the process of system functioning as a result of transaction processing. To support reliability of Bitcoin as many members as possible have to perform transaction processing. Bitcoins are proportionally distributed between these members to encourage their work. Members verify transactions within 10 minute intervals, and every time they compete for the opportunity to be the first one, that can claim the reward.

 

What is the blockchain and where is it stored?

The blockchain is a publicly distributed database that stores the unified history of all all Bitcoin transactions and as a result the state of the accounts. Every member is supposed to store a copy of this database. The bitcoin protocol has mechanisms to synchronize the state of the blockchain for all members in an unstable environment with network delays, internet cut-off, attacks of malicious members etc. Main difference of blockchain from other distributed databases is its ability to only add transactions to the history - old validated transactions cannot be altered or deleted. The blockchain is organized as a chain of blocks of transactions. Integrity of the blockchain is protected by cryptographic methods - hashes and digital signatures. This makes the blockchain a perfect financial history.

 

How bitcoins are moved

Bitcoins are moved by making a transaction - a signed piece of data that authorizes moving of bitcoins from one account to another. As there is no direct balance of an account, you have to move bitcoins that you received from somebody else. Technically it means that you take some digital cheques that you have and create a new cheque from them with your signature. You cannot use cheques that you’ve sent to someone else before. So each cheque contains information about previous cheques that were used to create it and so on.

 

What are wallets and addresses?

Each account is represented by a public key of ECDSA key pair. Bitcoins can only be “attached” to a valid public key and a person who has the corresponding private key is their owner. The hash of a public key (or sometimes the public key itself) is named an “address”. Having bitcoins means having a possibility to authorize sending of them, i.e. the possibility to generate a correct signature on the digital cheque that moves bitcoins from one public key to another. If you lost the private key - you lost your bitcoins, if it was stolen - bitcoins can be moved without your approval. There are no other entities in the system that can authorize the moving of bitcoins except those that have the private key. A Bitcoin wallet in the simplest meaning is an address (public key) and a corresponding private key. In a more complex case a Bitcoin wallet will be a set of addresses and a set of corresponding private keys (or even only one master key) that usually are controlled by the same person. It is important to note that anybody can create any amount of addresses (and wallets) and in fact Bitcoin encourages to create a new address for each new transaction to increase privacy.

General architecture

Bitcoin transactions are processed by members (so called “miners”) who are willing to spend their computing resources in exchange for a reward. Each transaction that is propagated in the network should be validated, confirmed and then included into the next block. The only way to achieve a consistent state of the blockchain in a decentralized environment is to “vote” for good or bad transactions. To prevent malicious miners from organizing together (Sybil attack) and validating “bad” transactions (those who spend non-existing money, double-spending, spam etc.) a proof-of-work mechanism is used. It means that to validate a transaction a miner has to spend a significant amount of computational resources. Now to create malicious miners the attacker has to invest in computing power. The idea is that a block of transactions will be created by a miner who solved the proof-of-work task faster than others. As soon as proof-of-work is designed in a way that every miner has a chance to win, the probability of becoming the first is equal to percentage of computing power that you control. The system works properly if members that control 51% of the computing power stay honest and support only “good” transactions. Now we will discuss why it was designed exactly like this.

 

Why was Bitcoin designed like this?

We will come over 7 steps to explain that. We will try to build an imaginary digital money system from the ground, find attacks, fix them, find attacks again etc. This will not exactly represent how Bitcoin is working, but you will grasp general ideas.

 

Step #1 - Digital cheques.

If Alice wants to pay Bob electronically she might create a digital cheque.

By analogy with physical ones each cheque has a few basic properties: sender, recipient, amount and signature. The signature is the only mechanism that ensures that the sender really had the intention to initiate the payment. The recipient and other involved parties (for example a bank) can verify that the signature is correct. But imagine that Alice sent to Bob 2 identical digital cheques. Bob might think that Alice is paying the double amount or sent them by mistake, or it was a network error or something else. It shows that  we cannot blindly apply the concept of cheques to a digital world - we will face the issue of the possibility to copy electronic data. Paper cheques have physical protection from copying (watermarks or so). Digital cheques cannot have this by design. So here we come to the second step.

 

Step #2 - Unique identifier on the cheque

Adding a unique identifier to the digital cheque will help Bob distinguish a double payment from double sending. But who will generate this identifiers and track their usage since we don’t have central bank?

 

Step #3 - Generating identifiers

The idea here is that every user is able to do generate identifiers himself! To prevent collisions an ordinary hash function is used (SHA256 or so). Here the probability of a collision for 2 people to generate the same identifier is smaller than probability of finding a particular atom from the whole universe.

 

But what if Alice tries to spend the same cheque twice - to Bob and Charlie at the same time?

 

Step #4 - Verification of cheques

When accepting the cheque, Bob has to evaluate the risk of fraud. The identifier doesn’t answer the question whether Alice has tried to pay with this cheque already (so called double spending attack). The best way to verify it in the decentralized network is asking around. So the idea is before accepting payment, ask everybody about possible collisions and accept the cheque only after receiving positive feedback. But here we come to the next problem - since participants are anonymous, Alice can create thousands of fake miners that will vote as she wanted (so called sybil attack).

 

Step #5 - Voting

Ok, so here we introduce proof-of-work! Before submitting a vote, miners have to show that they worked hard and spend some resources. The first miner that finished proof-of-work is eligible to validate a transaction. And there is a reward that encourages this competition: new coins are paid to the first miner. Now Alice has to invest a lot of resources to support all her fake miners. Stop! Does this mean that Alice having the fastest computer will always be the first and therefore become very powerful? Because she can convince Bob that the cheque is valid, but then she can initiate re-voting for the transaction, pretending that there was some misunderstanding? Not really.

 

Step #6 - 51%

Proof-of-work was designed in such a way that everybody can become the first - it is like a lottery. Buying a lot of tickets (i.e. having a lot of computing power in our case) just increases your chances, but doesn’t guarantee the first place. Actually the probability of becoming the first is equal to the percentage of computational resources that you control. So only if Alice has a majority (51% and more) of resources she can influence the network’s decisions. For example if the fastest supercomputer joins the Bitcoin network, it will not even get 0.01% of needed computing power. So as soon as 51% of power is under control of honest participants, the network is robust - they will approve only good transactions and broadcast corresponding blocks. Once somebody broadcasted a valid block the rest of the miners stop doing proof-of-work for it and take the next one. But what if two miners finished the proof-of-work almost simultaneously? Internet obviously has network delays, and a miner from San-Francisco will not know immediately about a solution from a miner in Sydney. How do the rest of the miners decide who was first?

 

Step #7 - Blockchain

Here we came to the point where we need to design a blockchain.

Each block of transactions is always based on some previous block. Blocks are like pages from a notary book - every new day the numeration has to be based on the previous day. So when a collision happens - a fork occurs in the blockchain. Obviously only one block will be considered valid afterwards (since they may contradict each other), but a particular miner cannot decide which one. The breakthrough idea is that miners don’t decide who was the first, they just save all well-formed blocks (even if transactions from these blocks contradict each other).

But there is one simple rule - miners continue working on the chain of blocks that had required to spend more resources. If honest miners follow that rule and they control 51% of the computing power then the chain of blocks that contains only good transactions will grow faster as soon as more resources are spent on its construction.

 

Back

comments powered by Disqus
Bitalo_link.png

You will get an awesome place to trade your
Bitcoin and more. Click for further information!

Choose your topic

and start the journey