In this post, I will explain the basic about Bitcoin Blockchain and Proof of Work, an algorithm that validate transactions and create new blocks (mining), as detailed in
Bitcoin whitepaper, by Satoshi Nakamoto. This apply also for Ethereum and other similar blockchains that use Proof of Work (PoW).
Please feel free to point out any mistakes, as I had some technical and English doubts while writing it First, we need to understand the concept of hashing, only then we can analyze how blockchain works.
What is a Hash? A hash is a cryptographic function that receive
an input of any length and generate an output of a fixed length , an alphanumerical sequence. Simply put, it is a bunch of random numbers and letters.
This is a great website, it shows how hashing and mining works. You can enter some text there to see how it works.
https://anders.com/blockchain/hash.htmlIt is important to note that a hash has a fixed size, no matter how big or small the input is. Any small change in one letter in the input will generate a completely different hash (output). This is important if you have a big data, because all this data can be converted to a small hash, which will work as a fingerprint of that data.
BlockchainThe idea proposed by Satoshi is to register transactions on a block. When the proof of work solution for that block is found, it is hashed. Each block includes the previous block’s hash, forming a chain of blocks (blockchain), and each additional block reinforcing the ones before it.
Because of that process, if any transaction in a past block is changed the output hash will be different.
When you make a Bitcoin transaction and you see that you have 5 confirmations, that means that 5 blocks were mined after that transaction. A transaction with 6 confirmations is considered irreversible.
Proof of WorkIn the Blockchain, all transactions are publicly announced to all nodes, as there is no central authority who validate transactions.
Proof of Work is an algorithm that rewards participants who solve a cryptographic puzzle in order to validate transactions and create new blocks (this process in known as mining).
This puzzle consists in scanning for a value (called Nonce) that when hashed together with thr block data, the hash begins with a number of zeros.
In this
website you can see how this process works. You can try to find a Nonce that when hashed generates a hash that start with 0000 on your own. You will see that it is hard, unless you are very lucky. And you are going to be lucky twice in row, if you do go to a casino or something like that lol.
The difficult in finding that nonce increases exponentially as more zeros are required by the block. Difficult is adjusted every 2016 blocks, based on the average hashrate of those past 2016 blocks, so that 2016 blocks are mined every two weeks. (So a block is mined every 10 minutes)
Miners only get their reward if they are mining the longest chain, as it has the greatest processing power invested. If the honest nodes control the majority processing power, the honest chain will always be the longest and will outpace attacker’s chain.
To modify a past transaction the attacker would have to redo the PoW of the block and all subsequent blocks, and outpace the honest chain. For this to happen, the attacker’s would need more processing power than the honest chain, also known as 51% attack.
The longest chain not only serves as proof of the sequence of events witnessed, but proof that it came from the largest pool of CPU power.
Source: bitcoin whitepaper. Images from:
https://nakamotoinstitute.org/bitcoin/Topic also available in
Portuguese (short version) and
Arabic (by Zwei)