A few basic questions about getting started with blockchain

foreword

When we mention the blockchain, many people know that it is something related to finance, that is, money. Rather than saying blockchain, the word we often use should be blockchain technology. This statement actually reveals Its essence-technology. What is another noun associated with blockchain? That, of course, is the famous Bitcoin (BitCoin).

bitcoin

Bitcoin, you can think of it as an electronic currency, its appearance is definitely not accidental, but it is the necessity of historical development. In Satoshi Nakamoto’s paper (see attachment), the causes and consequences of the emergence of Bitcoin are roughly described as follows (the translation may be wrong)

In the physical world, currency is issued by the central banks of various countries. This is a centralized issuance mechanism. To put it bluntly, it is vulnerable to the control
of a centralized organization.
Etc.) Undertake the circulation of currency
Physical currency: people directly hand over cash to another person
. Of course, people directly trade and circulate currency. This method is of course safe (unless counterfeit banknotes are encountered, this is not discussed here. Ha)
So, is there anything wrong with having a trusted third party as an intermediary for money transfers? I think Alipay is usually used well. In Satoshi Nakamoto’s paper, he said:

A centralized third party cannot fully guarantee a credible
centralized third party. All transactions and user balances are stored in a centralized database, which cannot fully guarantee that transactions cannot be changed (because only one person knows, you change Already, who do I talk to?)
In the process of person-to-person transactions, the third party, as an intermediary, also needs to bear risks. If two people in the transaction argue, do you think I will be bored as a guarantor? Loss, this will increase the cost of this kind of transaction virtually, and may even make many people give up this kind of transaction. The
centralized third party is not a welfare organization. Why should they manage the books for you and argue with you? Woolen cloth? Isn't there a service charge?
Then, Satoshi Nakamoto imagined that in the process of electronic transactions, could this third party be given away in some way, like the advanced transactions in the physical world, where user A directly transfers the currency to user B’s account? in the wallet?

Ever since, Bitcoin has just entered the stage of history. . .

blockchain

After reading the above, I believe that you already have a general understanding of what Bitcoin is used for. In Satoshi Nakamoto’s paper, Bitcoin is a peer-to-peer electronic cash system, so as a currency corresponding to banknotes in the physical world What problems need to be solved for electronic cash?

The issuance of currency, first of all, has a certain mechanism to ensure that these currencies can be issued normally, just like the central bank’s issuance of soft sister coins. However, it’s not like the central bank’s issue of soft sister coins. I can send as much as I want. It will be over sooner or later. I won’t list many bloody examples of currency transfer. Bitcoin is an electronic cash system
. There must be a mechanism to ensure that the currency can be circulated between users, and this kind of circulation can no longer be intervened by a third party.
Transactions, balances, etc., I have to have a mechanism to store the transactions between people For transaction information, I still need to record how much money a person has left. Moreover, this process cannot be done by a centralized organization as mentioned above. It can be regarded as the realization of the
electronic cash system of Bitcoin. Among the key issues that must be solved, how to solve these problems? That's where today's protagonist - blockchain technology comes into play. The general meaning is: what is the blockchain, an electronic currency like bitcoin, and the underlying technology that guarantees the function of bitcoin!

Blockchain Secrets Revealed

throw bricks and start jade

Next, let's tell a story to draw out the key issues of blockchain technology.

story one

It was a sunny morning, and Shi Jin went to work happily as usual. As soon as he arrived at the company, Cheng Xiao told him that the boss thought you were very good, and just said that he would give you a promotion and salary increase. Hearing this, he thought he must have lied to me, so he didn't take it seriously. Unexpectedly, Brother Sheng came again after a while, and said the same thing as Cheng Xiao, Shi Jin's heart began to beat. Is this true? After a while, Li Chen also said the same thing to him, Zimo, and Han Yu too, this is a big deal, Shi Jin began to believe it, it has to be believed, after all so many people have said it, it must be Really!

story two

It was a sunny morning, and Shi Jin went to work happily as usual. As soon as he arrived at the company, Teacher Ma told Shi Jin that the company decided to give you a promotion and salary increase, and Shi Jin immediately believed it.

Through the above two stories, you can see that there are actually two ways to convince users of one thing. One is that many people in Story 1 say it is true, and the other is that there is an authoritative This is true for third parties. The blockchain technology formally uses the idea of ​​story 1 to realize the guarantee of the validity of the transaction.

Summarize

This is the most important idea of ​​blockchain technology - decentralization

Of course, this decentralization includes two meanings. The first is the decentralization of currency issuance; the other is the decentralization of currency transfer (circulation). It means that the issuance of currency is no longer controlled by a centralized institution like the central bank, but is determined by the entire system. As for the factors that determine the issuance of currency, we will talk about it later; at the same time, the circulation of currency among users De-centralization is also required. Users transfer currency directly to another user without the need for a third party to guarantee the bookkeeping. Instead, all participating users will jointly guarantee that everyone will witness the transaction together to ensure the validity of the transaction. .

fascinating

Let's take the transfer (transaction) of Bitcoin between users as an example to introduce various magical mechanisms of the blockchain.

broadcast transaction information
insert image description here

