很多人都听过,比特币共识模式是POW(Proof Of Work),即工作量证明机制,但究竟证明了什么呢?本文由简入难,会让你明白一些名词解释,以及那些困惑以久的原理。
As many have heard, the Bitcoin consensus model is Proof Of Work, the workload proof mechanism, but what does it prove? From a brevity, this paper will give you some explanation of terminology, and some of the long-difficult principles.
区块头
Blockhead
一个区块包含了 区块头 和 区块体。区块体包含了这个区块里打包的所有比特币转帐记录,而区块头里包含了一些元数据,如版本号,前一个区块的hash值,Merkle树根,时间戳,难度值,Nonce。
One block contains a block header and a block. The block contains all bitcoin transfer records that are packed in this block, while the block header contains some metadata, such as version numbers, the hash value of the previous block, the Merkel root, the time stamp, the difficulty value, Nonce.
与挖矿有关的两个信息即难度值和Nonce。难度值是系统自动调整,根据过去一段时间产生新区块的时间来平衡,目地就是维护比特币十分钟左右挖出一个区块来。
Two types of information are relevant for mining, namely, difficulty values and nence. The difficulty values are automatic adjustments to the system, which are balanced by the time a new block was created over a period of time, with the aim of maintaining a bitcoin to dig up a block for about ten minutes.
Nonce值,即一个随机数,即谁能找到了一个随机数满足难度值设定的范围,那这个Nonce就是一个正确的方程解,挖矿成功获得奖励。
The Nonce value, a random number, that is, who can find a random number to meet the range set by the difficulty value, is the right equation, and the mining success is rewarded.
现在,你大概知道了,所谓挖矿:就是所有矿工去寻找一个随机的数字,使它一个方程解。
Now, as you probably know, mining: it's all miners looking for a random number and making it an equation.
听上去就这么简单,但事实是,要找到一个这样的随机数字,需要数百亿次的尝试……
It sounds as simple as that, but the fact is that finding a random number like this requires tens of billions of attempts...
思考:如果你思考的比较深会问:如果有多个矿工几乎同时找到了一个解,怎么办?
Thinking: If you think deeply, you ask: What if there are many miners who have found a solution at the same time?
答案是:比特币主链会暂时的分叉,然后看哪个链增长的更快,矿工就会在下一个区块时切换到最长的那一个链作为主链。这又是另一个非常有趣的话题。
The answer is: Bitcoin's main chain will be split temporarily, and then see which chain grows faster, and the miners will switch to the longest one at the next block as the main chain. This is another very interesting topic.
SHA256函数
SHA256 function
这个一个神奇的Hash函数,我们可以把这个函数当成一个黑盒,或魔法盒,你想怎么认为都可以,只要记住它有一个功能:
This magical Hash function, we can treat it as a black box, or a magic box, whatever you want, just remember that it has a function:
“任何长度的输入数据,经过SHA256处理之后,都会生成一个256位长度的字符串,并且,输入数据不同,并生的结果也一定不同”
"Input data of any length, processed by SHA256 will generate a 256-digit string, and the input data will be different and the resulting results will be different."
这就是Hash函数,用途非常广泛,在区块里面很多内容都是经过Hash处理的。
This is the Hash function, which has a wide range of uses, and much of what is in the block is processed by Hash.
例如: "I am Satoshi Nakamoto" 这句话,经过SHA256处理后,得到一个结果:
For example, the phrase "I am Satoshi Nakamoto", which was processed by SHA256 has one result:
5d7c7ba21cbbcd75d14800b100252d5b428e5b1213d27c385bc141ca6b47989e
这个结果是没有任何规律的,只要输入有一丁点变化,结果也会相差万别。更神奇的地方是,你无法从结果反向计算出输入的数据是什么。
There is no pattern of this result, and as long as you enter a fraction of the change, the result will be very different. What's more amazing is that you can't calculate the data entered in reverse from the result.
难度值
Difficulty value
上面的HASH值,如果我说要满足一个条件,第一位必须是0,那么概率是十六分之一,即每产生16个结果,就会有一个是0开头的,因为每一位数字都是0-9a-f这16个数之间的。
The HASH value above, if I say that to satisfy a condition, the first place must be zero, then the probability is one in sixteen, that is, for every 16 results, one starts at zero, because each number is between the 16 numbers of 0-9a-f.
如果前两位都必须是0,那概率就是256分之一了,难度增加了。如果三位,四位,十位呢?你要前面出现越多的0,那就越难实现,且这个难度将呈指数级爆增,当然这个还是按二进制的256位来细分的。
If the first two have to be zero, the probability is one-fifth. If three, four, ten, the harder it is. The harder it is for you to get ahead of the zero, the harder it will be, and the more exponential it will be, which is, of course, divided by 256 binary.
比如说:难度值为1024, 2的10次方为1024,即前10位为0,(总共256位)。
For example, the difficulty value is 1024, with 1024 in 10, i.e. 0 in the top 10, or a total of 256.
比特币会每隔2016个区块(大概2周)进行一次难度的调整,以确保每个区块的时间间隔是10分钟左右。因为算力的变化时增时减,因此难度值也要相应的自动调整,对应的也有一个算难度的算法在平衡这一切。
Bitcoin makes a difficult adjustment every 2016 blocks (about two weeks) to ensure that each block has a time interval of about 10 minutes. Because of changes in arithmetic, the difficulty value is automatically adjusted accordingly, and there is a difficult algorithm that balances all of this.
方程式
Equation
基本上,一个POW的挖矿的方程式就可以简单归如下了:
Essentially, the equation for a Pow mine can be summarized as follows:
SHA256( 区块头 + Nonce )< 目标值
SHA256(block + Nonce)< Target value
将区块头的信息,和 一个Nonce相加,然后计算SHA256得到了一个256位的字符串,这个字符串的前多少位必须是0,以满足上面的方程式成立。
Adds the information on the block header to a Nonce and calculates that SHA256 has a 256-digit string, which must be zero in the front to satisfy the equation set up above.
这里唯一需要尝试的就是这个Nonce值了,从0开始暴力计算,0不行就1,1不行换2,2不行再换3……可能百亿次尝试后,结果就对了。
The only thing that needs to be tried here is this Nonce value, which is one, one, one, two, two.
假如你发现了999是正确的,于是你把999写入到你本地创建的新区块头的Nonce字段里面了。再广播区块给其它的矿工,矿工会检验接收到的区块是否正确,然后就同步你的区块并广播给其它矿工,同时开始争夺下一个区块了。
If you find out that 999 is correct, you put 999 in the Nonce field of the new block that you created locally. Then you broadcast the block to the other miners, the mining union checks that the received block is correct, then synchronizes your block and broadcasts it to the other miners, and starts to compete for the next block.
这个999就是你工作量的证明,证明你尝试了1000次。你因此也获得了25个BTC的奖励,还有当前打包所有交易的提供的转帐费用。
This 999 is proof of your workload, which proves that you tried 1,000 times. So you got 25 BTC awards, and the transfer costs provided by the current package.
新区块生成后,马上所有矿工又从0开始计算下一个区块的Nonce……
Once the new block is generated, all miners will calculate the next block's Nonce...
思考:为什么不从999接着计算呢?
Thinking: Why not proceed from 999?
答案是:因为区块头变化啦,所以要一切从头开始。
The answer is: because the block head changes, it starts from scratch.
比特币的POW挖矿机制让所有矿工通过贡献自己的算力,公平的加入网络参与比特币的发行,并自动的调整奖励与难度系数,所有矿工都有独立验证区块合法性,拒绝欺诈的矿工,这一切机制构造了一个完全去中心化的运作系统。
The Bitcoin Pow mining mechanism, which allows all miners to participate in the distribution of Bitcoin by contributing their numeracy, participating fairly in the network and automatically adjusting the incentive and difficulty factors, has independent verification of block legitimacy by all miners, and rejects fraudulent miners, all of which construct a completely decentralized operating system.
注册有任何问题请添加 微信:MVIP619 拉你进入群

打开微信扫一扫
添加客服
进入交流群
发表评论