Teach you how to easily learn the basic technical principles of blockchain and Bitcoin

Teach you how to easily learn the basic technical principles
of blockchain and


Bitcoin
, Japanese...) published a report called "Bitcoin: A Peer-to-Peer Electronic Cash System" on a covert cryptography discussion group, and Bitcoin appeared and got more and more people's attention.


The price of Bitcoin has risen from the first few cents to the current tens of thousands of dollars. The price has risen sharply and has fallen sharply, but the overall trend of the price is increasing.


Mining has developed over several generations from the personal computer at the beginning to the later mining machine, and then to the later mining pool. The policy has been supported by some countries, and some countries have opposed it, and some countries have an ambiguous attitude towards Bitcoin.


The most interesting thing is that on May 21, 2010, in the first Bitcoin transaction, Florida programmer Laszlo Hanyecz used 10,000 BTC to buy a $25 pizza coupon, which has recently been worth hundreds of millions . All of these have witnessed the magical development history of Bitcoin.


The past and present of the blockchain
Although Bitcoin has not been fully recognized by governments of various countries, nor is it a standard financial organization, the mining activities of Bitcoin have never stopped for more than ten years, and Bitcoin transactions can be carried out anytime, anywhere. In carrying out, without a doubt, a successful financial product, technically, every technical point of Bitcoin.


For example, asymmetric cryptography, P2P network, consensus mechanism, intelligent script, etc. are not innovations, but the combination of these technologies is a big innovation.


Due to the success of Bitcoin, the core technology of Bitcoin, the blockchain, has attracted more and more attention, so that the blockchain is considered to be the next outlet of the Internet financial industry, and all walks of life are studying the blockchain. And looking for usage scenarios for the blockchain, there is an inappropriate example.


But it is very vivid. The blockchain technology is like a hammer, looking for nails all over the world. The few nails I finally found are still screws, but I have to replace them with a screwdriver, but I have to use a hammer to smash them in. It's not impossible, it's just a bit of effort.


The above example vividly illustrates the current status of blockchain technology. For example, some companies use blockchain for storage, some companies use blockchain for customer accounts, and some companies use blockchain for storage. electronic assets.


These are all looking for scenarios for the blockchain. Although the blockchain has not been fully applied, there is no doubt that the blockchain has emerged in the financial field.


Another phenomenon is that many companies claim that their products use blockchain in order to hype new concepts. For example, a certain electronic asset company uses blockchain, and carefully understands the private chain used by others.


This makes people feel unbelievable. The purpose of a private blockchain is to improve performance, but certainly not. The hardest thing about blockchain is performance, which is security. Private security lies in the construction of private products, not whether to use blockchain. So what is the use of private chains for? Readers here can YY by themselves.


In fact, the blockchain is divided into a public chain, a private chain and a consortium chain. The public chain has no restrictions on participating nodes. The entire system runs on the public network without the control of a central organization, free development, and self-organization. The typical case is Bit Coin;


private chain, as the name suggests, is a blockchain system running within an organization. This kind of system runs in an organization, and it is difficult to guarantee decentralization. In an organization, it is a product of centralization. Therefore, I always think that everything Private chains don’t even have the characteristics of decentralization; alliances are the form that the author is most optimistic about.


Why did I write this article
The Bitcoin system is one of the most popular electronic currencies, and there are many altcoins, but the ideas and even the source code are all from Bitcoin. There are many introductory articles in the circle of friends, and some people try to pass Comics to vividly explain the characteristics of Bitcoin.


But I still can't get to the point, and there are always some problems that I can't figure out. In order to figure out these problems, I have recently studied several Bitcoin books and the Bitcoin paper published by Satoshi Nakamoto himself. I hope to discuss and make progress together with everyone.


2. What is the core point of Bitcoin
? Bitcoin is an electronic cash system implemented by peer-to-peer technology, which allows one organization to make online payments directly with another organization without the need for an intermediate authoritative clearing agency.


In the world of bitcoin, if you want to own bitcoin, you need to apply for a bitcoin address, just like when you deposit money in a bank, you need to open an account.


