Blockchain technology refers to 2.1 blockchain technology

Source: Internet
Author: User
Tags bitcoin blockchain blockchain technology blockchain system blockchain transactions cryptography encryption

Blockchain foundation

Blockchain is a new technology that is gradually emerging with the increasing popularity of digital cryptocurrencies such as Bitcoin. It provides a decentralized credit establishment paradigm that does not require trust accumulation. It has already caused financial industry and scientific research institutions. Government departments and investment companies attach great importance and extensive attention. Blockchain technology records all past transaction and historical data by creating a database that is maintained together and cannot be tampered with. All data is distributed and transparent. Under this technology, any unfamiliar network users can reach a credit consensus through contract, peer-to-peer accounting, digital encryption, etc., without any central trust authority. With this technology, we can build digital currencies, digital assets, smart assets, and smart contracts.

Through the introduction of the previous chapter, I believe that everyone has a preliminary understanding of the blockchain and Bitcoin. In this chapter, we will continue to explore the technical details of the blockchain.

This chapter will first introduce the basic concepts of the blockchain and its operating principles, then introduce the operations and related details on the blockchain, and finally discuss the transaction process on the blockchain and its verification process.


2.1 Blockchain technology

A blockchain is essentially a peer-to-peer distributed ledger database. The underlying structure of Bitcoin uses the technical architecture of the blockchain. The blockchain itself is actually a series of linked data blocks, and the link pointer is the block header hash value generated by the cryptographic hash algorithm for processing the block header. Each block of data records a set of tree transaction status information composed of hash algorithms, which ensures that the transaction data in each block cannot be tampered with, and the blocks linked in the block chain cannot be tampered with.


2.1.1 Basic concepts

A complete blockchain system contains many technologies, including data blocks for storing data and digital signatures, timestamps, etc., as well as a consensus algorithm for supporting P2P networks and maintenance systems, with mining and Workload proof mechanism, anonymous trading mechanism and Bitcoin wallet, as well as related technology concepts such as age, UTXO, Merkle tree, and double flower. It is these technologies that enable the blockchain to form an inexhaustible engine on a non-central network, providing a constant source of power for blockchain transactions, verification, and links.


1. Data block

Bitcoin transaction records are stored in the data block. Each bit of the bitcoin system generates a block every 10 minutes. Each data block generally contains two parts: a header and a body. 

The block header encapsulates the current version number (Version), the previous block address (Prev-block), the timestamp (Timestamp), the random number (Nonce), the target block value of the current block (Bits), and the Merkle tree. Information such as the root value (Merkle-root).

The block body mainly contains the transaction count and transaction details. The transaction details are the bookkeeping in the Bitcoin system, and each transaction is permanently recorded in the data block and can be queried by anyone. The Merkle tree in the block will digitally sign each transaction, which ensures that every transaction is unforgeable and there are no duplicate transactions. All transactions will generate a unique Merkle root value into the block header through the Merkle tree's hash process. The Merkle tree will be described in detail later in this chapter.

If you are using Bitcoin core, the block data files will be synced to your computer's hard drive whenever you open the client, and you can find them in the blocks folder. 

We can also use the hexdump command to display the data block in hexadecimal on the terminal. We can parse the data to get basic information such as transaction records, block size, etc., so we say that the data in the blockchain is completely transparent. As shown in Figure 2-3, we use the command hexdump -n 10000 -C blk00000.dat to open the creation block numbered 00000 (the first blockchain in Bitcoin).


2. Mining and fork problems

The block is produced during the mining process. The so-called mining is actually an exhaustive random number algorithm, which packs the hash value of the previous block plus all the transactions in 10 minutes, plus a random number to calculate a 256-bit string hash value. The input random number Nonce makes the hash value satisfy the certain condition to obtain the transaction accounting right of the block. The newly generated blocks need to be quickly broadcasted out so that other nodes can verify them to prevent fraud. Each block stores the hash value of the previous block, which can be traced back to the source. Only after verification, will the transaction credit of the block be finally obtained. The Bitcoin system will allow mining miners to compete for billing rights (the right to link blocks in the main chain). This competitive mechanism is the proof of work mechanism. Mining requires a lot of energy and time, and whoever pays more work can get a block of billing rights with greater probability. The miners who obtain the bookkeeping rights link the current block to the previous block to form the latest block main chain, and the miner will also receive a certain amount of system rewards (50 bitcoins are generated every 10 hours from 2009 to 2013, Bitcoin generated every 10 minutes from 2014 to now will be halved to 25). All the blocks are linked together to form the main chain of the blockchain. From the creation block to the current block, all data histories above the blockchain can be traced and queried.

