论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(7)

比特币:一个点对点的电子货币系统

9 合并和分割货币

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.

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.

尽管单独处理每个货币是可能的,但将一次转账按每一分拆成多次交易太笨拙。为允许交易额被分割和合并,交易将包含多个输入值和输出值。通常是一个从之前交易而得的较大输入值或多个较小输入值的组合,以及最多两个输出值:一个作为支付,另一个作为找零,如果有的话,退还给支付发送方。

需要注意的是,这里的扇出(fan-out),即一笔交易依赖数笔交易,这数笔交易又依赖更多的交易,形成了一个树状结构。在比特币系统中,这种情况不会成为问题,因为不需要获取一笔交易历史的完整独立副本。

【关注点】:

  • 扇出(fan-out), 是一个比较形象的说法,后面直接给出了定义。
  • 不需要获取一笔交易历史的完整独立副本,并没有解释原因,为什么呢?

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(6)

比特币:一个点对点的电子货币系统

8.简化的支付验证

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.

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.

不运行一个完整的网络节点也是可以进行支付验证的。用户只需拥有一个最长工作量证明链的区块头副本,他可以通过向其他网络节点查询以确认他拥有了最长的链,并获取链接交易到给交易打时间戳区块的默克尔分支。虽然他自己不能核实这个交易,但如果交易已经链接到链中的某个位置,就说明一个网络节点已经接受了此交易,而其后追加的区块进一步确认网络已经接受了它。

同样地,只要诚实节点控制着网络,这种简化验证就是可靠的;如果网络被攻击者控制,简化验证会变得比较脆弱。虽然网络节点可以验证他们自己的交易,但只要攻击者持续控制网络,那么这种简化的方法就可能被攻击者的伪造交易欺骗。一种对策是接受其他网络节点发现一个无效区块时发出的警告,提醒用户软件下载整个区块和被警告的交易来检查一致性。为了更加独立的安全性以及更快的支付确认,收款频繁的公司可能仍需运行他们自己的节点。

【关注点】:

  • 向其他网络节点查询以确认他拥有了最长的链, 如何做到?
  • 仍需运行他们自己的节点,是指要运行全节点吗?

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(5)

比特币:一个点对点的电子货币系统

6. 激励

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.

我们约定,区块中的第一笔交易是区块创建者开创一枚属于他的新货币的特殊的交易。这就加入了对支持网络的节点的激励,并提供了一种初始分发货币到流通领域的方法,因为这里没有中央机构来发行货币。新货币按固定量稳定地增加就像金矿矿工消耗资源并增加黄金到流通领域一样。对我们而言,消耗的是 CPU 时间和电力激励也可以由交易费充当。如果交易的输出值小于其输入值,差价就作为交易费被加到包含此交易的区块的激励中。一旦预定量的货币进入了流通领域,激励将变为只含有交易费,这样可以完全避免通货膨胀。
激励会有助于鼓励节点保持诚实。如果一个贪心的攻击者有能力聚集比所有诚实节点更多的 CPU 算力,他将面临是以骗回已付款的方式欺诈别人还是使用这些算力生成新货币的抉择。他将发现遵守规则比破坏系统和他自己财产的有效性更有利,因为这些规则准许他获得比所有其他人都多的新货币。

7. 回收磁盘空间

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

    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.

一旦某个货币的最新交易已经被足够多的区块覆盖,这之前的支付交易就可以被丢弃以节省磁盘空间。为便于此而又不破坏区块的哈希值,交易将被哈希进默克尔树 [7][2][5],只有根节点被纳入到区块的哈希值。老的区块可通过剪除树枝的方式被压缩。树枝内部的哈希不需要被保存。

每个不包含交易的区块头大约是 80 bytes。如果每 10 分钟生成一个区块,每年生成80 bytes * 6 * 24 * 365 = 4.2 MB,2008 年在售的典型计算机有 2 GB 内存,并且摩尔定律预测目前每年内存增加 1.2 GB,所以就算区块头一定要存在内存里,存储也不是问题。

【关注点】:

  • If the output value of a transaction is less than its input value,这句话不是太理解,什么情况下会出现?
  • favour him with more new coins,翻译为 有利于他 获得更多的新币。问题是当到后期新币越来越少的时候,做这个事情是否是就有利可图了?
  • enough blocks ,多少算足够?
  • transactions are hashed in a Merkle Tree,为什么这样就可以不改变Hash值?

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(4)

比特币:一个点对点的电子货币系统

5. 网络

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

运行网络的步骤如下:

  1. 新交易向所有节点广播。
  2. 每个节点将新交易收集到一个区块。
  3. 每个节点为它的区块寻找工作量证明(困难)。
  4. 当一个节点找到了工作量证明,就向所有节点广播这个区块。
  5. 节点只有在区块内所有交易都是有效的且之前没有被支付的情况下接收这个区块。
  6. 节点通过使用这个区块的哈希值作为上一个哈希值,在链中创建下一个区块的方式表示对这个区块的接受。

节点总是认为最长的链为正确的并持续致力于延长它。如果两个节点同时广播了不同的下一个区块,有些节点可能先收到其中一个而其他节点先收到另一个。这种情况,节点基于他们收到的第一个区块工作,但是也保存另一个分支以防它变为更长的链。当下一个工作量证明被找到后僵局就会被打破,从而其中一个分支变得更长;在另一个分支上工作的节点将切换到更长的链上来。

