Block chain question and answer day2

Block chain question and answer day2

How autonomous block chain is reached? Why can freely exchange data securely to trust in the environment?

Block chain has many nodes contain malicious node, a node failure, normal nodes, those nodes you want to make a joint decision on the need for a consistent set of common mechanisms to resolve.

In 1982, the famous computer scientist Lamport proposed Byzantine generals problem: the Byzantine Empire sent a few troops attacking a castle, if these generals have led traitor, at only rely on messengers to communicate, how to ensure loyal generals at the same time, precise action? The essential problem is to say: in a distributed computer network, if there is a fault and malicious nodes, the network is able to maintain the consistency of normal nodes. In the nearly 40 years time, many solutions have been proposed to solve this problem, called Byzantine fault tolerance method. After Lamport own example presented an oral agreement, a written agreement law, was then proposed a practical algorithm for Byzantine fault tolerance PBFT, in 2008, Nakamoto Bitcoin invention, people conceived to address this issue through the block chain .

What is a brief overview of the Byzantine generals problem (BFT, Byzantine fault tolerance)?

The problem is that there is a strong castle, requires a number of generals in different locations (only communicate with the messenger) while the fall in order to attack it, then what kind of method requires the use, in the presence of General traitors, all the generals reached unanimous decision to attack the castle.

Suppose there are seven generals in making decisions, in the absence of a traitor way voting can be used to make decisions, as long as more than half of the voting generals attack then attack together, otherwise retreat together, without causing part of the general offensive part of the general retreat lead case loss.

But if the seven generals in the presence of a traitor, appeared three times in the vote: Case 3, then traitor will tell three generals of offensive support I support the attack, but told the other three generals supported retreat, I support the retreat. So in the eyes of the general voting results support three offensive is 4: 3 to support the attack, in support of the withdrawal of three generals in the eyes is 3: 4 support withdrawal. Such traitor successfully reached its purpose, undermine the decision-making generals consistency and correctness.

How do BFT maintain consistency and correctness?

  • General - adjutant model

    Defector set number is m, n is the total number of general

    Problems require:

    1. All loyal lieutenants are to comply with a command, namely consistency.
    2. If the sender is loyalty, each loyal lieutenant comply with its order issued, that is correct.
    • oral agreement

      Verbal messaging during the default number of conditions:

      1. Each transmitted message can be correctly delivered.
      2. Information is the recipient know who sent the message.
      3. To know the lack of news.

      Under these three conditions it will not default traitor truncated message, and others will not be traitors forged information.

      Suppose there are three general a, b, c, c is a traitor, a is the sender. A sends a b, c attack command, b because they do not know is not a traitor, received a command after it receives an inquiry to c what order, because c is a traitor, it tells it receives is b evacuation orders, this time b hand received the attack and evacuation orders are 1: 1, b know there must be between a and c is a traitor, but I do not know who is, you can not execute a command. This can not reach a unanimous decision.

      Suppose there are four general a, b, c, d, c is a traitor, a is the sender. A sends a b, c, d attack command, b because they do not know is not a traitor, he asked c, d receive what command, c as a traitor told b is received evacuation orders, d tell b the attack command is received. At this time b hand attack and received evacuation orders is 2: 1, then b can determine the command to be executed attack, also received the same d attack and retreat command is 2: 1. Thus a, b, d agreement reached a command, and a correct execution of the command.

      So verbal agreement to solve the problem Byzantine needs to satisfy a condition: if the total number of m traitor general must be more than 3m + 1.

    • Written messages

      Written messaging protocol required orally and appends a three conditions:

      1. The signature can not be forged or tampered with once can be found; anyone can verify the signature of the general reliability.

      Each command is issued in a written agreement and will bring forward the issue and forwarded's signature in the back, hands each General has received an order to hold a collection of the type (not quantity), when the generals receive a message, If the command type is not a collection of this command will put into the collection in their own, and if this command has not been signed over the other generals, will be forwarded to the other generals. Until all the generals no longer after receiving the news, the judge set of hands, General, if the collection is consistent then it will make the same choice.

      Conclusion: In the way of a written message, will be able to make loyal generals agree, but the results are not necessarily correct.

How Bitcoin system work?

