What is blockchain?
In summary, a blockchain is a list of data records that functions like a decentralized database. The data is organized into blocks, which are ordered chronologically and secured cryptographically.
The first concept of blockchain was created in the early 1990s when computer scientist Stuart Haber and physicist W. Scott Stornetta used cryptographic techniques in a blockchain to protect digital documents against data tampering.
Haber and Stornetta's work certainly inspired that of many other computer scientists and cryptography enthusiasts, which ultimately led to the creation of bitcoin, the first decentralized electronic money system (and the first cryptocurrency).
Although blockchain technology is older than cryptocurrencies, it was not until the creation of bitcoin in 2008 that its potential began to be recognized. Since then, interest in blockchain technology has gradually increased and cryptocurrencies are now being recognized on a larger scale.
Blockchain technology is most commonly used to record cryptocurrency transactions, but it is suitable for many other types of digital data and can be applied to a wide range of use cases. The oldest, most secure and largest blockchain network is Bitcoin, which was designed using a balanced combination of cryptography and game theory.
How does a blockchain work?
In the context of cryptocurrencies, a blockchain consists of a chain of blocks, each of which stores a list of previously confirmed transactions. As the blockchain network is maintained by a myriad of computers distributed around the world, it functions as a decentralized database. This means that participants (or nodes) each maintain a copy of the blockchain data and communicate with each other to ensure they are on the same page (or block).
Therefore, blockchain transactions take place within a global peer-to-peer network and this is what makes bitcoin a decentralized, borderless and censorship-resistant digital currency. Additionally, most blockchain systems are considered trustless because they do not require any trust. There is no single authority that controls bitcoin.
A central element of almost all blockchains is the mining process, which relies on hashing algorithms. Bitcoin uses the 256-bit Secure hash algorithm (SHA-256). It takes an input of any length and generates an output that will always be the same length. The output produced is called a “hash,” and in this case it is always 64 characters (256 bits).
So the same input will result in the same output no matter how many times the process is repeated. But if a small change is made to the input, the output will change completely. As such, hash functions are deterministic, and in the world of cryptocurrencies, most of them are designed as a one-way hash function.
Being a one-way function means that it is almost impossible to calculate the input from the output. One can only guess what the entry was, but the chances of guessing it correctly are extremely low. This is one of the reasons why the Bitcoin blockchain is secure.
Now that we know what the algorithm does, let's show how a blockchain works with a simple example transaction.
Imagine that Alice and Bob each have a balance of bitcoins. Suppose Alice owes Bob 2 bitcoins.
So that Alice can send Bob these 2 bitcoins, she broadcasts a message containing the transaction she wants to make to all the miners on the network.
In this transaction, Alice gives Bob's address to the miners and the amount of bitcoins she wants to send, along with a digital signature and her public key. The signature is made with Alice's private key and miners can validate that Alice is the owner of these bitcoins.
Once miners are sure the transaction is valid, they can place it in a block with many other transactions and attempt to mine the block. To do this, the block is subjected to the SHA-256 algorithm. The output must start with a certain number of 0s to be considered valid. The necessary amount of 0s depends on the so-called “difficulty” which changes depending on the computing power of the network.
In order to produce an output hash with the desired amount of 0s at the beginning, miners add what is called a “nonce” into the block before passing it through the algorithm. Since a small change to the input completely changes the output, miners try random nonces until they find a valid output hash.
Once the block is mined, the miner broadcasts this newly mined block to all other miners. They then verify that the block is valid so they can add it to their copy of the blockchain and the transaction is complete. But in the block, miners must also include the output hash of the previous block so that all the blocks are linked together, hence the name blockchain. This is an important part because of how trust works in the system.
Each miner has their own copy of the blockchain on their computer and everyone trusts the blockchain that has had the most work done on it, or the longest running blockchain. If a miner modifies a transaction in a previous block, the output hash of that block will change, which will imply a modification of all hashes of subsequent blocks. The miner would have to redo all the work for anyone to accept their blockchain as the correct one. So, if a miner wanted to cheat, they would need more than 50% of the network's computing power, which is very unlikely. So network attacks like this are called 51% attacks.
The model of putting computers to work to produce blocks is called Proof of Work (PoW); there are also other models like proof of stake (PoS) which does not require as much computing power and is supposed to require less electricity while still being able to scale to a larger number of users.