Blockchain learning | core concepts of blockchain

To learn the relevant knowledge of the blockchain, the core concepts of the blockchain-blocks, hash algorithms, public and private keys, timestamps, etc. must be understood. Blockchain is composed of multiple connected blocks, so we start with understanding the concept of blocks!

1. Block

Block structure diagram

First look at the block diagram above. In the blockchain, transaction data exists permanently in electronic form, and the unit that forms the data storage is called a block. The data structure of the blockchain actually consists of two parts, the block header and the block body. You can understand it this way. The block body is the main body of the block. The main body contains various transaction data. The block header contains other miscellaneous things. It consists of version number, difficulty value, timestamp, etc. It contains each area. Identification information of the block itself. To make a simple analogy, what is the main message of the Zambian community? It is all types of posts in Zambia community forums, including essence posts and ordinary posts. So the block body is the content of various posts in the Zambia community. What is the block header? "Zambia Community is the first blockchain communication community in China that integrates online and offline. It provides an open blockchain communication forum for all blockchain technology enthusiasts to share real-time information and spread the popularization of blockchain "Knowledge, etc.", that is, the introduction, title and other miscellaneous information of the Zambia community is the block header.

The block header includes three parts:

The first three parts of the block

①The hash value of the parent block is the hash address of the previous block. We know that the blockchain is a blockchain that is arranged one by one in order. Just like a real ledger, each page has a page number. You can find the content you are looking for through the page number. In the blockchain, The information after the settlement of the previous block can be found through the hash value of the parent block. ②Mining difficulty, timestamp and random number. The difficulty of mining is to adjust the mining time according to the computing power of the network; the random number is a counter used in the proof of work algorithm; the timestamp is to record the creation time of each block, which will be described in detail later. ③Merkle (merkel) tree roots. The Merkle tree root data that can summarize and quickly summarize all transaction data in the verification block. Relatively difficult to understand, this will be described in detail later. The block body is very simple, that is, all transaction records in a block. For example, each block body of the Bitcoin system is about 2500 transaction records, and the transaction records are transfer information. Next, let's talk about the genesis block.

Genesis block

What is the genesis block? In the data structure of the blockchain network, the first block to be constructed is called the genesis block. It has a unique ID identification number. Except for the genesis block, each subsequent block will contain two IDs, one is the ID number of the block itself, and the other is the ID number of the previous block. Because the first genesis block has no context, it has and only one ID number. Blocks are automatically generated at regular intervals. For example, the Bitcoin network stipulates that a new block will be generated every ten minutes. On average, a new block will be generated in Ethereum about every 15 seconds. EOS because of his A lot of improvements and optimizations, now the block generation time, that is, the time to generate a new block is 0.5 seconds against the sky. The generated blocks are directed through the front and back relationship between the ID numbers, and all blocks are connected in order to form a blockchain. Two, hash algorithm

Hash algorithm

Hash algorithm is a kind of encryption algorithm. Simply put, if you don't want others to see some content, you might think of encrypting the content, and hash algorithm is one of them. Among them, the information before encryption is called plaintext, and the information after encryption is called ciphertext; to put it more complexly, the hash algorithm is a one-way cryptographic mechanism in the blockchain to ensure that transaction information is not tampered with. After the hash algorithm receives a piece of plaintext, it converts it into a short-length, fixed-digit hash data in an irreversible way. The hash algorithm has two characteristics: ①The encrypted plaintext is one-way irreversible! How to understand? If the content we want to encrypt is: happy National Day! Then the encrypted ciphertext becomes ABCD. When someone sees ABCD, he can't use ABCD to express what you want to express: Happy National Day! ② Once the plaintext changes, the output encrypted content, that is, the hash data, will change accordingly. This is like we wanted to transmit at the beginning: I love you, it becomes ABC after encryption. The content transmitted later is changed to: I hate you, then the content will become ADF. The hash algorithm is a secure and confidential algorithm in the blockchain system, which can ensure that the content we want to transmit is encrypted and not stolen. The role of the hash algorithm: to prevent block information from being tampered with. The hash value is a string of numbers and letters that are compressed into a hashed string of numbers and letters after encrypting all transaction records in each block. The hash value of the blockchain can uniquely and accurately identify a block. Any node in the blockchain can obtain the hash value of this block through a simple hash calculation. If the calculated hash value does not change, It means that the information in the block has not been tampered with. On the contrary, it means that the information in the block is hard to change. This is very useful in blockchain and is an effective means to prevent block information from being tampered with! , Third, public key (yue) and private key (yue) Public key and private key are closely related to our assets. First, the public key and the private key come in pairs. Let's briefly introduce the model of email encryption: the public key is for everyone to use, you can publish it by email, and you can download it through the website. The public key is actually used for encryption/verification. The private key is your own and must be kept very carefully. It is best to add a password. The private key is used for decryption/signature, and the private key is owned by the individual. Second, many people have invested in the blockchain, which must use the wallet on the blockchain. The wallet has three elements: address, public key and private key. The address means that the wallet of "Anqing" can be found through this address, that is, the ID; the public key means that the wallet of "Anqing" is a public key that can be used to match the private key for verification; and the private key , It is not open, and it mainly serves as an electronic signature to prove that the wallet is "safe". The public key and private key are the keys used in the transaction process. We use a transaction process to express the role of public and private keys. For example, as shown in the figure below:

 

