Hacking Book | Free Online Hacking Learning


on the operation principle of bitcoin

Posted by graebner at 2020-02-27

Some time ago, wannacry pushed bitcoin to a climax. I decided to have a deeper understanding of bitcoin and came to the conclusion that this article is suitable for readers with zero base or little understanding of bitcoin. //All the pictures in this article are from the Internet

A kind of virtual electronic cryptocurrency, using P2P technology, decentralized, highly anonymous, no trust, distributed ledger, entity equivalent to ledger, transaction record equivalent to currency.

1. Bitcoin address: This is the only information you need to provide when someone pays you bitcoin. For example, 1exspdxa9bq6znxru23eubhjfuhinjwso (first 1) has a strong correlation with the public key. It can be considered that the address is the public key. It is recommended that bitcoin holders set an independent address for each transaction to protect the privacy and security of the account. 2. Block: a block is a collection of transaction data, which will be marked with time stamp and unique mark (hash value) of the previous block. After the block is hashed, a proof of workload will be generated to verify the transactions in the block. Effective blocks will be added to the blockchain after the consensus of the whole network. On average, about every 10 minutes, a new block containing transactions is added to the blockchain through mining. 3. Blockchain: a series of verified blocks, each of which is connected to the previous block, all the way to the first block, and shared by all bitcoin users. It is used to verify the permanence of bitcoin transactions and prevent double consumption. 4. Proof of workload: refers to a small piece of data obtained through effective calculation. As for bitcoin, the miner must solve SHA-256 algorithm under the condition that the whole network target difficulty is met, and calculate the lucky number mentioned below, so that there is a specified n zeros at the beginning of the value after block SHA-256, and this n has a change mechanism to maintain 10 minutes to produce a new block, and the difficulty increases with the increase of miner. 5. Mining: include the transaction data to be confirmed into the block chain, so as to complete the confirmation of these transactions. Miners can get the handling fees included in the confirmed transactions, as well as the newly created reward bitcoin (currently, August 2017 is the 5btc reward). In short, it is to receive transaction information and build blocks. 6. Miner: each network node that generates workload proof through repeated hash (SHA-256) operation. 7. Confirmation: when a transaction is included in the block, we can say that it has one confirmation (about 10 minutes). For each block that the miners generate after this block, the number of confirmations for this transaction is increased by one. When the number of confirmations reaches six or more, it is generally considered that the transaction is relatively safe and difficult to reverse. 8. Dual consumption: if a malicious user tries to pay bitcoin to two different payees at the same time, it is called dual consumption. 9. P2P: P2P network (peer-to-peer for short), also known as peer-to-peer network, also known as point-to-point network. This is a kind of Internet system without central server and completely exchange information by clients. A client is both a client node and a server. An important goal of P2P network is to provide all clients with resources, including bandwidth, storage space and computing power.

