Leçon 2

How Bitcoin Works

Bitcoin is based on blockchain technology, which is a publicly distributed ledger that uses a PoW consensus mechanism to maintain network security.

The birth of bitcoin and blockchain involves two long-standing problems in digital currency: the Double-Spending Problem and the Byzantine Generals Problem

From Physical to Digital Currency: Solving the Double-Spending Problem

Compared with the physical currency in daily life, the biggest difficulty in developing electronic cash is how to overcome the “trust problem”. The reason why the earliest shells and precious metals can be used as general equivalents is that they have a certain scarcity, and the later physical banknotes rely on the credibility of the state to solve the trust problem.

These physical currencies had value and were able to complete the transfer of value instantly. In the digital era, any content is essentially a combination of 0 and 1 codes, and digital money can be copied into two copies and released to two different recipients at the same time, which is the so-called “double spending problem”. The Internet itself does not have the ability to represent value, so people previously had to use a centralized account system with a centralized server, such as a bank, in order to use credit cards and other types of electronic money.

A system that does not require trust: Distributed Ledger

But whether there is a truly trusted third party is a question. There is a risk of single point of failures, such as attacks on centralized servers, and even governments may collect a “Seigniorage” by over-issuing money. Bitcoin’s proposed solution is to abandon third-party intermediaries and build a distributed ledger where everyone is at the center of the ledger.

Consider a village where there is only one “chief” in charge of keeping the ledger, and all of the village members’ expenses are registered with the village chief, who is the hub of the ledger system. The system can work well if the village chief is trustworthy; however, if the chief, who is the center of the system, is a thief, it may be difficult for others to detect.

Consider a “decentralized” village in which each member holds an identical ledger. When a member wants to make a change to the ledger, he or she must notify the other members via “broadcast” so that they can confirm the entries and copy them to their own ledgers. The transaction process is not complete until all members have confirmed and updated their ledgers. This is essentially how the Bitcoin network operates.

Distributed Ledger Implementation: Blocks and Blockchain

Bitcoin invented a new type of digital system for recording the transaction of assets known as the distributed ledger. In contrast to centralized recording, where data is stored on centralized servers, the blockchain is a decentralized database, with each node in the network acting as the database’s holder and maintainer.

Bitcoin was the first large-scale application of blockchain, and blockchain is the underlying foundation of Bitcoin.

The Bitcoin system can be divided into three layers: the data Layer, the protocol layer, and the application layer. Let’s start with the “ledger” (data layer) that each Bitcoin system member possesses.

From Merkle Trees to Block “Chains”

A blockchain is essentially a distributed ledger maintained by all nodes in the network, with each node storing the entire blockchain data. The block “chain” stored by a node is an ordered chain of blocks connected together, and the block itself is an unalterable structure of data maintained by the Cryptographic Hash algorithm.

The hash function (SHA-256 and RipeMD160) is a critical cryptographic algorithm in Bitcoin that can convert an arbitrary-length input value into a fixed-length value output with randomness, collision-free features.And it’s difficult to guess the input value for a hash function from its output. A small change in the input can result in a drastically different output. The output of a hash function can be easily derived from the input, but inferring the input from the output requires brute-force enumeration, which takes a significant amount of time and computing power. The repeated use of hash functions simplifies and defines Bitcoin’s data structure.

A Bitcoin block consists of two parts: the block body and the block header. The block body contains all the transaction information on that block, which is hashed several times to form a structure known as a Merkle tree, which makes up the block body. The first transaction message on each of these blocks is also known as the coinbase transaction and is the transaction that generates new bitcoins and rewards them to the miner, while all other transactions are transfers between users to each other.

These transactions undergo multiple hashing operations to finally arrive at a value called Merkle Hash, which is the sum of all the transaction data. The Merkle Hash, together with Nunce, timestamps, parent block hashes, and other data, constitute the block header, and calculating the hash value of the block header can get the Block Hash of this block. Since the block header of each block contains the hash value of the parent block, all blocks are connected into a chain. The blocks are interlocked, and any change to the block data will result in a change to the block hash, which will break the chain.

Proof-of-Work(PoW): the Consensus Mechanism for Network Security

