原始文献 / 白皮书

白皮书

《Bitcoin: A Peer-to-Peer Electronic Cash System》,中本聪(Satoshi Nakamoto),2008 年。

版本事实
  • 2008-10-31 公开版 — 在密码学邮件列表(Cryptography Mailing List)首次公开发布的版本,是后世引用的标准版本。
  • 2009-03 修订 — 白皮书在 2009 年 3 月有过一次文字修订(以 bitcoin.org 存档版本为准),内容无实质改动。
  • 2008-08 草稿已佚 — 中本聪在公开前曾向 Adam Back 等人发送过早期草稿征求引用意见,该草稿未公开流传,现已不可得。
获取白皮书
  • PDF 下载 — bitcoin.org/bitcoin.pdf(英文原版,9 页)。
  • 权威归档 — bitcoin.org。以下全文逐字转录自 bitcoin.org 上的白皮书 PDF,7 幅插图亦取自该 PDF 原文;引用白皮书时请以该版本为准。

白皮书全文 英文原版

本页版本:英文原版 · 中文版(杨靖武 译)↓

Bitcoin: A Peer-to-Peer Electronic Cash System

Satoshi Nakamoto
[email protected]
www.bitcoin.org

Abstract

A purely peer-to-peer version of electronic cash would allow online payments to be sent directly from one party to another without going through a financial institution. Digital signatures provide part of the solution, but the main benefits are lost if a trusted third party is still required to prevent double-spending. We propose a solution to the double-spending problem using a peer-to-peer network. The network timestamps transactions by hashing them into an ongoing chain of hash-based proof-of-work, forming a record that cannot be changed without redoing the proof-of-work. The longest chain not only serves as proof of the sequence of events witnessed, but proof that it came from the largest pool of CPU power. As long as a majority of CPU power is controlled by nodes that are not cooperating to attack the network, they'll generate the longest chain and outpace attackers. The network itself requires minimal structure. Messages are broadcast on a best effort basis, and nodes can leave and rejoin the network at will, accepting the longest proof-of-work chain as proof of what happened while they were gone.

1. Introduction

Commerce on the Internet has come to rely almost exclusively on financial institutions serving as trusted third parties to process electronic payments. While the system works well enough for most transactions, it still suffers from the inherent weaknesses of the trust based model. Completely non-reversible transactions are not really possible, since financial institutions cannot avoid mediating disputes. The cost of mediation increases transaction costs, limiting the minimum practical transaction size and cutting off the possibility for small casual transactions, and there is a broader cost in the loss of ability to make non-reversible payments for nonreversible services. With the possibility of reversal, the need for trust spreads. Merchants must be wary of their customers, hassling them for more information than they would otherwise need. A certain percentage of fraud is accepted as unavoidable. These costs and payment uncertainties can be avoided in person by using physical currency, but no mechanism exists to make payments over a communications channel without a trusted party. What is needed is an electronic payment system based on cryptographic proof instead of trust, allowing any two willing parties to transact directly with each other without the need for a trusted third party. Transactions that are computationally impractical to reverse would protect sellers from fraud, and routine escrow mechanisms could easily be implemented to protect buyers. In this paper, we propose a solution to the double-spending problem using a peer-to-peer distributed timestamp server to generate computational proof of the chronological order of transactions. The system is secure as long as honest nodes collectively control more CPU power than any cooperating group of attacker nodes.

2. Transactions

We define an electronic coin as a chain of digital signatures. Each owner transfers the coin to the next by digitally signing a hash of the previous transaction and the public key of the next owner and adding these to the end of the coin. A payee can verify the signatures to verify the chain of ownership.

Transaction chain: an electronic coin as a chain of digital signatures
图 1:交易链 —— 电子货币被定义为一串数字签名

The problem of course is the payee can't verify that one of the owners did not double-spend the coin. A common solution is to introduce a trusted central authority, or mint, that checks every transaction for double spending. After each transaction, the coin must be returned to the mint to issue a new coin, and only coins issued directly from the mint are trusted not to be double-spent. The problem with this solution is that the fate of the entire money system depends on the company running the mint, with every transaction having to go through them, just like a bank. We need a way for the payee to know that the previous owners did not sign any earlier transactions. For our purposes, the earliest transaction is the one that counts, so we don't care about later attempts to double-spend. The only way to confirm the absence of a transaction is to be aware of all transactions. In the mint based model, the mint was aware of all transactions and decided which arrived first. To accomplish this without a trusted party, transactions must be publicly announced [1], and we need a system for participants to agree on a single history of the order in which they were received. The payee needs proof that at the time of each transaction, the majority of nodes agreed it was the first received.

