The Bitcoin transaction process

The Bitcoin transaction process
Recently, the blogger has been compiling an easy-to-understand popular science album on mining , hoping to comprehensively introduce what happens in the mining process, from the initial cryptocurrency transaction to the various links of mining confirmation transactions, which links generate mining income, what is the computing power we often talk about, why mining income is distributed in this way, etc.
Take Bitcoin as an example. We know that the purpose of mining in the Bitcoin network is to package transactions and maintain the Bitcoin network . Therefore, transactions are actually the first link closely related to mining. The transaction process in the Bitcoin network uses asymmetric encryption technology, digital summary technology, blockchain technology, etc. The technical implementation of these technologies has been demonstrated by many great masters, so I will not show off my skills. The main purpose of this article is to show the Bitcoin transaction process in a relatively simple language , so that more technical laymen like the author can understand Bitcoin.

Before we start, we need to first introduce a few concepts :

Knowledge Points
  • Asymmetric encryption : also known as public key encryption, it generates a pair of public and private keys through cryptographic algorithms. The public key is open to the public, and the private key is kept by the person himself. It has two uses : First, others can encrypt data with a public public key and transmit it to the public key holder. The public key holder uses the corresponding private key to decrypt the data and read the information. In this way, the security of information transmission can be guaranteed ; second, the public key holder can use the private key to sign the information (the signing process is similar to the encryption process), and then send the information and the signature to others. Others can verify the signature of the information through the public key (the verification process is similar to the decryption process). If the signature information is consistent with the sent information, it proves that the information was sent by the public key holder, which can ensure the reliability of the source of information without exposing the identity and private key of the public key holder. ( Reference link: https://en.wikipedia.org/wiki/Public-key_cryptography )

  • Hash algorithm : also called hash function, it can be used to calculate a digital summary with a fixed format and small data volume from a message or data with a large amount of data, also called fingerprint, hash value, or hash . A good hash algorithm should be irreversible (it is impossible to reverse the original information or data through the digital summary), sensitive (any slight change in the original data will cause a huge change in the digital summary), and anti-collision (it is difficult to find two different information with the same digital summary). ( Reference link: https://en.wikipedia.org/wiki/Hash_function )

  • Public key and private key in Bitcoin : In the Bitcoin world, the public key and private key generated according to the Bitcoin protocol are used to determine the ownership of Bitcoin. They are generated by an asymmetric encryption algorithm (elliptic curve algorithm). The public key is calculated by two hash algorithms (SHA256) to obtain a hash value (also called hash), and then Base58Check encoding is used to generate the Bitcoin wallet address we often see. 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, etc.

  • UTXO : Unspent transaction output, unspent transaction output, is an abstract currency in the Bitcoin world. Each UTXO is locked by a public key (wallet address) . Only the person who holds the private key corresponding to the public key can sign (unlock) and use the UTXO through the private key. UTXO can be understood as an abstract banknote, but its face value is not fixed (not just 5 or 10, it can be any number). (Reference link: https://en.wikipedia.org/wiki/Unspent_transaction_output)

Putting aside the code, let's take a look at the Bitcoin transaction process:

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

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

On this day, C bought a batch of goods from D and needed to pay D 0.8 BTC. C transferred money to D through the Bitcoin network, but C's two existing UTXOs were less than 0.8 BTC, so he needed to use both UTXOs together, similar to a cash transaction: he paid D 1.2 BTC, and D gave C 0.4 BTC in change . But in the Bitcoin network, this change was initiated by C himself .
The entire transaction process is as follows:
  1. C prepares transaction information through his Bitcoin wallet. The transaction information includes two parts: input and output. The input is UTXO(1) and UTXO(2) , as well as C's wallet private key signature (because UTXO(1) and UTXO(2) are locked by C's wallet public key, they need to be unlocked by C's private key signature before they can be used)
  2. The output of the transaction is an unconfirmed UTXO(3): C gives D 0.8 BTC . This new UTXO points to D’s wallet public key . After the transaction is confirmed, it will be locked by D’s wallet public key.
    At this time, there is still 0.4 BTC that needs to be changed to C, so an unconfirmed UTXO (4) needs to be output : C gives C 0.3999 BTC . This new UTXO points to C's wallet public key. After the transaction is confirmed, it will be locked by C's wallet public key.
    Why is the change not 0.4 BTC ? Because the Bitcoin network requires that transaction fees must be paid to the Bitcoin network for transaction transfers. The remaining 0.0001 BTC does not point to any wallet public key and will be paid as a transfer fee to the miner who packaged the transaction (if no change is given, all the remaining unspecified bitcoins will be paid as a fee to the miner who packaged the transaction, but currently the change work is automatically completed by the wallet, so don't worry).
  3. After the transaction information is prepared, after C's wallet verifies that the transaction is legal (UTXO is legal, the signature is valid, the input and output amounts are valid, etc.), the transaction is broadcast to the Bitcoin network. After the mining node verifies the transaction, it packages the transaction (records the transaction in the Bitcoin block) and broadcasts it to the Bitcoin network , and the transaction is completed.
  4. The old UTXO is consumed and the new UTXO takes effect . At this time, there is an unused UTXO in D's wallet (3): C gives D 0.8 BTC , and there is an unused UTXO in C's wallet (4): C gives C 0.3999 BTC .

The above is a relatively abstract process of Bitcoin transactions. 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 will be introduced separately later 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 and new UTXOs are generated, Bitcoin transactions are completed again and again.
The transaction process is doubly protected by asymmetric encryption and hashing algorithms. Bitcoin holders can complete transactions without worrying about their identities being leaked. A portion of Bitcoin is also consumed during the transaction process to reward miners who package transactions, making miners happy to complete their tasks of maintaining the Bitcoin network. Thus, an internally driven blockchain network is formed.

<<:  $9,200 becomes the deciding factor between long and short BTC, and the trend during the day is worth paying attention to

>>:  HackFS plan released, Filecoin reignites!

Recommend

Ethereum the new hard currency?

A debate has raged over the possibility of Ethere...

Is it good to have a mole at the corner of the mouth?

Is it good to have a mole at the corner of the mo...

Bitcoin trading is very popular and has attracted a lot of venture capital

Decentral and the Ethereum Meetup team will hold ...

How to read a woman's nose

As the saying goes, a man's nose determines h...

Treat your colleagues as well as your lover

Sometimes, people treat other people completely d...

Origin: Bitcoin was born from this block!

This week, Turong will interpret the hottest conc...

How to read the face of a man with bad luck

Why do some men get something without any effort,...

Bitcoin miners say 2019 is too difficult

Written by: Xiao Maoge Special thanks to Zhu Yu f...

Analysis of different nose shapes of women

The nose is responsible for a person's fortune...

Detailed Explanation of the Sixty-Four Hexagrams_The 20th Hexagram: Fengdi Guan

The sixty-four hexagrams of the Book of Changes a...