4. 工作量證明-Proof-of-Work
To implement a distributed timestamp server on a peer-to-peer basis, we will need to use a proofof-work system similar to Adam Back's Hashcash [6], rather than newspaper or Usenet posts. 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. The average work required is exponential in the number of zero bits required and can be verified by executing a single hash. 為了在點對點的基礎上實作分布式時間戳伺服器,我們需要使用類似于Adam Back的Hashc.[6]的校驗系統,而不是報紙或Usenet文章。工作證明包括掃描一個值,當進行散列時,例如使用SHA-256,散列以零位數開始。所需的平均功在所需零位的數量上是指數的,并且可以通過執行單個散列來驗證。
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. 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. 對于我們的時間戳網絡,我們通過在塊中增加一個nonce來實作工作證明,直到找到使塊的哈希值達到所需的零位為止。一旦CPU工作耗費了使其滿足工作的證明,塊就不能被改變而不重做工作。當後面的塊被連結後,改變塊的工作将包括重做之後的所有塊。
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. 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. 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. 工作證明也解決了在多數決策中确定表示的問題。如果大多數是基于一個IP位址一次投票,它可以被任何能夠配置設定許多IPS的人所颠覆。工作證明基本上是一個CPU一個表決。多數決策由最長連結清單示,它具有最大的工作投入證明。如果大部分CPU功率由誠實的節點控制,誠實鍊将增長最快,并超過任何競争鍊。要修改過去的塊,攻擊者必須重做塊及其後的所有塊的工作證明,然後追趕并超過誠實節點的工作。稍後我們将顯示,較慢的攻擊者追趕的機率随着後續塊的增加而指數降低。
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. 為了補償硬體速度的提高和對運作節點随時間變化的興趣,工作證明難度通過以平均每小時塊數為目标的移動平均數來确定。如果它們生成得太快,難度就會增加。
為了在點對點的基礎上建構一組分散化的時間戳伺服器,僅僅像報紙或世界性新聞網絡組一樣工作是不夠的,我們還需要一個類似于亞當•柏克(Adam Back)提出的哈希現金(Hashcash)[6] 。在進行随機散列運算時,工作量證明機制引入了對某一個特定值的掃描工作,比方說SHA-256下,随機散列值以一個或多個0開始。那麼随着0的數目的上升, 找到這個解所需要的工作量将呈指數增長,而對結果進行檢驗則僅需要一次随機散列運算。
我們在區塊中補增一個随機數(Nonce),這個随機數要使得該給定區塊的随機散列值出現了所需的那麼多個0。我們通過反複嘗試來找到這個随機數,直到找到為止,這樣我們就建構了一個工作量證明機制。隻要該CPU耗費的工作量能夠滿足該工作量證明機制,那麼除非重新完成相當的工作量,該區塊的資訊就不可更改。由于之後的區塊是連結在該區塊之後的,是以想要更改該區塊中的資訊,就還需要重新完成之後所有區塊的全部工作量。

