Recreating Bitcoin

Page 3


Recreating Bitcoin 16:Block chain

Epilogue

Bitcoin in its peer-to-peer architecture has realized the synchronization of transactions and ledger. Although the synchronization of the ledger still relied on a centralized Timestamp Server, we will leave it for now and shift focus to a new idea Gilfoyle just came up with: the dissection of the ledger.

“Out-of-Control” Improvisation

Gilfoyle was waiting for Satoshi when he came into the store. Before he even sat down, Satoshi started talking to Gilfoyle, “Come on, let’s continue to discuss the idea of dissecting the ledger you mentioned yesterday.”

“Well, wait for me to have a cup of coffee.”

Boss Bob brought the coffee over: “Recently, you two brothers have been drinking coffee quite a bit. Got inspiration? Hurry up and upgrade, let Bitcoin go online soon!”

Satoshi said: “Ok, we are working hard! It is almost done!”

Although he said that it was almost finished, he...

Continue reading →


Recreating Bitcoin 17:Network Flexibility

Epilogue

In the last chapter, we introduced the technical concepts of block chain and block reward.

This chapter focuses on the connection mechanism to make the network more flexible.

The Problem

In the café, Satoshi and Gilfoyle deployed the new code.

Block rewards is another world-class design that was previously UTXO. It cleverly enables the Bitcoin system to simultaneously implement the incentive mechanism of node accounting and the minting and issuing mechanism of currency.

“With block reward, the network will have more nodes joining in, and based on the network design, between all the nodes, there would be a star network,” Satoshi said (see graph below).

图片 1.png

Star network

Satoshi continued: “Star network is not the type of network I want. It is too fragile, what I want is a mesh network.” (see graph below)

图片 1.png

Mesh network

“The reason it has become a star network was...

Continue reading →


Recreating Bitcoin 18:Proof of Work(Part I)

Epilogue

In the previous chapter, Bitcoin’s peer-to-peer network evolved into a autonomous swarm system.

In this chapter, we will solve the final problem of Bitcoin. That is the single-point failure problem of the ledger-writing task assignment: Timestamp Server.

The Last Single-Point - Timestamp Server

Early in the morning, Satoshi and Gilfoyle arrived at the cafe. Bitcoin’s accounting network had evolved into a swarm system in its true sense of word. This made them very excited. They wanted to take advantage of the success and solve the issue of the last single point in the system:

Timestamp Server, which is responsible for allocating ledger-writing author.“
“This last solution is so important that if it is not well designed, all our previous efforts will be wasted,” Satoshi said.

“Yes,” says Gilfoyle, “It determines if the system will break or live!”

Though Satoshi had a...

Continue reading →


Recreating Bitcoin 19:Proof of Work (Part II)

Epilogue

Now let’s design a problem that requires Proof of Work to solve (POW).

Looking for the Random Number

Many times, in sleep you get the answer you would not get while awake. Satoshi was lucky to have experienced that. But it was not time for him to wake up yet.

“So what kind of problem can prove the work done by the node?” asked Tauren.

“I have precisely the problem in mind: finding a random number. You know, like guessing someone’s birthday, as long as you keep guessing, you can eventually guess it right with some effort,” Little Boy gave out his idea.
Tauren said, “I see. The nature of the problem is logic-less random collision. Such randomness is the fairest.”

“Yes! But it’d not be birthday we’d be guessing, but a random number, a number added to the message at the end of the message. And the Hash Value is asked for such that there are many zeros at the start of the...

Continue reading →


Recreating Bitcoin 20:The Reorganization and Division of Forking

Epilogue

So far, all the concepts of Bitcoin have been introduced.
    In this chapter, we will take a look at a phenomenon in the system: fork.
    A key philosophy of Bitcoin is competition. One manifestation of this competition is forking.

Fork

In the café, Satoshi and Gilfoyle were surrounding by several monitors with texts flashing through the screens, like scenes from the matrix.

图片 1.png

Bitcoin Logs

In the eyes of Satoshi and Gilfoyle, the chaotic logs is like a big show.
    Inside the Bitcoin network were the competitions between miners, as natural as in the nature itself and as chaotic as the chaos that gave rise to the natural order.

图片 1.png

The most primitive power competition

Computing power determines the block reward. There are no back-door operations, everything is transparent, and anyone can join, as long as if you are willing to pay for the computing cost. Mostly...

Continue reading →


重新创造比特币1:从一个简单的web交易系统开始

作者:何岩,由 recreating.org发行。

0.前言:

1-1.png

对于伟大的造物,重新创造就是一种膜拜

欢迎来到Bitcoin的世界!!!

1.缘起

1999年,中途镇,咖啡馆,上午10点,中本聪准时出现在靠窗子的位置。
中本聪喜欢这个位置,不是因为窗外的风景,而是因为窗边的电源插口。

中本聪是个程序员,最近休假,每天都来写代码,对于他来说,完美的日子不过如此。

o-CAFE-facebook.jpg

coding at cafe

世界新生伊始,许多事物还没有名字,提到的时候尚需用手指指点点。

中本聪端着咖啡在发呆,老板Bob问道:“Hi Satoshi!这几天咋不鼓捣你的代码啦?想啥呢?”。

