The blockchain indeed originates from lottery and How to find it, and it is born to serve lottery and How to find it. On the other hand, the distributed accounting mechanism of the blockchain depends on the incentives of lottery and How to find it. It can be said that the blockchain and lottery and How to find it are twin brothers, to some extent, interdependent.
Why study the digitalization of currency?
Convenience;
Eliminate dependence on the central node;
The problems that need to be solved in lottery and How to find it (the key to solving these problems is blockchain)
Digitalization of accounts;
Digitalization of signatures;
Decentralization of accounting;
(Centralization means that the center determines the nodes, and the nodes must depend on the center. Without the center, the nodes cannot survive.)
The essential problem (the powerful tool to solve these problems is cryptography)
There is a secluded mountain village called Jade Village, where the main job of the villagers is to dig jade. The wealth of the village is also calculated in jade. The jade that everyone has dug is piled together, and the village chief comes to count and keep records. Zhang San, Li Si, and Wang Wu have their wealth recorded in the village chief’s ledger, and they can exchange them for other daily necessities. However, the village chief is somewhat unscrupulous. When keeping records, he writes more for beautiful rural women and less for troublemakers. Moreover, the ledger is often problematic in terms of storage, with some places getting damp and blurred, and others being chewed by mice. Even worse, the village chief’s son Zhao Liu often secretly alters the ledger. Therefore, the villagers decided to废除 the village chief who eats without working and often makes mistakes. So, who will keep the records? The villagers thought of a method: everyone carries a ledger. When someone finds jade, they record it and use the loudspeaker at the village entrance to notify everyone. Everyone writes the same content in their own ledger. Each villager keeps their own ledger, and in the future, direct exchange of goods and exchange of jade among villagers will also be recorded in this way. This not only saves the labor of keeping records but also avoids problems such as dampness in the ledger. Even if the widowed woman alters Zhang San’s ledger, everyone can compare it with Li Si, Wang Wu, and Sun Liu’s ledgers to quickly identify and correct the problem. As long as the number of villagers is sufficient, even if the widowed woman is powerful, she cannot alter the ledgers of more than half of the villagers. This is the decentralized distributed recording of accounts.
Li Si proposed a new question, ‘If I record the jade that has already been recorded again, won’t the wealth double and double quickly?’ To solve Li Si’s deception, the villagers came up with a method to mark each piece of jade, recording the time, location, person, and information of the previous jade that was dug up. Therefore, each villager’s account book records the complete information of each jade, and each jade is associated with the information of the previous jade, forming a chain. Li Si cannot concoct it out of thin air or change the previous records, which is the blockchain—P2P distributed accounting.
The decentralized idea of blockchain
After the reform, every villager in the jade village has an account book, and each account book records the information of the jade dug up by the villagers, abandons the previous ‘centralized’ accounting method where only the village chief has the only account book, and adopts a ‘decentralized’ distributed accounting method where everyone has an account book.
The anti-tampering idea of blockchain
Each villager’s account book is marked with each piece of jade, recording the time, location, and person when the jade was dug up, as well as the information of the previous jade that was dug up. Each piece of jade is associated with the previous piece of jade, forming a chain, so that no one can concoct it out of thin air or change the previous records, thus achieving anti-tampering.
The idea of public and transparent transaction information
After the villagers dig up jade, while recording it in their account books, they also use the big loudspeaker at the village entrance to notify everyone. Everyone writes the same content in their own books. All villagers have a complete set of jade information, and they can随时翻阅自己的账本,对记录的玉石信息进行查询.
The idea of consensus
When a villager finds that there is an error in the record of jade information and needs to be corrected. At this time, at least 51% of the villagers must agree to modify this record. In other words, only when at least 51% of the villagers agree with this piece of jade information, can it be recorded in each person’s 100% account book. This reflects a very simple consensus idea.
The establishment of Crypto-Punks
In 1992, Tim May, an advanced scientist at Intel, gathered with friends at his home. At the gathering, they discussed how the internet should better protect people’s privacy. How can the privacy of people worldwide be protected so that it is not exploited by the malicious? They formed a group: Crypto-Punks. Eric Hughes wrote a program that could receive encrypted emails, erase all identity tags, and send them back to the user list. When you sign, you will receive Hughes’ reply. In 1993, Eric Hughes and others upgraded and iterated the encrypted email system, directly renaming the system to ‘Crypto-Punks’. Ecash
David Chaum invented the cryptographic anonymous cash payment system, Ecash. Chaum believed that a distributed, truly digital cash system should encrypt people’s privacy. Therefore, his system used mathematical encoding for encryption. There is also a small feature that the payer is anonymous during payment, but the payee is not anonymous. HashCash
In 1997, Adam Back invented HashCash, using the proof of work system. In fact, Adam Back initially invented this system to solve the problem of spam emails, that is, to avoid others sending emails containing the same information. His proof of work system solved a major problem of lottery and How to find it: how to ensure that lottery and How to find it is not traded many times? This requires computers to perform a certain amount of work before obtaining information to avoid duplicate transactions. The concept of timestamp
Timestamps ensure the security of lottery and How to find it, ensuring the sequence of files. It is required that files cannot be altered after creation. When an Online casino and How to find it is traded, it is timestamped and cannot be altered. In the blockchain system, every new block is timestamped, ultimately connected in sequence according to the generation time of the blocks.
The birth of Bitcoin
Satoshi Nakamoto optimized Ecash, integrating timestamp, proof of work mechanism, asymmetric encryption technology, and UTXO structure, ultimately inventing Bitcoin. People refer to Bitcoin’s underlying technology as the blockchain.
Blockchain technology has gone through three stages from its birth to the present.
Blockchain 1.0—–lottery and How to find it, represented by Bitcoin, is decentralized digital payment.
Blockchain 2.0—–Smart contracts, represented by Ethereum, support users to write smart contracts themselves and build decentralized applications (DAPPs).
Blockchain 3.0—–Extending to various fields, that is, applying blockchain technology to specific scenarios in various industries.
For Bitcoin, the significance of the blockchain is similar to that of the internet for email.
(1). Bitcoin does not rely on a designated currency issuing institution but is generated through a specific algorithm by a large amount of computation, which is known as ‘mining’.
(2). The total quantity is limited and possesses strong rarity. The total quantity of Bitcoin was permanently limited to 21 million at the initial setting by the system.
The essence of blockchain is a decentralized distributed ledger. Transactions that previously needed to be completed through banks or third-party payments can now be completed through a network composed of distributed nodes.
The formulation of transaction rules and system governance is jointly executed by the executive members, and each executive member has a ledger. After each transaction information is verified by the executive members, it is recorded in their respective ledgers. Therefore, the information recorded in each ledger is the same.
(1) Narrowly speaking, blockchain is a chain-like data structure that combines data blocks in chronological order and is guaranteed to be unalterable and unforgeable by cryptographic methods, forming a distributed ledger.
(2) Broadly speaking, blockchain is a new type of distributed infrastructure and computational paradigm that uses block chain data structure to verify and store data, consensus algorithms to generate and update data, cryptographic methods to ensure data security, and smart contracts to program and operate data.
In essence, a blockchain is a decentralized distributed ledger. If the blockchain is a ledger, then each block that constitutes the blockchain is a page of the ledger. Every time a new block is added, a new page is added to the ledger. The longer the blockchain, the thicker the ledger. This ledger exists in the hands of each node in the network, rather than being stored in a central node, and it is an open ledger that anyone can see.
According to whether the entry or exit of nodes requires approval, blockchains are divided into public chains, private chains, and consortium chains. (Nodes are the backbone of the network, used to verify and record transactions. Usually refers to computers, smartphones, mining machines, desktop computers, and servers in the blockchain network.)
(1). A public chain is an open blockchain where anyone can freely join or leave as a node in the network, and nodes work based on the consensus mechanism. It is truly a completely decentralized system.
(2). A private chain is generally used within enterprises, and the operational rules of the system, as well as the read and modify permissions of the nodes, are set according to the requirements of the enterprise.
(3). A consortium chain is a multi-centralized or partially decentralized blockchain, whose consensus mechanism is controlled by certain specified nodes. Generally, it is initiated by several institutions, such as within an industry, and it is between public chains and private chains, with some characteristics of partial decentralization.
Hash encryption algorithm, SHA256, was developed by the National Security Agency of the United States and released by the National Institute of Standards and Technology in 2001. Entering any string of data into SHA256 will result in a 256-bit hash value. Its characteristic is that the same data input will result in the same outcome. If there is any slight change in the input data (such as a 1 in the data changing to 0), it will result in a vastly different outcome, and the result cannot be predicted in advance. Specifically, the hash algorithm scrambles, mixes, and compresses the data into an abstract, making the data volume smaller and creating a fingerprint called the hash value.
The first is unidirectionality, hash algorithms must have unidirectionality;
It can only calculate a fixed-length hash value from the input data or message, and cannot deduce the input data or message from this hash value.
The second is that fixed-length hash values can be calculated based on messages of any length;
The length of the hash value generated by the hash algorithm must be fixed and tailored for input data of any length. This property ensures the ease of use of hash algorithms. Because one of the purposes of using hash algorithms is to represent the input data with the final hash value, then if the final hash value is very long, not fixed, or the same length as the original data, it is as laborious to verify the original data through the comparison of hash values as it is to directly verify the original data. The final length needs to be controlled at a fixed and appropriate value to reflect the characteristics of the hash value as a fingerprint or summary of the original data.
The third is that different inputs have different outputs;
One of the purposes of inventing hash algorithms is to meet this demand, and it has become one of the major characteristics of hash algorithms. It can realize the determination of data integrity and consistency; only the same data obtained through the same hash operation will have the same hash value. No matter the length of the input data, a fixed-length hash value will be generated, making the comparison results more fast and convenient. It is a very good verification method for data anti-tampering and anti-loss.
The fourth is that the algorithm is efficient, and the time to calculate the hash value is short.
It ensures that no matter how long the data is, the hash result can be obtained within an acceptable range.
Famous ones are the MD series and the SHA series. SHA represents Secure Hash Algorithm. It is an algorithm developed based on MD4 and MD5 and released by the National Security Agency of the United States as the U.S. government standard.
The hash function used by hash algorithms is a class of relatively mature hash functions.
Characteristics of hash algorithms:
It can be used for messages of ‘any’ length. The generated hash value is of fixed length. For any given message, it is easy to calculate the corresponding hash value of the message. It is not possible to deduce the input data or message from the given hash value.
(1) It is necessary to know the concept of hash pointer in the blockchain.
A regular pointer only saves the position of the structure in memory. While a hash pointer not only saves the position of the structure in memory but also saves the hash value of the structure.
The benefits are not only that the position of the structure can be found, but also whether the structure has been tampered with.
Hash computation can help identify whether the block data has been tampered with. The hash value of the blockchain can uniquely and accurately identify a block. Any node in the blockchain can obtain the hash value of this block through simple hash computation, and if the calculated hash value does not change, it means that the information in the blockchain has not been tampered with. In addition, hash computation can also help link various blocks into a blockchain. Each block contains the hash value of the previous block and the value of the next block, which is equivalent to being linked to this block through the hash value of the previous block and to the next block through the hash value of this block, thereby naturally forming a blockchain with a chain-like structure.
Hash operations can also encrypt transaction addresses.
The role of Merkle tree
First, it can quickly locate each transaction, as transactions are stored linearly, locating a transaction requires traversal, which is inefficient and slow. Through this binary tree, the desired transaction can be located quickly. Second, without storing the entire data, it can be clearly verified whether the transaction has been tampered with. From the transaction to each binary tree hash value, any change in a number will cause the root hash to change. At the same time, if there is an error, it can quickly locate the error location.
Characteristics of Merkle tree
Merkle tree is a tree-like structure with all the characteristics of a tree; the value of the leaf nodes of the Merkle tree is the unit data of the data set or the hash value of the unit data; the value of non-leaf nodes is calculated according to the hash algorithm based on the values of all leaf nodes below it.
What is ‘consensus’?
The term ‘consensus’ can be simply explained from a linguistic perspective as many different people reaching the same or at least a consistent view on the same thing. This explanation is also applicable to the Bitcoin network.
The subject of reaching a consensus
It is a question of which nodes in the current blockchain need to reach a consensus, which is also a problem that needs to be considered. What do these nodes need to reach a consensus on?
The consensus mechanism involves how to generate blocks and how to select them after generation.
In the Bitcoin network, each miner has the power to generate new blocks. Then, whose block should we choose as the new block of the entire network? Can transactions be carried out on this chain after the new block is generated?
In daily life, we can have a leader or a decision-maker to make decisions on these issues. However, in the blockchain, each node is equal, and there is no central institution. In this case, it is necessary to reach a consensus among nodes through the consensus mechanism.
Consensus algorithms are a set of rules based on which consensus is achieved and a method to filter out representative nodes. For this purpose, the blockchain is designed with certain underlying algorithms, which select the node that can generate a new block through this specific algorithm, and at the same time, restrict and regulate whether each transaction on this blockchain can be completed, which is the consensus algorithm.
Consensus algorithms specify which miner generates the next new block. At the same time, for a transaction to be completed on this blockchain, it needs to be agreed upon by some nodes selected by the consensus algorithm: ‘Oh, we think this transaction can be carried out!’ If a number of nodes with no interest in the transaction can reach a consensus, it can be considered that the entire network can also reach a consensus on this.
There are many consensus algorithms, mainly including Proof of Work, Proof of Stake, Delegated Proof of Work, Delegated Proof of Stake, Practical Byzantine Fault Tolerance algorithm, etc. Their ultimate goal is consistent, but each has its own characteristics in the specific implementation process.
Proof of Work, the full name in English is proof of work, usually we call it POW.
Proof of Work is a proof that confirms that you have done a certain amount of work. How to prove it? Through the work result – when the user completes a certain difficulty of work and gets a result, by showing this result, it proves that you have completed a certain amount of work – that is, as a consensus mechanism, POW is result-oriented rather than process-oriented.
Reason
In practical applications, if we prove the work by monitoring the entire process of work, it is extremely inefficient. In order to ensure a certain level of efficiency, the method of proving the work load by verifying the result has been designed. Key feature: Asymmetry
Users who perform actual work need to exert a lot of work to get a result that meets the predetermined conditions, but as a verifier, it is easy to recalculate this result based on the materials provided by the user, and at the same time verify whether this result meets the conditions predetermined in advance.
In the Proof of Work, the longer you work and the more advanced equipment you use while working, the higher your work load will be, and the more you will earn.
Proof of Work mechanism POW
Firstly, when generating a new transaction information to be added to the blockchain, that is, the requirements that must be met for a new block, all nodes in the blockchain network based on the Proof of Work mechanism start to continuously try and calculate until the first node finds the random hash value solution, and then it gets the power to generate a new block. (Mining)
The Proof of Work mechanism has the advantage of complete decentralization.
Disadvantages of the Proof of Work mechanism: It causes a lot of resource waste, and the cycle for achieving consensus is relatively long.
Advantages:
1. Fully decentralized, simple algorithm, easy to implement;
2. Nodes can reach consensus without exchanging additional information;
3. It requires a great deal of cost to destroy the system.
Disadvantages:
1. Mining causes a large amount of resource consumption;
2. The cycle for consensus achievement is relatively long.
Proof of Stake mechanism (Proof of Stake), abbreviated as PoS, also known as the equity proof mechanism, requires each node to prove that it owns a certain number of tokens (that is, the so-called equity) to compete for the bookkeeping rights of the next block.
Users can buy tokens with real money and use them in the PoS mechanism. In this way, users have the opportunity to participate in bookkeeping, and the more tokens they own, the greater the probability of obtaining bookkeeping rights.
Typical Application -点点币
Using the Proof of Stake mechanism, and using the coin age to represent the rights of each node, but it still adopts the PoW mechanism for mining. Coin age is the product of the number of coins held and the timeonline casino tutorial and The latest plan. Each node must hold tokens for more than 30 days to be eligible to compete for the bookkeeping rights of the next block. When a node signs a block, its coin age will be reset to zero, and it must wait at least 30 days to sign the next block. The coin age will automatically reset to zero after 90 days.
Basic principle
This is the innovation of PPC (Peercoin). There is no mining process, the equity allocation ratio is clearly written in the genesis block, and then it is gradually dispersed to users through the way of transfer and transaction (usually IPO), and new currency is added through the ‘interest’ way to reward the nodes. Ethereum combines PoW and PoS.
In simple terms, it is a system that distributes interest based on the amount of currency held by the user and the time (coin age). The most typical example in reality is stocks or bank deposits. If the user wants to obtain more currency, they can open the client, keep it online, and benefit from obtaining ‘interest’ while ensuring the security of the network.
PoS rewards
For cryptocurrency using the PoS mechanism, the system allocates corresponding rewards based on coin age. After signing a POS block, the coin age will be cleared to 0. Every time the coin age is cleared by 365, a reward of 0.01 coins is obtained.
For example, if a user signs a block with 3000 coin age, the interest obtained is:
3000 * 1%/365 = 0.082 coins.
The advantages of PoS over PoW
1. To some extent, it shortens the time required for the entire network to reach consensus.
2. Each node does not need to compete for computing power mining, which will not cause excessive waste of computing power.
3. The difficulty of attackers attacking the currency system increases.
Advantages:
Energy-saving. No mining is required, no need for a large amount of electricity and energy consumption. More decentralized. Firstly, decentralization is relative. Compared with Bitcoin and other PoW types of cryptocurrency, PoS mechanism cryptocurrency has no high requirements for computer hardware, and everyone can mine (obtain interest), without worrying about the concentration of computing power leading to centralization (a single user purchases 51% of the currency, at a higher cost), the network is more secure and guaranteed. Avoid deflation. PoW mechanism cryptocurrency may lead to deflation due to various reasons such as user loss, but PoS mechanism cryptocurrency issues new currency at a certain annual interest rate, which can effectively avoid deflation and maintain basic stability. After Bitcoin, many new currencies adopt PoS mechanism, and many old currencies that adopt the proof of work mechanism also modify the protocol,
Disadvantages:
Pure PoS mechanism cryptocurrency, which can only be issued through the IPO method, leading to ‘a few people’ (usually developers) obtaining a large amount of cryptocurrency at an extremely low cost. In the face of profits, it is difficult to ensure that they will not sell off in large quantities. The credit basis of PoS mechanism cryptocurrency is not solid enough. To solve this problem, many adopt dual mechanisms of PoW+PoS, issuing cryptocurrency through PoW mining and using PoS to maintain network stability. Or adopt DPoS mechanism, enhancing trust through community elections.
Similar to Alipay and WeChat Pay, Bitcoin belongs to internet payment. However, Alipay and WeChat Pay handle the Chinese yuan, which is the legal currency issued by the government, representing the trust of the people in the power institutions. Bitcoin, on the other hand, is a decentralized virtual ‘currency’ with no institutional or legal backing, and it is completely managed by the participants.
Since it is based on the blockchain platform and uses a distributed accounting mechanism, all nodes in the system participate in the accounting process. Then, after a transaction is generated, which node will record it? If there is a malicious node that wants to arbitrarily alter the data to gain benefits, how should this be discovered? This is where the concept of ‘proof of work’ comes in.
Proof of Work (PoW) is an economic countermeasure against service and resource abuse or denial-of-service attacks. It generally requires users to perform some time-consuming complex calculations, and the answer can be quickly verified by the service provider, using the time, equipment, and energy consumed as the guarantee cost to ensure that the service and resources are used for real demand.
Simply put, it is a proof that confirms that you have done a certain amount of work. Monitoring the entire process of work is usually extremely inefficient, while authenticating the result of the work to prove that the corresponding amount of work has been completed is a very efficient way. For example, graduation certificates and driver’s licenses in real life are proofs obtained through the examination of results.
Any node in the blockchain, if it wants to generate a new block and write it to the blockchain, must solve the puzzle of the proof of work issued by the Bitcoin network, which process we call ‘mining’. The key three elements of this puzzle are the proof of work function, the block, and the difficulty value. The proof of work function is the calculation method of this puzzle, the block determines the input data of this puzzle, and the difficulty value determines the amount of computation required for this puzzle.
(1) Proof of Work Function
Just like the hash function used in the example we mentioned in the previous section, the proof of work function used in the Bitcoin system is SHA256.
(2) Block
The size of the block header is 80 bytes, consisting of the version number, the hash value of the previous block, the Merkle Root Hash, the block creation time, the difficulty value, and the random number. The transaction list included in the block is attached to the end of the block header.lottery victoryClick to enter
The block header is the input string used for Bitcoin’s proof of work. In order to make the block header reflect all the transactions contained in the block, during the construction of the block, it is necessary to generate the Merkle Root Hash of the transaction list to be included in the block through the Merkle Tree algorithm, and store it as the summary of the transaction list in the block header. See the figure below:
Mining: There is a parameter called Nonce in the block header of Bitcoin, and the process of finding this random number is called ‘mining’;
Any machine on the network can find a suitable number to fill into its own Nonce position, making the hash value of the 6 fields (80 bytes) of the block header data meet the target hash value.
(3) Difficulty Value
The difficulty value (difficulty) is an important reference index for miners when mining. It determines how many hash operations the miner needs to go through to produce a valid block. The Bitcoin block is generated approximately every 10 minutes. If the generation of new blocks needs to maintain this basic rate under different global computing power conditions, the difficulty value must be adjusted according to the change of global computing power.
The achievement of Bitcoin proof of work is that the block hash value calculated by the miner must be less than the target value.
We can also simply understand that the process of Bitcoin proof of work is to find a hash value with a specific format (that is, requiring a certain number of leading zeros) by continuously changing the block header (that is, trying different nonce values) as input for SHA256 hash calculation. The more leading zeros required, the greater the difficulty.
We can roughly summarize the steps for Bitcoin miners to solve the proof of work puzzle as follows:
Generate Coinbase transactions (this is a special transaction to reward miners and charge transaction fees), and combine them with all other transactions prepared to be packed into the block to form a transaction list. Generate Merkle Root Hash through the Merkle Tree algorithm. Assemble the Merkle Root Hash and other related fields into the block header, and use the 80-byte data (Block Header) as the input for proof of work. Keep changing the random number (nonce) in the block header and perform double SHA256 operations (that is, SHA256(SHA256(Block_Header))) on the block header after each change. Compare the resulting value with the current network target value. If it is less than the target value, the puzzle is solved successfully, and the proof of work is completed.
It can be found that although mining equipment is used to help the blockchain record, most of the work they actually do is to find the correct random number, which is unrelated to recording.
By now, you may understand how blockchain achieves decentralization. Without the authority endorsement of a central institution, the blockchain system on the one hand provides rewards to encourage participants to record, and on the other hand, increases the cost of fraud and ensures the authenticity of the ledger through a resource consumption competition among the recorders. The recorders compete for ‘recording rights’ to obtain Bitcoin rewards.
The ownership of Bitcoin is established through private keys and addresses. The address is similar to a bank account number, and to transfer Bitcoin to someone, you only need to know their Bitcoin address. The main function of the private key is to sign transactions, proving that the transaction was initiated by you, and others can confirm the legality of the funds involved in the transaction by verifying the signature.
在比特币中,公钥用于接收比特币,私钥用于生成其对应地址上支付比特币所必需的签名,以唯一确定这些比特币的所有权。具体到比特币地址的生成,其实是先产生私钥,私钥通过椭圆曲线算法这种不可逆的函数来产生公钥,公钥经过一系列不可逆的运算再来产生地址。
私钥持有者才是比特币的拥有者,那么私钥放在哪呢?
钱包是私钥的容器,是密钥的管理工具,它只包含密钥而不是确切的某一个代币。一个比特币钱包中包含一系列的密钥对,每个密钥对包括一个私钥和一个公钥。(钱包的地址类似于银行账户,私钥类似于银行卡密码)
比特币钱包有很多种,有PC端的、手机端的,也有专门的硬件钱包,甚至还有用纸写上私钥的纸钱包。我们一般使用的都是软件钱包,私钥存在一个叫wallet.dat的文件中。wallet.dat文件其实是用我们自己设置的密码加密过的,登录钱包软件时,需要用户输入密码来对文件进行解密得到真正的私钥,这时私钥存在钱包程序的内存中,当我们需要发起一笔交易时,钱包软件去内存中获取这一私钥来对交易进行签名操作。
从一个比特币钱包向另一个中转账,每笔交易都有数字签名来保证安全。一个交易一旦发生那么就是对所有人都公开的,每个交易的历史可以最终追溯到相应的比特币最初被挖出来的那个点。用户用钱包中的私钥来签名交易,从而证明他们拥有交易的输出,也就是其中的比特币。
比特币是以交易输出的形式储存在区块链中的。
比特币并不存在于任何地方,即使是硬盘上。持有比特币其实是拥有特定比特币的地址,但是其实所谓的币并不是直接就存在于这个地址中的,地址就相当于你的银行账户。世界上没有一个可以摸得着的实物,或者是一个数据文件,可以被叫做“比特币”的。
有的只是各个地址之间的转账记录,余额时增时减。所有的交易都存放在一个非常大的账本文件中,这个文件叫做“区块链”。如果想知道一个比特币地址中的余额,那么这个不是直接存放在比特币地址中的,我们需要到区块链中去计算出来。
第一笔矿工挖矿的收入交易通常被称为Coinbase,它没有输入,所以交易输入的哈希总是被标记为00000000…0000;其他的交易,任何一个交易输入都会唯一追溯到区块链上在本区块之前的某个交易哈希,以及索引。
通过交易哈希和索引,即可唯一确定一个未花费的交易输出——UTXO。这样,每一个交易输入都和之前的某个交易输出关联了起来。
地址是公钥的哈希。
当使用一个UTXO时,用户要提供这个UTXO中描述的地址对应的公钥、同时用这个公钥对应的私钥对这个交易进行签名,这样比特币的接收者才能去验证这笔交易是否有效。
冲突问题的产生
多人记账的账本不—致怎么办?
奖励该给谁呢?
冲突问题的解决方案
选择信任最长区块链
我们来看看在选择信任最长区块链这条原则下,普通用户和矿工的具体行为和产生的效果是怎么样的。
首先,对于普通用户A来说,他并没有记账所以在他那里并没有正本的记录,那么当A需要查账时,它就需要像P2P网络的其他用户发起获取账本的请求。
此时可能会有多个用户BCD来响应他的请求,告知A自己所拥有的区块链的长度。A收到响应之后,只会选择那个拥有最长区块链用户的回应,从他那里获得区块链账本。
我们再来看看矿工的行为。由手有了奖励机制,可能会有很多个矿工同时挖矿记账以求获得奖励。如果你是一个矿工,你从P2P网络中得知当前最长的区块链长度是一千,那么你会从第一个区块开始创建区块链吗?当然不会。因为即便你以最快速度挖出了第零个区块并在其中加入一条奖励自己的交易记录,然后向全网公开,那么你所创建的区块链由于长度太短并不会得到其他用户的信任,也就相当于是作废了。所以聪明的做法是你从收到的那些还没有被记录到前一千个区块的交易记录中,选择若干交易打包形成区块,计算它的Nonce值,当然你肯定要把那笔奖励给自己的交易记录也记录进去,而且为了获得更多的奖励,你肯定会选择那些提供手续费的交易,一旦你计算出了Nonce值,你就应当立即向全网公布你挖到了第1001个区块。这样才能得到全网认可这个长度为1001的区块链,从而认可你记录在第1001个区块中那个给自己的奖励。
不仅你会这么做,所有其他的矿工都会这么做,他们为了获得奖励都会争着抢着想最快速度挖出第1001个区块并以最快速度向全网公布。如果你正在挖第1001个区块B,突然收到了别的矿工公布过来的信息其他矿工已经护到了第1001个区块B‘。你会怎么做呢?是继续挖第1001个区块B吗?如果你继续坚持,即便你最终挖出了这个区块B,别人可能已经在挖第1002个区块了,你的第1001个区块B就形同作废了。所以,一旦听说别人挖出了下一个区块就应该立即停止手头的工作,转而投入下一个区块的争夺之中。
Mining is a competition among miners, and in order to win the reward, they must make the block they dig out the top of the current blockchain.
How do multiple miners record transactions simultaneously when the ledgers are inconsistent?
Miners spontaneously calculate the next block from the known longest blockchain. The vast majority of blockchains circulating in the network are consistent. Although there are very few inconsistencies at the end of the gold page, also known as forks, only the longest chain, that is, the main chain, can survive over time.
How to allocate rewards when multiple miners record transactions simultaneously?
Only the miner who wins the mining competition can create the top block of the longest blockchain and will be recognized by most users. Only one miner receives the reward. The reward naturally goes to the only miner who wins the mining competition.
What is the double-spending problem? A piece of money is spent twice or even more times.
In the lottery and How to find it system, digital assets are essentially virtual digital based on the Internet. Simply put, so-called digital assets are actually a string of characters, so they are easily copied or sent multiple times. In this case, without the existence of a central institution, people cannot determine whether a piece of asset has been spent, which may lead to the situation that the same digital asset is misused and reused.
The basis for the implementation of double-spending attacks
Proof of Work requires a longer time, and there is a longer delay from the creation of transaction information to its posting. Merchants may deliver goods before the transaction is posted.
To solve the double-spending problem, our daily use of digital assets depends on third-party trusted institutions. These institutions manage data centrally, keep the general ledger of transactions, and prevent the occurrence of double payments by modifying account balances in real-time. The biggest drawback of third-party institutions is that the verification fee is extremely high.
How does the Bitcoin system avoid the double-spending problem?
When miners generate blocks, they collect transaction information from the network, which includes the private key signature of the payer. Miners first verify whether the signature is correct, and only the correct signature is considered as the payer’s recognized payment. Then miners trace back from the previous blockchain to see if the Bitcoin consumed by the payer this time has been used before. Then they record the payer’s available Bitcoin balance. This process is also known as the UTXO mechanism.
UTXO is the abbreviation of Unspent Transaction Outputs, and its full name is ‘Unspent Transaction Output’.
U代表Unspent,表示未支付的或尚未使用的,“尚未支付”指的是这个交易输出还没有出现在其它交易的输入端。TX是transaction的缩写,交易是从一个比特币钱包向另一个钱包转账,是唯一可以改变比特币所有权的方式,包含了输入、数目和输出这些基本内容。O是Output,是输出的意思,TXO连起来就是指交易输出。
比特币是以交易输出,也就是TXO的形式存在的。我们说自己有多少比特币实际上是指的我们拥有所有权的那些UTXO中所指明的比特币的数量。所以可以说并没有比特币,只有UTXO。Alice有10个比特币,本质上是当前区块链账本中,有若干笔交易的UTXO项收款人写的是Alice的地址,而这些UTXO项的数额总和是10。
比特币的分布式区块链账本
比特币的分布式区块链账本,由一笔一笔的交易形成的,每一笔交易都要花费一笔输入,产生一笔输出,而其所产生的输出,就是“未花费过的交易输出”,也就是UTXO。这些交易构成了一组链式结构,所有合法的比特币交易都可以追溯到前一个或多个交易的输出,链条的源头就是挖矿奖励,末尾则是当前未花费的交易输出。
比特币交易规则
除了coinbase交易之外,所有的资金来源都必须来自前面某一个或者几个交易的 UTXO。任何一笔交易的交易输入总量必须等于交易输出总量,等式两边必须配平。
当然,UTXO技术也并非100%保证基于区块链的交易中杜绝双花问题。51%攻击,又被称为Majority attack,这种攻击是通过控制网络算力实现双花。
Block
区块是一种被包含在公开账簿里的聚合了交易信息的容器数据结构,这个公开账簿就是区块链。它是构成区块链的基本单元,由包含元数据的区块头和包含交易数据的区块主体构成。
那么这个区块生成之后要怎么跟原先的区块链接起来呢?
区块头主要由三组数据组成,第一组是父区块的哈希值,父哈希值用来将该区块与它的前一区块相连接;第二组数据和矿工竞争挖矿有关,即难度、时间戳和Nonce(随机数);第三组是由刚才我们讲到的区块体中计算出来的根哈希值,即默克尔树根。
这时区块头发挥作用,区块头中包含了三组元数据,其中第一组就是上一个区块的哈希值。也就是说,第二个区块的父哈希为第一个区块的哈希,第三个区块的父哈希为第二个区块的哈希,通过这种方式,就把一个个区块链接起来了,形成了一个前向的链表。online casino secrets and The latest method
区块高度是用来标识一个区块在区块链中位置的一个概念。
算力也叫哈希率,是用来衡量进行哈希运算的能力的指标,或者说进行一次哈希计算所需要使用的时间。如果说网络达到了10T哈希每秒的哈希率时,就意味着它可以每秒进行10万亿次哈希运算。
区块链网络中每个矿工都有资格生成区块,因此为了决定下一个区块由谁生成,需要通过—定的方法来决定。
在PoW机制中,所有节点通过随机的尝试和计算,直到有一个节点找到那个随机哈希散列的数值解,成为有资格生成新区块的主体。
哈希碰撞:解出随机哈希值不断尝试的过程。
一个挖矿机每秒钟能做这种碰撞的次数,代表其算力。矿工进行挖矿所使用的机器越先进,算力就会越高。
区块链转账的基本原理
整个区块链网络之所以能运行,靠的就是整个网络的“矿工”,因为他们通过算力解答加密难题,从而挖出新的区块。挖出区块后,他们就有权力将转账信息放入到区块中,然后完成这笔转账,这就是区块链转账的基本原理。
entry method lottery entry method and The latest plan
中本聪一开始就定义了比特币总量为2100万个,并且加密数学题的难度也越来越大。正所谓众人拾柴火焰高,越来越多的人把自己的矿机拿出来,组成了“挖矿小分队”,这类组织就被称为“矿池”。
51%攻击出现的根本原因:在整个网络中,有人的算力超过了全网的50%,那么在他的控制算力的这段时间,可以将区块逆转,进行反向交易,实现双花。
尽管51%的攻击不会产生新币或直接导致区块链崩溃,但对参与者对加密货币的信心会产生严重影响。
什么时候会出现51%攻击的问题呢?由于某个矿池的算力过大。
例子:Alice一个矿工掌握了全网50%以上算力的可能性微乎其微,但由于现在生产新区块越来越困难,出现了矿工间合作组成矿池,汇聚数以千计参与者们的算力,一起参与挖矿并分享奖励的行为。在这种情况下,一旦某个矿池汇集了过多的矿工,其算力超过了全网的50%,这时就出现了51%攻击的风险,也对矿工的道德提出了要求。
一个典型51%攻击案例
Alice 和 Bob之间使用比特币完成了一杯咖啡的交易,因为是小额交易,Bob在收到Alice的转账通知(不是交易确认的通知,只是表面发起了交易)就给Alice提供了咖啡。
Under normal circumstances, this transaction would be immediately placed in the transaction pool waiting for mining nodes to add it to a new block and start working hard to ‘mine’.
Suppose Alice is the big boss who has 51% of the network’s computing power, and he really doesn’t want to pay for this coffee (the rich can also be very stingy), so he started the attack.
Many nodes on the network have received this transaction and joined the block for calculation, and Alice also began to contribute computing power, but before starting, he changed the transaction in the block. Originally, this was a transaction where Alice paid Bob, but it was changed to a transaction where Alice transferred to herself (the change is easy, just change the receiving address and signature).
Alice began to try to calculate with this pseudo-block (after the calculation is correct, this block will be added to the main chain), because she has 51% of the computing power, Alice is more likely to calculate successfully first than other nodes, leading to a forged block being added to the main chain. Now there are two blockchains in the network:
One is the original main chain, and the other is a forged chain that is one block higher than the main chain.
According to the longest blockchain principle, the higher chain replaces the original chain to become the main chain. This forged transaction is recognized by all nodes as a ‘real transaction’.
This means that Bob will never receive the money, but the coffee has already been given out.
Attack result: Since all outward payment transactions were revoked, it is equivalent to recovering the Bitcoin that has been spent.
51% attack paradox
Although the 51% attack may seem terrifying, it usually only exists in theoretical situations. Because if you want to do it, you first need enough money to control 51% of the network’s computing power, which will be a very large investment. Secondly, after the attack, the price of the currency will be affected, and you need to sell a lot of coins to achieve a balance between income and expenditure. This is the paradox of the 51% attack.
Bitcoin system
The Bitcoin system is equivalent to a decentralized large ledger, with each block being a page in the ledger. The system automatically generates Bitcoin as a reward to incentivize miners to participate in the accounting process. Every ten minutes, all miners together calculate a problem, and the miner who first calculates the answer is granted the right to record a page of the account. After completing the accounting, they will automatically receive a certain amount of Bitcoin. This is the issuance process of Bitcoin.
Miner
Miners refer to individuals participating in Bitcoin mining, that is to say, the owner of each Bitcoin node dedicated to producing new blocks is a miner, the operator of all actions, and the main body of participation in the Bitcoin network.
Mining pool
The concept of a mining pool extends from the basis of miners. As more and more miners participate in mining, the possibility of an individual miner finding a block and obtaining the power to generate a new block becomes increasingly low. Therefore, some miners gather together, combining their computing power to increase the likelihood of finding a block. This collective of miners is known as a mining pool.
Public key, private key
Public key and private key are concepts used in conjunction, and they are closely related. Simply put, the private key is randomly generated by the system, and the public key is calculated from the private key; the public key is responsible for encryption, and the private key is responsible for decryption; the private key is responsible for signing, and the public key is responsible for verification. With the cooperation of both, miners can complete Bitcoin transactions.
Wallet
A Bitcoin wallet is a container used to store keys. It only contains keys and does not include the specific amount of Bitcoin. Specifically, the wallet stores a series of keys, each corresponding to a private key and a public key generated by this private key, used to complete the Bitcoin transactions that the owner of the wallet may want to carry out. The wallet also has an address, which is similar to your Alipay account. You need to provide your account to transfer money to others or to recharge yourself.
Transaction
The transactions mentioned here refer to the behavior of transferring Bitcoin from one address to another using the private key held by the miner. The Bitcoin we are talking about is actually a collection of transaction outputs. When we say we have a certain amount of Bitcoin, we actually mean the number of Bitcoin indicated in the UTXOs that we own.
Block
A block is the basic unit that constitutes a blockchain. In a blockchain, a new block is formed every so often. Miners are competing through mining to gain the power to generate new blocks. Each block consists of a block header and a block body. The block header contains the hash information of the previous block, which helps link the new block with the previous blocks; while the block body contains all the transaction information within this period.
Hashing power
Hashing power is a measure of the ability to perform hashing operations, which can be measured by the number of hash collisions completed per second. The stronger the hashing power, the greater the possibility of mining the next new block.
Technical concept
Hash algorithm consensus algorithm UTXO
Reference links:
https://www.icourse163.org/learn/NJU-1449346161
https://www.jianshu.com/p/c616155eae91
http://www.chidaolian.com/article-1574-4
https://www.jianshu.com/p/9ce0dc83efb4
https://www.icourse163.org/course/FZU-1002765004
https://www.icourse163.org/course/PAEU-1003640007