3. Timestamp Server

The solution we propose begins with a timestamp server. A timestamp server works by taking a hash of a block of items to be timestamped and widely publishing the hash, such as in a newspaper or Usenet post [2-5]. The timestamp proves that the data must have existed at the time, obviously, in order to get into the hash. Each timestamp includes the previous timestamp in its hash, forming a chain, with each additional timestamp reinforcing the ones before it.

Timestamp server: chain of hashes
图 2:时间戳服务器 —— 哈希链

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. 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.

Proof-of-work: blocks with previous hash and nonce
图 3:工作量证明 —— 包含前一区块哈希与随机数的区块

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. 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.

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.

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.

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. 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.

7. Reclaiming Disk Space

Once the latest transaction in a coin is buried under enough blocks, the spent transactions before it can be discarded to save disk space. To facilitate this without breaking the block's hash, transactions are hashed in a Merkle Tree [7][2][5], with only the root included in the block's hash. Old blocks can then be compacted by stubbing off branches of the tree. The interior hashes do not need to be stored.

Transactions hashed in a Merkle tree (left); after pruning Tx0-2 (right)
图 4:默克尔树中的交易哈希(左)与剪枝 Tx0–Tx2 之后(右)

A block header with no transactions would be about 80 bytes. If we suppose blocks are generated every 10 minutes, 80 bytes * 6 * 24 * 365 = 4.2MB per year. With computer systems typically selling with 2GB of RAM as of 2008, and Moore's Law predicting current growth of 1.2GB per year, storage should not be a problem even if the block headers must be kept in memory.

8. Simplified Payment Verification

It is possible to verify payments without running a full network node. A user only needs to keep a copy of the block headers of the longest proof-of-work chain, which he can get by querying network nodes until he's convinced he has the longest chain, and obtain the Merkle branch linking the transaction to the block it's timestamped in. He can't check the transaction for himself, but by linking it to a place in the chain, he can see that a network node has accepted it, and blocks added after it further confirm the network has accepted it.

Simplified payment verification: longest proof-of-work chain and Merkle branch for Tx3
图 5:简化支付验证 —— 最长工作量证明链与 Tx3 的默克尔分支

As such, the verification is reliable as long as honest nodes control the network, but is more vulnerable if the network is overpowered by an attacker. While network nodes can verify transactions for themselves, the simplified method can be fooled by an attacker's fabricated transactions for as long as the attacker can continue to overpower the network. One strategy to protect against this would be to accept alerts from network nodes when they detect an invalid block, prompting the user's software to download the full block and alerted transactions to confirm the inconsistency. Businesses that receive frequent payments will probably still want to run their own nodes for more independent security and quicker verification.

9. Combining and Splitting Value

Although it would be possible to handle coins individually, it would be unwieldy to make a separate transaction for every cent in a transfer. To allow value to be split and combined, transactions contain multiple inputs and outputs. Normally there will be either a single input from a larger previous transaction or multiple inputs combining smaller amounts, and at most two outputs: one for the payment, and one returning the change, if any, back to the sender.

Transaction inputs and outputs
图 6:交易的输入与输出

It should be noted that fan-out, where a transaction depends on several transactions, and those transactions depend on many more, is not a problem here. There is never the need to extract a complete standalone copy of a transaction's history.

10. Privacy

The traditional banking model achieves a level of privacy by limiting access to information to the parties involved and the trusted third party. The necessity to announce all transactions publicly precludes this method, but privacy can still be maintained by breaking the flow of information in another place: by keeping public keys anonymous. The public can see that someone is sending an amount to someone else, but without information linking the transaction to anyone. This is similar to the level of information released by stock exchanges, where the time and size of individual trades, the "tape", is made public, but without telling who the parties were.

Traditional privacy model (top) and new privacy model (bottom)
图 7:传统隐私模型(上)与新的隐私模型(下)

As an additional firewall, a new key pair should be used for each transaction to keep them from being linked to a common owner. Some linking is still unavoidable with multi-input transactions, which necessarily reveal that their inputs were owned by the same owner. The risk is that if the owner of a key is revealed, linking could reveal other transactions that belonged to the same owner.

11. Calculations

We consider the scenario of an attacker trying to generate an alternate chain faster than the honest chain. Even if this is accomplished, it does not throw the system open to arbitrary changes, such as creating value out of thin air or taking money that never belonged to the attacker. Nodes are not going to accept an invalid transaction as payment, and honest nodes will never accept a block containing them. An attacker can only try to change one of his own transactions to take back money he recently spent. The race between the honest chain and an attacker chain can be characterized as a Binomial Random Walk. The success event is the honest chain being extended by one block, increasing its lead by +1, and the failure event is the attacker's chain being extended by one block, reducing the gap by -1. The probability of an attacker catching up from a given deficit is analogous to a Gambler's Ruin problem. Suppose a gambler with unlimited credit starts at a deficit and plays potentially an infinite number of trials to try to reach breakeven. We can calculate the probability he ever reaches breakeven, or that an attacker ever catches up with the honest chain, as follows [8]:

p = probability an honest node finds the next block
q = probability the attacker finds the next block
qz = probability the attacker will ever catch up from z blocks behind
qz =⎧
⎩
1 if p ≤ q
(q/p)z if p > q

Given our assumption that p > q, the probability drops exponentially as the number of blocks the attacker has to catch up with increases. With the odds against him, if he doesn't make a lucky lunge forward early on, his chances become vanishingly small as he falls further behind. We now consider how long the recipient of a new transaction needs to wait before being sufficiently certain the sender can't change the transaction. We assume the sender is an attacker who wants to make the recipient believe he paid him for a while, then switch it to pay back to himself after some time has passed. The receiver will be alerted when that happens, but the sender hopes it will be too late. The receiver generates a new key pair and gives the public key to the sender shortly before signing. This prevents the sender from preparing a chain of blocks ahead of time by working on it continuously until he is lucky enough to get far enough ahead, then executing the transaction at that moment. Once the transaction is sent, the dishonest sender starts working in secret on a parallel chain containing an alternate version of his transaction. The recipient waits until the transaction has been added to a block and z blocks have been linked after it. He doesn't know the exact amount of progress the attacker has made, but assuming the honest blocks took the average expected time per block, the attacker's potential progress will be a Poisson distribution with expected value:

λ = z(q/p)

To get the probability the attacker could still catch up now, we multiply the Poisson density for each amount of progress he could have made by the probability he could catch up from that point:

∑k=0∞ λke−λ/k! · (q/p)(z−k)  if k ≤ z

Rearranging to avoid summing the infinite tail of the distribution...

1 − ∑k=0z λke−λ/k! · (1 − (q/p)(z−k))

Converting to C code...

   #include <math.h>
   double AttackerSuccessProbability(double q, int z)
   {
       double p = 1.0 - q;
       double lambda = z * (q / p);
       double sum = 1.0;
       int i, k;
       for (k = 0; k <= z; k++)
       {
           double poisson = exp(-lambda);
           for (i = 1; i <= k; i++)
               poisson *= lambda / i;
           sum -= poisson * (1 - pow(q / p, z - k));
       }
       return sum;
   }

Running some results, we can see the probability drop off exponentially with z.

   q=0.1
   z=0     P=1.0000000
   z=1     P=0.2045873
   z=2     P=0.0509779
   z=3     P=0.0131722
   z=4     P=0.0034552
   z=5     P=0.0009137
   z=6     P=0.0002428
   z=7     P=0.0000647
   z=8     P=0.0000173
   z=9     P=0.0000046
   z=10    P=0.0000012
   q=0.3
   z=0     P=1.0000000
   z=5     P=0.1773523
   z=10    P=0.0416605
   z=15    P=0.0101008
   z=20    P=0.0024804
   z=25    P=0.0006132
   z=30    P=0.0001522
   z=35    P=0.0000379
   z=40    P=0.0000095
   z=45    P=0.0000024
   z=50    P=0.0000006

