Principles of Bitcoin Technology

Table of contents

The Rise of Bitcoin

1. Barter

2. Physical currency

3. Symbol currency

4. Central system virtual currency

5. Distributed virtual currency

Bitcoin principle

Three core issues

Question 1 - Necessity of Bookkeeping

Question 2 - Who shall prevail

Question 3 - How to prevent counterfeiting

RSA algorithm

digital signature

Pros and Cons of Bitcoin

advantage:

shortcoming

reference link

PPT:

Introduction to Bitcoin Technology PPT (xinanzhijia.xyz.)

The Rise of Bitcoin

The rise of Bitcoin originated from a geek paper on November 1, 2008, and the author has not disclosed his identity so far. The paper proposes the concept of a decentralized currency - Bitcoin.

This idea was considered crazy in the context of the financial crisis at that time, but with the support of countless enthusiasts and insightful people, it has now become a reality. Not only has the transaction of Bitcoin exploded, but it has also inspired the birth of thousands of virtual currencies:

So why do we want to decentralize? This has to start from the beginning.

1. Barter

A long time ago in the countryside, people lived a life of bartering.

2. Physical currency

Due to the problem of mutual disagreement of value, we uniformly set prices and use some rare and easily divisible things as currency for transactions, such as gold or shells.

3. Symbol currency

At present, there is still a problem, the currency itself is inconvenient to carry, there are many problems such as wear and tear, and collecting currency, such as alchemy, collecting shells, etc., consumes a lot of financial and material resources. At this time, someone proposed a solution. It is not necessary for us to trade with real gold. We can find reliable institutions (such as village committees) to issue some banknotes with "one gram of gold" on them. There are special anti-counterfeiting marks on the banknotes. Everyone Transactions with paper money.

4. Central system virtual currency

The problem just now is obviously a temporary solution, not the root cause. Greedy human beings feel that it is too troublesome to carry banknotes for transactions, so someone has proposed an improvement method. We don't have to actually carry currency transactions. For example, find a reliable agency at the moment, count the balance of all villagers, and report transactions directly to this reliable agency in the future. This reliable institution is responsible for recording every transaction and calculating everyone's balance, and everyone trusts this "reliable institution".

5. Distributed virtual currency

However, the good times didn't last long. The "reliable institution" that everyone trusted had corruption problems, which led to the collapse of the entire central system virtual currency system. However, people have completely become accustomed to the life mode of not carrying cash transactions. What should we do... …

At this time, the geek Satoshi Nakamoto made his debut.

Bitcoin principle

We simulate a transaction, which can be abstracted into the form of the following ledger:

payer Payment amount Beneficiary ... (validation field)
Alice 10BTC Bob
Bob 5BTC Cici
Cici 2BTC David

Everyone keeps accounts, and we use blocks to store transaction records. Each block has a size of 1M and can store about 4000 transaction records. Connecting this block to previous blocks forms a blockchain.

  • Pre Hash: The hash value of the previous block.

  • Nonce: The value that makes the hash value of the block meet the requirements, that is, the result of mining calculations.

  • Transaction Data: Transaction data in the block.

Three core issues

  • Why keep accounts?

  • Who shall prevail? (network delay)

  • How to prevent counterfeiting?

Question 1 - Necessity of Bookkeeping

Why keep accounts? Because there are rewards for bookkeeping. The ultimate source of all bitcoins is bookkeeping, that is, mining. And there is a certain amount of handling fees for recording transactions (much smaller than the current bank handling fees). The Bitcoin transaction system expects to package a transaction block every 10 minutes. After the Genesis block appeared in 2008, 50 bitcoins can be obtained for each packaged block, and then halved every 4 years. So it works out:

50 \times 6 \times 24 \times 365 \times 4 \times(1+\frac{1}{2}+...+\frac{1}{2^n}) \approx 2100w

Bitcoin will eventually issue 21 million.

Question 2 - Who shall prevail

To explain this problem clearly, we have to understand the principle of mining. First introduce a function like this: sha256(), using the link

Hash function

sha256()It is a hash algorithm that can convert any string into a 256bit hash value. The algorithm has the following key features:

1. Irreversibility

The hash function is irreversible, and the specific irreversibility can be compared to:

y=x^8+log_6x+sin(x)+cot(x)

Given an x, one can easily compute y; but given y to invert x, it would be a disaster.

2. Small changes, big changes

import hashlib
​
message = "Hello, world!" # 待计算哈希值的消息
message2 = "Hello, w0rld!"
hash_object = hashlib.sha256(message.encode('utf-8'))
# 获取哈希值(以16进制表示)
hex_dig = hash_object.hexdigest()
​
print(hex_dig)  # b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
print(hex_dig2) # 3FBE0E7AA29A4A4071A2DD78E2A02AD6209D23CEC2F861BE75D24B72462D911B