Then, you have this account. With your own account, you can deposit money to your account, and others can also transfer money to your account.


When you need to withdraw money or transfer money to others, you need to show a key that can open this address, which is your private key, just like you need to provide a password when you withdraw money at an ATM.


Unlike legal currency issued by banks, the issuance of legal currency is managed by the central banks of various countries. Everyone believes that the central bank is reliable and will not make mistakes or be attacked.


However, the issuance of Bitcoin does not require an authoritative institution such as the central bank. It allows a transaction to be directly settled from one organization to another, eliminating the need for authoritative institution settlement, improving the efficiency of transactions and settlement, and saving transactions. costs, especially for cross-border transactions.


How does a peer-to-peer online transaction system ensure the anonymity, correctness, and immutability of transactions? And how to prevent double spending and prevent cheating and attacks?


The following chapters will unravel the mystery of Bitcoin through the most common language, let you logically understand how Bitcoin works, let you learn Bitcoin without leaving dead ends, and let all aspects of Bitcoin be clearly presented to you. in mind.


The core points of blockchain technology
This section introduces the core points of blockchain technology, including: blockchain storage, keys and addresses, unlocking scripts, mining processes, consensus mechanisms, P2P networks, etc.
How is the blockchain stored?
For a cash account system, the first thing to solve is how to keep accounts, where to keep accounts, and how to store accounts.


For example, if you make a deposit in the Bank of China, the Bank of China opens an account for you, and your account is stored on the server of the Bank of China. If you make a deposit in the China Construction Bank, the China Construction Bank opens an account for you, and your account is stored in the China Construction Bank. on the bank's server.


If you need to transfer money to other people's accounts in the same bank, you need to transfer and settle for you through this bank, and if you need to transfer money to other people's accounts in other banks, you need to transfer and settle for you through UnionPay.


Although an ordinary user cannot perceive so many processes, these steps do exist. From this process, we can see that the account system for bookkeeping is dedicated, centralized, owned and maintained by a certain organization, usually This organization is authoritative and trustworthy.


Bitcoin does not have a centralized accounting system, but records the ownership and transaction information of Bitcoin through a distributed blockchain.


Each Bitcoin participant has an identical copy of the blockchain. The blockchain contains multiple blocks ordered over time. The latter block points to the previous block through a hash pointer, forming a chain. With this pointer, the top end can be found all the way to the first block at the bottom, the first block becomes the Genesis block.


Each block records the hash value of the previous block, which is actually the hash value of the previous node header. If you want to change the transactions contained in a block, you must change all transactions after this block. .


Since the generation of each block requires conditions and time, and the conditions are quite harsh (will be explained in detail in the articles related to the consensus mechanism later).


Therefore, once a block is generated and accepted by the nodes of the blockchain, and a certain number of blocks are generated after the node, the block is basically immutable.


The schematic diagram of the blockchain is as follows:
 


As can be seen from the above figure, the blockchain is composed of multiple blocks, each block is composed of a block header and a block body, each block header contains the meta information of the block, and at the same time Also contains a pointer to the hash of the previous block header, which is critical information to prevent the blockchain from being tampered with.


The block body contains the transaction information of Bitcoin. The first transaction is a special transaction, which is a reward to the mining node. This is also the only way to generate Bitcoin, that is, the way to issue Bitcoin. The rest Transactions are all transfer transactions, and bitcoins are paid from one address to another, which is the only way to transfer the value of bitcoins.


To sum up, Bitcoin has only two transactions: issuance and transfer. After Bitcoin is created, it can only be transferred from one person to another, and cannot disappear out of thin air. The total amount of Bitcoin issued is limited, a total of 21 million, so it is It is a deflationary currency, and we will introduce the deflationary characteristics of Bitbin in detail in related articles.


How does the owner of Bitcoin prove that he owns Bitcoin?
The previous section introduced the storage of the blockchain. The blockchain is actually the ledger of bitcoins, which records who owns how many bitcoins. However, this ledger is stored on the Internet and distributed, not by a central institutions or servers for storage.