Solving for P less than 0.1%...

   P < 0.001
   q=0.10    z=5
   q=0.15    z=8
   q=0.20    z=11
   q=0.25    z=15
   q=0.30    z=24
   q=0.35    z=41
   q=0.40    z=89
   q=0.45    z=340

12. Conclusion

We have proposed a system for electronic transactions without relying on trust. We started with the usual framework of coins made from digital signatures, which provides strong control of ownership, but is incomplete without a way to prevent double-spending. To solve this, we proposed a peer-to-peer network using proof-of-work to record a public history of transactions that quickly becomes computationally impractical for an attacker to change if honest nodes control a majority of CPU power. The network is robust in its unstructured simplicity. Nodes work all at once with little coordination. They do not need to be identified, since messages are not routed to any particular place and only need to be delivered on a best effort basis. Nodes can leave and rejoin the network at will, accepting the proof-of-work chain as proof of what happened while they were gone. They vote with their CPU power, expressing their acceptance of valid blocks by working on extending them and rejecting invalid blocks by refusing to work on them. Any needed rules and incentives can be enforced with this consensus mechanism.

References

  1. [1] W. Dai, "b-money," http://www.weidai.com/bmoney.txt, 1998.
  2. [2] H. Massias, X.S. Avila, and J.-J. Quisquater, "Design of a secure timestamping service with minimal trust requirements," In 20th Symposium on Information Theory in the Benelux, May 1999.
  3. [3] S. Haber, W.S. Stornetta, "How to time-stamp a digital document," In Journal of Cryptology, vol 3, no 2, pages 99-111, 1991.
  4. [4] D. Bayer, S. Haber, W.S. Stornetta, "Improving the efficiency and reliability of digital time-stamping," In Sequences II: Methods in Communication, Security and Computer Science, pages 329-334, 1993.
  5. [5] S. Haber, W.S. Stornetta, "Secure names for bit-strings," In Proceedings of the 4th ACM Conference on Computer and Communications Security, pages 28-35, April 1997.
  6. [6] A. Back, "Hashcash - a denial of service counter-measure," http://www.hashcash.org/papers/hashcash.pdf, 2002.
  7. [7] R.C. Merkle, "Protocols for public key cryptosystems," In Proc. 1980 Symposium on Security and Privacy, IEEE Computer Society, pages 122-133, April 1980.
  8. [8] W. Feller, "An introduction to probability theory and its applications," 1957.

白皮书全文 中文版 · 杨靖武 译

译者:杨靖武

比特币:一种点对点的电子现金系统

Satoshi Nakamoto(中本聪)
[email protected]
www.bitcoin.org

摘要

纯粹点对点版本的电子现金,将允许在线支付直接从一方发送给另一方,而无需经过金融机构。数字签名提供了部分解决方案,但如果仍需可信第三方来防止双重支付,其主要优势便荡然无存。我们提出一种基于点对点网络的双重支付问题解决方案。该网络通过将交易哈希后纳入一条持续延伸的、基于哈希的工作量证明链来为交易加盖时间戳,从而形成一份记录:若不重做工作量证明,便无法篡改。最长链不仅证明了所见证事件的先后顺序,也证明了它来自最大的 CPU 算力池。只要多数 CPU 算力由不合谋攻击网络的节点控制,它们就能生成最长链,并甩开攻击者。网络本身几乎不需要任何结构。消息以尽力而为的方式广播,节点可以随意离开和重新加入网络,并接受最长工作量证明链作为其离线期间所发生之事的证明。

1. 引言