新交易的广播不必到达所有的节点。只要到达一些节点,不久就会进入到一个区块。区块广播也是能容忍消息丢失的。如果一个节点没有收到某个区块,它将在收到下一个区块时发现它丢失了一个区块然后去请求这个区块。

【关注点】:

  • 另一个分支上工作的节点将切换到更长的链,也就意味着有些交易会失效,对于这些失效的交易如何处理?
  • 不久就会进入到一个区块,这个是指这笔交易会被保存到区块里。那一个区块会包含多少笔交易呢?

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(3)

比特币:一个点对点的电子货币系统

3. 时间戳服务器

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.

我们提出的方案从时间戳服务器开始。时间戳服务器计算包含多个需要被打时间戳的数据项的区块的哈希值并广泛地发布这个哈希值,就像在报纸或新闻组帖子里 [2-5]。时间戳能证明要得到这个哈希值,显然这些数据当时一定是存在的。每个时间戳的哈希值都纳入了上一个时间戳,形成一条链,后面的时间戳进一步增强前一个时间戳。

More...

哈希函数和数字签名

1. 哈希函数 Hash

1.1 概念

  • Hash,一般翻译做散列,也有直接音译为哈希的。就是把任意长度的输入通过散列算法变换成固定长度的输出,该输出就是散列值。
  • 这种转换是一种压缩映射,也就是散列值的空间通常远小于输入的空间,不同的输入可能会散列成相同的输出,所以不可能从散列值来确定唯一的输入值。简单的说,就是一种将任意长度的消息压缩到某一固定长度的消息摘要的函数。
  • 单向散列函数:又称单向Hash函数、杂凑函数,就是把任意长的输入消息串变化成固定长的输出串且由输出串难以得到输入串的一种函数。这个输出串称为该消息的散列值。一般用于产生消息摘要,密钥加密等.

1.2 特点

  • 算法是公开的
  • 对相同数据运算,得到的结果是一样的
  • 对不同数据运算,如MD5得到的结果默认是128位,32个字符(16进制标识)。
  • 没法进行逆运算信息摘要。
  • 信息“指纹”,是用来做数据识别的。
  • 加密后密文的长度是定长的

1.3 用途

  • 用户密码的加密
  • 搜索引擎,关键字识别(搜索多个关键字,先对每个关键字进行散列,然后多个关键字进行或运算,如果值一致则搜索结果一致)
  • 版权标注 对文件进行散列判断该文件是否是正版或原版的
  • 数字签名 (文件完整性验证 对整个文件进行散列,比较散列值判断文件是否完整或被篡改)
More...

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(2)

比特币:一个点对点的电子货币系统

2. 交易

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

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.

More...

Is-A 和 Has-A 的取舍

问题

组合和继承是允许在新建的类中放入子对象。其中“Is-A (是一个)”的关系是用继承来表达的,而“Has-A(有一个)”的关系则是用组合来表达的。
组合是显示的这样做的,而继承是隐式的做。组合一般是将现有的类型作为新类型底层实现的一部分来加以复用,在一个类中引用另一个类,而继承是拥有了父类的非私有方法。
二者是之间有何区别?或者怎样在二者之间做出选择呢?

优缺点分析

继承的优点:

  1. 子类可以重写父类的方法来方便地实现对父类的扩展。

继承的缺点:

  1. 父类的内部细节对子类是可见的。
  2. 子类从父类继承的方法在编译时就确定下来了,所以无法在运行期间改变从父类继承的方法的行为。
  3. 如果对父类的方法做了修改的话(比如增加了一个参数),则子类的方法必须做出相应的修改。所以说子类与父类是一种高耦合,违背了面向对象思想。

组合的优点:

  1. 当前对象只能通过所包含的那个对象去调用其方法,所以所包含的对象的内部细节对当前对象时不可见的。
  2. 当前对象与包含的对象是一个低耦合关系,如果修改包含对象的类中代码不需要修改当前对象类的代码。
  3. 当前对象可以在运行时动态的绑定所包含的对象。可以通过set方法给所包含对象赋值。

组合的缺点:

  1. 容易产生过多的对象。
  2. 为了能组合多个对象,必须仔细对接口进行定义。
More...

论文学习 - Bitcoin:A Peer-to-Peer Electronic Cash System(1)

比特币:一个点对点的电子货币系统

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.

摘要: 本文提出了一种完全通过点对点技术实现的电子货币系统,它使得在线支付能够直接由一方发起并支付给另外一方,中间不需要通过任何的金融机构。虽然数字签名部分解决了这个问题,但是如果仍然需要可信任的第三方的支持才能防止重复支付的话,那么这种系统的也会失去价值。我们在此提出一种解决方案,使支付系统在点对点的环境下运行,并防止重复支付问题。该网络通过随机散列对全部交易加上时间戳,将它们合并入一个不断延伸的基于随机散列的工作量证明(proof-of-work)的链条作为交易记录,除非重新完成全部的工作量证明,形成的交易记录将不可更改。最长的链条不仅将作为被观察到的事件序列的证明,而且被看做是来自 CPU计算能力最大的池。只要大多数的节点的CPU 计算能力没有被控制用来进行对全网的攻击,那么这些节点将会生成最长的、超过攻击者的链条。这个系统本身需要的基础设施非常少。信息尽最大努力在全网传播即可,节点可以随时离开和重新加入网络,并将接受最长的工作量证明链条作为在该节点离线期间发生的交易的证明。

More...

请我喝杯咖啡吧~

支付宝
微信