It should be noted that two miners in different regions may simultaneously “dig out” two new blocks to link, and “bifurcation” will appear on the main chain. The system does not immediately confirm which block is unreasonable, but agrees that the follow-up miner always chooses the blockchain with the largest cumulative workload. Therefore, when the main chain is forked, the miners of the subsequent blocks will calculate and compare them, link their blocks to the alternative chain that maximizes the current cumulative workload, form a longer new main chain, and automatically discard the points. A short chain at the fork to solve the fork problem.


3. Time stamp and non-defective modification

The timestamp is the total number of seconds from the time of 01:00:00, 01:00, GMT, January 1, 1970 (Beijing time, January 01, 1970, 08:00:00), usually a sequence of characters. , uniquely identifies the time of a certain moment. In the bitcoin system, the node that obtains the billing right needs to stamp a time stamp in the block header when linking the block, and is used to record the write time of the current block data. The timestamp in each subsequent block enhances the previous timestamp to form a time-increasing chain. Timestamp technology itself is not complicated, but the application of timestamps in blockchain technology is a major innovation. Timestamps add a time dimension to the future of blockchain-based Internet and big data, making data easier to trace. It is also possible to reproduce history. At the same time, the time stamp can be used as an important parameter of the Proof of Existence. It can confirm that certain data must exist at a certain moment, which ensures that the blockchain database is not tamperable and unforgeable. It is possible to apply blockchain technology to time sensitive areas such as notarization and intellectual property registration.


4. Distributed database

The blocks in the Bitcoin system, like a bookkeeping, record all bitcoin transaction information, and each bitcoin user's bitcoin revenue and expenditure situation is permanently embedded in the data block for others to query. The transaction data in these data blocks is stored in the client nodes of each Bitcoin user, all of which form Bitcoin and its tough distributed database system. The destruction of the data of any one node will not affect the normal operation of the entire database, because the complete database is saved in other healthy nodes.


5. UTXO trading mode

UTXO (Unspent Transaction Outputs) is an unspent transaction output that is the basic unit in the bitcoin transaction process. Except for the creation block, transactions (Tx) in all blocks will have several inputs (Tx_in, also known as the source of funds) and several outputs (Tx_out, also known as the whereabouts of funds), the creation block and later mining In the raw block, there is no input for the bonus to the miner. In addition, in the bitcoin system, the input of one transaction must be the output of another transaction that is not used, and the input also needs the last one. The private key corresponding to the output address is signed. Currently UTXO in the entire blockchain network will be stored in each node, and only transactions that are subject to UTXO and digital signature conditions are legal. Therefore, the new transaction in the blockchain system does not need to trace the entire transaction history to confirm whether the current transaction is legal.


6. Hash function

Hash functions also have important applications in the Bitcoin system. The data in the blockchain is not just the original data or transaction records, but also their hash function values, that is, the original data is encoded into a specific length, by the number and After the string consisting of letters, it is recorded in the blockchain. The hash function has a lot of data suitable for storing blockchain data.

advantage:

1) The data processed by the hash function is unidirectional, and it is almost impossible to calculate the original input value through the processed output value;

2) The time taken by the hash function to process data of different lengths is consistent, and the output value is also fixed length;

3) If the input value of the hash function differs by only one byte, the result of the output value will be quite different. The most commonly used hash function in the Bitcoin system is the dual SHA256 hash function. In general, the raw data of different lengths is processed by two SHA256 hash functions, and the binary number of length 256 is output to be unified. Identify and store.

In summary, the hash function is a key technology in the Bitcoin system, providing a lot of convenience for the Bitcoin system. The hash function will be described in detail in the later chapters of this book, so I won't go into details here.


7. Merkle tree

A Merkle tree is a tree in a data structure. It can be a binary tree or a multi-fork tree. It has all the characteristics of a tree structure. As shown in Figure 2-4, the Bitkle blockchain system uses the Merkle binary tree, which is mainly used to quickly summarize and verify the integrity of the block data. It will group the data in the blockchain. Hash operation, up and down recursive operation to generate a new hash node, and finally only one Merkle root is stored in the block header, each hash node always contains two adjacent data blocks or their hash values. There are many advantages to using a Merkle tree in a Bitcoin system: first, it greatly improves the efficiency and scalability of the blockchain, so that the block header only needs to contain the root hash value without having to encapsulate all the underlying data, which makes the hash The operation can run efficiently on smartphones and even IoT devices; secondly, the Merkle tree supports the Simplified Payment Verification Protocol (SPV), which allows transaction data to be executed without running a full blockchain network node. test. Therefore, it is very meaningful to use a data structure such as a Merkle tree in a blockchain. A detailed description of the Merkle tree will be given later in the book.


