Transaction of BTC


BTC deal

Each transaction has at least one input (txin) and at least one output (txout) except coinbase. The transaction model of bitcoin is utxo (unspend transaction output), that is to say, only the unused bitcoin output is recorded, and each transaction costs one or more previous outputs.

Transaction important information

      "version": 1,    
      "locktime": 0, 
    //Input section
      "vin": [           
          "txid": "7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18",     
           "vout": 0,                                    
          "Scriptsig": "adfadfadf" (payer's public key, payer's address, payer's signature)                 
    //Output section, there are two outputs below
      "vout": [         
          "value": 0.01500000,             
          "scriptPubKey": "OP_ DUP OP_ HASH160 OP_ EQUALVERIFY OP_ Checksig "(payee address)          
           "value": 0.08450000,             
          "scriptPubKey": "OP_DUP OP_HASH160 OP_EQUALVERIFY OP_CHECKSIG",    

Input part

Txid: the transaction ID of the referenced utxo

Vout: the serial number (starting from 0) in the output of the transaction of the referenced utxo is the subscript of the output part

Scriptsig: Unlocking script, including a public key and a signature of the whole transaction

Output – output part

Value: number of bitcoin

Scriptpubkey: Lock script, including command (OP)_ DUP, etc.) and the address of the payee.

Utxo concept

  1. The bitcoin client will update the unused output every time it receives a new block. To check whether a transaction is legal, it only needs to see whether all the inputs of the transaction are in the unused output table
  2. The output has two states: used and unused. To see how much BTC an address has is to calculate the total amount of all utxo records of the address.
  3. When an address wants to publish a transaction, what it does is broadcast the transaction to the nodes in the BTC network, and the transaction will be marked as “unconfirmed”. BTC network does not update the system status immediately after receiving a broadcast, but has block and memory pool design. At a certain time, all BTC nodes maintain an account book to record utxo, and have a memory pool to receive unconfirmed transactions. When a transaction broadcast is received, the node will add the transaction to its own memory pool.
  4. Each client also maintains a utxo set to hold all unused output.

Transaction verification of BTC

Transaction of BTC

There are two transactions TX: a – > b, TX: B – > C

To verify TX: B – > C, the most important thing is to verify whether its input part is legal.

Transaction verification

Transaction is generated by this node

1. Received data: address of payee, public and private key of payer

2. Get the output available to the payer from the utxo of this node and package it into the input of this transaction

3. Generate a new transaction and update the local utxo

4. Package the transaction into the block and wait for release

Transaction is generated by other nodes and verified by this node

When someone publishes a block, this node needs to verify all transactions of the block

1. Verify that all inputs of this transaction are legal

1. The key is to verify whether the signature matches. The signature is generated with the payer's private key and must be verified with the public key in input,
2. Verify whether the input is in the local utxo. If you want to use the money, you must first find the source. Use the payer's address (public key double hash) in input to match utxo. The matching indicates that there is BTC in this address
These two verifications complement each other. If you get a person's public key and want to use it to transfer money to your address, you must use its private key as a signature to pass the verification. If you use a fake public key and a fake signature, the address corresponding to the fake public key cannot match utxo. Therefore, only when there are public and private keys at the same time can transactions occur.

2. Verify that the total input is equal to the output

3. After the transaction is passed, the utxo of this node needs to be updated

Account security

The payer needs to publish not only the mybitcoin addr, but also the mypubkey and signature. The payee only needs to disclose the bitcoin address, so if an address has not initiated a transaction, it only exposes the bitcoin address. If he wants to crack the private key of the account, he must first crack the public key through the address and then crack the private key, which is almost impossible. So in order to crack the private key, try to put the remaining BTC on a new address to avoid public key exposure.

This work adoptsCC agreementReprint must indicate the author and the link of this article

What tools have you used? Why use this tool (fast, support high concurrency…)? How is the underlying implementation?

Recommended Today

MacOS Big Sur 11.2.1 official update push

As you all know, apple once again released the official update of MacOS Big Sur 11.2.1 to the public. This update solves the problem that some 2016 and 2017 MacBook Pro models may not be able to be charged. Interested friends should not miss it. Apple has not released an update to explain the impact […]