After receiving the transaction information, the people who eat melons take out their own notebooks and write down the transaction of A and B. Once the record is successful, it is irrevocable and cannot be changed.

insert image description here

Focus on it!!!

Why do people who eat melons keep accounts for others? This leads to miner mining, which is also the issuance mechanism of Bitcoin. That is to say, the system will give corresponding rewards to users who keep accounts.
There are so many people who eat melons, and everyone keeps accounts with a small book, so who should take the final account book? Therefore, there must be a mechanism that allows everyone to agree on the validity of the final bookkeeping results. This is the consensus mechanism adopted by Bitcoin-the consensus mechanism based on proof of work. Readers, keep your notebooks in mind
. ?

Continuing, under the protection of the consensus mechanism, the people who have obtained the final bookkeeping rights will broadcast the transaction information of this transaction to the entire network, and other people will check and confirm the transaction, and the transaction will be recorded when it reaches more than 6 confirmations. (What? Why 6?)

When the melon eaters record the transaction information, they will stamp the time stamp (Hash value) to form a complete time chain. This time stamp is actually a proof of existence, indicating that the transaction has indeed happened every time it is confirmed
. Transaction records will form a block (Block)
and blocks will be linked by a magical algorithm
insert image description here

talk eloquently

Well, after going through the above operations, I believe that you all have a perceptual understanding of the basic concepts of Bitcoin, blockchain, and general processes (well. I seem to know the area What is the block chain!) Let's summarize the key ideas and technologies of the block chain in depth!

decentralized

In the Bitcoin network, there is no centralized server. The entire network is composed of various nodes, which together form a decentralized network
of decentralized currency issuance. In the Bitcoin network, currency issuance is "miners digging Mine" is guaranteed by this mechanism, and this mechanism is a completely decentralized mechanism. The
transaction circulation of currency is decentralized. Every transaction of Bitcoin is jointly guaranteed by all nodes in the network. sex and immutability

openness

The transaction information of all Bitcoin users is recorded in a distributed ledger. This ledger information is open to all users, and anyone can download the ledger information. The Bitcoin network is open, and any server can be connected to the network
. You can also download the full amount of ledger information

Immutable

Each transaction information is stored in a block, and each newly generated block is linked together in the order of time (Hash value). The irreversibility of time causes any operation that attempts to modify block information to be
Every newly generated block that can be traced back is encrypted with the volume hash algorithm. The factors involved in the hash include not only the information of this transaction, but also the hash value of the previous block. In this way , , if the information of a certain block is modified, the information of all blocks needs to be changed, and it is almost impossible to falsify

related technology

The figure below is a display of a real block. The fields in the block that we will focus on this time are:

Bits
Nonce
Hash
Previous Block
Merkle Root
insert image description here

consensus mechanism

http://c.biancheng.net/view/1897.html

Blockchain technology solves the problem of value representation and value transmission in a decentralized network, and how to reach consensus on data in this distributed decentralized network is a very critical issue. In our daily life, almost everything is a process of consensus. And this is precisely one of the core breakthroughs of Bitcoin, namely: how to reach a consensus on a certain transaction event in a decentralized environment.

The two cores of the consensus mechanism

Economic incentives: Reward participants by generating a certain amount of new bitcoins in each block.
Introduce external resources to ensure security: that is, through a large number of external calculations to ensure the security of consensus, that is, Proof of Work

The main process of reaching consensus (the process of generating new blocks)

Listening: The node monitors the transaction information of the whole network, and the verified transaction will enter the memory pool of the node
Construction: Build an empty block, called the candidate block
Transaction: Package the transaction from the memory pool to the candidate block
Head: Construction Block header, fill in the following fields of the block header
Version number version field: Indicates the verification rules complied with by this block
Parent block hash value Previous Block
uses the merkle tree to summarize all transactions, and fills in the hash value of the merkle root to the merkle root Field
Timestamp timestamp field
Fill in the target value Bits field
Operation: Constantly adjust the random number Nonce, and perform Hash calculation, so that the calculated Hash value meets certain requirements, namely: less than the target Hash. (OR: The binary representation of the calculated Hash value has a certain number of leading 0s)
Because when comparing binary numbers, the comparison is actually the preceding 0s, and whoever has more 0s will be smaller
. Broadcast (gossip protocol) new block
verification: After other nodes pass the verification, link (Previous Block) to the main chain (is there a side chain? Well...)
Wait: wait for the main chain to link 5 new blocks ( That is, after 5+1 blocks), the block will officially take effect and cannot be tampered with.
This process of reaching consensus is called the consensus mechanism based on workload proof. Here are a few points to explain:

How to understand the workload?

Constantly adjusting random numbers to perform SHA-256 calculation competition is computer computing power. This calculation based on computing power is a kind of workload. Why can the
calculated Hash value be smaller than the target Hash to reflect the workload?
The number of points thrown by the dice is <= 6, and it needs to be rolled once on average, and the workload can be quantified as 1; what about the required number of points thrown <= 3? An average of 2 throws is required, doubling the workload. When the target value is very small, is it very large to make the calculated Hash value smaller than the target value
With the increase of computer computing power, how to control the difficulty of calculation?
The target Hash value composed of 256-bit binary numbers, if one bit is changed arbitrarily, the difficulty will be doubled. Therefore, the difficulty can be adjusted by adjusting the target Hash value

