《詳解比特幣白皮書》- Proof-of-Work(PoW工作量證明機制)
工作量證明:要求使用者進行一些耗時適當的複雜運算,並且答案能被服務方快速驗算,以此耗用的時間、裝置、能源作為擔保成本,以確保服務與資源是被真正的需求所使用。
To implement a distributed timestamp server on a peer-to-peer basis, we will need to use a proof- of-work system similar to Adam Back's Hashcash [6], rather than newspaper or Usenet posts.
為了在點對點的基礎上建立一個分散式的時間戳伺服器,我們將使用一種與AdamBack的Hashcash相類似的工作量證明(POW)系統,而不是像報紙或Usenet發帖子。
重點:作者參考的Hashcash,是由Adam Back在1997年提出的工作量證明系統。起初是為了抵禦垃圾郵件和DoS拒絕服務攻擊,即要求發送端在請求的時候附加一段以多個0開頭的雜湊值,這種雜湊值只能用通過暴力枚舉的方法嘗試不同的隨機數來生成,需要消耗一定的CPU計算時間。
工作量證明的技術原理:
工作量證明最常用的技術原理是雜湊函式。由於輸入雜湊h()的任意值n,會對應到一個h(n)結果,而n只要變動一個位元,就會引起雪崩效應,所以幾乎無法從h(n)反推回n,因此藉由指定查找h(n)的特徵,讓用戶進行大量的窮舉運算,就可以達成工作量證明。
我們若指定h(n)的16進位制值的前四值,求
驗算時只要將Hello World107105代入SHA256函式一次即可。
The proof-of-work involves scanning for a value that when hashed, such as with SHA-256, the hash begins with a number of zero bits.
這個工作量證明需要在雜湊(Hash)的過程中(以列舉的方式)尋找一個以一定數量0位元開頭的雜湊值,比如用SHA-256演算法。
The average work required is exponential in the number of zero bits required and can be verified by executing a single hash.
所需的平均工作量隨所需的0位元位數量以指數級增長,而驗證工作量只需做一次雜湊。
For our timestamp network, we implement the proof-of-work by incrementing a nonce in the block until a value is found that gives the block's hash the required zero bits.
在我們的時間戳網路中,我們不斷遞增區塊中的nonce隨機數來找到那個滿足所需0位元數量的區塊雜湊值,並將這個計算過程作為PoW。
Once the CPU effort has been expended to make it satisfy the proof-of-work, the block cannot be changed without redoing the work. As later blocks are chained after it, the work to change the block would include redoing all the blocks after it.
一旦CPU的消耗使之滿足了工作量證明要求,這個區塊就不能改變了,除非重做這項工作。隨著後來的區塊在其後鏈接,改變區塊的工作量將包括改變之後所有的區塊。
工作量證明的步驟如下:
- 構建區塊,把將要寫入區塊交易資訊組成交易列表,通過Merkle樹演算法把交易列表資訊生成Merkle根雜湊。
- 把Merkle根雜湊、難度值等相關欄位組裝成區塊頭,把區塊頭80位元組資料作為工作量證明的資料輸入。
- 不停地變更區塊頭的隨機數,即nonce的數值,變更後不斷採用SHA256運算。與目標值做對比,如果小於目標值,則解題成功,工作量證明完成。
The proof-of-work also solves the problem of determining representation in majority decision making.
工作量證明還解決了多數決策過程中的表決問題。
If the majority were based on one-IP-address-one-vote, it could be subverted by anyone able to allocate many IPs. Proof-of-work is essentially one-CPU-one-vote.
如果多數(的統計)是基於一個地址一票的,那麼可以分配多個IP的人將破壞規則。工作量證明本質上是一個CPU一票。
The majority decision is represented by the longest chain, which has the greatest proof-of-work effort invested in it.
那麼大多數的決定表達為最長的鏈,因為有最多工作了證明的努力投入其中。
If a majority of CPU power is controlled by honest nodes, the honest chain will grow the fastest and outpace any competing chains.
如果大部分CPU功率由誠實節點控制,那麼誠實的鏈將以最快的速度增長從而淘汰任何競爭的鏈。
To modify a past block, an attacker would have to redo the proof-of-work of the block and all blocks after it and then catch up with and surpass the work of the honest nodes.
要修改一個過去的區塊,攻擊者將不得不重做該區塊和之後所有區塊的工作量證明,然後追上並趕超誠實結點的工作量。我們隨後會介紹,隨著後來區塊的不斷增加,較慢的攻擊者追上的概率以指數級降低。
We will show later that the probability of a slower attacker catching up diminishes exponentially as subsequent blocks are added.
我們隨後會介紹,隨著後來區塊不斷增加,較慢的攻擊者追上的概率以指數級降低。
To compensate for increasing hardware speed and varying interest in running nodes over time, the proof-of-work difficulty is determined by a moving average targeting an average number of blocks per hour. If they're generated too fast, the difficulty increases.
為了補償日益增長的硬體速度和日益變化的運營節點的利息,工作量證明的難度由一個每小時平均區塊產生數量為目標的變化的均值來決定。如果它們(區塊)產生的太快,難度就會增加。
重點:尋找工作量證明的過程就是傳說中的“挖礦”。位元幣為了控制出礦的速度,加入了難度設定。隨著科技的進步,計算機硬體效能的提升,以及參與人群的擴大,中本聰預料到會有越來越多的算力投入到挖礦的行列。如果對出礦速度不加控制,位元幣將會很快達到預設的上限。