I have read some articles on the Internet to explain the principle of bitcoin in the form of metaphor and story. I think that although it is easy to understand, it will inevitably deviate from the real principle and cover up some details, so I will analyze the operation principle of bitcoin with a complete bitcoin transaction process next. //It is recommended to first understand the public key encryption, hash, digital signature and other related pre knowledge. Take Alice, the two protagonists of cryptography, as an example to Bob 5btc. Alice and Bob first generate the key pair (public key and private key, elliptic curve) with the client (bitcoin wallet). The client will download all the transaction records of bitcoin to verify the balance. The public key forms bitcoin address through one-way encryption hash function (sha256 and ripemd160) and encoding (base58check). If conversion is not considered here, then the public key is bitcoin address (collection address). The private key is randomly generated by bitcoin wallet and used for digital signature. Because the number of private keys is extremely large, it can be considered that it will not be repeated, and it should be kept secret and not disclosed Leakage is equivalent to the loss of a real wallet. When someone else has your private key, they can push out the public key and use the bitcoin in your bitcoin wallet. Input: TxN: the source of the transferred amount of the transaction scriptsig: Alice's digital signature output: amount: transferred out The bitcoin system needs to find out the public key in Alice's last transaction through TxN, and then verify with Alice's private key in scriptsig. Only after the verification is successful can Alice have the right to use the 5btc. Alice's digital signature proves that the transaction is sent by Alice and is associated with a unique ID of the transaction information, which avoids forgery and tampering. After the transaction, the whole network will be broadcast, and one node will notify other nodes nearby. In a short time, all nodes in the whole network will receive the transaction. After receiving the transaction, each node will first put the transaction into memory, and then carry out the legitimacy test on the transaction. After the test is passed, an unconfirmed transaction will be formed. The transaction will enter the effective transaction pool and wait to be loaded into the block. In bitcoin network, the miner node will extract nearly one thousand unconfirmed transactions from the effective transaction pool in memory, and then package (block). Start to calculate the lucky number continuously (key point 1: how to calculate? ) When a node calculates the lucky number, it assembles the information used to calculate the hash value into a new block, records it on its own hard disk, and initiates a network wide accounting. After receiving the broadcast message, the surrounding nodes also record the new block. Because the miner node uses the text containing the hash value of the previous block to calculate the hash value of the current block every time, it is difficult for the blockchain to be forged. Miners need to listen to every transaction. Ordinary users only need to listen to the calculated new block (key point 2: what if their blockchain is split?). At this time, the block where Alice gave Bob 5btc's transaction record was calculated lucky number by a miner's node, broadcast the whole network, and then add it to each node's blockchain, but it will take about 60 minutes (6 confirmations) to confirm that the transaction is true and reasonable, and the blockchain of this exchange in the block is recognized as the global blockchain in bitcoin network. This completes a bitcoin transaction. Key point 1: how to calculate the lucky number to combine nearly 1000 transactions in the effective trading pool (including the transaction records for which you are rewarded), the hash value calculated in the previous block, and the lucky number parameters into a text, and then calculate the hash value of this text. The hash algorithm used here is SHA-256. The lucky number is guessed by continuous brute force guessing, so that there are n zeros in front of the hash value of this text. This is the proof of workload. This n has a change mechanism. It takes about 10 minutes for the whole bitcoin network to guess the lucky number. This is the process of mining. Miners who have successfully calculated the lucky number will be rewarded with bitcoin. Key point 2: what if your blockchain is split? I believe that the maximum workload is the blockchain with a long fork. So you don't need to trust the listening blocks immediately. You can listen to about six more blocks. If there is no longer fork, it means that this chain is the recognized chain of bitcoin network.

Let's first review the composition of the block, the hash of the previous block + a bunch of transactions + lucky numbers. Suppose Alice pays 5btc to Bob as well as 5btc to her other wallet (suppose Alice has only 5btc). At this time, the lucky number of the first reasonable trading block is calculated to join the blockchain, and Alice is not willing to be outdone. With her own computing power, she calculates the lucky number of the second deceptive trading block (Alice has super luck at this time), thus forming two different Branching blocks, the hash of their previous block is the same. Then the miners continue to calculate the lucky digital production new block and add it to the blockchain. Because bitcoin rules believe that the longest chain is the one with the largest workload, Alice will continue to calculate the lucky digital production new block for the sake of its own fraudulent transactions. Unless Alice has super powerful computing power and can defeat the computing power of all miner nodes with the power of one node, that is, 51% attack, after multiple confirmations, Alice's calculated fraud bifurcation will be denied.

In short, the private key should be protected in all aspects.

1. For every 210000 blocks, the number of BTCs that people who produce new blocks are recognized to obtain by air is half less than that before. Now (201708) is 5btc. 2. From 1 can only, the miner will not be able to get rewards out of thin air finally, then how does the miner's income come from? The answer is transaction tax. In order to make their transactions be added to the block as soon as possible and finally confirmed by bitcoin network as soon as possible, the trading party will add the tax to the miners in the transaction records, encouraging the miners to add their own transaction records to the block as soon as possible. 3. Bitcoin will eventually reach a total of about 21 million. 4. If the private key (no backup) is lost due to the crash or damage of the computer, then no one can transfer the bitcoin they own and it can't circulate, which means it will disappear forever. 5. The upper limit of a block transaction record is about 2400 transactions. 6. I recommend you go to see the original paper of bitcoin. 7. Attach two brain maps found on the Internet. It's very good

In fact, there are many others, such as bitcoin money laundering, investment, gambling and so on. As for the use and mining of bitcoin, I may write a separate article to introduce them. I am not very talented, and there may be mistakes and omissions in the article. Please correct them! Exchange and study together! If you think the article is good or helpful, like it. Your support is my driving force!

Oin.it/wiki/protect your wallet