When Alice Bob want to transfer, to start her own purse which payment address to find the private key , using the private key of the deal once a signature to prove that the deal was initiated by Alice himself. By asymmetric encryption algorithm , anyone on the network can use the public key to validate the deal, indeed belong to Alice's.

Alice used wallet is a file that allows users to access multiple Bitcoin address. Each address is a string of a string of letters and numbers. Each address has its own Bitcoin balance.

Bob receives Alice payment is required to generate a payment address , generates an address actually generate a key pair consists of a private key and a public key. Private key held by themselves, not for others to see, the public key can be for all to see, Bob's payment address corresponds to a unique public key, the private key is stored in Bob's wallet.

Bitcoin users can create as many addresses, and incentives for each new transaction to create a new address alone, in order to enhance privacy. As long as no one knows what address is Bob, and his anonymity will be protected.

Fair Alice is submitted miners packaged into a new trading block, this block which contains the transaction within the last 10 min. Miner's job is to calculate a cryptographic hash function. Computer-based miner hash value from the previous block, new trading block and random number to calculate the new hash value. Because the hash value of the hash value of a block former and new trading blocks are the same, only the random number can vary, so the miners in order to achieve the required format hash value (as must begin with a certain number of 0) , generates a random number to keep the recalculated hash value to meet the requirements.

After successful generation block, Alice to Bob's transfer was saved to the block chain which, in each block will have a sum called the initial transaction Coinbase, which is to reward the miners dug block. Anyone who wants to change the historical transaction details, it is necessary to be redone for the winning work of miners, and then redo the work of the miners to win the next one block to calculate the amount of such operations will be very huge so basically impossible .

Overall system Bitcoin six parts:

  1. Wallet and address
  2. New Address
  3. Private and public keys
  4. Submit payment
  5. Verify the transaction
  6. Transaction Confirmation

How purse address is generated?

  1. Using a random number (256 bit) as the private key, you need to save safely.

  2. Prefixed by SECP256K1 generated public key algorithm (512 bit)

    secp256k1 by ( Standards for Efficient Cryptography ) customized Elliptic Curve signature algorithm, the bit popular coin before the algorithm hardly been used. Most commonly used curve having a random structure, but secp256k1 is more efficient to calculate constructed of a non-random structure. Therefore, if the algorithm is implemented by the rational optimization, which may be faster than other computational efficiency curve than 30%. Meanwhile, with the conventional NIST curves different constants secp256k1 is selected by a predictable manner, which can effectively reduce the possibility of preventing the back door disposed designer curve.

  3. Reuse SHA256 algorithm into the public key hash 256 bit string, the use of RIPEMD (RACE Integrity Primitives Evaluation Message Digest) algorithm RIPEMD160 the 256 bit hash value becomes 160 bit hash string

    RIPEMD-160 is based on the original version of RIPEMD improved version of 160 yuan, and RIPEMD series is the most common version. RIPEMD-160 is designed for the academic community to be used, just with respect to the NSA designed SHA-1 and SHA-2 algorithm. On the other hand, RIPEMD-160 used less than SHA-1, it may cause RIPEMD-160 review is not often than SHA. Further, RIPEMD-160, and there is no limitation patent.

  4. Finally, using the public key Base58 Check coded form readable string address

    Base58 encoding Base64 encoded subset removed 0 (digital), O (uppercase), L (lower case letters), I (uppercase letters) and the "+" and "/" symbol.

    Base58 Check process:

    1. In the public key hash of the header connector version number (bits credits for pubkey network address, the byte is "0"), forming "0x00 + hash of the public key"

    2. After "0x00 + hash of the public key" for double-SHA256 taken before treatment 4bit

    3. The removed former 4bit check code as address information, the public key hash is formed into the back "+ 0x00 + public key hash check code"

    4. The "+ 0x00 + public key hash check code" is formed into Base58 encoding human readable string address, address wallet

Bitcoin system What are the advantages and disadvantages?

