[written to programmers] Bitcoin popular text

Source: Internet
Author: User
Tags asymmetric encryption

Blockchain is one of the current technology hotspots, some people compare it with the internet, and some people claim that the blockchain has no future. There are companies and individuals who have tried to apply it to other areas of the world, when most people's understanding of the blockchain still rests on the concept of cryptocurrency and other cryptographic digital currencies. To make a reasonable assessment of a thing, a more in-depth understanding is essential, and the faster way to learn is to start with a specific application. Now the most well-known and "success" of the blockchain application is still the birth of the bitcoin, there is no shortage of popular science of Bitcoin, but I think, these articles are either too abstract, or write too popular, after reading can get a few concepts, but to deep want to go down or confused. This post is for the company's training to do the PPT finishing, mainly elaborated the core concept of Bitcoin, PPT for the company, remove the necessary knowledge of the programmer to organize into this blog post.

Note: This article is intended to help you understand the Bitcoin [& blockchain], so there is a deliberate simplification of some concepts that do not guarantee that the description and the actual scenario are exactly the same. Key points are shown in bold.

Blockchain = Block collection with chain as a string

There's no objection to that, so what does the chunk contain? For the time being, it can be considered as follows:

Focus on the hash value , its figure throughout the blockchain always. There are many kinds of hash functions, in SHA256, for example, the output has 2256 kinds of possible (training cost the eldest to let everyone on the size of this number has a perceptual understanding). The feature of the hash function is irreversible, that is, given a hash value, it is virtually impossible to derive the corresponding input. This feature allows it to have tamper-proof features, such as The block is broadcast and determined by other nodes, if you change the other fields in the block (such as the transaction bitcoin amount, stored in the data field), the new data will be computed by the hash value ≠ the original hash value, then this chunk must be problematic. We protect the security/legality of the block in this way.

At present, one of the key applications of the blockchain is the anti-tampering and correlation calculation.

What about the security of the data itself? As is known to all, the [public] blockchain is anonymous, so how to know who the data belongs to, who can access the data, here leads to the concept of the key.

Key: A rule for encryption and decryption

It can be divided into symmetric and asymmetric encryption according to whether the encryption key and decryption key are the same. You must be very familiar with them, their advantages and disadvantages in the pure encryption and decryption here does not elaborate, in efficiency, the former is generally higher than the latter. So we use asymmetric encryption instead of encrypting it, but in order to use the benefits of its "asymmetric" feature, many scenarios are used, such as invoking a third-party openapi, or a more complex OAuth authentication process, where the caller invokes the message with the private key signature. The service party uses the caller's public key to verify the caller's legitimacy. This feature makes anonymity and de-centering possible, and a single Bitcoin transaction can be as follows:

XX will 1000B into Bob's account (that is, with Bob's public key encryption), Bob's private key is decrypted and removed

The public key does not need to contain any of Bob's personal information, so while others can use the public key to bind data to this "account", it is no longer necessary for them to know exactly who the public key belongs to (unless the public key owner exposes personal information themselves); As long as someone can solve it, That means that the person has a corresponding private key, that is, his identity is legal (if he gave the private key to others, there is nothing to say). Thus, an anonymous transaction was completed.

Of course, the above illustration is very non-rigorous. First, the Bitcoin network is a closed loop, and Bob can't take the Bitcoin out (have you seen bitcoin long?). ), of course, can not be actively deposited, which is similar to our only on the ATM machine account transfer between the operation, but not to cash out; that Bob's private key to decrypt the bitcoin to where, or, originally this money in the "public key" to stay good, take and not out, you get it out of what to do? The answer is that when Bob is going to put money into someone else's public key, he's going to transfer it with his private key, and that's how it was before XX was transferred to Bob. So the more accurate diagram is as follows:

Bitcoin's trading chain

Now let's look at how the encryption and decryption process in Bitcoin is specific.

First we put the deal to it structured, can be simply understood as: trade = My money transferred to you = My money + to you.

By the know: my money = I use the private key to solve the other people transferred to my public key money = Others transferred to the public key of the money + I use the private key out; transfer to you = How many to your public key.

