Bitcoin: A Peer-to-Peer Electronic Cash System
Ⅰ. 思考并摘录比特币系统中全部技术原理,适当拓展相关知识Abstract:去中心化,实现端到端的网络(or 电子?)交易,并(更重要的是)解决双花问题【支付系统的固有问题】
-
Abstract:去中心化,实现端到端的网络(or 电子?)交易,并(更重要的是)解决双花问题【支付系统的固有问题】
-
‘ allow online payments to be sent directly from one party to another without going through a financial institution, propose a solution to 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. ”
-
**该网络通过随机散列(hashing)对全部交易加上时间戳(timestamps),将它们合并入一个不断延伸的基于随机散列的工作量证明(proof-of-work)的链条作为交易记录。**形成一个非工作量证明全部重做不可更改的记录
??什么CAP原则??
-
? 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 longest chain:被观察到的事件序列的证明;来自最大的CPU算力池的证据, 只要不攻击全网的算力占多数,网络的honest就能得以保证。
-
? 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. ”
??为何节点会主动参与到信息的广播,广播的具体形式(交易双方进行全网广播?)。
??节点重新加入后接受最长链:是指重新登陆网络后可以选择一条链进行挖掘新区块?接收方式是在本地下载最长链的信息?
- 验证比特币网络当前状态是否有效的唯一方法是从创世区块的状态开始,执行从创世区块到当前状态的每个交易。
- 时间链为新验证者提供审计轨迹,它是通过证明区块高度12中的交易发生并必须在区块高度11的区块交易之后执行来提供的。
-
-
Introduction:互联网交易对金融机构作为可信第三方的依赖是一种固有的缺陷,通过本文系统解决诈骗问题,以达到在通信通道上不借助第三方保证可信交易
-
“Completely non-reversible transactions are not really possible, since financial institutions cannotavoid mediating disputes. ”
这里是指存在纠纷,经第三方调停后,难免会存在撤销的交易(即逆交易)。|| ??此外第三方的存在会增加成本,而导致小型的交易无法进行?(这里存在一个议论点,去中心化后的网络会倾向与卖方,货物的质量无法保证?依据可靠的交易凭证,借助法律从而保障权利)
-
“an electronic payment system based on cryptographic proof instead of trust ”
使用密码学原理取代可信第三方
-
“Transactions that are computationally impractical to reverse ”
-
“routine escrow mechanisms”——程序化的合约机制?常规的第三方担保机制
-
“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. ”
使用一个点对点的分布式时间戳服务器,生成按时间序列的交易的计算证明。
- 中心?安全性?其为何不存在被攻击可能性?——全节点时间整理以保证时间戳的正确性? 从其功能上分析,服务器负责生成(交易记录?),是否有攻击的价值?
- 生成的 computational proof 的内容——区块?或者准确说是区块上的交易记录?
-
该系统的可信前提是:诚信(不蓄意攻击网络)的人拥有更多的算力
-
-
Transactions :
-
“Bitcoin is a chain of digital signatures”
-
transfer the coin: “ 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”
-
-
不对称加密算法——公钥可以加密数据或验证数据,私钥可以解密数据或对数据签名
payee can verify the signatures to verify the ownership “the chain of ownership”
如何确认无双花的问题
-
“introduce a trust mint”, 每次交易后都会硬币“回炉”,只有铸币厂直接issue的货币是受到未双花保证的
————这样就衍生出一个老生常谈的问题:铸币厂不是一种中心化的存在吗?安全吗?可信吗?第三方金融机构又有何区别?——PASS
-
故采用这样的方式:“ publicly announced”(收款人如何便捷的实现对coins的交易历史进行查验?——投票公决制度:majority nodes 判别 first received —— timestamp server?) & “ a system for participants to agree on a single history of the order in which they were received“
-
补充:比特币交易是存在手续费的,节点参加验证计算 都? 是有奖励的;即作为矿工除了挖矿会带来收益,参与验证机制也会带来收益。—— Q:同样存在线上交易的手续费,比特币系统与传统第三方网络交易的优势仅在于低廉吗?
-
“The only way to confirm the absence of a transaction is to be ware of all transtactions”
-
Timestamp Server (?):taking a hash of a block of items to be timestamped,and publish the hash widely.
-
“The timestamp proves that the data must have existed at the time, obviously, in order to get into the hash. ”
显然,为了进入hash,时间戳用于证明当时数据已存在。
-
taking a hash of a block of items to be timestamped
-
hash ( timestamp( block=Σ item + preious hash )
hash-hash-hash-hash……
-
-
Attention:如何获取一个去中心化的时间?——是否存在safer的可能性**
利用“多数人的honest”,时间来自与其他节点时间的中位数(**mean?**比平均数更不易受极端数据的影响)
-
要求连接至少为5个节点
-
中位数与本地系统时间差不超过70mins,否则会提醒更新本机时间
-
在接收到新的block时会拒绝时间与本机差距+2hours 和 -(前11个block的时间中位数) 的block
-
-
Proof-of-work:
-
a Proof-of-work system similar to Adam Back’s Hashcash ,rahter than Usenet posts.
-
POW involves scanning for a value that when hashed ,such as with SHA-256
-
the hash begin with a number of zero bit
-
the average work required is exponential in the number of zero bit required
安全有三个延伸层面:可管理、可察觉、攻击成本,比特币使用了可管理、攻击成本,hash的0数目是可控的,而0的数目决定工作量。计算成本为CPU算力与电力,成本会高于收益?(大额交易的双花会不会收益大于成本?)
此外,如果一个51%攻击达成,攻击者会达成目的,但是整个系统的价值会崩溃掉,那么攻击中获取的比特币也没有任何意义了,攻击者付出的大量硬件投资和电费就没有意义了
-
can be verified by executing a single hash ——如何进行验证?
-
increment 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.
-
Solve the problem of determining representation in majority decision making.
-
majority of systems were based on one-IP-address-one-vote(IP地址共识机制)(IP地址分配是一种中心化的形式——IP地址的分配受ICP控制,政府组织可以很轻易回收和控制这些ip地址资源)
-
POW is essentially one-CPU-one-vote
- the majority of CPU power is represented by the longest chain, which has the greatest proof-of-work effort inested in it.
- so if a majority of CPU power is controlled by honest node,the honest chain grow the fastest and outpace any competing chains.
-
modify the chain:
-
need redo the POW of the block and all blocks after it.
-
And catch up and surpass the woek of honest nodes
-
-
The difficulty of POW: it determinded by a moving average targeting an average number of blocks per hour.
-
Attention:
- 比特币系统使用的是SHA-256进行加密,目前常见的加密方式还有哪些(国密?)
- 在系统中如何选择并使用加密方式?
- 是否可以对区块链的加密方式进行更改?如何实现?
-
-
Network:系统运行流程
-
如何进行广播?广播的内容是什么形式?
- 类似DHT网络的P2P网络协议进行无中心化的网络连接,这种协议在比特币出现前已经被广泛使用,Kad,eMule、BT等都使用了类似的协议
- 比特节点通常采用TCP协议、使用8333端口(该端口号通常是比特币所使用的,除8333端口外也可以指定使用其他端口)与已知的对等节点建立连接。
-
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.
-
If two nodes broadcast different versions of the next block simultaneously
- nodes will receive one and save the other one in case it becomes longer earily, and that forms a tie
- when the next POW(block) was found and on branch becomes longer, the tie will be broken.
-
New transaction broadcasts do not necessarily need to reach all nodes.
- 至少需要被多少节点接受?
-
block broadcasts are also tolerant of dropped messages.
- If a node not receive a block, it will request it when it receives the next block and realizes it missed one.
- 如何申请错过的区块?效率如何,仅仅是同区块数据即可(是否仍需要进行验证)?
- 容缺的数量是否有上限?
-
Incentive: 比特币与区块链的实际关系
-
区块上的第一笔交易:一枚新币被赋予这个区块的创造者(矿工)
-
而这就是对网络中的参与者的激励,并作为比特币发行的源头(无中心的货币发行方式)
-
know more about inflation:
- 通过不再发币从而避免了通货膨胀???
-
encourage nodes to stay honest ——以激情开始,以利益维持
- the attacker assemble more CPU power than all the honest nodes
- defraud people by stealing back his payments——by this way the validity of bitcoin will be undermined, his wealth is nothing.
- generate new coins——play by the rules is more profitable
- the attacker assemble more CPU power than all the honest nodes
-
比特币系统实际上是一个非常依赖CPU算力的系统,需要大量的运算进行POW和交易确认,激励机制的设计最重要的就是要维持系统核心需求,而比特币需要的就是算力。 这里其实算力的需求更多是为了交易的记录和认证,产生区块需要计算,交易的有效认可需要多数节点的验算还是需要算力的参与。
-
区块链的激励主要来自:挖矿 & 交易费,当固定值的矿尽后,激励就只来自交易费。
风险需要注意,这需要有矿机的同学进行一下计算,一旦比特币进入后期,需要单位挖矿的电力成本超过比特币价值时矿场就无法通过挖矿盈利,结果就是矿场只能靠交易盈利,但是如果比特币不能有有效的大规模商业应用,会出现一个问题,就是没有足够的交易量维持计算所需的“交易费”,计算节点就会萎缩,导致交易时间过长,只能不断提升“交易费”,最终导致整个系统崩盘,这绝对不是危言耸听,所以目前比特币进行的闪电网络包括BU分叉都是为了解决这个问题,越到后期越要注意交易成本和确认效率。
-
闪电网络、BU分叉
Attention:关于激励可以鼓励诚实仍存在疑虑,
-
-
并且需要考虑激励机制在其他场景中的运用是否存在同样的问题或是新问题?
-
Reclaiming Disk Space:节点可选择删除过早的交易数据,仅保存其对应的Merkle Root,从而压缩老区块。
-
the latest transaction in a coin is buried under enough blocks, the spent transaction before it can be discarded to save disk space.
-
without break the block’s hash, transactions are hashed in Merkle Tree,with only the root included in the block’s hash.
- Old block can then be compacted by stubbing off branches of the tree.
- The interior hashes do not need to be stored
-
Merkle Tree
- 区块上的交易记录的大小及区块的存储能力(大小及读写速度)
-
-
Simplified Payment Verification:
- 通过向其他点查询以确认最长链——每个节点的认可链数据是全公开的?可随意查看?
- 将交易信息链接到给交易打时间戳的区块的默克尔分枝上——所以交易信息是以hash的形式结合在默克尔分支上,而默克尔分支存于区块中。
- 区块中的上一个哈希是指区块头的hash?
-
在时间序列的背景下,区块链的每个区块包含两份信息:区块头和区块体。区块头主要包含:前一区块区块头的hash 、Nonce、Merkle Root(的hash),区块体主要是交易的具体信息(数量、数据)
-
区块头共80字节,分为6个部分:version,prevBlockHash,merkleRoot,time difficultyTarget,nonce。version:大小为4字节,记录了区块头的版本号,用于跟踪软件/协议的更新;
prevBlockHash:大小为32字节 ,记录了该区块的上一个区块的Hash地址;
merkleRoot:大小为32字节,记录了该区块中交易的merkle树根的哈希值;
time:大小为 4字节,记录了该区块的创建时间戳;
difficultyTarget:大小为4字节,记录了该区块链工作量证明难度目标;
nonce:大小为4字节,记录了用于证明工作量的计算参数。
-
区块体的内容是该区块的交易信息,包括交易数量和交易数据。区块体共分为三部分:
numTransactionsBytes,numTransactions,transactions。
numTransactionsBytes:大小为1字节,记录了交易数量占用的字节数;
numTransactions:大小为0-8个字节,记录了区块内的交易数量;
transactions:大小不确定,记录了区块内存的多个交易数据。
-
在区块体部分中,numTransactions(记录区块内交易数量)是存储交易信息的重要字段,将numTransactions(记录区块内交易数量)部分使用压缩存储方式,这样可以大量的节约存储空间。numTransactionsBytes字段的存在是为了指出numTransactions在区块体中存在的部位,为读取交易数量而做准备,因此,应最先读取numTransactionsBytes字段值,并根据该字段值的不同做出如下规定:
如果numTransactionsBytes字段值小于253,则交易数量为numTransactionsBytes字段值作为;
如果numTransactionsBytes字段值等于253,则交易数量为numTransactionsBytes字段值之后的两个字节;
如果numTransactionsBytes字段值等于254,则交易数量为numTransactionsBytes字段值之后的4个字节;
否则,交易数量为numTransactionsBytes字段值之后的8个字节。
-
-
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问题,即一笔交易 depend on 多笔交易,而这些交易又 depend on 更多的交易,这种问题在区块链中不再是一个问题。我们永远也不需要提取出一个交易历史的完整独立副本。
扇出(fan-out)——多输入影响一个输出,即一笔交易依赖与过去多笔交易的合并。
对于交易来说,历史并不是最重要的,重要的是这笔钱目前未被花费过,即UTXO。
-
比特币账本设计方式:——比特币的面额(value)是不定的,其变化是通过combine&split实现的,面额的变化是在交易中发生的,这样每个币都是有可溯源的历史的。
-
拓展对比:账户余额记账法
-
UTXO(Unspent Transaction Output)
-
###ATTENTION: Privacy:announce all transaction publicly & keep public keys anonymous
-
The public can see that someone is sending an amount to someone else, but without information linking the transaction to anyone.
-
关于公开尺度——公开交易信息的内容,将会决定他人通过信息相关性确定你的个人信息,这种交易与参与人信息的隔离性隐私保护极为脆弱。
-
参考文章:《比特币隐私保护的工作原理介绍》电子发烧友 周亮
http://www.elecfans.com/blockchain/1042303.html
-
-
Calculations: 关于一条攻击替代链反超诚信链的概率计算
-
前提:在比特币系统中,攻击者有能力并真实攻击了最长链后,其可获得的收益只有两种,而这两种选择都不是对其有利可图的。
- 摧毁网络的可信度
- 重新拥有自己的一笔支付款
-
假设背景:攻击者想要对过去的一区块进行修改,即产生一个分叉生成一个平行区块,并在此基础上生成一条超过诚信链的最长链
-
挑战:要拥有远超honest的挖矿概率
-
计算过程:
-
how long the recipient of a new transaction needs to wait before being sufficiently certain the sender can’t change the transaction ?
-
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;
}
-
-
Conclusion: