Fundamentals of a Bitcoin transaction, its purpose and outcome. The difference between private and public keys, a detailed explanation of a digital signature and 51% attack
You have already got familiar with the definition of Bitcoin and its legal status, but the best way to understand how its works is to start with transactions.
Sending and receiving Bitcoins only requires a computer (or a smartphone) and a connection to the Internet. Making a transaction, in its simplest form, is broadcasting a message into the Bitcoin network. This message contains the amount of Bitcoins and the address you want to send Bitcoins to. If the transaction is valid, it gets added to the blockchain, and the transfer is complete.
Private Keys and Public Keys
A Bitcoin account is an address. This address holds the history of all the transactions associated with it. This address is called a public key. It looks like a set of 34 random letters and numbers. If someone wants to send you bitcoins, they only need to know your public key.
Sending bitcoins, however, requires you to use your private key to ‘sign’ the transactions, so that other users know that it was actually you who sent bitcoins. Each user has their own private key. A private key is a set of 64 random letters and numbers, and it is used to create the public key. Nobody can use your public key to figure out your private key. Under no circumstance should you tell anyone your private key.
To make a transaction, you enter the amount of Bitcoins and the public key of the receiving user. After that, Bitcoin software uses your private key and the transaction details to produce a unique digital signature, which is then attached to the transaction.
The transaction goes out and waits for validation. The Bitcoin system validates the transaction by checking your public key against your digital signature. It does so without even knowing your private key. If it checks out and you have enough Bitcoins, the transactions is validated.
Your validated transaction, along with others, gets added into a block. When the block is successfully mined (after about 10 minutes), it gets added to a chain of other previously mined blocks, a blockchain.
Each block contains the hash of the previous block. This hash is a set of random letters and symbols, which is produced by running all the data in the block through a special mathematical equation called a hash function. This means if someone changes something in a block, they have to change all the blocks after that as well. What makes it even harder is the fact that they have to do it in 10 minutes, before the next block is mined. This ensures the immutability of the blockchain, meaining transactions cannot be changed or reversed.
Mining a block means finding the hash of a block. Each miner uses their computer to find the hash. The total computing power of all miners in the network is called the hashrate. If a malicious person or group possesses more than 50% of the network’s hashrate, they overpower the rest of the miners. They can decide what gets added to the blockchain, thus monopolizing the network. This is called a 51% attack. Now new blocks are mined only by the attackers and only they get the reward. The control over the network gives them the power to reject valid transactions and spend same coins twice.
The success of a 51% attack depends on the total hashrate of the network. The more computing power the network has, the harder it is for attackers to overpower the rest of nodes.