What Is Bitcoin?
Part 2.
In the previous article, I gave you a vague sense of what Bitcoin is or what Bitcoin aims to do. In this article, let’s take a deeper dive into the technology behind Bitcoin.
TO understand Bitcoin, you need to first understand Blockchain. Now, what’s a Blockchain? Let’s try to answer this question.
Blockchain is what its name says, i.e. Blockchain is a chain of Blocks.
To understand Blockchain, we first need to know the properties of blockchain, and they are:
- Transparent
- Public
- Persistent
- Append only
Let’s tackle each property one by one building on the previous story.
Transparent:
Blockchain is decentralized i.e. everyone has a copy of it and everyone knows the transactions that are going on there, hence transparent.
Public:
Everyone having a copy of the blockchain makes it public.
Persistent:
This is a little complicated, so stay with me…
So, blockchain is a chain of blocks, but what are blocks?
Blocks are individual units of data, for example, if I send you $100 on the blockchain, new data will be recorded in the block and this block will be chained to the previous block using a hash. Now, whats a hash? A hash is a function by which we can get some fixed sized data representing any variable-size data, in simpler words, hashing is the process that converts one value to another.
Let’s say you have a file named a.txt, if you hash it, you’ll get some data bits which will represent the data in that file. Every time you hash it, it returns the same data, but this process is irreversible, i.e. you cannot get the data back from the hash, so calling it a representation.
One more property of hash is that a small change in data i.e. a little change in a.txt results in a drastic change in the hash, so a hash is used to check for file’s integrity. In bitcoin’s case, the hashing algorithm used is SHA-256.
Coming back to Persistentency, every block of data has some hash, and the next block takes the previous hash as the input, so the hash of this block also depends on the hash of the previous block.
So if some attacker tries to tamper with some data somewhere in the block, that person will now have to change the hash of all the following blocks. But again everyone has a copy of the blockchain with them, so when the attacker tries to publish this data publically, no one believes his copy, because he is not the majority, he is just a single person. that is why blockchain is persistent.
Append Only:
Because of the above explanation of persistency, we can say that once some new data has entered the blockchain, and once the block is formed and once the network has accepted it, it is close to impossible to change it, hence Append Only.
This is most of how a blockchain works, most of it…
One more important thing to understand is mining.
Mining:
Mining is very easy to understand. Consider gold mines, people spend money to mine gold, now, consider the hash for each block as gold for blockchain, we need to find the hash of each block to add it to the blockchain, so we spend electricity and computer power to generate these hashes.
Hashing data is pretty easy, but then why is mining compared to gold mining, because mining for block hash can be difficult and it is based on various factors, we’ll look into these when we start bitcoin.
We are all set to understand how Bitcoin works, let’s start…
What Is Bitcoin?
In simple words, Bitcoin is an implementation of blockchain where our transactions are the block data. Let’s elaborate…
In a blockchain, every block contains the previous block’s hash, data, and this block’s final hash.
In bitcoin, every block contains previous block’s hash, transaction data, and this block’s final hash, the only difference is data and transactional data.
Let’s come back to mining.
Incentivized Mining:
What happens in bitcoin mining is, whenever someone gets the correct hash for the block, that person is rewarded by the system with some bitcoin, in essence, mining creates new bitcoin, hence the name mining.
Only 21Million bitcoins can be mined, once they are all mined, the miners will be incentivized with transaction fees. This promotes good miners, hence collectively making the network.
UTXO:
UTXO is unspent transaction output. To understand this let’s consider this, you have 2 notes of $10 and you are buying something for $15, what will you do, you’ll give 2 $10 notes and get back $5 note, right?
The same way, if I have 2 bitcoins, and I’m spending 1.5 Bitcoins, I’ll send 2 bitcoins and get 0.5 in return.
Network Rules:
The steps to run the bitcoin network are as follows:
- New transactions are broadcasted to everyone (every node) in the network.
- Each node collects a new transaction in the block.
- Each node works on mining (finding proof-of-work) of the block.
- When the block is mined by one node, it broadcasts the block in the network.
- Everyone accepts the block only if the transactions are valid and are not spent already.
- If nodes have started working on the block following the current broadcasted block, that means they have accepted the block.
Now, what is Proof-of-work?
Proof-of-Work:
Remember gold mining comparison, now, let’s understand why the hash is so important.
In bitcoin, when mining hash, we have to make sure we get a hash with some leading zeros. To modify the hash to get the required amount of zeros, we introduce a term called as nonce and start the nonce from 0 and go on incrementing it until we find the desired hash.
Sometimes, miners exhaust the value of nonce, but cannot find the required hash, in that case, miners change the transaction order inside the block and start the nonce again until they find a valid nonce.
It requires a lot of power, and hence the miners are rewarded with bitcoin.
Privacy:
Since the transactions are public in bitcoin, one can argue that there is no privacy, but privacy is maintained by using the public key cryptography, what’s this now?
consider this, you have two keys for your home, with the one you can lock the house, and unlock with another, that is exactly what public-key cryptography is.
Here one key is private, and one is public, public-key is derived from private-key, and as the name says, private-key must be kept safe and public-key must be shown to everyone. People will see transactions as public-key of one sending money to public-key of another participant. There is no way to know who the pubic key belongs to. Hence privacy is maintained.
Attack on Bitcoin:
Even such a public system is prone to attack, but to understand the attack dynamics of the attack, let’s establish what we have understood so far…
- It’s a chain of blocks.
- Blocks contain transactions that we make.
- We need hashing and mining to publish a new block.
- One thing that I mentioned in an implied manner is that majority wins, why is that? If the majority (≥51%) of participants come together and start mining, they will form a chain which is the longest chain because of more processing power and the longest chain always wins in bitcoin.
So now with all this in mind, let’s start to understand the possibility of attacks in bitcoin.
Let’s say a rogue attacker wants to get monetary benefits from the network by using the double-spending problem, i.e. let’s say he sent money to someone and now he starts creating his own chain to send the same money (which he already spent) to send to someone else, how can he do this?
- He starts extending his own version of the chain in isolation and comes back after some time, now if he does not have ≥51% computing power, he is already dismissed, because his chain will not be the longest one.
- If he has ≥51% computing power, he might be able to make the longest chain, in which case he wins. But since the bitcoin network and community is so big, no one can have such power, so this attack is not possible in bitcoin.
That’s it for today. Please clap if you liked the article and follow to see more such articles.
Reference: https://bitcoin.org/bitcoin.pdf