8. Double payment

The double payment problem is also known as the "double flower" problem, that is, using the digital characteristics of money to complete two or more payments with "the same money." In the traditional financial and monetary system, since the money currency is a physical entity with an objective and unique attribute, double payment can be avoided. But in other e-money systems, a trusted third-party management agency is required to provide assurance. Blockchain technology effectively solves the double payment problem in the decentralized system without any third-party organization and only through the mutual authentication and consensus mechanism between distributed nodes, and completes the value transfer while transmitting information. . The blockchain technology uses the timestamp technology formed by the block link to verify whether the bitcoin satisfies UTXO (unexpended transactions) and digital signatures, effectively avoiding the problem of double payment. If someone constructs two transactions for different parties using the same UTXO, the Bitcoin client will only forward the one that was first heard. The miners chose to include the transaction in the future block. When there is a five-linked block behind the block where the transaction is located, the transaction has been confirmed six times. On the Bitcoin blockchain, after 6 confirmations, it is basically guaranteed that Bitcoin is not double-flowered.


9. P2P network

A peer-to-peer network (P2P network) is a distributed application architecture that distributes tasks and workloads among peers. It is a group formed by peer-to-peer computing models at the application layer. Web or network form. Therefore, P2P can be understood as a peer-to-peer computing or peer-to-peer network. The schematic diagram of a P2P network is shown in Figure 2-5. The domestic Thunder software uses P2P technology. The blockchain system is based on IP communication protocols and distributed networks. It does not rely on traditional circuit switching, but rather builds on network communications and exchanges information entirely over the Internet. All nodes in the network have the same status. There are no special central nodes and hierarchical structures. Each node will assume functions such as network routing and verification of data blocks. The nodes of the network can be divided into full-node and lightweight nodes according to the amount of stored data. The whole node stores all blockchain data since the creation block (the bitcoin network is now about tens of gigabytes, and still Growing up). The advantage of the whole node is that it does not need to rely on other nodes for data verification, and can perform verification and update operations only by itself. The disadvantage is that the hardware cost is high. The lightweight node only needs to store part of the data information. When other data is needed, the neighboring node can request the required data to complete the verification update through the simple payment verification method (SPV).


10. Encryption algorithm

In addition to the hash algorithm, there is an asymmetric encryption algorithm (elliptic curve encryption algorithm) for encrypting transactions in Bitcoin. An asymmetric encryption algorithm refers to the existence of a pair of mathematically related keys. Data information encrypted using one of the keys can be decrypted only by using another key. In the pair of keys, the publicly disclosed key is called a public key, and the undisclosed key is called a private key. For example, the public key is like a bank account, and the private key is like the password of the account or the signature of the account owner. A valid transaction above the blockchain has a digital signature valid for the transaction initiator's private key signature, and the signature of the transaction can be verified by using the transaction initiator's public key. The public key can be calculated from the private key by an algorithm, but the private key cannot be pushed out of the public key. A very typical asymmetric encryption algorithm, the Elliptic Curve Cryptography (ECC), is used in the Bitcoin system.

The Bitcoin system generally takes a 256-bit random number as a private key from a cryptographically secure random source under the operating system. The total number of private keys is 2256, so it is difficult to traverse all possible The private key derives the private key corresponding to the public key. The private key used by the user is also converted into a 50-bit private key that is easy to write and recognize through SHA256 and Base58. The public key is first generated by the private key and the Secp256k1 elliptic curve algorithm to generate a random number of 65 bytes. In general, the address of the Bitcoin wallet is also generated by the public key. The process is to first perform the double hash operation of the SHA256 and RIPEMD160 on the public key, and generate a summary result of 20 bytes in length (ie, Hash160 result). As the body information of the bitcoin address, the version prefix 0x00 is added in front, and a 4-byte address check code is added later. The address check code is generated by performing two SHA256 operations on the digest result and taking the first four bits of the hash value. Finally, through the Base58 processing, the connected version prefix, body information and check code are converted into bitcoin character addresses that can be easily recognized.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.