With the ledger, the remaining question is how does the owner of Bitcoin prove that he owns Bitcoin? It's like opening an account with a bank, and when you want to transfer money to someone else, you need to insert your card at the ATM and enter your PIN.


The card is equivalent to the address of Bitcoin, and the password is equivalent to the secret key of Bitcoin. With the correct address and secret key, you can claim your own right to Bitcoin and transfer Bitcoin to others. Make a transfer transaction.


Withdraw a sum of cash at the ATM, enter the password to unlock the account, we believe that the ATM machine will not reveal the password. So in the world of bitcoin, how do we verify the ownership of bitcoins on an address through the private key?


The ownership of Bitcoin is realized through technology in the field of encryption. Let’s first understand the principle of the field of encryption. The field of encryption has generally gone through three stages. The first stage is to spell the algorithm, and write the encryption logic in a very advanced. In the code, it was later discovered that no matter how complicated the logic is written in the code, there are always experts who can crack it.


Therefore, symmetric key encryption is generated. Symmetric key encryption encrypts data through a symmetric key, and then transmits or saves it. When needed, it decrypts and restores the original data through the same key. The disadvantage is that the key is shared. It is not possible to store keys securely, especially in cross-organizational scenarios.


Later, smart security scientists invented asymmetric encryption algorithms, such as: RSA. Asymmetric algorithms have a pair of secret keys, a public key and a private key. The private key can deduce the public key, but the public key cannot deduce the private key. The data encrypted by the public key can be decrypted by the private key, and the data encrypted by the private key can be decrypted by the public key. If organization A passes data to organization B, then organization A uses the public key to encrypt, and organization B uses the private key to decrypt. Therefore, Organization B needs to keep the private key carefully, while the public key is public. This is a typical asymmetric encryption scenario, which can effectively prevent data from being peeped and tampered with.


There is another scenario of asymmetric encryption, that is, signature. Signature is the reverse scenario of the encryption scenario. Merchant B encrypts data with its own private key, and then transmits the encrypted data to merchant A. Merchant A decrypts with the public key. If the data is correct, it means that the data is sent by A, which effectively guarantees the tamper-proof of the data. From these two scenarios, we can see that the public key is public and can be sent to anyone, and the private key is private. to decrypt or sign.


The schematic diagram of bitcoin proof of ownership is as follows:
 


As can be seen from the above figure, in real life, we use the key to open the lock, and we use the password to withdraw cash from the ATM, then in the bitcoin system, we use the secret key to transfer bitcoins , to realize the transfer of value.


More specifically, a Bitcoin transaction locks a certain number of scripts at an address, and the user who claims to own the address will prove that he/she owns the address by signing the key.


Then, spend this bitcoin. After this bitcoin is spent, it will not disappear, but will be locked in other people's addresses. Others can use the same method to spend this bitcoin.


From the above process, we have summarized two actions, locking and unlocking, which correspond to our usual locking and unlocking heads, which are implemented in the Bitcoin system through locking scripts and unlocking scripts.


1. The locking script associates bitcoins with a bitcoin address, proving that bitcoins belong to this address.
2. The unlock script provides proof that this address is owned by me, and this bitcoin is also owned by me, and I can use it to pay.


Let's take an example to explain in detail:


user Alice owns 10 bitcoins at address A in bitcoin, Alice and Bob want to make a transaction, Bob sells his car to Alice, and Alice needs to pay Bob 10 bitcoins Bitcoin, Bob's Bitcoin address is B.


In the previous transaction, the 10 bitcoins owned by Alice were locked on Alice's bitcoin address A. The source may be mining income or transfer from others. We will describe how to obtain bitcoins in detail later. Here we will Just focus on the locking script of the transaction that proves Alice owns the bitcoins.


The logical format of the lock script is:


 




if you want to spend this lock script, the required unlock script is as follows:
 


The specific unlock process is as follows:
1. Use the public key of address A to derive the address and compare it with address A, if it is consistent, it proves that the public key provides Correct, go to the next step.
2. Use the public key of address A to decrypt the signature. If the obtained value is consistent with the hash value of the previous block, it proves that the unlocking is successful and 10 bitcoins on the address can be spent.


