比特币里的计算机知识
一、人民币、支付宝和比特币有什么区别
(1)人民币
(1) RMB
大家都很清楚,人民币就是中国人民银行发行的货币。这些货币流通到市场中,每个人有了钱以后可以去购买各种商品和服务,人民币就会从一个人手里转到另外一个人手里。钱流通到市场中后,具体某一个编号的纸币在某个特定的时候在谁身上是不确定的,国家也不关心。纸币在实际中是很难复制的,复制成本高、风险也很大。
& nbsp; & nbsp; & nbsp; Everyone is well aware that the renminbi is the currency issued by the People’s Bank of China. These money flows to the market, where each person can buy a variety of goods and services when he or she has the money, and the renminbi moves from one person to another. When money flows to the market, a specific number of coins is uncertain at a given time, and the country does not care.
(2)支付宝
(2) Payment of Treasures
支付宝,当然包括微信,里面的余额说白了就是一个数据,存储在支付宝和微信公司的服务器上。同人民币不同,数据的复制、修改是不需要成本的。这些电子货币在市场上是怎样运行的?以支付宝为例,首先你要申请一个支付宝账户,然后关联一张银行卡,这样你就可以把支付宝中的钱转出到银行卡或者将银行卡的钱充值到支付宝中。当你消费时利用支付宝付款或者营收通过支付宝收款时,对方也必须要有一个支付宝账号,这样付多少钱实际上是从你的支付宝账号上扣款,给对方支付宝账户加钱。
& nbsp; & nbsp; & nbsp; & nbsp; payment treasures, including, of course, micro-mails, the balance of which is a data item that is stored on the servers of payment and micro-mail companies. Unlike the renminbi, there is no cost in copying and modifying the data. How do these electronic currencies operate in the market? For example, you have to apply for a payment bond account and then link it to a bank card so that you can transfer the money from the payment treasure to a bank card or revalue the money from the bank card to a payment bond. When you consume it, you must also have a payment account number, so how much money is actually withheld from your payment number, and you pay the other party for the payment.
这其中涉及到两个方面的数据变动。一是和银行相关:支付宝在各大银行都开了一个账号,个人在用银行卡往自己的支付宝账号充值或者提现,实际上是银行中支付宝那个大账号和你的账号之间的存款变动。当然支付宝公司会将你支付宝账号上的数值进行相应的变动。二是和银行无关,支付宝内部数据转换。当你和对方之间一个用支付宝进行付钱、另一个进行收钱,这个时候就跟银行没有关系,是支付宝自己内部数据的转换问题。
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; this involves data changes in two areas. First, it is bank-related: payment treasures have an account number in each of the major banks, and individuals are charging or cashing their own payment numbers with a bank card, which is actually the change in deposits between the big account number and your account number in the bank. Of course, payment treasure companies will change the value on your payment number. Second, it is not bank-related, the internal data on payment treasures.
国家发行的纸币是以国家的信用进行背书,确保纸币有购买力,而不是废纸,通货膨胀贬值除外。银行卡里的存款安全是以银行的信用进行背书,当然我国的银行主要是国有银行,其实也是以国家的信用背书。支付宝、微信的电子货币支付是以蚂蚁金服和腾讯公司的信用进行背书的。如果有一天蚂蚁金服把在各大银行中开的账户钱全部转移后注销掉,同时宣告各位支付宝上的余额就是一个数字,没有任何意义,甚至直接将所有的支付宝账户余额全部清零。这并非不可能发生。作为国家肯定有一定的监管措施的,比如支付宝在工行开的账号在一定时间内有异于平时有大量的资金流出到其他少数账号中,那就进行冻结交易,进行调查。但是支付宝公司直接将每个人支付宝账户数字清零,即使其在银行开的大账户有钱也不知道怎么给各位分配。
& nbsp; & nbsp; & nbsp; & nbsp; & & nbsp; banknotes issued by the state are endorsed by the credit of the state, ensuring the purchasing power of the bank, not waste paper, with the exception of inflation depreciation. Bank’s deposit security is endorsed by bank credit, although our banks are mainly state-owned banks and, of course, by the credit endorsement of the state. Payment of treasures, micro-trust electronic currency payments are backed by the credit of the company’s ants and tethers. If one day antscoat cancels the entire amount of the money in the bank’s accounts and announces that the balance on the payment treasures is a number that makes no sense to you, even directly clear all the balance of the payment treasures account. This is not possible.
支付宝的支付、数额在不同用户的支付宝账号之间变动,这个实现是比较复杂的,最难的就是怎样确保安全,可靠,不会出错,所以安全是互联网金融的生命线。
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; the payment of payment bonds, the amount of which varies between payment accounts of different users, is a more complex achievement, the most difficult being how to ensure safety, reliability, and no error, so security is the lifeline of Internet finance.
(3)比特币
(3) Bitcoin
上面提的人民币、银行卡、支付宝等都是中心型的。英国的思想史学家阿克顿在《自由与权力》中说到:权力导致腐败,绝对权力导致绝对腐败。永远信任某个机构不作恶是比较危险的。
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; the renminbi, bank cards, payment treasures, etc. mentioned above are all central. The British think historian Akton said in Freedom and Power that power leads to corruption and absolute power leads to absolute corruption. It is more dangerous to trust an institution forever not to do evil.
为了解决这个问题,比特币就是采取了另外一种思路:简而言之就是去中心化。每一个人都有一个账本,账本都是公开的,每个人都可以去查,看看什么时候谁给谁付了多少钱。其次账本只能写入新的交易记录,任何已经写入的记录永远都无法更改,如果有人尝试着想篡改,所有的人都可以发现。这与海上进行航海日志填写相似,当天的日志记录完毕后以后是不能更改的。
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; in order to solve this problem, Bitcoin has taken another approach: in short, to centralize. Everyone has an account book, and the book is public, so everyone can look into it and see when they pay. The second account book can only be written into a new transaction record. Any record that has been written can never be changed, and if anyone tries to tamper with it, everyone can see it. This is similar to the log entry at sea, which cannot be changed when the log is finished.
这里要重点解决两个问题:
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; focus here on two issues:
第一,怎么要做到账本无法篡改,不管谁修改了大家都可以发现。需要用到计算机中的密码学。主要用到了两点,一是数字签名技术,比特币采用的是椭圆曲线数字签名算法,二是哈希算法,比特币中用的是SHA256。
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; first, how to make the account book immutable, no matter who changes it can be discovered. You need to use cryptography in a computer. The first is digital signature technology. Bitcoin uses elliptical digital signature algorithms, and the second is Hashi algorithm, and bitcoin uses SHA256.
第二,比特币是一个去中心化的分布式系统,就存在一致性问题,分布式系统中最核心的就是一致性问题。
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; and second, Bitcoin is a decentralised distributed system, with consistency at its core.
二、比特币怎么做到防篡改
& nbsp; ii, how bitcoin's tampering
(一)区块中的交易记录怎么防篡改
(i) How to prevent tampering with transaction records in blocks
每个区块中有若干条交易记录,这些交易记录怎么防篡改?比如A给C转了100块钱。大家查账本时怎么确定是A转的,而如果B说是他转的,怎么确定B是撒谎。这里就用到数字签名。密码学里有对称加密和非对称加密。对称加密中加密秘钥和解密秘钥是相同的,而非对称加密中公钥和私钥是不同的,且为成对出现。比特币这里用到的就是非对称加密:椭圆曲线算法。
& nbsp; & nbsp; & nbsp; & nbsp; & nbsp; there are a number of transaction records in each block, and how are these transaction records protected from tampering? For example, A transferred $100 to C. How is it determined that it was a transfer of A when checking the books, and if B says he did, how is it a lie? Here's the digital signature. There's symmetric encryption and non-symmetric encryption in cryptography. The cryptography encryption key and the cryptography key are the same, and not the public and private keys in symmetric encryption are different and present. Bitcoin here is used as an asymmetric encryption: elliptic curve algorithm.
一个人的公钥是公开在互联网上的,每个人都知道,私钥是自己留存的,只能自己掌握。一些可信任的第三方组织或者公司专门进行颁发公钥和私钥对的数字证书。用自己公钥加密过的数据只能用自己私钥解开,同样用自己私钥加密过的数据也只能用自己公钥进行解密。所以这里存在正反两个方向:(1)如果他人要发送数据给我,那么先用我公开在互联网上的公钥对数据进行加密,加密完毕发送给我,我再用自己的私钥对数据进行解密。这样即使数据被人截获也不要紧,只有我自己有可以解密的私钥,这就是利用公钥私钥对进行数据的加密传输。(2)另一个方向:如果我有一份文件需要传给朋友,朋友收到之后怎么确定是我发的呢,这就需要我先用自己的私钥对文件进行加密,朋友收到后利用我的公钥进行解密,只有用我的私钥加过密的文件才能用我的公钥正确的解密,这就是数字签名功能。
& nbsp; & nbsp; & nbsp; A person's public key is publicly available on the Internet, and everyone knows that the private key is self-held. Some trusted third-party organizations or companies specialize in digital certificates that issue public and private key pairs. Data encrypted with their own public key can only be broken with their own private key, and data encrypted with their own private key can only be decrypted with their own public key.
目前流行的非对称密码算法主要有3中:RSA密码体制、基于离散对数问题的密码体制和椭圆曲线密码体制。比特币中使用的签名算法就是椭圆曲线算法,相对于其他两种,加密性更强。在比特币系统中,一对公钥和私钥就代表了一个人,每个人的公钥是公开的,其他人要验证一条消息是否是某个人发送的,只需要将他的公钥来去验证一下即可判断真伪。
& nbsp; & nbsp; & nbsp; The current popular asymmetric cryptography has three main components: RSA password system, password based on discrete logarithm problems and elliptical cryptography. The signature algorithm used in Bitcoin is an elliptical curve algorithm, which is more encrypted than the other two. In Bitcoin, a pair of public and private keys represents a person, the public key of each person is public, and others need to verify whether a message is sent by one person, and only his public key is used to verify authenticity.
(二)区块链中的区块怎么防篡改
(ii) How to prevent the tampering of blocks in the chain of blocks
怎么确保之前区块不会被篡改。这里要用到计算机加解密中另外一项技术:哈希。哈希和前面讲的对称加密和非对称加密不同,对称和非对称加密是双向的、可逆的,比如我用对称加密密钥对数据加密后可以再用该秘钥进行解密,用非对称加密中的公钥对数据进行加密或者私钥进行签名后,对端可以用私钥进行解密或者公钥进行验证签名。
& nbsp; & nbsp; & nbsp; & nbsp; How to ensure that previous blocks are not tampered with. This is to use another technique in computer decryption: Hashi. Hashi differs from the previous symmetric encryption and non-symmetric encryption, which is two-way, reversible, for example, when I encrypt the data with a symmetric encryption key and then use the key to encrypt or sign the data with a public key in asymmetric encryption, the end can be authenticated with a private key or a public key.
而且哈希函数是不可逆的,哈希函数计算了一个消息的摘要,而这个摘要是一个非常短的、固定长度的字符串,这个消息摘要可以看成是该消息的指纹。哈希函数必须满足几个条件,第一哈希函数是单向的,即不可逆的,也就是说给定一个哈希值,你是无法倒推出对应的消息的。第二哈希函数要弱抗冲突性,完全的抗冲突性是不可能的,比如常用的MD5摘要算法其得出的消息摘要是128位,根据鸽笼原理可知,必定有不同的消息得到的消息摘要是一样的。存在弱冲突不要紧,只要在实际应用中不要被发现即可。这是操作可行的,在实际应用中碰到两个消息得到的消息摘要是一样的概率几乎可以忽略不计。第三抗冲突性,消息1经过哈希计算得到摘要1,理论上存在消息2经过哈希计算也得到摘要1,但是这在计算上是不可行的。满足了这三个基本条件才可以,目前常用的有MD5、SHA-256、SHA-384、SHA-512哈希函数。比特币中使用的是SHA-256哈希算法。我们平时下载一个软件安装包,下载完毕后进行完整性校验,防止被不法之徒加入一些病毒之类的,用的就是这个原理。
& nbsp; & nbsp; & nbsp; and the Hashi function is irreversible, and the Hashi function calculates a summary of the message, which is a very short, fixed-length string, which can be seen as a fingerprint of the message. The Hashi function must meet several conditions. This is operational, that is, it is not irreversible, that you are given a copy of the message. The second Hashi function is less conflict-resistant and completely conflict-resistant. For example, the typical MD5 abstract is 128, which, according to the dovery theory, must be identical.
(三)区块链的结构及形成
(iii) Structure and formation of the block chain
前面介绍了区块中的交易记录怎么防篡改和已经写入到区块链系统中的区块怎么防篡改,下面来具体看下。
& nbsp; & nbsp; & nbsp; & nbsp; A description of how trade records in blocks are protected from tampering and how blocks that are already in the block chain system are protected from tampering is provided below.
首先来看每个区块中有什么:第一有若干条交易记录,前面分析过一条条的交易记录是通过公钥密码算法进行数字签名确定记录的真实性。第二有表头,每个区块前面都有一个表头,表头中存了前一个区块的地址和前一个区块的哈希值。
& nbsp; & nbsp; & nbsp; & nbsp; First, see what's in each block: First, there are a number of transaction records, and the transaction log for which a single article has been analysed has been digitally signed through a public key password algorithm to determine the authenticity of the record. Second, there is a watchhead, with each block front, where the address of the previous block and the Hashi value of the previous block are stored.
每一个区块是有大小限制的,区块链中的区块数目是在不断增加的。这样就形成了一个单向链表,且最新生成的区块在链表的最端。其中第一个区块称为创始区块。我们来看一下整个区块链的生成过程:
& nbsp; & nbsp; & nbsp; & nbsp; Each block is limited in size and the number of blocks in the block chain is increasing. This creates a one-way chain table, and the most recently generated blocks are at the end of the chain table. The first of these blocks is called the founding blocks.
首先系统中只有一个区块A,区块A中包含了若干条交易记录,这些交易记录都是用各自用户的私钥进行签名过的。区块A的地址和哈希值广播给系统中的每一个成员。如果区块A被修改了则其他人将区块A进行一下哈希运算其哈希值是否对应得上就可以判断是否篡改过。
& nbsp; & nbsp; & nbsp; First there is only one block A in the system, and block A contains several transaction records that are signed by their respective users' private keys. Block A addresses and Hashi values are broadcast to every member of the system. If block A is modified, others can judge whether the Hashi values are matched by Hashi values.
运行一段时间后,区块A存储不下了,这就需要新增一个区块B。B的表头记录了A的地址和哈希值,这样B的地址和哈希会被广播给系统中的所有人。这样B无法篡改了,因为B的哈希值大家手上都有,同样A也无法篡改,A篡改了通过B中存储的A的哈希值同样可以发现。按此方式,系统继续运行,区块C、区块D按照同样的方法添加进来。
& nbsp; & nbsp; & nbsp; After a certain period of operation, block A will not be stored, which will require the addition of block B. The header of block B records the address of block A and the Hashi value, so that the address of block B and Hashi will be broadcast to everyone in the system. The B cannot be tampered with because the Hashi value of block B is in everyone's hands and the same A cannot be tampered with, and the Hashi value of block A stored in block B can also be altered. In this way, the system continues to operate and blocks C and D are added in the same way.
三、区块链中共识问题
iii. Consensus issues in block chains
比特币系统中每一个人都可以进行查账,由此判断是否发生了篡改。那么谁负责记账呢,就是一条条的交易信息谁负责将其写入区块中。本来由一个权威的人负责写入是最简单的,但是这和区块链去中心化思想是矛盾的。所以比特币采用的是人人记账方法。这里就产了一个难题,就是分布式系统一致性问题,这也是分布式系统中最核心的问题。
& nbsp; & nbsp; & nbsp; & nbsp; Everyone in the Bitcoin system can check the accounts and see if they have been tampered with. So who's in charge of the bookkeeping, then, is who's in charge of the article's transactional information and who's in charge of the block. It's the simplest thing to write, but it's in contradiction with the idea of centralizing the block chain. So Bitcoin uses a universal accounting method. Here's the problem: the consistency of the distribution system, which is at the heart of the distribution system.
分布式系统一致性:这个系统中某个节点提出某个值,经过一系列步骤,所有的节点达成共识,选取了相同的值,而且这个值必须是某个节点提出来的。
& nbsp; & nbsp; & nbsp; & nbsp; Distributive System Consistency: After a series of steps to reach consensus on all nodes, the same value has to be given by a node.
采用区块链技术实现一款电子货币,其不可篡改采用的方法是通用的,就是公钥密码算法和哈希算法,不同的是选取的算法不一样。最重要的是解决分布式系统一致性问题,也就是说共识问题才是关键。
& nbsp; & nbsp; & nbsp; and
一个简化的共识算法:
& nbsp; & nbsp; & nbsp; & nbsp; a simplified consensus algorithm:
1.提议的某条交易信息被广播到系统中的每一个节点中。
& nbsp; & nbsp; & nbsp; & nbsp; 1. A proposed transaction information is broadcast to every node in the system.
2.每个节点把自己收到的交易信息写入一个新的区块,写入新区块的交易信息如果成功加入到了区块链中,就被成功执行了。
& nbsp; & nbsp; & nbsp; & nbsp;
3.新的一轮开始的时候,整个系统中某个节点被随机选中,被选中的节点把自己的新区块广播给大家。
& nbsp; & nbsp; & nbsp; & nbsp; 3. At the start of the new round, a node was randomly selected throughout the system, and the chosen node broadcasted its new block to everyone.
4.每个收到新区块的节点会对新区块里的交易记录进行验证,采用交易记录中相关成员的公钥信息进行验证,验证无误之后将这个新的区块加到自己的本地账本中。
& nbsp; & nbsp; & nbsp; & nbsp;
怎么确保每一个人的账本是一致的呢?如果上述算法在完美的条件下运行是可以做到的,什么是完美的环境:就是系统中的每个成员都是守规矩的、网络相当可靠。但是在实际中是不可能存在的。一个是系统中网络是复杂不可靠的,二是不是系统中每一成员都值得信赖。在比特币系统中采取的方法是:遵循一条原则,就是整个系统中最长的那个区块链是大家公认的真相。
& nbsp; & nbsp; & nbsp; & nbsp; How to ensure that everyone's books are consistent? If the algorithms are working under perfect conditions, what is the perfect environment: every member of the system is disciplined and the network is reliable. But in practice, it is impossible. One is that the network of the system is complex and unreliable, and the second is that every member of the system is trustworthy. The approach taken in the Bitcoin system is that following a principle that the longest chain of blocks in the system is the accepted truth.
那为什么比特币系统中被选到的节点愿意努力去生成这个区块呢?因为系统会给奖励。如果他创建的那个区块最终进入到系统中那条最长的区块链中,可以获得可观的奖励。对于它成功写入的交易,都要给他一笔手续费;每个新区块的创建者都会获得一笔额外的比特币,这个数目每四年减少一半,最开始四年是50个比特币,之后是25个,依次类推。
& nbsp; & nbsp; & nbsp; & nbsp; Then why is the chosen node in the Bitcoin system willing to try to generate the block? Because the system will reward him. If he creates the block, he will be given a considerable incentive to enter the chain of the longest block in the system. For transactions that he has successfully written, he will be given a fee; the creator of each new block will receive an additional bitcoins, which will be reduced by half every four years, from 50 bitcoins in the first four years to 25, by analogy.
那到底谁创建的区块可以被系统接受?一个区块被创建出来,是需要计算其哈希值进行完整性校验的。区块中有一段随机填充的空间,其值无意义,唯一的作用就是为这个区块产生不同的哈希值。比特币网络要求产生的哈希值的前若干位全部为0。为了生成合法的哈希值,对于生成的新区块,必须通过改变随机区域的值,这个没有捷径可以走,只能采用穷举法,一次一次的进行计算,一直计算到前面若干位都是0的哈希值。这就是比特币的挖矿,大家通过贡献的算力进行奖励的分配。不管网络上有多少算力在进行计算,反正比特币的区块都是每10分钟产生一个,如果算力多了,那么产生的哈希前面的0的个数就多,反之就少一些。比特币系统中参与计算的人越多,算力越强,整个系统就越稳定。
& nbsp; & nbsp; & nbsp; Who created a block that could be accepted by the system? A block was created that needed to calculate its Hashi value for completeness verification. There was a randomly filled space, which had no value, and the only role was to create a different Hashi value for the block. No matter how much weight the Bitcoin network required, the first Hashi value was zero. In order to generate a legitimate Hashi value, the new block had to be changed by changing the value of the random area, there was no shortcut to go, but it had to be calculated in a single way, and the first number of places was zero. That was the greater the number of diggers than Tetco, the greater the number of people involved in the system, the greater the strength of the system.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论