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

Bitcoin: A Peer-to-Peer Electronic Cash System

저자 Satoshi Nakamoto · 2008

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.

Abstract

一种完全的点对点电子现金系统将允许在线支付从一方直接发送到另一方,而无需通过金融机构。数字签名提供了部分解决方案,但如果仍然需要一个可信赖的第三方来防止双重支付,那么其主要优势就会丧失。我们提出一种使用点对点网络来解决双重支付问题的方案。该网络通过将交易 hash 到一条基于 hash 的 proof-of-work 的持续增长的链中来为交易打上时间戳,形成一份不重做 proof-of-work 就无法更改的记录。最长的链不仅作为所见证事件序列的证明,而且证明它来自最大的 CPU 算力池。只要大多数 CPU 算力由不合谋攻击网络的节点控制,它们就会生成最长的链并超过攻击者。该网络本身只需要最小化的结构。消息以尽最大努力的方式广播,节点可以随时离开和重新加入网络,并接受最长的 proof-of-work 链作为其离开期间所发生事件的证明。

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

Introduction

互联网上的商业活动已经几乎完全依赖金融机构作为可信赖的第三方来处理电子支付。虽然该系统对于大多数交易运行得足够好,但它仍然受制于基于信任模型的固有弱点。完全不可逆的交易实际上是不可能的,因为金融机构无法避免调解纠纷。调解成本增加了交易成本,限制了最小实际交易规模,并切断了小额临时交易的可能性,而且在无法为不可逆服务进行不可逆支付方面存在更广泛的成本。由于存在逆转的可能性,对信任的需求就会蔓延。商家必须对客户保持警惕,向他们索要比其他情况下更多的信息。一定比例的欺诈被认为是不可避免的。这些成本和支付的不确定性可以通过使用实物货币进行面对面交易来避免,但不存在一种无需可信赖方就能通过通信渠道进行支付的机制。

所需要的是一种基于密码学证明而非信任的电子支付系统,允许任何两个有意愿的当事方直接进行交易,而无需可信赖的第三方。在计算上不可行的逆转交易将保护卖家免受欺诈,而常规的托管机制可以很容易地实施以保护买家。在本文中,我们提出一种使用点对点分布式时间戳服务器来生成交易时间顺序的计算证明的双重支付问题解决方案。只要诚实节点共同控制的 CPU 算力超过任何合谋的攻击者节点群组,该系统就是安全的。

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.

Bitcoin transaction chain showing the signature-linked ownership transfer model

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.

Transactions

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

Bitcoin transaction chain showing the signature-linked ownership transfer model

当然,问题在于收款人无法验证某个所有者是否对该货币进行了双重支付。一个常见的解决方案是引入一个可信赖的中央权威机构,即铸币厂,来检查每笔交易是否存在双重支付。每次交易后,该货币必须返回铸币厂以发行新的货币,并且只有直接从铸币厂发行的货币才被信任未被双重支付。这个方案的问题是,整个货币系统的命运取决于运营铸币厂的公司,每笔交易都必须经过他们,就像银行一样。

我们需要一种方式让收款人知道前任所有者没有签署任何更早的交易。就我们的目的而言,最早的交易是算数的那个,所以我们不关心后来的双重支付尝试。确认一笔交易不存在的唯一方法是了解所有交易。在基于铸币厂的模型中,铸币厂了解所有交易并决定哪个先到达。为了在没有可信赖方的情况下实现这一点,交易必须被公开宣布 [^1],并且我们需要一个系统让参与者就它们被接收的顺序的单一历史达成一致。收款人需要证明在每笔交易发生时,大多数节点都同意它是第一个被接收的。

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] [^3] [^4] [^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.

Bitcoin timestamp server hash-chain diagram linking blocks and items

Timestamp Server

我们提出的解决方案从一个时间戳服务器开始。时间戳服务器通过对要加时间戳的一个数据区进行 hash 并广泛发布该 hash 来工作,例如在报纸或 Usenet 帖子中 [^2] [^3] [^4] [^5]。时间戳证明了数据在当时必然已经存在,显然,这是为了能够进入该 hash。每个时间戳在其 hash 中包含前一个时间戳,形成一条链,每个额外的时间戳都加强了之前的时间戳。

Bitcoin timestamp server hash-chain diagram linking blocks and items

Proof-of-Work

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

Bitcoin proof-of-work block chain diagram with previous hash transaction set and nonce

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.

Proof-of-Work

为了在点对点的基础上实现分布式时间戳服务器,我们需要使用类似于 Adam Back 的 Hashcash [^6] 的 proof-of-work 系统,而不是报纸或 Usenet 帖子。proof-of-work 涉及扫描一个值,使得对该值进行 hash(例如使用 SHA-256)时,hash 以一定数量的零位开头。所需的平均工作量随所需零位数呈指数增长,并且可以通过执行一次 hash 来验证。

对于我们的时间戳网络,我们通过在区中递增一个 nonce 来实现 proof-of-work,直到找到一个使区块的 hash 满足所需零位数的值。一旦 CPU 花费了足够的努力使其满足 proof-of-work,该区块就无法在不重做工作的情况下被更改。随着后续区块被链接在其后,更改该区块的工作将包括重做其后所有区块的工作。

Bitcoin proof-of-work block chain diagram with previous hash transaction set and nonce

proof-of-work 还解决了在多数决定中确定代表性的问题。如果多数决定是基于一个 IP 地址一票,那么任何能够分配大量 IP 的人都可以颠覆它。proof-of-work 本质上是一个 CPU 一票。多数决定由最长的链代表,因为它投入了最大的 proof-of-work 努力。如果大多数 CPU 算力由诚实节点控制,诚实链将增长最快并超过任何竞争链。要修改一个过去的区块,攻击者必须重做该区块及其后所有区块的 proof-of-work,然后追上并超过诚实节点的工作。我们将在后面展示,一个较慢的攻击者追上的概率随着后续区块的增加呈指数下降。

为了补偿不断提高的硬件速度和随时间变化的运行节点兴趣,proof-of-work 难度由一个移动平均值确定,目标是每小时平均产出一定数量的区块。如果它们生成得太快,难度就会增加。

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

Network

运行该网络的步骤如下:

  1. 交易被广播到所有节点
  2. 每个节点将新交易收集到一个区中。
  3. 每个节点为其区块寻找一个困难的 proof-of-work。
  4. 当一个节点找到一个 proof-of-work 时,它将该区块广播到所有节点。
  5. 节点只有在区块中所有交易都是有效的且未被花费过的情况下才接受该区块。
  6. 节点通过在链中创建下一个区块来表示对该区块的接受,使用被接受区块的 hash 作为前一个 hash。

节点始终将最长的链视为正确的链,并将继续在其上扩展。如果两个节点同时广播了下一个区块的不同版本,一些节点可能先接收到其中一个或另一个。在这种情况下,它们在先接收到的版本上工作,但保留另一个分支以防它变得更长。当下一个 proof-of-work 被找到且其中一个分支变得更长时,平局将被打破;在另一个分支上工作的节点将切换到更长的那个。

新交易广播不一定需要到达所有节点。只要它们到达足够多的节点,它们不久就会进入一个区块。区块广播也容忍丢失的消息。如果一个节点没有收到一个区块,它会在收到下一个区块并意识到它遗漏了一个时请求该区块。

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.

Incentive

按照惯例,区中的第一笔交易是一笔特殊交易,它创建一枚由区块创建者拥有的新货币。这为节点支持网络增加了激励,并提供了一种将货币最初分配到流通中的方式,因为没有中央权威机构来发行它们。稳定地增加固定数量的新货币类似于金矿矿工消耗资源将黄金加入流通。在我们的案例中,消耗的是 CPU 时间和电力。

激励也可以通过交易费来资助。如果一笔交易的输出值小于其输入值,差额就是交易费,它被加到包含该交易的区块的激励值中。一旦预定数量的货币进入流通,激励就可以完全过渡到交易费,并且完全没有通货膨胀

激励可能有助于鼓励节点保持诚实。如果一个贪婪的攻击者能够集结比所有诚实节点更多的 CPU 算力,他将不得不在使用它来通过偷回自己的付款来欺骗人们,或使用它来生成新货币之间做出选择。他应该发现按照规则行事更有利可图,因为这些规则使他获得比所有其他人加起来还多的新货币,而不是破坏系统和他自身财富的有效性。

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.

Bitcoin Merkle Tree diagram showing transaction hashing and block pruning by stubbing off branches

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.

Reclaiming Disk Space

一旦一枚货币中的最新交易被埋在足够多的区之下,之前已花费的交易就可以被丢弃以节省磁盘空间。为了在不破坏区块 hash 的情况下实现这一点,交易被 hash 到一棵 Merkle Tree [^7] [^2] [^5] 中,只有根节点包含在区块的 hash 中。旧区块随后可以通过裁剪树的分支来压缩。内部 hash 不需要被存储

Bitcoin Merkle Tree diagram showing transaction hashing and block pruning by stubbing off branches

一个没有交易的区块头大约是 80 字节。如果我们假设区块每 10 分钟生成一次,80 字节 * 6 * 24 * 365 = 每年 4.2MB。截至 2008 年,计算机系统通常配备 2GB 的 RAM,而摩尔定律预测当前每年增长 1.2GB,即使区块头必须保存在内存中,存储也不应该成为问题。

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.

Bitcoin simplified payment verification showing the longest proof-of-work chain with Merkle branch linking to a transaction

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.

Simplified Payment Verification

在不运行完整网络节点的情况下验证支付是可能的。用户只需要保留一份最长 proof-of-work 链的头">区块头副本,他可以通过查询网络节点直到确信自己拥有最长的链来获取它,并获取将交易链接到其被打上时间戳的区块的 Merkle 分支。他无法自己检查交易,但通过将其链接到链中的某个位置,他可以看到网络节点已经接受了它,而在其后添加的区块进一步确认了网络已经接受了它。

Bitcoin simplified payment verification showing the longest proof-of-work chain with Merkle branch linking to a transaction

因此,只要诚实节点控制着网络,验证就是可靠的,但如果网络被攻击者制服则更加脆弱。虽然网络节点可以自己验证交易,但只要攻击者能够继续制服网络,简化方法就可能被攻击者伪造的交易所欺骗。一种防御策略是接受来自网络节点的警报,当它们检测到无效区块时,提示用户的软件下载完整区块和被警报的交易以确认不一致性。频繁接收支付的企业可能仍然希望运行自己的节点以获得更独立的安全性和更快的验证。

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.

Bitcoin transaction combining and splitting value with multiple inputs and outputs

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.

Combining and Splitting Value

虽然可以单独处理每枚货币,但为转账中的每一分钱都创建一笔单独的交易将是笨拙的。为了允许价值的拆分和合并,交易包含多个输入和输出。通常要么有一个来自较大前序交易的单一输入,要么有多个合并较小金额的输入,最多有两个输出:一个用于支付,另一个将找零(如果有的话)返回给发送者。

Bitcoin transaction combining and splitting value with multiple inputs and outputs

应该注意的是,扇出(即一笔交易依赖于多笔交易,而那些交易又依赖于更多的交易)在这里不是问题。从来不需要提取一笔交易的完整独立历史副本。

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.

Bitcoin privacy model comparison showing traditional model with trusted third party versus new model with anonymous public keys

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.

Privacy

传统的银行模型通过限制相关方和可信赖第三方对信息的访问来实现一定程度的隐私。公开宣布所有交易的必要性排除了这种方法,但隐私仍然可以通过在另一个地方打断信息流来维持:保持公钥匿名。公众可以看到某人正在向其他人发送一笔金额,但没有将交易与任何人关联的信息。这类似于证券交易所发布的信息级别,个别交易的时间和规模,即"行情",是公开的,但不会透露当事方是谁。

Bitcoin privacy model comparison showing traditional model with trusted third party versus new model with anonymous public keys

作为额外的防火墙,每笔交易应使用一对新的密钥,以防止它们被关联到一个共同的所有者。对于多输入交易,某些关联仍然是不可避免的,因为它们必然揭示其输入属于同一所有者。风险在于,如果密钥的所有者被揭露,关联可能会揭示属于同一所有者的其他交易。

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 = \begin{cases} 1 & \text{if } p \leq q \\ \left(\frac{q}{p}\right) z & \text{if } p > q \end{cases} \]

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:

\[ \lambda = z\frac{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:

\[ \sum_{k=0}^{\infty} \frac{\lambda^k e^{-\lambda}}{k!} \cdot \left\{ \begin{array}{cl} \left(\frac{q}{p}\right)^{(z-k)} & \text{if } k \leq z \\ 1 & \text{if } k > z \end{array} \right. \]

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

\[ 1 - \sum_{k=0}^{z} \frac{\lambda^k e^{-\lambda}}{k!} \left(1-\left(\frac{q}{p}\right)^{(z-k)}\right) \]

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

Calculations

我们考虑一个攻击者试图比诚实链更快地生成替代链的场景。即使这一目标达成,也不会使系统面临任意更改的风险,例如凭空创造价值或夺取从不属于攻击者的资金。节点不会接受无效交易作为支付,诚实节点永远不会接受包含无效交易的区。攻击者只能尝试更改自己的一笔交易,以收回他最近花费的资金。

诚实链与攻击者链之间的竞赛可以被描述为一个二项随机游走。成功事件是诚实链被延长一个区块,使其领先优势增加 +1,失败事件是攻击者的链被延长一个区块,使差距缩小 -1。

攻击者从给定落后距离追上的概率类似于赌徒破产问题。假设一个拥有无限信用的赌徒从亏损开始,进行潜在的无限次尝试以达到盈亏平衡。我们可以计算他最终达到盈亏平衡的概率,即攻击者追上诚实链的概率,如下 [^8]:

p = probability an honest node finds the next block
q = probability the attacker finds the next block
q = probability the attacker will ever catch up from z blocks behind
``````

\[
qz =
\begin{cases}
1 & \text{if } p \leq q \\
\left(\frac{q}{p}\right) z & \text{if } p > q
\end{cases}
\]

假设 p  q,概率随着攻击者需要追赶的区块数量的增加而呈指数下降。如果他没有在早期幸运地向前冲刺,随着他进一步落后,他的机会变得微乎其微。

我们现在考虑新交易的接收者需要等待多长时间才能充分确定发送者无法更改交易。我们假设发送者是一个攻击者,他想让接收者相信他已经付款了一段时间,然后在一段时间后将其改为支付给自己。接收者在那时会收到警报,但发送者希望那时已经太晚了。

接收者生成一对新密钥,并在签名前不久将公钥提供给发送者。这防止了发送者通过持续在其上工作来提前准备一条区块链,直到他足够幸运地取得足够的领先,然后在那个时刻执行交易。一旦交易发送,不诚实的发送者开始秘密地在一条包含其交易替代版本的并行链上工作。

接收者等待交易被添加到一个区块中,并且在其后链接了 z 个区块。他不知道攻击者已经取得的确切进展,但假设诚实区块按照每个区块的平均预期时间产出,攻击者的潜在进展将是一个期望值为以下值的泊松分布:

\[
\lambda = z\frac{q}{p}
\]

为了获得攻击者现在仍然能够追上的概率,我们将他可能取得的每个进展量的泊松密度乘以他从该点追上的概率:

\[
\sum_{k=0}^{\infty} \frac{\lambda^k e^{-\lambda}}{k!} \cdot \left\{
\begin{array}{cl}
\left(\frac{q}{p}\right)^{(z-k)} & \text{if } k \leq z \\
1 & \text{if } k > z
\end{array}
\right.
\]

重新整理以避免对分布的无穷尾部求和......

\[
1 - \sum_{k=0}^{z} \frac{\lambda^k e^{-\lambda}}{k!} \left(1-\left(\frac{q}{p}\right)^{(z-k)}\right)
\]

转换为 C 代码......

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

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.

Conclusion

我们提出了一种不依赖信任的电子交易系统。我们从由数字签名构成的货币的通常框架开始,这提供了对所有权的强有力控制,但如果没有防止双重支付的方法则是不完整的。为了解决这个问题,我们提出了一种使用 proof-of-work 的点对点网络来记录交易的公共历史,如果诚实节点控制了大多数 CPU 算力,对攻击者来说更改记录在计算上很快就变得不可行。该网络在其非结构化的简单性中是健壮的。节点同时工作,几乎不需要协调。它们不需要被识别,因为消息不会被路由到任何特定的地方,只需要以尽最大努力的方式传递。节点可以随时离开和重新加入网络,接受 proof-of-work 链作为其离开期间所发生事件的证明。它们用自己的 CPU 算力投票,通过在有效区块上扩展来表示接受,通过拒绝在无效区块上工作来表示拒绝。任何需要的规则和激励都可以通过这种共识机制来执行。

References


  1. W. Dai, "b-money," http://www.weidai.com/bmoney.txt, 1998.

  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. 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. 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. 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. A. Back, "Hashcash - a denial of service counter-measure," http://www.hashcash.org/papers/hashcash.pdf, 2002.

  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. W. Feller, "An introduction to probability theory and its applications," 1957.

References


  1. W. Dai, "b-money," http://www.weidai.com/bmoney.txt, 1998.

  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. 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. 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. 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. A. Back, "Hashcash - a denial of service counter-measure," http://www.hashcash.org/papers/hashcash.pdf, 2002.

  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. W. Feller, "An introduction to probability theory and its applications," 1957.