In fact, the locking and unlocking scripts are implemented by stack-based scripts in reverse Polish notation. Due to the limited space of this article, I will not introduce them here. The principles and processes of locking and unlocking scripts will be introduced in detail in subsequent articles.
Mining
The previous section introduced Bitcoin's use of the distributed storage blockchain as an accounting system, and also addressed the process of how to claim Bitcoin ownership and pay Bitcoin to others.
Now we have encountered a new problem. Since the blockchain is a distributed accounting system, and each participating node has a copy, who is responsible for recording a transaction to the blockchain?
This has to introduce a new concept, that is, the consensus mechanism. Bitcoin determines the bookkeeping rights through the consensus mechanism of proof of work. Generally speaking, whoever proves that he has the most workload is responsible for bookkeeping.
The schematic diagram of the proof of work is as follows:
 




the size of the work is reflected by calculating the hash value of the Bitcoin block header that meets a certain standard.


The nodes that try to compete for the accounting right are called mining nodes. The mining nodes will verify the transactions sent from the network nodes (the network propagation mechanism will be introduced in the next section). After verification, they will be stored in the buffer to form a certain The transaction storage structure (transactions are stored in the Merkle tree, and various introductions will be asked later), placed in the block body.


The block header is then constructed based on the basic information of the block, which usually contains the hash value of the previous block, the Merkle root (more on this in a later article), a timestamp, a difficulty target, and a padded random value.


The random value here is randomly generated and filled. The mining process is to find a random value that can fill the block header, so that the hash value of the block header meets a certain standard.


For example: the first bits of the hash value are 0, and the difficulty target is the difficulty coefficient used to express the standard of the hash value. The difficulty value and the probability of successful mining can be calculated through a probability algorithm.


Each miner on the network receives and verifies a batch of transactions, and then starts mining. View calculates the hash value of the block header that satisfies a certain difficulty value. If the calculation is successful, the mining is successful. After the network broadcasts the mining income, after the whole network node is verified, the block is connected to the top of the block, and an agreement is reached in the whole network.


The mining machine needs to repeatedly test the random filling value to solve the problem. Generally, the random number is generated, and the generated random number is tried to be filled into the block header.


Then calculate the hash, and the follow-up article will introduce the mining machine alliance. The mining machine alliance will divide the random number into multiple small sections and assign them to the members of the alliance to solve together.


In addition to the proof-of-work mechanism introduced above, there are also proof-of-stake, share-based proof-of-stake consensus mechanisms, etc., which I will share with you in a special article on consensus mechanisms.


P2P Network
The previous two sections introduced the account system and accounting mechanism of Bitcoin. In this section, we discuss how Bitcoin's distributed blockchain ledger is transmitted on the network, and how transactions are transmitted and verified on the network.
Nodes in the Bitcoin network are all peer-to-peer, and there is no centralized server. There are different types of nodes, and different types have different responsibilities. We will introduce them in detail in future articles. Here we only introduce full nodes. This is how the Bitcoin Core client works.


In addition to storing the complete blockchain, the full nodes in Bitcoin also have the roles of miners, wallets, routing nodes, etc. Their responsibilities are as follows:


1. Miners: Just like mining workers, they do manual work, constantly Try to fill the random field of the constructed block header with numbers to find a hash value that meets certain criteria. If found, connect the block to the top of the blockchain and send the legal blockchain to adjacent nodes.
2. Wallet: The blockchain records coin creation transactions and transfer transactions, which is different from the usual account system, which records account balances.
In the blockchain, only transactions are recorded, and there is no balance. The wallet is used to calculate the balance of a block owned by an address from the blockchain.
If you have studied relational databases, you can understand the blockchain as the index of the database, or it can be regarded as the directory of a book.
3. Routing node: responsible for transmitting transactions and blocks in a decentralized network environment. A node creates a transaction and sends it to adjacent nodes. After adjacent nodes are verified, they are sent to adjacent nodes. It will spread all over the web soon.
If a node finds a block that meets the standard through mining, this node will also pass it to adjacent nodes in the same way, and then the adjacent nodes will continue to propagate, so that all nodes in the network reach an agreement.