After introducing the “ledger” (data layer) held by each node, let’s move on to the Bitcoin consensus layer, which is responsible for network security.

Before delving into distributed consensus, it is critical to understand the “Byzantine Generals” problem.

Byzantine Generals: A multi-message synchronization problem

The Byzantine Generals problem dates back to the medieval period when the Byzantine army relied on messengers to transmit information due to Byzantium’s vast territory. If a traitor deliberately misrepresented the operational information of the higher-ups, it would lead to inconsistent operational plans, resulting in the “Byzantine Generals Problem”.

The Bitcoin network consists of a number of decentralized nodes, each of which is an independent, autonomous, and equal “corps”. Every node in the network has its own unique copy of the blockchain data, and they all want to be the first to package transactions and earn the bitcoin rewards. So, which node will be successful in gaining the ledger rights and convincing the entire network to reach a consensus to modify the blockchain data?

Proof-of-Work(PoW): Calculate the answer and publish it to the network for real-time verification

Bitcoin’s answer is the Proof-of-Work (PoW) consensus mechanism, commonly known as “mining”, which is a digital computing process performed by nodes, where the first node to find the “answer” gets the ledger rights. Specifically, the node needs to keep trying to change the Nunce of the block header, calculating the block hash, and finally get a block hash where the first few bits are zero.

At this point, the Nunce value is the answer to the question. After finding the answer, the node will broadcast it to other network nodes, and after verifying the answer, the other nodes will quickly take the block as the new parent node and continue the next round of mining operations.

That presents a problem in that the data take time to broadcast between nodes, and it is entirely possible that two or more nodes discovered the answer to the puzzle at the same time before the community as a whole come to an agreement. However, because two nodes pack different coinbase transactions, this results in two distinct valid blocks. Because of the different signaling sequences, miner nodes will operate on both forks chain. At this point, the Bitcoin network will follow the “longest chain rule,” treating the fork chain with the most blocks as the only recognized blockchain. This fork competition is typically completed in less than 6 blocks, and all transactions on the other abandoned chain are voided.

The essence of Bitcoin: UXTO model

Bitcoin nodes can synchronize updates to the distributed ledger by mining and the longest chain rule to reach consensus. This consensus-based distributed ledger also makes peer-to-peer digital currencies like Bitcoin possible.

Traditional electronic currencies use a centralized account system where accounts are created for each user on a central server, and balance data is stored for all accounts. After each transaction, the account balance is increased or decreased in chronological order. Bitcoin, on the other hand, uses a UXTO model, which represents the output of unspent transactions.

Asymmetric cryptography is used to secure bitcoin transactions. Each Bitcoin user must have a pair of public and private keys, similar to a account and password. The user must sign the transaction data with the private key, and publish the transaction data, signature, and public key together. However, in each transaction, the user does not transfer the account balance directly but uses the “unspent amount” of the multiple previous transactions, i.e. UTXO.

In the Bitcoin system, there is no concept of an account or account balance, only the UTXO of all transactions in the historical record. Bitcoin wallets can scan the data of all previous transactions and calculate the total UTXO of a specific address (i.e., public key) to determine the account balance. Furthermore, when a transaction is initiated, bitcoin wallets can automatically match the UTXO with the correct balance to complete the transfer.

Highlights

  • Bitcoin is based on block technology. The blockchain is a decentralized database used to create a distributed ledger, so no third-party trust is required and each node in the network acts as a data maintainer.
  • Bitcoin uses the SHA256 algorithm to generate hashes and store data in block headers and block bodies. It becomes a structure made up of individual blocks chained together, and because the data is unalterable, it is extremely secure.
  • Bitcoin’s consensus mechanism is Proof-of-Work(PoW), which is a mechanism that allows nodes to spend arithmetic power to solve a puzzle and then synchronize the transaction to other nodes for the block reward.
Clause de non-responsabilité
* Les investissements en cryptomonnaies comportent des risques importants. Veuillez faire preuve de prudence. Le cours n'est pas destiné à fournir des conseils en investissement.
* Ce cours a été créé par l'auteur qui a rejoint Gate Learn. Toute opinion partagée par l'auteur ne représente pas Gate Learn.
Catalogue
Leçon 2

