BTC
ETH
HTX
SOL
BNB
View Market
简中
繁中
English
日本語
한국어
ภาษาไทย
Tiếng Việt

Popular science: Bitcoin transaction process

闲话挖矿
特邀专栏作者
2020-06-20 03:21
This article is about 2487 words, reading the full article takes about 4 minutes
The main purpose of this article is to show the transaction process of Bitcoin in a relatively simple language, so that more technical laymen like the author can understand Bitcoin.
AI Summary
Expand
The main purpose of this article is to show the transaction process of Bitcoin in a relatively simple language, so that more technical laymen like the author can understand Bitcoin.

During the recent period, the blogger is compiling an easy-to-understand mining science album, hoping to comprehensively introduce what happened in the mining process from the initial cryptocurrency transaction to the mining confirmation transaction. Which links have generated mining revenue, and what we often refer to as computing power, why mining revenue should be distributed in this way, and so on.

Taking Bitcoin as an example, we know that the purpose of mining in the Bitcoin network is toPack transactions and maintain the Bitcoin network, then the transaction is actually the first link closely related to mining. The process of trading in the Bitcoin network uses asymmetric encryption technology, digital abstract technology, blockchain technology, etc. The technology implementation has already been preceded by many great gods, and bloggers will not show their ugliness. The main purpose of this article is toShow the transaction process of Bitcoin in a relatively simple languagesecondary title

Asymmetric encryption:

Asymmetric encryption:Also known as public key encryption, it generates a pair of public and private keys through cryptographic algorithms, the public key is made public, and the private key is kept by the individual. it hastwo purposesdatadataEncrypted with public keytransmissionTo the public key holder, the public key holder uses the corresponding private key to decrypt the data and read the information. In this way, you canEnsure the security of information transmission; Second, the public key holder can use the private key pairinformation signature(The signature process is similar to the encryption process), and then send the information and the signature to others, and others can verify the information signature through the public key (the verification process is similar to the decryption process), and verify that the signature information is consistent with the sent information, it proves that the information is from the public issued by the key holder, without revealing the identity and private key of the public key holder,Ensure the reliability of information sources. (reference link:https://en.wikipedia.org/wiki/Public-key_cryptography)

hash algorithm: Also called a hash function, it can be used to calculate a message or data with a large amount of data into a format with a fixed format and a small amount of datadigital abstract,Also known asfingerprinthash valuehashhash. A good hashing algorithm should beirreversible(The original information or data cannot be reversed through the digital summary),Sensitive(Any small change in the original data will cause a huge change in the digital summary),anti-collision(It's hard to find two different pieces of information with the same numeric digest). (reference link:https://en.wikipedia.org/wiki/Hash_function)

Public and Private Keys in Bitcoinpublic keypublic keyhashhashAlgorithm (SHA256) operation to get a hash value (also called hash), and thenEncoded by Base58Checkgeneratewallet addresswallet address. Therefore, after the wallet address is decoded, the hash of the corresponding public key can be obtained, which can be used to verify the private key signature, encrypt data, and so on.

UTXO: Unspent transaction output, unspent transaction output, it is theabstract currency, each UTXO is covered by aPublic key (wallet address) lock, only the person who holds the corresponding private key of the public key canSign (unlock) by private keyAnd use that UTXO. UTXO can be understood asabstract banknotessecondary titlehttps://en.wikipedia.org/wiki/Unspent_transaction_output)

Aside from the code, let's take a look at what a bitcoin transaction is like

As shown in the figure below, there are four people, A, B, C, and D. They all have Bitcoin wallets, and the private keys of the wallets are held by themselves. The wallet addresses (generated by the public keys of their respective wallets) are made public on the Bitcoin network, and are used for UTXO locking and verify.

Initially, A gives C 0.7BTC, the record in the Bitcoin network isUTXO(1): A to C 0.7BTC;B to C 0.5BTC, the record in the Bitcoin network isUTXO(2): B to C 0.5BTC. At this time, the account balance of C's Bitcoin wallet is the sum of these two UTXOs,C’s total number of bitcoins = UTXO(1)+UTXO(2)=1.2BTC. As shown below:

On this day, C bought a batch of goods from D and needs to pay 0.8 BTC to D. C transfers money to D through the Bitcoin network, but C’s existing two UTXOs are both less than 0.8 BTC, so the two UTXOs need to be used together.Similar to cash transaction: pay 1.2BTC to Ding, and Ding pays 0.4BTC to Bing. But in the Bitcoin network, thisThe change job was initiated by C himself

The entire transaction process is as follows:

  • C prepares transaction information through the Bitcoin wallet. The transaction information includes two parts: input and output. The input is UTXO(1) and UTXO(2), and C’s wallet private key signature (because both UTXO(1) and UTXO(2) Locked by C's wallet public key, it needs to be unlocked by C's private key signature before use)

  • The output of the transaction is unconfirmedUTXO(3): C to D 0.8BTC, this new UTXO points to Ding's wallet public key, and will be locked by Ding's wallet public key after the transaction is confirmed.

    At this time, there is still 0.4BTC to give change to C, so it is necessary to output an unconfirmedUTXO(4): C to C 0.3999BTC, this new UTXO points to C’s wallet public key, and will be locked by C’s wallet public key after the transaction is confirmed.

    Why is the change amount not 0.4BTC?? Because of the requirements of the Bitcoin network, transaction transfers need to pay transaction fees to the Bitcoin network.Remaining 0.0001BTCdoes not point to any wallet public key, theas a transfer feePay to the miner who packaged the transaction (if there is no change, all the remaining unspecified bitcoins will be used as a handling fee to the miner who packaged the transaction, but the change work is currently done automatically by the wallet, don't worry).

  • After the transaction information is prepared, through C's walletVerify that the transaction is legal(UTXO is legal, signature is valid, input and output amount is valid, etc.), the transaction is broadcast to the Bitcoin network, after the transaction is verified by the mining node, the transaction is packaged (the transaction is recorded in the Bitcoin block), and sent to the Bitcoin Coin network broadcast, the transaction is completed.

  • The old UTXO is consumed and the new UTXO takes effect, at this time Ding's wallet has an unusedUTXO(3): Propanedine 0.8BTC, C's wallet has an unusedUTXO(4): C to C 0.3999BTC


The above is a more abstract bitcoin transaction process, about the construction of bitcoin transactions, signature verification, node verification, transaction broadcasting, joining the mining node mempool, miners constructing preliminary blocks, and the final block confirmation process. They are introduced separately, and will not be expanded in this article.

From this abstract transaction process, we can find that Bitcoin transactions are essentially a process of input and output of a bunch of UTXOs. As old UTXOs are consumed, new UTXOs are generated, completing Bitcoin transactions again and again. The transaction process is double-protected by asymmetric encryption and hash algorithms. Bitcoin holders can safely complete the transaction without worrying about their identity being leaked. A part of Bitcoin is also consumed during the transaction process, which is used to reward the miners who pack the transaction. Miners are happy to do their job of maintaining the Bitcoin network.

BTC
矿业