互联网上的商业活动,几乎完全依赖作为可信第三方处理电子支付的金融机构。尽管这套系统对大多数交易而言运转良好,但它仍深受基于信任模式的内在缺陷之苦。完全不可撤销的交易实际上并不存在,因为金融机构无法避免介入纠纷调解。调解成本推高了交易成本,限制了可行的最小交易规模,扼杀了小额随意交易的可能性;更广泛的代价在于,人们失去了为不可撤销服务进行不可撤销支付的能力。一旦存在撤销的可能,对信任的需求便会蔓延。商家不得不提防顾客,向他们索取超出必要的更多信息;一定比例的欺诈被当作不可避免而接受。面对面使用实物货币可以避开这些成本与支付不确定性,但通过通信渠道支付、又不借助可信一方,目前尚无任何机制可用。我们需要的是一种基于密码学证明而非信任的电子支付系统,让任意两个愿意的当事方直接交易,无需可信第三方。在计算上难以撤销的交易可以保护卖方免受欺诈,而常规的第三方托管机制也能轻易实现以保护买方。在本文中,我们提出一种基于点对点分布式时间戳服务器的双重支付问题解决方案,用它生成交易时间顺序的计算证明。只要诚实节点共同控制的 CPU 算力超过任何合谋的攻击者节点群体,该系统就是安全的。

2. 交易

我们将电子货币定义为一串数字签名。每一位所有者通过对前一笔交易的哈希与下一位所有者的公钥进行数字签名,并将签名附加到该币的末尾,从而将币转移给下一位。收款人可以通过验证签名来验证所有权链。

Transaction chain: an electronic coin as a chain of digital signatures
图 1:交易链 —— 电子货币被定义为一串数字签名

问题在于,收款人无法验证某位前所有者是否曾将该币双重支付。常见的解决方案是引入一个可信的中央机构(或称铸币厂),由它检查每一笔交易是否存在双重支付。每笔交易之后,币必须交回铸币厂以发行新币,只有由铸币厂直接发行的币才被信任为未被双重支付。这种方案的问题在于,整个货币体系的命运系于运营铸币厂的公司一身,每笔交易都必须经过它,如同银行。我们需要一种办法,让收款人确信此前的所有者没有签署过更早的交易。就我们的目的而言,最早的那笔交易才是有效的,因此我们不在乎之后的双重支付企图。要确认某笔交易不存在,唯一的办法是知晓全部交易。在基于铸币厂的模型中,铸币厂知晓全部交易,并裁定哪笔先到。要在没有可信一方的情况下做到这一点,交易必须公开宣布 [1],并且我们需要一套系统,让参与者就"交易被接收的顺序"这一单一历史达成一致。收款人需要证明:在每笔交易发生时,多数节点都认同它是第一笔被接收的交易。

3. 时间戳服务器

我们提出的方案从时间戳服务器开始。时间戳服务器的工作方式是:对一批待加盖时间戳的条目取哈希,并将该哈希广泛发布,例如刊登在报纸或 Usenet 帖子中 [2-5]。时间戳证明了这些数据在当时必然已经存在——显然,只有存在的数据才能被纳入哈希。每个时间戳的哈希中都包含前一个时间戳,从而形成一条链,每新增一个时间戳,就加固了它之前的所有时间戳。

Timestamp server: chain of hashes
图 2:时间戳服务器 —— 哈希链

4. 工作量证明

要在点对点基础上实现分布式时间戳服务器,我们需要使用类似 Adam Back 的 Hashcash [6] 那样的工作量证明系统,而非报纸或 Usenet 帖子。工作量证明的做法是:搜寻这样一个值,使得对其哈希(例如用 SHA-256)后,哈希值以若干个零比特开头。所需的平均工作量随要求的零比特数呈指数增长,而验证只需执行一次哈希即可。在我们的时间戳网络中,工作量证明的实现方式是:在区块中递增一个 nonce(随机数),直到找到一个值,使该区块的哈希具有所需的零比特数。一旦付出了 CPU 算力使区块满足工作量证明,若不重做这些工作,区块便无法再被更改。随着后续区块链接其后,要更改该区块,就必须重做其后所有区块的工作。

Proof-of-work: blocks with previous hash and nonce
图 3:工作量证明 —— 包含前一区块哈希与随机数的区块

工作量证明还解决了多数决机制中代表权如何确定的问题。如果多数决基于"一 IP 一票",任何能分配大量 IP 的人都可以颠覆它。工作量证明本质上是"一 CPU 一票"。多数决由最长链代表,因为它投入的工作量证明算力最大。如果多数 CPU 算力由诚实节点控制,诚实链将增长得最快,甩开所有竞争链。要修改过去的区块,攻击者必须重做该区块及其后所有区块的工作量证明,然后追上并超过诚实节点的工作量。我们稍后将证明:随着后续区块不断增加,速度较慢的攻击者追上的概率呈指数下降。为补偿硬件速度的提升和不同时期运行节点的意愿变化,工作量证明难度由一个移动平均值决定,目标是每小时平均生成一定数量的区块。如果区块生成过快,难度就会上调。

