百科问答小站 logo
百科问答小站 font logo



比特币挖矿一定要用计算机吗?用纸笔来计算可行吗? 第1页

  

user avatar   xiao-gu-hui-90 网友的相关建议: 
      

Mining Bitcoin With Pencil and Paper

楼主,这里有教程,我很看好你。解出来以后比特币的开采就有你掌控了。挣钱了记得给我冲50元话费。

结论写在这吧:作者做了个比喻,用手算出哈希值的难度比在全世界的沙子里面找到特定的一粒沙子还要难,可能性还要低。

教程每天算出来手算的速度是0.67hash(不吃不喝不睡),楼主经过训练以后速度应该有所提升,和现在主流挖矿机比起来挖矿机的速度是楼主的一百万的三次方倍(quintillion)。

但是楼主没问难不难,只问可不可以,所以答案是可以的。

Ken Shirriff

I decided to see how practical it would be to mine Bitcoin with pencil and paper. It turns out that the SHA-256 algorithm used for mining is pretty simple and can in fact be done by hand. Not surprisingly, the process is extremely slow compared to hardware mining and is entirely impractical. But performing the algorithm manually is a good way to understand exactly how it works.

我决定看看用铅笔和纸来演算挖比特币的矿是不是一件可行的事情。结果我发现挖矿所用的SHA-256算法其实很简单并且也可以用手算。当然了,与硬件挖矿相比这个过程是漫长的,但这不失为一中理解比特币挖矿算法的一种好方法。

The mining process

Bitcoin mining is a key part of the security of the Bitcoin system. The idea is that Bitcoin miners group a bunch of Bitcoin transactions into a block, then repeatedly perform a cryptographic operation called hashing zillions of times until someone finds a special extremely rare hash value. At this point, the block has been mined and becomes part of the Bitcoin block chain. The hashing task itself doesn't accomplish anything useful in itself, but because finding a successful block is so difficult, it ensures that no individual has the resources to take over the Bitcoin system. For more details on mining, see my Bitcoin mining article.

比特币挖矿是比特币系统安全的保证。中心思想就是比特币矿工们汇聚到一个矿区并且重复进行加密的哈希运算(不计其数的,zillion应该是比trillion还大的多得多的计量单位。)直到找到产生合适的哈希的字符串。到此为止,这个区块就已经被挖到了并成为了比特币区块链上的一环。哈希运算本省并没有任何意义。但是挖矿的难度由于是巨大的,这就保证了没有任何一个人可以有足够多的资源占据整个比特币系统。

A cryptographic hash function takes a block of input data and creates a smaller, unpredictable output. The hash function is designed so there's no "short cut" to get the desired output—you just have to keep hashing blocks until you find one by brute force that works. For Bitcoin, the hash function is a function called SHA-256. To provide additional security, Bitcoin applies the SHA-256 function twice, a process known as double-SHA-256.

加密的哈希计算确保了解出这个运算没有任何捷径,只能够不断觉得进行运算用暴力的方法直至成功。

In Bitcoin, a successful hash is one that starts with enough zeros. [1] Just as it is rare to find a phone number or license plate ending in multiple zeros, it is rare to find a hash starting with multiple zeros. But Bitcoin is exponentially harder. Currently, a successful hash must start with approximately 17 zeros, so only one out of 1.4x1020 hashes will be successful. In other words, finding a successful hash is harder than finding a particular grain of sand out of all the grains of sand on Earth.

The following diagram shows a block in the Bitcoin blockchain along with its hash. The yellow bytes are hashed to generate the block hash. In this case, the resulting hash starts with enough zeros so mining was successful. However, the hash will almost always be unsuccessful. In that case, the miner changes the nonce value or other block contents and tries again.

Structure of a Bitcoin block


The SHA-256 hash algorithm used by Bitcoin

The SHA-256 hash algorithm takes input blocks of 512 bits (i.e. 64 bytes), combines the data cryptographically, and generates a 256-bit (32 byte) output. The SHA-256 algorithm consists of a relatively simple round repeated 64 times. The diagram below shows one round, which takes eight 4-byte inputs—A through H—then performs a few operations, and generates new values of A through H.

SHA-256 算法把输入为64bytes的区块整合成加密数据并产生了32byte的输出。SHA-256 算法包含了相对而言简单的64轮操作。下面的图展示了把8个4byte的输入从A到H,展开了一些运算以后产生了从A到H新的值。


