How does the Bitcoin protocol work?

Author: The Little Dream, Created: 2017-01-19 18:30:04, Updated:

How does the Bitcoin protocol work?

  • Bitcoin

    Now, let's move away from Infocoin and move on to the real Bitcoin protocol.

    To use Bitcoin, you first have to install a wallet in your computer. To give you a better understanding, the following is a screenshot of a wallet called Multibit. You can see in the upper left-hand corner the Bitcoin balance is 0.06555555 bitcoins, which at the time of the transaction price in the screenshot is almost $70. The screenshot on the right shows the two most recent transactions, which they deposited in this 0.065555555 bitcoins.

    img

    Suppose you are a merchant and you have set up an online store and you decide to allow customers to pay with Bitcoin. All you need to do is generate a new Bitcoin address with your wallet program. It will automatically generate a pair of public and private keys and then hash your public keys to form your Bitcoin address.

    img

    Then you send your Bitcoin address to the person who is going to pay you. You can use the mailbox, or put it directly on your website. This is safe, because your address is just a hashed public key, and you can be sure to make it public to anyone (no one can get your private key through it).

    Now the person who is ready to pay needs to create a new transaction. Let's look at a real transaction data that translates into 0.319 bitcoins. Below this is almost the original data, with three changes: 1) the data is not continuous; 2) the line number is added for better understanding; 3) a long string of hash data is omitted and only the first 6 digits are kept.

    1.  {"hash":"7c4025...",
    2.  "ver":1,
    3.  "vin_sz":1,
    4.  "vout_sz":1,
    5.  "lock_time":0,
    6.  "size":224,
    7.  "in":[
    8.    {"prev_out":
    9.      {"hash":"2007ae...",
    10.      "n":0},
    11.    "scriptSig":"304502... 042b2d..."}],
    12. "out":[
    13.   {"value":"0.31900000",
    14.    "scriptPubKey":"OP_DUP OP_HASH160 a7db6f OP_EQUALVERIFY OP_CHECKSIG"}]}
    
    • Let's explain it one by one.

      The first line, transaction hash value ((16 entry system), is the only tag used to represent this transaction.

      The second line tells us that the transaction uses the first version of the Bitcoin protocol.

      Lines 3, 4, tell us that the transaction has an input and an output.

      The fifth line, a lock time, can be used to control when the transaction is completed. Most Bitcoin transactions now have a lock time of 0, i.e. the transaction is completed immediately.

      Line 6 tells us how many bytes the size of the transaction is, note that this is not the transaction money.

      Lines 7 through 11, this section defines the input part of the transaction, exactly, lines 8 through 10 tell us that the input value of the money to be moved is the money from the output value of the previous transaction. That 2007ae... is the hash value of the 16th-order hash value of the previous transaction, used to point upwards to a transaction.

      It is noteworthy that the input part here does not say how many bitcoins from the previous transaction will be transferred to the next one. In fact, all the bitcoins in the output of n = 0 in the previous transaction have been transferred. For example, if the first output of n = 0 in the previous transaction had 2 bitcoins, then both of those bitcoins would be spent in this new transaction.

      Lines 12 to 14, this section defines the output of the transaction. Specifically, line 13 tells us the amount of money output, which is 0.319 bitcoins. Line 14 is more complicated, and it is worth noting that the string a7db6f... is the address of the bitcoin collection.

      Now, you can see how Bitcoin solves the problem of where the serial numbers come from that we mentioned earlier. First, Bitcoin is not a separate individual coin, but a long string of transactions that exist on the blockchain. Second, in this way, we don't need a central authority to issue the serial numbers.

      We can keep going back and forth along the chain of transactions. At the end of the day, there are two possibilities: first, you might end up with the first bitcoin transaction, which is in a block, which we call the Genesis block. This is a special transaction, it has no input, only 50 bitcoins are output. In other words, it is the earliest bitcoin supply.

      The second result you see going back and forth in the transaction chain is that you arrive at a transaction known as a coinbase hash. Except for the Genesis block, each block starts with a special coinbase transaction. This transaction is used to reward miners who verify transactions in the block.

      It is not clear what exactly is digitally signed in the 11 lines described above. The most obvious approach is to have the payer digitally sign the entire transaction. For now, this is not the case, and some transactions are ignored. This makes part of the transactions plastic, which means that they can be modified later.

  • There are multiple input and output transactions

    In the previous section, we talked about a transaction that has only a single input and a single output. In fact, most Bitcoin transactions have multiple inputs or multiple outputs. Let's look at the raw data for this transaction first.

    1. {"hash":"993830...",
    2. "ver":1,
    3. "vin_sz":3,
    4.  "vout_sz":2,
    5.  "lock_time":0,
    6.  "size":552,
    7.  "in":[
    8.    {"prev_out":{
    9.      "hash":"3beabc...",
    10.        "n":0},
    11.     "scriptSig":"304402... 04c7d2..."},
    12.    {"prev_out":{
    13.        "hash":"fdae9b...",
    14.        "n":0},
    15.      "scriptSig":"304502... 026e15..."},
    16.    {"prev_out":{
    17.        "hash":"20c86b...",
    18.        "n":1},
    19.      "scriptSig":"304402... 038a52..."}],
    20.  "out":[
    21.    {"value":"0.01068000",
    22.      "scriptPubKey":"OP_DUP OP_HASH160 e8c306... OP_EQUALVERIFY OP_CHECKSIG"},
    23.    {"value":"4.00000000",
    24.      "scriptPubKey":"OP_DUP OP_HASH160 d644e3... OP_EQUALVERIFY OP_CHECKSIG"}]}
    
    • As before, we explain the line by line, most of which is the same as the one just mentioned.

      The first line, the hash value of the transaction, is used as a unique identifier of the transaction.

      Line 2, version of the Bitcoin protocol, first edition.

      The third and fourth lines say that there are three inputs and two outputs in this transaction.

      Line 5, lock time ((as before) ⇒

      Line 6, the byte size of the transaction.

      Lines 7 to 19, which define all inputs, each corresponding to the output of the previous transaction. The first input is lines 8 to 11; its content form is the same as before. The second input is lines 12 to 15; the third is lines 16 to 19.

      Lines 20 to 24 define all outputs, the first outputs are lines 21 and 22, and as before, line 21 says there are 0.01068 bitcoins in it. Line 22 is a scripting language for a bitcoins. String e8c30622... is the address of the recipient.

      It seems a bit odd that although each output records the number of bitcoins, the input does not. Of course, how many bitcoins can be obtained from each input from its previous transaction. In a typical Bitcoin transaction, the sum of all the inputs is greater than the sum of the outputs (except for the Genesis block and Coinbase transactions just mentioned), and if the sum of the inputs is greater than the outputs, then the excess bitcoins are provided as a transaction fee to the miners in the block where the transaction takes place.

      The role of multiple inputs and outputs is to find zeroes. Suppose I want to give you 0.15 bitcoins. I can spend the 0.2 bitcoins I received before. Of course, I don't want to give you all 0.2 bitcoins, so the solution is that I send you 0.15 bitcoins and then send 0.05 bitcoins to my other bitcoin address.

  • The ending

    The basic concept behind Bitcoin is already described. Of course, I also ignore many details. This is not a formal manual after all. But I want to describe the concept behind Bitcoin that is commonly used.

    While the rules behind Bitcoin are simple and easy to understand, that doesn't mean that all the possible outcomes of these rules are easy to understand. There's a lot more to be said about Bitcoin, and I'll elaborate on some of it in a later article.

    How anonymous is Bitcoin? Many people say that Bitcoin can be used anonymously. This claim was made on a black market similar to Silk Road. However, this claim is fictitious. The blockchain is public, which means that anyone can see all Bitcoin transactions. Although the Bitcoin address does not directly correspond to the identity of a person in the real world, computer scientists have done a lot of work to decipher the anonymous social network.

    You can get rich with Bitcoin? Maybe, Tim O'Reilly once said, "Making money is like a pump in a car that you need to pay attention to, otherwise you'll get stuck on the side of the road, but life doesn't revolve around a gas station!" Well, most of the interest in Bitcoin seems to come from people whose goal in life is simply to find a big gas station. I have to admit, this is confusing.

    Details I've overlooked: While this article describes the main concept behind Bitcoin, there are many details I didn't mention. One of them is the great space-saving trick in the protocol, based on a data structure called a Merkle tree. It's a detail, but it's an incredibly cool detail, and it's worth checking out if you like the data structure. You can learn about it from the Bitcoin white paper.

    Bitcoin Script: In this article, I explain Bitcoin as an online electronic currency. But this is only a small part of a larger and more interesting story. As we have seen, there is a Bitcoin script language in every Bitcoin transaction. The script is simplified in this article to something similar to this: "I'm going to give Alice 10 Bitcoins to Bob". But the script language can also be used to describe more complex transactions.

    If you find it helpful, I recommend that you tip the original author of this article, Michael Nielsen, at 17ukkKt1bNLAqdJ1QQv8v9Askr6vy3MzTZ. You can also follow him on Twitter.

    Welcome to the translator's microblog: 1015 Please excuse any inconvenience

This article is adapted from the booklet Young People Ask.


More