The schematic diagram of P2P network propagation is as follows:


 




We will introduce the working mechanism of the Bitcoin P2P network in detail in subsequent articles, including node classification, node discovery, node connection and broadcast.


3. How to advance blockchain learning
Due to the limited space, the three basic concepts of Bitcoin are introduced in the previous article, including blockchain, mining and P2P network. However, Bitcoin is a huge system, and beginners may have questions on each side.


This involves how to prevent double spending, smart contracts, blockchain forks, deflationary features, locking and unlocking scripts, Merkle tree storage of transactions, storage format of transactions, probability of blockchain attack, mining difficulty and mining Success time, more consensus mechanisms, coin creation transactions and transfer transactions, Bitcoin performance, different types of mining nodes, and Bitcoin application scenarios, etc.


Want to know the answer? miss! Then skip the question immediately and read the materials I share later. After reading it, you can understand these questions in seconds, so that you can understand that Bitcoin and blockchain do not leave dead ends. Are you bragging? Well, maybe not, look, I really understand it after reading it.


1. Where is Bitcoin?
2. How much is Bitcoin?
3. How to buy Bitcoin?
4. What blockchain trading platforms are there now?
5. Is Bitcoin safe?
6. How are Bitcoins stored?
7. Is Bitcoin the world currency?
8. What is the relationship between Bitcoin and blockchain?
9. Who Invented Bitcoin?
10. Who is Satoshi Nakamoto?
11. How many bitcoins are there in total?
12. How many bitcoins have been mined now?
13. How many ways are there to generate Bitcoin?
14. Which country recognizes Bitcoin? Does China recognize Bitcoin?
15. What is mining? How to mine?
16. Who can mine?
17. How to verify that a mining machine has mined mines?
18. Fundamentals of Cryptography? Algorithmic encryption, symmetric encryption, asymmetric encryption.
19. What is the relationship between Bitcoin's private key, public key, public key hash, and wallet address?
20. What is a smart contract?
21. Why should the mining succeed every 10 minutes? How to keep it every 10 minutes instead of every 20 minutes?
22. How are the blocks connected? How to prevent tampering?
23. How is the difficulty value of mining determined? How was it adjusted?
24. Why is Bitcoin deflationary? What to do after mining bitcoins?
25. What does the consensus mechanism include? pow, pos, dpos
26. How is Bitcoin transaction achieved? Including production transactions and transfer transactions
27. The structure of the block header? How are the block headers connected to each other to form a chain?
28. How are transactions stored and how are they added to a block?
29. Where is the ledger? How to obtain and store the ledger? How big is the ledger?
30. What is a Merkle tree? How to verify transactions?
31. Is Bitcoin really decentralized?
32. How does Bitcoin use the P2P network?
33. How does Bitcoin perform? Only 7 transactions can be done per second, is the transaction confirmation speed really 10 minutes?
34. What are soft forks and hard forks?
35. What is 50% attack?
36. Why does the public ledger say that no one can change it?
37. What rest apis are available for bitcoin wallets?
38. How does a person prove that he is the owner of an address?
39. What is the relationship between Bitcoin and virtual currency? The relationship between bitcoin and fiat currency?
40. What are public chains, private chains, and alliance chains?
41. What is the side chain, dyed chain?
42. What is Litecoin and Dogecoin?
43. What other application scenarios does blockchain have in addition to Bitcoin?
44. Is blockchain an innovation?
45. What are the types of Bitcoin p2p network nodes?
46. ​​How are Bitcoin transactions charged? According to the number of transactions, the amount or?
47. Does each node have to download such a large ledger?
48. Do Bitcoin wallets really have wallets? What is a paper wallet?
49. How does Bitcoin guarantee the anonymity of transactions? How does the exchange conduct real-name authentication compliance?
50. How did Satoshi Nakamoto use the mathematical Poisson theorem to prove the probability of a transaction being attacked?
51. Does Bitcoin still have bugs?
52. How much limit is there for one Bitcoin transaction?
53. What is payment to script? What is Pay-to-Public-Key Hash?
54. Do you stand on the side of expansionists or conservatives?