One round of the SHA-256 algorithm showing the 8 input blocks A-H, the processing steps, and the new blocks. Diagram created by kockmeyer, CC BY-SA 3.0.

The blue boxes mix up the values in non-linear ways that are hard to analyze cryptographically. Since the algorithm uses several different functions, discovering an attack is harder. (If you could figure out a mathematical shortcut to generate successful hashes, you could take over Bitcoin mining.)

右侧深蓝色的格子里面把输入的数值用非线性的方法进行整合,这样就很难进行分析。因为这种算法用到了数种方法,找到一条捷径就更难了。如果谁找出来了,他就能掌管比特币的开采。

The Ma majority box looks at the bits of A, B, and C. For each position, if the majority of the bits are 0, it outputs 0. Otherwise it outputs 1. That is, for each position in A, B, and C, look at the number of 1 bits. If it is zero or one, output 0. If it is two or three, output 1.

Ma这个运算主要关注与A,B和C的值。如果他们主要的值是0.那输出就是0.如果主要不是0,那输出就是1.比如说,A,B,C上都是0或者1,那么输出0,如果是2或3那么就输出1.

The Σ0 box rotates the bits of A to form three rotated versions, and then sums them together modulo 2. In other words, if the number of 1 bits is odd, the sum is 1; otherwise, it is 0. The three values in the sum are A rotated right by 2 bits, 13 bits, and 22 bits.

Σ0转换A的值并且相加,找出除以2的余数。如果1bits是偶数那么总和为偶,不然就为0.三个值加起来的总和是A向右移2bits,13bits和22bits。

The Ch "choose" box chooses output bits based on the value of input E. If a bit of E is 1, the output bit is the corresponding bit of F. If a bit of E is 0, the output bit is the corresponding bit of G. In this way, the bits of F and G are shuffled together based on the value of E.

Ch的值由E的输入来决定。如果E的bit为1,那么输出为F的bit。如果E为0,那么输出为G的bit。这样F 和 G 一定程度上有E决定。

The next box Σ1 rotates and sums the bits of E, similar to Σ0 except the shifts are 6, 11, and 25 bits.

Σ1与Σ0类似,只是向右移6,11,25bits.

The red boxes perform 32-bit addition, generating new values for A and E. The input Wt is based on the input data, slightly processed. (This is where the input block gets fed into the algorithm.) The input Kt is a constant defined for each round.[2]

红格子产生了新的A和E. 输入的Wt是由输入的数据决定的,经过稍微的处理。输入的Kt 是一个常数由每一轮运算定义。

As can be seen from the diagram above, only A and E are changed in a round. The other values pass through unchanged, with the old A value becoming the new B value, the old B value becoming the new C value and so forth. Although each round of SHA-256 doesn't change the data much, after 64 rounds the input data will be completely scrambled. [3]

每一轮只有A和E产生了变化。其他的值都没有变。旧的A变成了新的B.旧的B变成了新的C.尽管每一轮都没有太大的变化,但是六十四轮以后输入的值就会有翻天覆地的变化。

Manual mining

The video below shows how the SHA-256 hashing steps described above can be performed with pencil and paper. I perform the first round of hashing to mine a block. Completing this round took me 16 minutes, 45 seconds.

youtube.com/watch? 这里有视频地址,需要翻墙才能看。

To explain what's on the paper: I've written each block A through H in hex on a separate row and put the binary value below. The major peration appears below C, and the shifts and Σ0 appear above row A. Likewise, the choose operation appears below G, and the shifts and Σ1 above E. In the lower right, a bunch of terms are added together, corresponding to the first three red sum boxes. In the upper right, this sum is used to generate the new A value, and in the middle right, this sum is used to generate the new E value. These steps all correspond to the diagram and discussion above.

解释一下我在纸上做了什么,我把从A到H分别在一行上面十六进制转换为二进制。主要的运算写在C下面。bits转换和Σ0展示在A行上面。同样的,choose运算在G下面,bits转换和Σ1在E的上方。在右下角,相对应于三个红格子的数值被加了上去。在右上方,总和被用于产生一个新的A值。在右中侧,总和被用于产生新的E值。

I also manually performed another hash round, the last round to finish hashing the Bitcoin block. In the image below, the hash result is highlighted in yellow. The zeroes in this hash show that it is a successful hash. Note that the zeroes are at the end of the hash. The reason is that Bitcoin inconveniently reverses all the bytes generated by SHA-256. [4]


What this means for mining hardware

