In short, the blockchain is equivalent to a decentralized digital ledger that records a series of data. These data are organized into blocks, protected by cryptography, and arranged in chronological order.
The earliest model of blockchain was built in the early 1990s. At the time, computer scientist Stuart Haber and physicist W. Scott Stornetta used encryption technology to protect data from tampering.
Haber and Stornetta's achievement inspired many computer scientists and cryptography enthusiasts to study blockchain, which also promoted the world's first decentralized electronic cash system (i.e. the first cryptocurrency) - the birth of Bitcoin.
Although blockchain technology came out before cryptocurrency, it was not until 2008, when Bitcoin was born, that the former gradually gained recognition. Since then, public interest in blockchain technology has grown, and cryptocurrencies have begun to gain popularity.
Blockchain technology is mainly used to record cryptocurrency transactions, but it can also record a variety of digital data and can also be applied to other fields. The oldest, most secure, and largest blockchain network is Bitcoin, which was carefully designed to blend cryptography and game theory in a balanced way.
In the field of cryptocurrency, we can think of a blockchain as a chain consisting of a series of stable blocks, each of which stores a series of previously confirmed transaction data. The blockchain network is jointly maintained by countless computers, so its main function is to act as a decentralized database (or ledger). In other words, all participants (i.e. nodes) in the blockchain maintain a copy of the blockchain data and maintain good communication with each other to ensure that everyone is always on the same page (or block).
As a result, blockchain transactions occur in a global peer-to-peer network, promoting Bitcoin as a decentralized, borderless and censorship-resistant cryptocurrency. However, most blockchains do not require any trust mechanism and are considered trustless systems. Bitcoin also has no independent regulator.
Almost all blockchains are centered on mining, which is inseparable from hashing algorithms. Bitcoin uses the SHA-256 algorithm (Secure Hash Algorithm 256 bits), which allows inputting a string of any length to produce an output of the same length. The output result can be called a "hash value", which is always 64 characters (256 bits).
Therefore, no matter how many times "mining" is repeated, the same input always produces the same output. However, if the input changes slightly, the output will be completely different. Therefore, the hash function is deterministic, whereas most cryptocurrencies are designed with a one-way hash function.
This type of function determines that the user cannot infer the input based on the output result. The only way is to guess, but the probability of guessing is very slim. This is one of the reasons why the Bitcoin blockchain is safe and reliable.
Now that we understand the functionality of the algorithm, let’s illustrate how the blockchain works through a simple transaction example.
Suppose Alice and Bob are two Bitcoin holders, and Alice owes Bob two Bitcoins.
In order to repay Bob with two Bitcoins, Alice broadcasts this transaction information to miners in the entire network.
In this transaction, Alice informs the miners of Bob's address and the number of bitcoins in the transaction, and attaches a digital signature with her public key. This signature is generated by Alice's private key and allows miners to verify that Alice is the actual owner of these Bitcoins.
After confirming that the transaction is true and valid, the miner can put this transaction information into a block together with other transaction information and try to "mine" this block ”. This block is operated through the SHA-256 algorithm, and the operation result must start with a certain number of "0"s before it can be judged to be valid. The number of "0" depends on the "difficulty" of the operation, which will change with changes in the computing power of the entire network.
In order to correctly output a hash value with the expected number of "0"s, miners will add a "nonce" to the block before running the encryption algorithm. Slight changes in this value will completely change the result of the operation, and miners must try different random nonces until they get the correct hash value.
Every time a block is mined, miners will broadcast the new block information to the entire network so that other miners can confirm the validity of the block. Afterwards, they will add the valid block information to their own blockchain, indicating that the transaction is completed. However, miners still need to add the hash value of the previous block to the new block, and eventually connect all the blocks to form a veritable "blockchain". This is very important and reflects the role of trust in the system.
Each miner stores a dedicated copy of the blockchain on his personal computer and reaches a consensus: the blockchain with the most computing power must be the longest. If someone wants to change the transaction information in the previous block, the hash value of this block will also change, causing the hash values of all blocks after this block to change. He must redo all previous calculations to convince others that his block information is correct. Therefore, if a miner attempts to tamper with block information, he must invest more than 50% of the computing power of the entire network, which is almost a fantasy. Similar network attacks are therefore called 51% attacks.
This model that requires computer operations to generate new blocks is called Proof of Work (PoW). There are also other mechanisms, such as Proof of Stake (PoS), which do not require huge computing power, consume less power, and attract more users to participate.