中本聪答道:“最近想做一点新玩意,之前编的东西太normal了,正好最近休长假,有大把的时间,想搞点大东西,something big!”。

这时候老顾客Alice插嘴道:“Someting Big! 哼!要我说最大的问题就是我们的美联储乱发钱,这些自私的家伙,让我的财富每年都在被动损失,这些强盗、小偷。这就是Something Big!”

中本聪说:“你这样可不好,有点无政府主义倾向啊!不过给我的启发倒是,可以做一个全球电子现金系统,并且绝不增发!”

“货币源于价值:无论是贝壳,还是黄金,或者说所有在历史上担任过货币的事物,他们本身并不具备价值,他们只是一种符号。经过时间的磨砺,共识形成,符号变得可以代表价值。这时它们才具有了货币属性。所以电子现金同样要能代表价值。与其代表系统之外的价值,不如让这个系统自身产生价值,即,作为一个不可篡改的全球交易系统被人们使用。”当然这是在很久以后,中本聪才拥有的认知。

“你要是做出来,我们咖啡店先试用!”老板Bob叫到!

“加油吧小子!”Alice挥舞着拳头。

一股热流上了头,中本聪拿出笔记本开始写写画画起来,Bitcoin的设计工作开始啦!

2.先设计一个最简单的交易系统吧

中本聪开始了思考,先设计一个最简单的版本,先让Bob老板用起来,他一边用,我一边改进,这个思路不错!

既然是电子现金那么系统名字就叫Bitcoin吧。

第一...

Continue reading →


重新创造比特币2:第一个版本上线啦

作者:何岩,由 recreating.org发行。

1.Bitcoin0.0.1版上线啦

一周之后,中本聪完成了Bitcoin第一版的编码工作,按照之前的计划,中本聪跑到最近的电脑城买了一个低配的服务器,把服务器抱回咖啡馆,连上网线,装上linux操作系统。最后将写好的系统部署了上去,启动!

又在godaddy.com(卖域名的网址)上买了域名:www.bitcoin.org,关联到Bitcoin的主机IP,通过域名可以访问Bitcoin系统啦。

Bitcoin就这么羞涩的向世界宣布:“我来啦!”

中本聪说:“老板,Bitcoin可以用啦!”

老板Bob冲着店里的顾客喊道:“哈哈,太棒了!有谁想成为历史上第一个使用Bitcoin的人?”

Alice说:“我来!Bitcoin还是受了我的启发呢!我要用它买杯拿铁。小子,这玩意怎么用?”

中本聪说:“你先用手机的浏览器打开这个网址:www.bitcoin.org"
Alice用手机打开Bitcoin的网站看到的是这个样子的界面:(见下图)

图片 1.png

登陆界面

Alice:“哇,真的运行起来啦!小子,我的用户名和密码是什么?”

中本聪:“忘了给你注册,稍等!”

中本聪进入到Bitcoin的主机后台,用vi工具(linux上的编辑文件的工具)在user.txt里面加上了一行数据。

Alice, Bitcoin123, 0

“好了,你的用户名是Alice,密码是Bitcoin123,密码千万别告诉别人”
Alice在登陆页面输入了用户名和密码,界面变成了这个样子:(见下图)

图片 1.png

个人余额界面

Alice:“我的余额是0,需要用美元兑换Bitcoin吗?”

中本聪:“是的,你给我美元现金,我给你转账Bitcoin。”

Alice给了中本聪100美元,中本聪用自己的账号登陆后给Alice转账了100个Bitcoin。

中本聪解释道:“如果你想换回美元,你再找我用Bitcoin兑换成美元”
中本聪就成为了人肉的Bitcoin交易所。

货币总量等同于中本聪自己的账号的默认余额:2100万个Bi...

Continue reading →


重新创造比特币3:舍弃账户模型

作者:何岩,由 recreating.org发行。

0.前言

Bitcoin的第一个版本已经上线,它的意义在于,展现了系统的使用场景。

1.舍弃账户模型

自从Bitcoin第一个版本(v0.0.1)上线,咖啡店的生意越来越好,老板Bob显然做了一个明智的决策。

中本聪却越来越烦恼:“这么多人来找我注册账号和兑换Bitcoin,都没时间编程了,我得想想办法。把兑换工作交给老板Bob吧。”

中本聪说:“我说,老板,现在越来越多的人来找我兑换Bitcoin,我都成了人肉交易所啦,没时间升级系统了,要不兑换的工作你来做吧。”

Bob说:“好啊,正合我意,不过我可以调整汇率吗?”

中本聪说:“当然可以。”

Bob高兴的答应了,中本聪将自己的账号密码告诉了Bob,咖啡馆就正式成为了Bitcoin的线下交易所。

中本聪感到轻松了很多:“那么,就还剩下用户注册的功能。”

中本聪一边思考着,一遍拿出笔记本准备开始编码。

忽然,有个大胆的想法在中本聪的脑子里闪过:“能不能彻底的去掉用户注册呢?”

之所以要有用户注册功能,是因为每个用户都要在user.txt中创建一条账号记录。