5. 网络

运行网络的步骤如下:

  1. 新交易向所有节点广播。
  2. 每个节点将新交易收集进一个区块。
  3. 每个节点为其区块寻找一个满足难度的工作量证明。
  4. 当某个节点找到工作量证明,它就向所有节点广播该区块。
  5. 只有当区块中的所有交易都有效且尚未被花费时,节点才接受该区块。
  6. 节点通过着手创建链中的下一个区块来表达对该区块的接受,并将已接受区块的哈希作为前一区块哈希。

节点始终将最长链视为正确的链,并持续致力于延长它。如果两个节点同时广播了下一个区块的不同版本,一些节点可能先收到其中一个。这种情况下,它们先在收到的第一个版本上工作,同时保留另一个分支,以防它后来变长。当找到下一个工作量证明、其中一个分支变长时,僵局即被打破;在另一个分支上工作的节点将切换到更长的那条。

新交易的广播不一定需要抵达所有节点。只要抵达了足够多的节点,它们很快就会被纳入某个区块。区块广播对消息丢失也有容忍度。如果某个节点没有收到某个区块,当它收到下一个区块并意识到自己错过了一个时,就会去请求补回。

6. 激励

按约定,区块中的第一笔交易是一笔特殊交易,它创造出一枚归区块创建者所有的新币。这为节点支持网络增加了激励,也提供了一种将币初始分配进流通的途径,因为没有中央机构来发行它们。以恒定数量稳定增发新币,类似于金矿矿工耗费资源将黄金注入流通;在我们这里,耗费的是 CPU 时间和电力。激励也可以来自交易手续费。如果一笔交易的输出总值小于输入总值,差额即为交易手续费,计入包含该交易的区块的激励。一旦预定数量的币进入流通,激励可以完全转为交易手续费,从而彻底摆脱通胀。激励有助于促使节点保持诚实。如果一个贪婪的攻击者能集结超过所有诚实节点的 CPU 算力,他将面临选择:用它通过窃回已支付款项来欺诈他人,还是用它来生成新币。按规则行事对他应当更有利可图——规则会让他获得比其他人加起来更多的新币——而不是去破坏系统、动摇自己财富的有效性。

7. 回收磁盘空间

当一枚币的最新交易被足够多的区块压在下面之后,它之前的已花费交易就可以丢弃,以节省磁盘空间。为在不破坏区块哈希的前提下实现这一点,交易被组织进一棵默克尔树 [7][2][5] 进行哈希,只有树根被纳入区块哈希。旧区块随后可以通过砍掉树的分支来压缩,内部节点的哈希无需存储。

Transactions hashed in a Merkle tree (left); after pruning Tx0-2 (right)
图 4:默克尔树中的交易哈希(左)与剪枝 Tx0–Tx2 之后(右)

不含交易的区块头大约 80 字节。假设每 10 分钟生成一个区块,80 字节 × 6 × 24 × 365 = 每年 4.2MB。以 2008 年市售计算机通常配备 2GB 内存、摩尔定律预测每年增长 1.2GB 来看,即使区块头必须常驻内存,存储也不成问题。

8. 简化支付验证

不运行完整网络节点也可以验证支付。用户只需保存最长工作量证明链的区块头副本——向网络节点查询,直到确信自己拿到的是最长链——并获取将该交易链接到其所在时间戳区块的默克尔分支。他无法亲自校验该交易,但通过把它锚定在链中的某个位置,他可以看到已有网络节点接受了它,而之后追加的区块进一步确认了网络对它的接受。

Simplified payment verification: longest proof-of-work chain and Merkle branch for Tx3
图 5:简化支付验证 —— 最长工作量证明链与 Tx3 的默克尔分支