How Bitcoin Works

Bitcoin is based on blockchain technology, which is a publicly distributed ledger that uses a PoW consensus mechanism to maintain network security.

The birth of bitcoin and blockchain involves two long-standing problems in digital currency: the Double-Spending Problem and the Byzantine Generals Problem

From Physical to Digital Currency: Solving the Double-Spending Problem

Compared with the physical currency in daily life, the biggest difficulty in developing electronic cash is how to overcome the “trust problem”. The reason why the earliest shells and precious metals can be used as general equivalents is that they have a certain scarcity, and the later physical banknotes rely on the credibility of the state to solve the trust problem.

These physical currencies had value and were able to complete the transfer of value instantly. In the digital era, any content is essentially a combination of 0 and 1 codes, and digital money can be copied into two copies and released to two different recipients at the same time, which is the so-called “double spending problem”. The Internet itself does not have the ability to represent value, so people previously had to use a centralized account system with a centralized server, such as a bank, in order to use credit cards and other types of electronic money.

A system that does not require trust: Distributed Ledger

But whether there is a truly trusted third party is a question. There is a risk of single point of failures, such as attacks on centralized servers, and even governments may collect a “Seigniorage” by over-issuing money. Bitcoin’s proposed solution is to abandon third-party intermediaries and build a distributed ledger where everyone is at the center of the ledger.

Consider a village where there is only one “chief” in charge of keeping the ledger, and all of the village members’ expenses are registered with the village chief, who is the hub of the ledger system. The system can work well if the village chief is trustworthy; however, if the chief, who is the center of the system, is a thief, it may be difficult for others to detect.

Consider a “decentralized” village in which each member holds an identical ledger. When a member wants to make a change to the ledger, he or she must notify the other members via “broadcast” so that they can confirm the entries and copy them to their own ledgers. The transaction process is not complete until all members have confirmed and updated their ledgers. This is essentially how the Bitcoin network operates.

Distributed Ledger Implementation: Blocks and Blockchain

Bitcoin invented a new type of digital system for recording the transaction of assets known as the distributed ledger. In contrast to centralized recording, where data is stored on centralized servers, the blockchain is a decentralized database, with each node in the network acting as the database’s holder and maintainer.

Bitcoin was the first large-scale application of blockchain, and blockchain is the underlying foundation of Bitcoin.

The Bitcoin system can be divided into three layers: the data Layer, the protocol layer, and the application layer. Let’s start with the “ledger” (data layer) that each Bitcoin system member possesses.

From Merkle Trees to Block “Chains”

A blockchain is essentially a distributed ledger maintained by all nodes in the network, with each node storing the entire blockchain data. The block “chain” stored by a node is an ordered chain of blocks connected together, and the block itself is an unalterable structure of data maintained by the Cryptographic Hash algorithm.

The hash function (SHA-256 and RipeMD160) is a critical cryptographic algorithm in Bitcoin that can convert an arbitrary-length input value into a fixed-length value output with randomness, collision-free features.And it’s difficult to guess the input value for a hash function from its output. A small change in the input can result in a drastically different output. The output of a hash function can be easily derived from the input, but inferring the input from the output requires brute-force enumeration, which takes a significant amount of time and computing power. The repeated use of hash functions simplifies and defines Bitcoin’s data structure.

A Bitcoin block consists of two parts: the block body and the block header. The block body contains all the transaction information on that block, which is hashed several times to form a structure known as a Merkle tree, which makes up the block body. The first transaction message on each of these blocks is also known as the coinbase transaction and is the transaction that generates new bitcoins and rewards them to the miner, while all other transactions are transfers between users to each other.

These transactions undergo multiple hashing operations to finally arrive at a value called Merkle Hash, which is the sum of all the transaction data. The Merkle Hash, together with Nunce, timestamps, parent block hashes, and other data, constitute the block header, and calculating the hash value of the block header can get the Block Hash of this block. Since the block header of each block contains the hash value of the parent block, all blocks are connected into a chain. The blocks are interlocked, and any change to the block data will result in a change to the block hash, which will break the chain.

Proof-of-Work(PoW): the Consensus Mechanism for Network Security