It can be seen that a slight change in the input will cause a huge change in the hash value.

3. Collision resistance

In the case of a well-designed hash function, the probability that two different values ​​will produce the same hash value after calculation is very small.

mining process

Miners first obtain transaction records, and start to calculate a string after the records reach a certain number. This string consists of: block header + bill + start time + random number.

Then, calculate Hash=sha256(sha256(string)), however, the calculated result Hash must be 0 in the first n digits to be considered successful.

Since the first three parts of the string cannot be changed arbitrarily, and the hash function cannot be reversed, we can only repeatedly test the random number until we calculate a string that satisfies the first n digits are all 0, then we consider mining successful. Since the hash value is affected by the first three items, mining is related to luck to a certain extent, but more importantly, it relies on computing power to find the corresponding random number.

Similarly, it is not difficult to see that the larger the value of n, the harder it is to mine. In order to ensure that miners can pack a block in 10 minutes, but the packing process is not so easy, currently set n=66

The overall Bitcoin mining flow chart is as follows:

In summary, we can conclude that all transactions are based on the blocks packaged by miners.

Question 3 - How to prevent counterfeiting

Anti-counterfeiting is based on asymmetrically encrypted digital signatures. The most common asymmetric encryption is the RSA algorithm.

RSA algorithm

 The encryption and decryption process of the algorithm is as follows:

  1. Choose a pair of unequal large prime numbers, denoted as p, q

  2. calculateN = p \times q

  3. calculate\phi(N) = (p-1)\times(q-1)

  4. Choose an \phi(N)integer e that is relatively prime to

  5. Calculate the inverse element d of e for φ(N)

  6. Public key KU = (e,N), private key KR = (d,N) Note that the brackets are not the greatest common divisor, but expressions.

Example questions are as follows:

  1. Take p=3, q=11;

  2. N=p \times q = 33

  3. \phi(N) = (p-1)(q-1) = 20

  4. Choose a number that is relatively prime to \phi(N), we choose e=3

  5. Find a d such that ed \equiv 1 \mod \phi(N), the solution isd \equiv 7 \mod 20

  6. Public key KU = (e,n) = (3,33) , private key KR = (d,n) = (7,33)

If the plaintext M=20, the encryption is 20^3 \mod 33 = 14, and the decryption is14^7 \mod 33 = 20

digital signature

The operation process of digital signature in Bitcoin transaction process is as follows:

First, A registers a Bitcoin account and obtains his own public-private key pair. A hashes his own transaction information to obtain a summary, and encrypts the summary with his own key to obtain a ciphertext.

After that, A broadcasts a set of information to the Internet, asking everyone to authenticate the message: transaction information + own public key + encrypted ciphertext.

Other users first perform Hash operation on the transaction information to obtain summary 1, and then use A's public key to decrypt the ciphertext to obtain the decrypted plaintext summary 2. If digest 1 and digest 2 are the same, the transaction is true. Because if we want to forge a broadcast message, we cannot create a ciphertext, so that the result of his decryption is a fake transaction message, because the hash function cannot be reversed; the same reason, this message can only be sent by A Yes, because only A has his own private key to create this ciphertext.

Pros and Cons of Bitcoin

advantage:

  1. Decentralization: Bitcoin is not regulated by any central agency or government, and transactions are maintained and verified by nodes in the network.

  2. Protection of privacy: Bitcoin uses public key encryption technology to protect user information and privacy.

  3. Traceability: All Bitcoin transactions are recorded on the blockchain, and their transaction history can be traced.

  4. Low inflation rate: The total amount of Bitcoin is limited to about 21 million, so the inflation rate is very low and has a certain value preservation function.

shortcoming

  1. Security issues: The risk of bitcoin being stolen, lost or hacked still exists, and users need to keep their own bitcoin private key.

  2. Limited transaction speed: Bitcoin transactions need to be packaged into blocks and wait for 6 blocks to ensure that the transaction is successful. 4,000 transaction records are packaged every 10 minutes, and only about 7 transactions can be completed per second. At present, in order to solve this problem, Bitcoin has launched a new protocol, hoping to change the block from 1M to 8M, and the protocol is still being promoted.

reference link

CodingLabs - A story tells you how Bitcoin works and how it works

https://coinmarketcap.com/zh/rankings/exchanges/

https://assets.pubpub.org/d8wct41f/31611263538139.pdf

<iframe src="//player.bilibili.com/player.html?aid=45247943&bvid=BV1Bb411B7dq&cid=79224469&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
<iframe src="//player.bilibili.com/player.html?aid=45597148&bvid=BV12b411q7ku&cid=79839195&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/bBC-nXj3Ng4" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
<iframe width="560" height="315" src="https://www.youtube.com/embed/BODyqM-V71E" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

Guess you like

Origin blog.csdn.net/qq_52504945/article/details/130330925