Each step of SHA-256 is very easy to implement in digital logic—simple Boolean operations and 32-bit addition. (If you've studied electronics, you can probably visualize the circuits already.) For this reaon, custom ASIC chips can implement the SHA-256 algorithm very efficiently in hardware, putting hundreds of rounds on a chip in parallel. The image below shows a mining chip that runs at 2-3 billion hashes/second; Zeptobars has more photos.



In contrast, Litecoin, Dogecoin, and similar altcoins use the scrypt hash algorithm, which is intentionally designed to be difficult to implement in hardware. It stores 1024 different hash values into memory, and then combines them in unpredictable ways to get the final result. As a result, much more circuitry and memory is required for scrypt than for SHA-256 hashes. You can see the impact by looking at mining hardware, which is thousands of times slower for scrypt (Litecoin, etc) than for SHA-256 (Bitcoin).

Conclusion

The SHA-256 algorithm is surprisingly simple, easy enough to do by hand. (The elliptic curve algorithm for signing Bitcoin transactions would be very painful to do by hand since it has lots of multiplication of 32-byte integers.) Doing one round of SHA-256 by hand took me 16 minutes, 45 seconds. At this rate, hashing a full Bitcoin block (128 rounds) [3] would take 1.49 days, for a hash rate of 0.67 hashes per day (although I would probably get faster with practice). In comparison, current Bitcoin mining hardware does several terahashes per second, about a quintillion times faster than my manual hashing. Needless to say, manual Bitcoin mining is not at all practical.[5]

SHA-256运算出奇的简单,简单到可以拿手算。做一轮要花我16分钟45秒,以这个速度得到一个完整的比特币区块(128轮)需要1.49天(不吃不喝一直做)每天的速度是0.67 hashes.目前挖矿机的效率是我的一百万的三次方倍数。所以说手算挖矿是不实际的。

A Reddit reader asked about my energy consumption. There's not much physical exertion, so assuming a resting metabolic rate of 1500kcal/day, manual hashing works out to almost 10 megajoules/hash. A typical energy consumption for mining hardware is 1000 megahashes/joule. So I'm less energy efficient by a factor of 10^16, or 10 quadrillion. The next question is the energy cost. A cheap source of food energy is donuts at $0.23 for 200 kcalories. Electricity here is $0.15/kilowatt-hour, which is cheaper by a factor of 6.7 - closer than I expected. Thus my energy cost per hash is about 67 quadrillion times that of mining hardware. It's clear I'm not going to make my fortune off manual mining, and I haven't even included the cost of all the paper and pencils I'll need.

有一个reddit网友问我关于能量消耗的事。其实并没有消耗我多少的体能。假设一个人一天啥也不干他的机体消耗是1500卡路里。手动挖矿找到一个哈希值大约消耗10兆焦耳。硬件挖矿通常消耗是100兆焦耳。所以我的能耗比机器要低的多得多的多。关于补充能量的事,一个甜甜圈能提供200卡路里需要23美分(1块5).电的价格是一千瓦时15美分(九毛八)。所以我的耗能是机器的百万的四次方倍,很明显靠笔算挖矿挣不了钱。而且我还没有考虑笔和纸的消耗。


user avatar   GalAster 网友的相关建议: 
      世界上为什么有“情话”这个词?


  

相关话题

  特朗普称「比特币是一个骗局」,比特币跌至33000美元/枚下方,对此你怎么看?你认为这是骗局吗? 
  怎样学范畴论? 
  为什么美国中小学生学的数学比我们简单,美国人却还能做出超级牛的东西? 
  生命体可以用数学来解释吗? 
  做学术需要搞清楚高级计量经济学里全部的数学原理吗? 
  如何看待国际数学联盟发表声明,取消在俄罗斯圣彼得堡线下举办国际数学家大会?其它国际组织会跟进吗? 
  为什么国内做偏微分方程(PDE)的人这么多,而且招学生非常快? 
  在圆上选取n个点,两两连线,最多可以在圆内形成多少个交点? 
  偏微分方程在纯数学有什么应用? 
  俄乌冲突以来,为什么数字货币一直在跌,是否有避险属性,如何理解数字货币在金融市场的作用? 

前一个讨论
孤独是一种怎样的状态?
下一个讨论
如何用最短的距离走过北京所有线路的地铁?





© 2024-05-18 - tinynew.org. All Rights Reserved.
© 2024-05-18 - tinynew.org. 保留所有权利