每个用户的账号信息只包括三个字段:用户名、密码、余额。

如果能用其他的方式来替代这三个字段,那么就可以舍弃“账户模型”了。

首先是用户名,可以用账本替代。

因为每笔交易记录都包含着付款方和收款方的用户名,所以账本(transaction.txt)可以代替账户(user.txt)定位出用户名。

其次是余额,账本也可以替代。

因为账本就是交易流水,累计交易流水可以得出用户的余额。所以账本(transaction.txt)可以替代账户(user.txt)实现余额。(具体获取余额的逻辑见下图)

图片 1.png

获取余额的两种方式对比

解决了用户名和余额之后,最难的部分是如何去掉密码。

密码的作用是向服务端证明Alice是真正的Alice,而不是一个叫Calor的家伙的冒充,除非Calor知道了Alice的账号密码。

所以密码的本质是一把钥匙。

那么除了密码,有没有其他方式呢?

“用...

Continue reading →


重新创造比特币4:数字签名

作者:何岩,由 recreating.org发行。

0.前言

前篇说到了对称加密,并且我们发现没必要将交易的消息全部加密,因为交易数据不怕见光。只需要加密一小部分即可,究竟应该加密哪部分呢?

1.签名

既然我们的根本目的并不是防止别人看到交易数据的明文,而只是要用密文证明“我是我”。那么我的要求就是尽量加密更少的文字,即,加密付款者的名字。

这是为什么呢?

启发往往来自于现实生活的例子:

赵四想买台拖拉机,但是钱不够,向刘能借了1万块钱,刘能要求赵四写个借条。

赵四当然不愿意写啊,赵四就说自己不会写字。

刘能当然不能放过他啊,刘能就帮赵四写了欠条:“赵四欠刘能壹万元整”。
但是这个欠条并不具有法律效果,因为赵四可以说是刘能自己瞎写的。那么为了让这个借条成为证据,赵四最少也要签上自己的名字。因为赵四的笔迹是全世界唯一的,所以赵四签上了自己的名字,就代表着这个名字的本人认可这张借条的内容。如果赵四签的不是自己的名字,这张借条也不成立,也就是说赵四的唯一的笔迹,只在写自己的名字的时候借条生效。(见下图)

图片 1.png

签名

赵四的写字方式就是私钥,因为全世界就赵四能用这种方式写字。

“赵四”这俩个标准汉字就是公钥。

赵四的私钥(写字方式)只有在加密自己的公钥(“赵四”)的时候有法律效应,加密别人的公钥(签别人的名字)就无效。

反之,法官看到赵四的签名(那个写得乱七八糟的签字,等价于加密后的密文),可以用公钥来解密签名,因为公钥是“赵四”。

所以法官可以调取法院保存的签名数据库,找到赵四过往的签名来对比。

也可以传唤赵四本人出庭,让他辨认(解密)一下这个签名(密文)是不是自己签署(加密)的。

现实中我们管借条上的名字叫做签名,签名就是证明“我是我”的最少文字。
根据上面得到的灵感,借鉴到Bitcoin交易系统中,Alice用私钥加密自己的名字“Alice”即可作为证明,加密后的密文就称为:数字签名。(见下图)

图片 1.png

利用数字签名来证明Alice是Alice

2.签名用户名的漏洞

中本聪一遍一遍的在脑子里模拟着系统的运行,忽然发现了一个漏洞...

Continue reading →


重新创造比特币5:公钥和私钥

作者:何岩,由 recreating.org发行。

1.公钥和私钥

那么用户的公钥和私钥又是如何生成的呢?

这里正是采用非对称加密真正精髓之处,用户的公钥是由私钥计算得来,而用户的私钥则反直觉的由用户自己生成。

用户如何自己生成一个私钥呢?
(备注:公钥私钥更加详细的技术讲解可以阅读aaron67的文章:[学习笔记] 比特币的私钥和公钥)

私钥的本质是一个数字,公钥的本质也是一个数字,如果把任何数字当成私钥,都可以利用椭圆曲线加密算法生成这个数字对应的公钥,即,Function椭圆曲线加密算法(私钥)=公钥

5-1.png

椭圆曲线加密算法

如果让用户随机生成数字,并且数字的随机范围足够大,就可以避免两个用户生成了相同的私钥,即,私钥冲突。

多大的数字够用呢?

答案是2的256次方。

创建私钥本质上是“取得一个1到2的256次方之间的数字”。

你可以通过投256次骰子,并且用铅笔和纸张将结果记录下来。

结果看起来是这样:

111110010111110010001
00110101010101011001
111000011010000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
000000000000000
0000000000000000
0000000000000000

一共256个二进制的字符。为了让它看起来短点,我们将其转换成十六进制,这样就减少到了64个字符,每位代表4个bit。

(备注:一个二进制的数字就代表着1bit。再进一步解释bit的定义是:可以让50%概率的事情变为100%的确定性的信息,这个信息所等价的能量就是1bit。例如:在二进制中,下一个我要写的数字只能在0或1中选择,这时候下一个数字的概率就是50%,如果我写出来了1,那么这个1就是将5...

Continue reading →