The most authentic material
As a senior in the industry said, the most authentic and serious material for learning Bitcoin and blockchain is the Bitcoin paper published by Satoshi Nakamoto. I always read the paper first when learning new technologies. .
Looking at the specific implementation or product, hearing the words of my predecessors made me feel like I found a confidant. I always insisted that it would be possible to realize a large-scale high-concurrency platform with a certain framework, a certain high-level open source project, and a certain microservice. The routine always feels a bit wild in constructing a sky garden.
Therefore, I immediately shared the bitcoin and blockchain information I learned, hoping to allow more people to start learning from the most primitive concepts of Bijie, lay a good foundation, and then expand the learning will have a natural feeling.
Readers can download the original paper from the link below:
Satoshi Nakamoto's Bitcoin Paper [English Version] ( http://pan.baidu.com/s/1jItBO6y Password: x0f8 )
Nakamoto's Bitcoin Paper [Chinese Version] ( http://pan.baidu.com/s /1eRBeLHo Password: 29fx )
Must-read books for proficient in Bitcoin
Studying the above paper can help you understand more of the theory. The content of this paper includes the core ideas of Bitcoin and blockchain.


So if you want to learn more technically about Bite, or want to understand the details of Bite and the implementation level of the blockchain, then I recommend the book "Mastering Bitcoin". Fortunately, this book is also available in Chinese.
Readers can download this book from the following link:


Mastering Bitcoin ( http://pan.baidu.com/s/1slFctY1 password: bbdb )
This book introduces the P2P network, transaction process, wallet structure, Smart contracts, consensus mechanisms, cryptography principles, script payments, solutions to network splits, etc. The content of the book can solve all the problems at the beginning of the article.
Information on advanced
technology As mentioned above, although the paper is the soul and core of a new technology, are the wildflowers on the roadside really unnecessary? You can change your taste from time to time, read other articles, look at other people's PPT, and learn from other people's learning methods. It is still very valuable. Here are a few helpful materials for learning Bitcoin.


1. A story tells you the principle and operation of Bitcoin (http://www.javacui.com/block/476.html)
This is an article that uses metaphors to explain Bitcoin. If you like listening to stories, just read this .
2. China Blockchain Technology and Industry Development Forum Standard (http://pan.baidu.com/s/1kVuVJqn Password: xa8y)
This is a blockchain standard formulated by a domestic organization. I can't figure out what the role of this standard is? : )
3. Blockchain and digital currency technology (http://pan.baidu.com/s/1mi0Zs28 Password: cu7y)
This is a widely spread bitcoin and blockchain PPT with a wide range of content and can be used as a Guided reading.
4. White Paper on Bubbi Blockchain Products (http://pan.baidu.com/s/1gfxLGT9 Password: uico)
This is the white paper of a domestic company that uses blockchain as a service for saving electronic assets, please read.
5. Contract-only PPT (http://pan.baidu.com/s/1qYVZqIK Password: v362)
This is a contract-only PPT that directly explains the code. It is difficult to understand, so you have to check the information while watching.
6. Blockchain Technology Guide (http://pan.baidu.com/s/1skAcDxr Password: 2qvg)
The technical guide comprehensively explains all aspects of blockchain technology.


Summary of
this article This article starts from the background of Bitcoin and blockchain technology, and introduces the ins and outs of Bitcoin and blockchain technology.
Then, the core principles of blockchain technology are explained to readers, including cryptography principles, smart contracts, P2P networks, unlocking scripts, etc.
Finally, I provide the common problems of beginners collected by the author in the blockchain research group, and guide readers to read the information provided by the author with these problems.
After reading this book and the information provided by the author, whether you are a technical person or a business person, whether you are a beginner or have a certain foundation, you will have a deeper understanding of the technical principles of Bitcoin and blockchain and understanding.


Transferred from the public account gitchat technical talk


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325650217&siteId=291194637