Bitcoin system has the following bit.

  1. Without third-party intervention, reduce transaction costs, while the entire P2P network with reciprocity.
  2. Bitcoin security SHA256 encryption algorithm, there is no effective way to crack. All Bitcoin transactions are public on the web, help everyone to reach a consensus, and can effectively prevent illegal activities. Generating token bits and authentication mechanisms also make it impossible to forge.
  3. Part anonymity, the main elements of the transaction wallet, address, anonymous user in the whole state. The reason why part anonymity, because all transactions are posted online for all to see. Combined with its big data analysis, it is likely to guess the true identity of certain users.
  4. Bitcoin limited supply, non-inflationary risk. Design Bitcoin system modeled on a little gold supply, which is the upper limit for the amount of 21 million, the central bank can effectively prevent inflation caused by spamming.

Meanwhile, there are some drawbacks bit credits, as follows.

  1. Transaction confirmation time is too long. 10 min to produce a block that is generally wait six blocks may confirm the transaction irreversible. In this way, confirming a deal to wait for 1 h, so much time cost can not be ignored. So now take the form of a number of small transactions are zero confirm payment.
  2. Block capacity. There is a full node hard physical size limitations (i.e., the maximum of each block 1 MB), therefore, generated per 10 min 1 MB block, divided by the average size of each transaction record can be drawn about the current limit 7 transactions per second, 600,000 pen transactions every day. When trading volume reached this threshold, did not have time to confirm the extension of trade fairs confirm the time.
  3. Turing poor block chain. Bitcoin block chain in the contract simply does not have the ability to become a free intelligent contracts. To solve this problem, block chain representing 2.0 Ethernet Square came into being.
  4. Single workload proof mechanism. Workload proof mechanisms bit credits based on the whole network operator force is 51% or more are honest. But if some groups can combine more than 51% of the force calculation of the Bitcoin system attack is also theoretically possible.

How bitcoin the P2P network set up?

Run Bitcoin Bitcoin P2P protocol the network is run by 7,000 to 10,000 different versions Bitcoin core client listening nodes and hundreds of kinds of running Bitcoin P2P protocol applications (such as BitcoinJ, Libbitcoin, btcd, etc.) nodes. Bitcoin P2P network node is part of mining nodes, which compete mining, verify the transaction and create a new block. Many large network of connections to Bitcoin Bitcoin-based company runs the core client-wide client nodes, and they have a complete copy of the network node block chain, but do not have the mining and wallet functions. These nodes are edge routers in the network, you can set up other services through them, such as exchanges, wallet, block browser, merchant payment processing (Merchant Payment Processing) and so on.

Bitcoin network structure does not include geographic information and geographic information between nodes thus completely independent.

Node connection process:

  1. 8333 port is generally used to establish a TCP connection

  2. The new version messaging node contains a basic certification content start by sending a "handshake"

    Messages include:

    • P2P protocol version (PROTOCOL_VERSION)
    • This node supports local service list (nLocalServices)
    • The current time (nTime)
    • The other node IP address (addrYou)
    • This node IP address (addrMe)
    • Bitcoin software version (subver)
    • This node of the current block height of the block chain (BassHeight)
  3. Peer node in response to the confirmation message verack and establish a connection, if the receiving node need to be interchanged and connected back to the start node is connected, also returns the peer version of the message

  4. Node discovery process:

    method one:

    Use seed node (Seed the Node) , Bitcoin client will maintain a list of long-term stability of nodes containing, called seed node. Core bits typically with five credits different seed node, but not necessarily be connected with the seed node, the user can set the opening and closing may also be provided a fixed IP address list to be replaced. Use seed node can quickly find other nodes in the network.

    Method Two:

    Find other neighbors as seed node through a known node. When the new node discovered new neighbor node, the new node will generally disconnected and seed point. The new node sends its own address information to the neighbor, the neighbor then came the address information to its neighbors, the address of the new node is found in other nodes in the network.

    The new node will be sent to a getaddr information, neighbor neighbor will own a known address information to the new node. Usually the new node maintains a connection with eight neighboring nodes. Neighbor address information after the end of the new node to start the process of discovery in mind, when you start again if the address information is invalid will be re-started the process.

  5. Periodically transmits the connection state information holding establish connections between nodes. If the connection node and a neighbor node does not link more than 90min, by default, the neighbor off the assembly line, looking for a new neighbor node with the connection.

Guess you like

Origin www.cnblogs.com/nykuvl/p/12078580.html