Hash calculation


Generally, a SHA-256 operation is used, and the Hash value output by the calculation is composed of a 256-bit binary number. For the convenience of expression, it is expressed in hexadecimal, so it is 256/4=64 bits of hexadecimal input. Changes will cause huge changes in output, and there is no law at all.

Bits and target hash value

Bits correspond to the difficulty. It uses a 32-bit integer to compress and store the current 256-bit target Hash value.

Target Hash value: 0x00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
Bits: 0x1D00FFFF
How to compress it? The rules are:

The effective number of digits of the target Hash value = (64-8) + 2 = 58 (that is, 29 bytes), then the highest byte of the Bits field = 29, and the hexadecimal representation is 0x1D + 2
because of the target Hash value The highest bit 0xFF (1111 1111) > 0x80 (1000 0000) The
remaining 3 bytes of Bits, take the highest 3 bytes of the Hash value to store

Merkle Root

The Merkle tree is used in Bitcoin to store transaction information in each block.

insert image description here

Use the Merkle tree to summarize all transaction information, and put the summarized Merkle Root in the block header. The benefits of this are obvious:

All transactions participate in Hash calculation until they are aggregated to Merkle Root. If someone tampers with some data blocks at the bottom of the Merkle tree, it will cause the hash pointer of the upper layer to not match, then he has to tamper with the hash pointer of the upper layer until the top of the number, and at this moment, tampering It is about to be terminated, because we store the hash pointer of the root node of the tree, so that the transaction information can be prevented from being tampered
. Users only need to download very small block header data to verify the authenticity of a transaction
According to the longest chain principle, pull all the block headers to the local
to calculate the tx_hash value of the transaction to be verified
Find the block header with tx_hash
to find this area Some key nodes of the Merkle Tree in the block, and build a Merkle-Tree-Copy according to the construction rules to
compare whether the Root of the Merkle-Tree-Copy is the same as the Root in the block
, as long as we remember the root node of the first tree Hash pointer , we can go back to any position in the table according to the hash
pointer
The block will officially take effect, mainly to solve the "double spending" problem. So what is the "double spending" problem? Here, let's sort out a few concepts related to this:

51% computing power attack
Double spending problem
3.1.6.1 51% computing power attack
In the consensus mechanism based on proof of work, nodes in the network compete with computer computing power to perform complex Hash operations, and the node that first calculates the result generates Blocks will be accepted by the entire network and linked to the blockchain, called new blocks. Then, when a person or organization has mastered 51% of the computing power of the entire network, they can forge transactions according to "whatever they want".

double spending problem

Assuming that Xiaohei has 666 BTC, he pays Dabai with these coins and at the same time sends these coins to another wallet address of his own.

In the end, the transaction sent to Dabai was confirmed first and packaged in a block with a block height of N.

At this time, Xiao Hei, who controlled more than 50% of the computing power, launched a 51% computing power attack. By reassembling the Nth block, he packaged the transaction sent to himself into the block, and continued in this chain. Due to the advantages of computing power, this amount will be called the legal longest chain. (The user only recognizes the longest chain he sees - the longest chain principle)

At this time, the transaction transferred to Dabai was tampered with.

how to avoid

In order to avoid losses caused by double spending, it is generally believed that Bitcoin transactions after 6 blocks are confirmed cannot be tampered with.
insert image description here

Generally speaking, the more confirmed blocks, the more secure, and the lower the possibility of transactions being tampered with.

In order to achieve double spending, it is actually a process in which malicious nodes and safe nodes compete with each other for mining. When the malicious chain formed by the malicious node is longer than the trusted chain formed by the safe node, the malicious node can realize double spending. Here, an assumption is made, that is, assuming that the malicious nodes account for the computing power of the entire network to be p, then the safe node is q=1-p, after passing the nth block, the probability of the malicious chain catching up with the trusted chain for:

(pq)n ( pq ) n
Then, when the trusted node generates n blocks, how many blocks does the malicious node generate?

Here, Satoshi Nakamoto assumes that the number of blocks generated by malicious nodes obeys a Poisson distribution:

P(X=k)=(λkk!)e−λ P ( X = k ) = ( λ kk ! ) e − λ This formula means
: the probability of a malicious node generating k blocks is: P(X=k)

Therefore, we can find out the expected value of malicious nodes generating blocks after trusted nodes generate n blocks.

∑∞k=0(λkk!)e−λ(pq)n−k ∑ k = 0 ∞ ( λ kk ! ) e − λ ( pq ) n − k Sum up this sequence, when N=6, p
= At 10%, sum=0.0002.

Indicates: when the trusted node generates 6 blocks, the expected value of the number of blocks generated by the malicious node is 0.0002

That is to say, under the conditions of the above assumptions, after the confirmation of 6 blocks, the possibility of malicious node fraud is almost zero.

Guess you like

Origin blog.csdn.net/jgku/article/details/128360418