Xiao Bai wants to start a transaction with Xiao Hei. First of all, she will keep the private key in her hand during the initiation process, and the public key will be disclosed to Xiao Hei. When initiating a transaction, Xiaobai will sign the transaction with her private key to prove that this record is "indeed" she initiated. After Xiao Hei obtains Xiao Bai's transaction slip, he unlocks Xiao Bai's public key with Xiao Bai's private key, and thus can prove that the transaction was indeed initiated by Xiao Bai, thus making an error-free transaction. In the financial system, the confirmation of identity is very important. When Xiaobai transfers 1 bitcoin to Xiaohei, everyone involved in the verification needs to verify that the account was initiated by Xiaobai, so that when Xiaobai wants to repay the account later, we can confirm that Xiaobai himself has already accepted the transaction. There is confirmation. Therefore, the existence of the private key is to authenticate a person's identity and verify the authenticity of each transaction, so that the account cannot be relied upon during proofreading. Whether it is the hash algorithm or the design mechanism of the public key and private key, it is actually to ensure the safety and reliability of the blockchain system and avoid tampering. 4. Timestamp To put it simply, a timestamp is actually to stamp a block. It records the precise time when the block was created, confirming that each block is unique and cannot be tampered with!

The timestamp in the blockchain exists in the block from the moment the block is generated. It corresponds to the authentication of each transaction record and proves the authenticity of the transaction record. The timestamp is written directly in the blockchain, and the blocks that have been generated in the blockchain cannot be tampered with, because once tampered, the generated hash value will change and become invalid data. Each time stamp will also incorporate the previous time stamp into its random hash value. This process is repeated and connected in sequence, and finally a complete chain is generated. Five, Merkle (merkel) tree structure

The picture above is a Merkel tree. Combining the concepts mentioned above, the transaction data of the block is the lowest-level data in this picture. At this time, these data are called leaf nodes. We first perform a hash calculation on these leaf nodes, and then obtain four hash values ​​through the hash calculation. After obtaining these four hash values, we enter the second round. In the second round, the four hash values ​​are combined in pairs for hash calculation, and the next two hash values ​​are obtained. Then repeat the hash calculation of this pairwise combination, and finally we get the unique hash value of the top layer in the picture-Merkel root. Merkel root's biggest role is to be able to determine whether the transaction data has been tampered with. Merkel root is the last unique value left after the hash value of all transactions in the block body is calculated by two-by-two hash calculation, so Merkel root has two keywords here: final value, unique value . The main role of Merkel root is to verify, to check whether a transaction exists in this block and to determine whether the transaction data has been tampered with! Similarly, the change of any data in the block will cause the Merkle tree structure to change. In the process of transaction information verification and comparison, the Merkle tree structure can greatly reduce the amount of data calculation. After all, we only need to verify the Merkle tree structure generation. The unified hash value of-Merkel root will do. Note: Part of the text and pictures in this article are excerpted from "Illustrated Blockchain", and the rest of the pictures are from the Internet.

From Zambia Community (zanbtc.com)-An Qing

Guess you like

Origin blog.csdn.net/oqzuser12345678999q/article/details/104671667