同時,該工作量證明機制還解決了在集體投票表決時,誰是大多數的問題。如果決定大多數的方式是基于IP位址的,一IP位址一票,那麼如果有人擁有配置設定大量IP位址的權力,則該機制就被破壞了。而工作量證明機制的本質則是一CPU一票。“大多數”的決定表達為最長的鍊,因為最長的鍊包含了最大的工作量。如果大多數的CPU為誠實的節點控制,那麼誠實的鍊條将以最快的速度延長,并超越其他的競争鍊條。如果想要對業已出現的區塊進行修改,攻擊者必須重新完成該區塊的工作量外加該區塊之後所有區塊的工作量,并最終趕上和超越誠實節點的工作量。我們将在後文證明,設想一個較慢的攻擊者試圖趕上随後的區塊,那麼其成功機率将呈指數化遞減。
另一個問題是,硬體的運算速度在高速增長,而節點參與網絡的程度則會有所起伏。為了解決這個問題,工作量證明的難度(the proof-of-work difficulty)将采用移動平均目标的方法來确定,即令難度指向令每小時生成區塊的速度為某一個預定的平均數。如果區塊生成的速度過快,那麼難度就會提高。
5. 網絡-Network
The steps to run the network are as follows:
1) New transactions are broadcast to all nodes.
2) Each node collects new transactions into a block.
3) Each node works on finding a difficult proof-of-work for its block.
4) When a node finds a proof-of-work, it broadcasts the block to all nodes.
5) Nodes accept the block only if all transactions in it are valid and not already spent.
6) Nodes express their acceptance of the block by working on creating the next block in the chain, using the hash of the accepted block as the previous hash. 運作網絡的步驟如下:
1)新的事務被廣播到所有節點。
2)每個節點将新的事務收集到一個塊中。
3)每個節點都在為其塊找到一個困難的工作證明。
4)當節點找到工作證明時,它将該塊廣播到所有節點。
5)隻有當所有的事務都是有效的而不是已經使用的時候,節點才接受塊。
6)節點通過建立鍊中的下一個塊,使用所接受塊的散列作為前一散列,來表達它們對塊的接受。
Nodes always consider the longest chain to be the correct one and will keep working on extending it. If two nodes broadcast different versions of the next block simultaneously, some nodes may receive one or the other first. In that case, they work on the first one they received, but save the other branch in case it becomes longer. The tie will be broken when the next proofof-work is found and one branch becomes longer; the nodes that were working on the other branch will then switch to the longer one. 節點總是把最長的鍊看作正确的鍊,并不斷地進行擴充。如果兩個節點同時廣播下一個塊的不同版本,則一些節點可以首先接收一個或另一個。在這種情況下,他們工作的第一個他們收到,但儲存另一個分支,以使其更長的時間。當發現下一個校驗工作并且一個分支變長時,綁定将被打破;在另一個分支上工作的節點将随後切換到更長的一個。
New transaction broadcasts do not necessarily need to reach all nodes. As long as they reach many nodes, they will get into a block before long. Block broadcasts are also tolerant of dropped messages. If a node does not receive a block, it will request it when it receives the next block and realizes it missed one. 新的交易廣播不一定需要到達所有節點。隻要它們到達許多節點,它們不久就會進入一個塊。塊廣播也容忍丢棄的消息。如果一個節點沒有接收到一個塊,它将在接收下一個塊時請求它,并意識到它丢失了一個塊。
運作該網絡的步驟如下:
1) 新的交易向全網進行廣播;
2) 每一個節點都将收到的交易資訊納入一個區塊中;
3) 每個節點都嘗試在自己的區塊中找到一個具有足夠難度的工作量證明;
4) 當一個節點找到了一個工作量證明,它就向全網進行廣播;
5) 當且僅當包含在該區塊中的所有交易都是有效的且之前未存在過的,其他節點才認同該區塊的有效性;
6) 其他節點表示他們接受該區塊,而表示接受的方法,則是在跟随該區塊的末尾,制造新的區塊以延長該鍊條,而将被接受區塊的随機散列值視為先于新區快的随機散列值。
節點始終都将最長的鍊條視為正确的鍊條,并持續工作和延長它。如果有兩個節點同時廣播不同版本的新區塊,那麼其他節點在接收到該區塊的時間上将存在先後差别。當此情形,他們将在率先收到的區塊基礎上進行工作,但也會保留另外一個鍊條,以防後者變成最長的鍊條。該僵局(tie)的打破要等到下一個工作量證明被發現,而其中的一條鍊條被證明為是較長的一條,那麼在另一條分支鍊條上工作的節點将轉換陣營,開始在較長的鍊條上工作。
所謂“新的交易要廣播”,實際上不需要抵達全部的節點。隻要交易資訊能夠抵達足夠多的節點,那麼他們将很快被整合進一個區塊中。而區塊的廣播對被丢棄的資訊是具有容錯能力的。如果一個節點沒有收到某特定區塊,那麼該節點将會發現自己缺失了某個區塊,也就可以提出自己下載下傳該區塊的請求。
6. 激勵-Incentive
By convention, the first transaction in a block is a special transaction that starts a new coin owned by the creator of the block. This adds an incentive for nodes to support the network, and provides a way to initially distribute coins into circulation, since there is no central authority to issue them. The steady addition of a constant of amount of new coins is analogous to gold miners expending resources to add gold to circulation. In our case, it is CPU time and electricity that is expended. 按照慣例,塊中的第一個事務是啟動塊建立者所擁有的新硬币的特殊事務。這增加了節點支援網絡的動機,并且提供了一種最初将硬币分發到流通中的方法,因為沒有中央機構發行硬币。新硬币數量不變的穩定增加,類似于黃金開采者耗費資源增加黃金流通。在我們的例子中,是CPU時間和耗電量。
The incentive can also be funded with transaction fees. If the output value of a transaction is less than its input value, the difference is a transaction fee that is added to the incentive value of the block containing the transaction. Once a predetermined number of coins have entered circulation, the incentive can transition entirely to transaction fees and be completely inflation free. 激勵也可以用交易費用來資助。如果交易的輸出值小于它的輸入值,那麼差額就是交易費用,它被加到包含交易的塊的激勵值上。一旦預定數量的硬币進入流通,刺激可以完全轉變為交易費用,完全沒有通貨膨脹。
The incentive may help encourage nodes to stay honest. If a greedy attacker is able to assemble more CPU power than all the honest nodes, he would have to choose between using it to defraud people by stealing back his payments, or using it to generate new coins. He ought to find it more profitable to play by the rules, such rules that favour him with more new coins than everyone else combined, than to undermine the system and the validity of his own wealth. 激勵可能有助于鼓勵節點保持誠實。如果一個貪婪的攻擊者能夠比所有誠實的節點組裝更多的CPU能力,那麼他必須選擇使用CPU能力通過偷回他的支付來欺騙人們,或者使用它來生成新的硬币。他應該發現遵守這些規則比破壞制度和他自己财富的合法性更有利可圖,這些規則比任何人合起來都更有利于他擁有更多的新硬币。
我們約定如此:每個區塊的第一筆交易進行特殊化處理,該交易産生一枚由該區塊創造者擁有的新的電子貨币。這樣就增加了節點支援該網絡的激勵,并在沒有中央集權機構發行貨币的情況下,提供了一種将電子貨币配置設定到流通領域的一種方法。這種将一定數量新貨币持續增添到貨币系統中的方法,非常類似于耗費資源去挖掘金礦并将黃金注入到流通領域。此時,CPU的時間和電力消耗就是消耗的資源。
另外一個激勵的來源則是交易費(transaction fees)。如果某筆交易的輸出值小于輸入值,那麼差額就是交易費,該交易費将被增加到該區塊的激勵中。隻要既定數量的電子貨币已經進入流通,那麼激勵機制就可以逐漸轉換為完全依靠交易費,那麼本貨币系統就能夠免于通貨膨脹。
激勵系統也有助于鼓勵節點保持誠實。如果有一個貪婪的攻擊者能夠調集比所有誠實節點加起來還要多的CPU計算力,那麼他就面臨一個選擇:要麼将其用于誠實工作産生新的電子貨币,或者将其用于進行二次支付攻擊。那麼他就會發現,按照規則行事、誠實工作是更有利可圖的。因為該等規則使得他能夠擁有更多的電子貨币,而不是破壞這個系統使得其自身财富的有效性受損。