Translated into data structures, examples are as follows:

    {from        : {            previous transaction  ' 7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18 ",            key: Private key decryption (to prove that I have the money transferred from the last transaction)        }, to        :            {" 8ae4538afc617cd284d36d135fe09f1a0d2f42a22d890d548f6f65cda45e6f1d2 ",            0.01500000,            lock : Public key encryption (only the correct decryption to get the money transferred        )}    }

We call the key and lock of the above code the script . Lock and key can be considered as questions and answers, note that the key in from is the lock of the last transaction transferred to me. For example, XX turned a sum of money to Bob, at the same time set up a lock:1+1=? ——? is a placeholder, then replace with key--when Bob is going to spend the money, he must provide the correct key value (here is 2), otherwise it cannot pass the transaction verification of the node, and Bob also set the lock of the transaction, and so on. Key and lock are interchangeable, as long as the equation is set together.

By substituting the public key into the script, the following transactions can be constructed:

XX transferred to bob--

    {from        : ..., to        : {            "7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18" ,                         Lock: The public key of the transfer party        }    }

Bob transferred to alice--

    {from        : {            "7957a35fe64f80d234d76d83a2a8f1a0d8149a41d81de548f0a65a8a999f6f18",            ? Decryption (ciphertext after the hash of this transaction) = hash value of this transaction        }, to        : ...    }.}

Node Check Bob to Alice this transaction will merge the last trade lock with the current trade key, here is: the transfer party's public key decryption (private key encryption (hash value of this transaction) ciphertext) = The hash value of the transaction. Easy to get, if the public key is a pair, then the equation is established.

The so-called node, we can understand for the daily heard of Bitcoin miners. They are constantly collecting deals and packing them into chunks, and the process is "digging." Mining = Creating a valid block , the process is as follows:

    1. After the transaction is verified correctly, the node puts it into the local "unacknowledged trading pool";
    2. Node Select some or all of the non-confirmed transactions (generally select the relatively high commission of the Transaction, Commission =from the amount of-to, you can adjust their change, such as XX to BOB10 block, Bob to Alice8 block, Turn yourself the change 1.5, then the Commission is 0.5, and put in the local temporary block;
    3. Calculates the temporary chunk hash value.

The ID of the previous block in the graph takes the ID of the active block at the bottom of the blockchain. The calculation of the hash value is an instant thing, if the transaction data enough, that every second can produce trillions of blocks, so, the throughput of the leverage. But billions of blocks of data may not be the same (depending on the node's own choice), not to mention the same transaction is packaged by multiple nodes, for the consistency of the ledger, we need to avoid the chain branch (fork), can be added to the end of the chain can only be one block, that can only admit that one chunk is valid. So how to select this chunk and let the other nodes be convinced, this is the consensus algorithm needs to solve the problem.

The consensus algorithm used in bitcoin is POW, proof of work, proof of workload. Specific to the implementation, is to improve the calculation of the hash value of the difficulty of this link. How to improve it?

Satoshi says that the hash value you calculate must conform to certain rules, such as the number of "9ce4538afc617cd284d361d53fe09f1a0d2f42a26d890d548f6f65cda45e6f1d2", So, Your chunks can be recognized.

As a remark, the miners have to spit: Wow, the great god you do not understand, the data (trading) I packed all, out of the hash value can change? You said RePack? Choose a low commission test? Please don't show up.

Satoshi said, "OK, give you a field, the field can be arbitrary to take the number, you will be included in the hash value calculation, the value of the field will inevitably affect the hash results, so that, as long as the correct random number , then can get the specified results, then, the block can be recognized."

Now, mining becomes: new active block = calculated hash value conforming to rule = Get a random number that matches the calculated hash value to the rule

The rules are:

We know that 2256 is a very large number, to find a random number (in order to cover the entire output range, the random number is also the same magnitude), so that the result is exactly equal to one of the current computer capabilities, to the end of time may not be able to find. So this rule is too difficult to define.

Well, let's make a very difficult rule, as follows:

As long as the hash results fall into a specific interval, the difficulty of quantification is self-evident: if the red zone fills the entire bar, then the difficulty is the lowest, that is, any arbitrary hash values are satisfied with the condition, that is, the state of the first no rule; if it accounts for half, then the probability of every two times will be successful, difficult , if adjusted to one-, then the probability of a trial and error 100 million times. In other words, we can adjust the difficulty of calculation by adjusting the interval size. Bitcoin currently has an average of 10 minutes to get out of the block, and will automatically adjust the calculation difficulty according to the previous time out of the block, but not due to the hardware development and other factors caused the speed change. In addition, the random number of bytes is not very large, Bitcoin is 4 bytes.

In the mining, the nonce random number is unknown, to try from 0 to 232, but this number is not small, only 4294967296, to the current mining machine 14T per second of the calculation, all calculate to the upper limit also does not need a second, certainly can not cover the difficulty corresponding to the hash range. So we need to use the accompanying information in the coin trade, the extra string becomes the extra nonce, see what is the problem of Bitcoin mining in the calculation? Manually validate the blockchain to give an answer. As for why it is 10 minutes, this is a matter of opinion, some people say that considering the network delay, bandwidth, 10 minutes is a relatively appropriate time, also some people feel too long, such as LTC is 2.5 minutes. In fact, this is only the original Nakamoto a set, always set a time well, as long as not too short on the line you say is not.

After digging into the mine, the nodes need to put chunks into the chain. The node is broadcast to peer, the other node after receiving the validation block legitimacy, error after the block into its own local chain, while continuing to broadcast, and open the next round of mining competition. By peer, the local chain of all nodes can be consistent so that the de-centrality is achieved.

It is worth discussing that, in the time period when the new block is found to be confirmed by the network, if there are multiple nodes to find a valid random number at the same time, or if the node receives the mining success message from many other nodes, whichever is it? The answer is random, because in general this temporary bifurcation of the situation will automatically disappear with subsequent chunks, because the Bitcoin preferred to select the longest branch of the chain, unless it can ensure that the branches out of the same rate of block, otherwise there will always be a certain time difference, resulting in one of the branches become longer as the main chain, The remaining branches are discarded by the network (there may also be malicious nodes that maintain a short branch, increasing the power to figure out the main chain in the future, which involves a 51% attack ).

In a paper published by researchers at Cornell University, Ittay Eyal and Emin Gun Sirer, describes a scenario where you can successfully attack a bitcoin network with 25% calculation, see selfish mining:a 25% Attack against the Bitco In Network

Please specify the source of this article: www.cnblogs.com/newton/p/9496872.html

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.