1. 程式人生 > >《詳解比特幣白皮書》- Proof-of-Work(PoW工作量證明機制)

《詳解比特幣白皮書》- 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 Back1997年提出的工作量明系。起初是了抵禦垃圾件和DoS,即要求送端在求的候附加一段以多個0的雜湊種雜湊只能用通暴力枚的方法嘗試不同的隨機數來生成,需要消耗一定的CPU計算時間。

工作量證明的技術原理:

工作量明最常用的技原理是雜湊函式。由於入雜湊h()的任意n,會對應到一個h(n)結果,而n只要變動一個位元,就會引起雪崩效,所以幾乎無法從h(n)反推回n,因此藉由指定h(n)的特徵,戶進行大量的窮舉運算,就可以達成工作量明。

若指定h(n)16進位制值的前四值,求

n這樣統計上平均要執行216h(n)雜湊運算,才會得到答案,但算只要行一次就可以了。如果想要增加度,那就增加指定的位數即可。以SHA256函式例,假理資料Hello World,並找出h(n)前四值為0000n,如果從Hello World0開始加上一個ASCII進行窮舉猜測,到Hello World107105時才會得到匹配條件的h(n)0000BFE6AF4232F78B0C8EBA37A6BA6C17B9B8671473B0B82305880BE077EDD9

驗算時只要將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的消耗使之滿足了工作量明要求,個區就不能改了,除非重做這項工作。隨著後來的區在其後接,改的工作量將包括改之後所有的區

工作量證明的步驟如下:

  1. 構建區塊,把將要寫入區塊交易資訊組成交易列表,通過Merkle樹演算法把交易列表資訊生成Merkle根雜湊。
  2. 把Merkle根雜湊、難度值等相關欄位組裝成區塊頭,把區塊頭80位元組資料作為工作量證明的資料輸入。
  3. 不停地變更區塊頭的隨機數,即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. 

為了補償日益增長的硬體速度和日益變化的運營節點的利息,工作量證明的難度由一個每小時平均區塊產生數量為目標的變化的均值來決定。如果它們(區塊)產生的太快,難度就會增加。

重點:尋找工作量證明的過程就是傳說中的。位元幣為了控制出的速度,加入了定。隨著科技的步,算機硬體效能的提升,以及參與人群的大,中本聰預料到會有越來越多的算力投入到挖的行列。如果速度不加控制,位元將會很快達到預設的上限。