After introducing the “ledger” (data layer) held by each node, let’s move on to the Bitcoin consensus layer, which is responsible for network security.

Before delving into distributed consensus, it is critical to understand the “Byzantine Generals” problem.

Byzantine Generals: A multi-message synchronization problem

The Byzantine Generals problem dates back to the medieval period when the Byzantine army relied on messengers to transmit information due to Byzantium’s vast territory. If a traitor deliberately misrepresented the operational information of the higher-ups, it would lead to inconsistent operational plans, resulting in the “Byzantine Generals Problem”.

The Bitcoin network consists of a number of decentralized nodes, each of which is an independent, autonomous, and equal “corps”. Every node in the network has its own unique copy of the blockchain data, and they all want to be the first to package transactions and earn the bitcoin rewards. So, which node will be successful in gaining the ledger rights and convincing the entire network to reach a consensus to modify the blockchain data?

Proof-of-Work(PoW): Calculate the answer and publish it to the network for real-time verification

Bitcoin’s answer is the Proof-of-Work (PoW) consensus mechanism, commonly known as “mining”, which is a digital computing process performed by nodes, where the first node to find the “answer” gets the ledger rights. Specifically, the node needs to keep trying to change the Nunce of the block header, calculating the block hash, and finally get a block hash where the first few bits are zero.

At this point, the Nunce value is the answer to the question. After finding the answer, the node will broadcast it to other network nodes, and after verifying the answer, the other nodes will quickly take the block as the new parent node and continue the next round of mining operations.

That presents a problem in that the data take time to broadcast between nodes, and it is entirely possible that two or more nodes discovered the answer to the puzzle at the same time before the community as a whole come to an agreement. However, because two nodes pack different coinbase transactions, this results in two distinct valid blocks. Because of the different signaling sequences, miner nodes will operate on both forks chain. At this point, the Bitcoin network will follow the “longest chain rule,” treating the fork chain with the most blocks as the only recognized blockchain. This fork competition is typically completed in less than 6 blocks, and all transactions on the other abandoned chain are voided.

The essence of Bitcoin: UXTO model

Bitcoin nodes can synchronize updates to the distributed ledger by mining and the longest chain rule to reach consensus. This consensus-based distributed ledger also makes peer-to-peer digital currencies like Bitcoin possible.

Traditional electronic currencies use a centralized account system where accounts are created for each user on a central server, and balance data is stored for all accounts. After each transaction, the account balance is increased or decreased in chronological order. Bitcoin, on the other hand, uses a UXTO model, which represents the output of unspent transactions.

Asymmetric cryptography is used to secure bitcoin transactions. Each Bitcoin user must have a pair of public and private keys, similar to a account and password. The user must sign the transaction data with the private key, and publish the transaction data, signature, and public key together. However, in each transaction, the user does not transfer the account balance directly but uses the “unspent amount” of the multiple previous transactions, i.e. UTXO.

In the Bitcoin system, there is no concept of an account or account balance, only the UTXO of all transactions in the historical record. Bitcoin wallets can scan the data of all previous transactions and calculate the total UTXO of a specific address (i.e., public key) to determine the account balance. Furthermore, when a transaction is initiated, bitcoin wallets can automatically match the UTXO with the correct balance to complete the transfer.

Highlights

  • Bitcoin is based on block technology. The blockchain is a decentralized database used to create a distributed ledger, so no third-party trust is required and each node in the network acts as a data maintainer.
  • Bitcoin uses the SHA256 algorithm to generate hashes and store data in block headers and block bodies. It becomes a structure made up of individual blocks chained together, and because the data is unalterable, it is extremely secure.
  • Bitcoin’s consensus mechanism is Proof-of-Work(PoW), which is a mechanism that allows nodes to spend arithmetic power to solve a puzzle and then synchronize the transaction to other nodes for the block reward.
Clause de non-responsabilité
* Les investissements en cryptomonnaies comportent des risques importants. Veuillez faire preuve de prudence. Le cours n'est pas destiné à fournir des conseils en investissement.
* Ce cours a été créé par l'auteur qui a rejoint Gate Learn. Toute opinion partagée par l'auteur ne représente pas Gate Learn.