因此,只要诚实节点控制着网络,这种验证就是可靠的;但如果攻击者压倒了网络,它就更脆弱。网络节点可以亲自验证交易,而简化方法在攻击者持续压制网络期间,可能被攻击者伪造的交易欺骗。一种防范策略是:当网络节点检测到无效区块时接受其告警,提示用户软件下载完整区块和被标记的交易,以确认不一致。频繁收款的商家可能仍希望运行自己的节点,以获得更独立的安全性和更快的验证。

9. 价值的合并与分割

虽然逐枚处理币在理论上可行,但为转账中的每一分钱都单独做一笔交易未免笨拙。为实现价值的分割与合并,交易包含多个输入和输出。通常,要么是来自一笔较大前序交易的单个输入,要么是合并较小金额的多个输入;输出至多两个:一个用于支付,另一个(如果有找零)将零钱返还给发送方。

Transaction inputs and outputs
图 6:交易的输入与输出

需要注意的是,扇出(fan-out)——即一笔交易依赖数笔交易,而这些交易又依赖更多交易——在这里不是问题。永远不需要提取某笔交易历史的完整独立副本。

10. 隐私

传统银行模式通过将信息访问限制在当事方与可信第三方之内来实现一定程度的隐私。所有交易必须公开宣布,这排除了上述做法,但仍可以在另一个环节切断信息流来维持隐私:保持公钥匿名。公众可以看到有人向另一个人发送了一定金额,却没有任何信息能把交易与具体的人关联起来。这类似于证券交易所披露的信息层级:每笔交易的时间和规模(即"交易带"tape)公开,但不透露交易双方是谁。

Traditional privacy model (top) and new privacy model (bottom)
图 7:传统隐私模型(上)与新的隐私模型(下)

作为一道额外的防火墙,每笔交易都应使用新的密钥对,以防它们被关联到同一个所有者。多输入交易仍不可避免地会产生关联,因为它必然暴露其输入属于同一所有者。风险在于:如果某个密钥的所有者被揭露,关联分析可能揭露出属于同一所有者的其他交易。

11. 计算

我们考虑这样一种情形:攻击者试图生成一条比诚实链更快的替代链。即使做到这一点,系统也不会任人随意篡改,例如凭空创造价值,或夺取从不属于攻击者的钱。节点不会接受无效交易作为支付,诚实节点也永远不会接受包含无效交易的区块。攻击者唯一能尝试的,是更改自己的一笔交易,以夺回他最近花出去的钱。诚实链与攻击者链之间的竞赛,可以刻画为一场二项随机游走。成功事件是诚实链延长一个区块,领先 +1;失败事件是攻击者链延长一个区块,差距 −1。攻击者从给定的落后局面追上的概率,类似于赌徒破产问题。假设一个拥有无限信用的赌徒从亏损开始,进行不限次数的试验以求回本。我们可以如下计算他最终回本的概率,即攻击者最终追上诚实链的概率 [8]:

p = probability an honest node finds the next block
q = probability the attacker finds the next block
qz = probability the attacker will ever catch up from z blocks behind
qz =⎧
⎩
1 if p ≤ q
(q/p)z if p > q

在 p > q 的假设下,攻击者需要追赶的区块数越多,概率呈指数下降。对他不利的赔率下,如果开局没有幸运地猛冲一段,随着越落越远,他的机会将微乎其微。我们现在考虑:一笔新交易的收款人需要等待多久,才能充分确信发送方无法再更改该交易。假设发送方是攻击者,他想让收款人相信自己已付款一段时间,然后在过了一段时间后把交易切换成付给自己。发生切换时收款人会收到提醒,但发送方希望为时已晚。收款人在签名前不久生成新的密钥对,并把公钥交给发送方。这可以防止发送方预先准备一条区块链——持续在其上工作,直到运气好到领先足够多,再在那一刻执行交易。交易一旦发出,不诚实的发送方就开始秘密地在一条平行链上工作,其中包含他的交易的另一个版本。收款人等待,直到该交易被纳入某个区块、且其后又链接了 z 个区块。他不知道攻击者确切取得了多少进展,但假设诚实区块耗时为平均期望出块时间,攻击者的潜在进展将服从期望值为:

λ = z(q/p)

的泊松分布。要得到攻击者此刻仍可能追上的概率,我们把他每种可能进展量的泊松密度,乘以他从该点追上的概率:

∑k=0∞ λke−λ/k! · (q/p)(z−k)  if k ≤ z

整理以避开对分布无限尾部求和……

1 − ∑k=0z λke−λ/k! · (1 − (q/p)(z−k))

转为 C 代码……

   #include <math.h>
   double AttackerSuccessProbability(double q, int z)
   {
       double p = 1.0 - q;
       double lambda = z * (q / p);
       double sum = 1.0;
       int i, k;
       for (k = 0; k <= z; k++)
       {
           double poisson = exp(-lambda);
           for (i = 1; i <= k; i++)
               poisson *= lambda / i;
           sum -= poisson * (1 - pow(q / p, z - k));
       }
       return sum;
   }

运行一些结果,可以看到概率随 z 呈指数下降。

   q=0.1
   z=0     P=1.0000000
   z=1     P=0.2045873
   z=2     P=0.0509779
   z=3     P=0.0131722
   z=4     P=0.0034552
   z=5     P=0.0009137
   z=6     P=0.0002428
   z=7     P=0.0000647
   z=8     P=0.0000173
   z=9     P=0.0000046
   z=10    P=0.0000012
   q=0.3
   z=0     P=1.0000000
   z=5     P=0.1773523
   z=10    P=0.0416605
   z=15    P=0.0101008
   z=20    P=0.0024804
   z=25    P=0.0006132
   z=30    P=0.0001522
   z=35    P=0.0000379
   z=40    P=0.0000095
   z=45    P=0.0000024
   z=50    P=0.0000006

求解 P 小于 0.1% 的情形……

   P < 0.001
   q=0.10    z=5
   q=0.15    z=8
   q=0.20    z=11
   q=0.25    z=15
   q=0.30    z=24
   q=0.35    z=41
   q=0.40    z=89
   q=0.45    z=340

12. 结论

我们提出了一种不依赖信任的电子交易系统。我们从数字签名构成货币的常规框架出发,它提供了强有力的所有权控制,但若没有防止双重支付的办法则并不完整。为解决这一问题,我们提出一种点对点网络,用工作量证明记录公开的交易历史;只要诚实节点控制多数 CPU 算力,攻击者要更改这份历史很快就会在计算上变得不可行。该网络以其无结构的简单性而健壮。节点同时工作,几乎不需要协调。它们无需身份标识,因为消息不发往任何特定地点,只需尽力送达。节点可以随意离开和重新加入网络,并接受工作量证明链作为其离线期间所发生之事的证明。它们用 CPU 算力投票:通过致力于延长有效区块来表达接受,通过拒绝在其上工作来拒绝无效区块。任何必要的规则和激励,都可以用这种共识机制来执行。

参考文献

  1. [1] W. Dai, "b-money," http://www.weidai.com/bmoney.txt, 1998.
  2. [2] H. Massias, X.S. Avila, and J.-J. Quisquater, "Design of a secure timestamping service with minimal trust requirements," In 20th Symposium on Information Theory in the Benelux, May 1999.
  3. [3] S. Haber, W.S. Stornetta, "How to time-stamp a digital document," In Journal of Cryptology, vol 3, no 2, pages 99-111, 1991.
  4. [4] D. Bayer, S. Haber, W.S. Stornetta, "Improving the efficiency and reliability of digital time-stamping," In Sequences II: Methods in Communication, Security and Computer Science, pages 329-334, 1993.
  5. [5] S. Haber, W.S. Stornetta, "Secure names for bit-strings," In Proceedings of the 4th ACM Conference on Computer and Communications Security, pages 28-35, April 1997.
  6. [6] A. Back, "Hashcash - a denial of service counter-measure," http://www.hashcash.org/papers/hashcash.pdf, 2002.
  7. [7] R.C. Merkle, "Protocols for public key cryptosystems," In Proc. 1980 Symposium on Security and Privacy, IEEE Computer Society, pages 122-133, April 1980.
  8. [8] W. Feller, "An introduction to probability theory and its applications," 1957.

阅读建议

白皮书是设计说明书,不是投资文件。建议通读一遍,再对照论坛帖中中本聪此后的公开讨论(如 SPV、隐私、发行量)看哪些想法被坚持、哪些被修正。