块的哈希码如何生成?
-
-
您可以做的一个测试是,首先通过生成一个真正随机的有效负载字节集并将其传递给base58校验和,然后评估您建议的转换,来评估base58校验和的分布属性.然后执行KS测试,以评估数字分布在统计上是否与实验数字相同.One test you can do is first assess the distribution properties of base58 checksum by generating a truly random set of payload bytes and passing this to base58 checksum and then do the transformation you suggest. Then perform a KS test to assess if the distribution of digits is statistically the same as the experimental one.
- 1
- 2019-05-17
- Ezy
-
2 个回答
- 投票数
-
- 2019-05-10
- 获取特定块头的字节表示形式: http://mainnet-node.tzscan.io/chains/main/blocks/head/header/raw .块标题的格式在the 中进行了描述文档.
- 获取其BLAKE2b(32位)哈希摘要
- 添加两个字节" \ x01 \ x34"(它们负责" B"字母)
- Base58使用校验和对其进行编码
没有随机性.
面包师选择块标题.面包师可以轻松地构造许多不同的块,并仅注入具有所需哈希值的块,从而操纵"随机"数的生成.由于Tezos区块仅需要简单的工作证明,因此比比特币或以太坊中的建议要简单得多,在比特币或以太坊中,建议"不,您不能以这种方式生成随机数"已经提出了多年.
- Take a byte representation of a particular block header: http://mainnet-node.tzscan.io/chains/main/blocks/head/header/raw. The format of the block header is described in the docs.
- Get a BLAKE2b (32bit) hash digest of it
- Prepend two bytes '\x01\x34' (they are responsible for "B" letter)
- Base58 encode it with checksum
There is no randomness.
The baker chooses the block header. A baker can easily construct many different blocks and inject only the block with the most desired hash, manipulating your 'random' number generation. Because a Tezos block only requires an easy proof of work, this is easier than in Bitcoin or Ethereum, where the advice "no, you can't generate random numbers that way" has been given for years.
-
谢谢.因此,下一个问题是,如何选择块头?"伪随机性"的原始来源是哪里?Thanks. So the next question is, how is that block header selected? Where is the original source of "pseudo-randomness" coming from?
- 0
- 2019-05-10
- luchonacho
-
块头是如何产生的?是什么使一个块头与另一个块头不同?How is the block header produced? What makes one block header different from the other?
- 0
- 2019-05-11
- luchonacho
-
如果您觉得需要提出后续问题,请修改原始问题(和标题?)以使其更加清晰.这似乎可以回答您到目前为止所写的问题.如果没有"官方"资源,答案本身是非常可信的.尝试一下,看看确实可以得到预期的哈希值.(你做.)If you feel you need to ask followup questions, please edit your original question (and title?) to be more clear. This seems to answer the question you wrote so far. The answer is very credible on its own without "official" sources. Just try it and see that you do indeed get the expected hash. (You do.)
- 1
- 2019-05-13
- Tom
-
@Tom我意识到最初的问题不足以满足我的目的.因此采取了后续行动.我更新了帖子.此外,尽管该程序可行,但知道它来自何处将很有趣.例如.这是写在区块链上的吗?@Tom I realized the original question didn't suffice for my purposes. Hence the follow up one. I updated the post. Also, albeit the proceedure works, it would be interesting to know where it comes from. E.g. is this written in the blockchain?
- 0
- 2019-05-14
- luchonacho
-
我试图使经典警告适应Tezos.我不确定是否有关于块哈希的有用引用.无论如何,细节不会改变您的真实问题的答案:不会.I tried to adapt the classic warning to Tezos. I'm not sure whether there are any useful citations about the block hash. In any case the details won't change the answer to your real question: don't.
- 0
- 2019-05-14
- Tom
-
@Tom,感谢您的更新! luchonacho,块散列确实不应该用作随机性的来源,请更好地了解Tezos在内部用于分配烘焙权的方案.它在代码中,但我希望很快能在这里得到答案:) https://tezos.stackexchange.com/questions/1201/how-to-calculate-a-random-seed@Tom, thanks for your updates! luchonacho, block hash indeed shouldn't be used as a source of randomness, better look at the scheme Tezos uses internally for baking rights distribution. It's in the code, but I hope there will be an answer here soon :) https://tezos.stackexchange.com/questions/1201/how-to-calculate-a-random-seed
- 0
- 2019-05-15
- Michael Zaikin
-
@MichaelZaikin感谢您的更新.我做了自己的分析,得出了不同的结论.看我的答案.任何想法都值得欢迎!@MichaelZaikin Thanks for the update. I made my own analysis, and got a different conclusion. See my answer. Any thoughts are more than welcome!
- 0
- 2019-05-16
- luchonacho
-
- 2019-05-16
我的问题的第1部分已由Michael回答.那第二部分呢?好吧,我只是看了一眼.我所做的是:
- 提取完整的哈希码系列,从块1到最新的(非常长).
- 提取此类哈希码中包含的数字(即删除字母).
- 通过专门设计的测试来分析这一系列数字的"随机性".
测试表明随机假设不能在5%时被拒绝.有趣的是,数字的分布非常偏斜.如果有的话,可能会希望它有点像均匀分布(请注意相反的说法不正确,即均匀分布并不意味着随机性).我仍然对此感到不安,但乍一看似乎表明该系列可能是随机的.
再现以上分析的R代码如下:
# Initialise stuff remove(list = ls()) options(timeout = 1000000) # in case request times-out library(jsonlite) library(ggplot2) library(randtests) # Get maximum number of blocks last_block <- fromJSON("https://api6.tzscan.io//v3/head") N <- last_block$level blocks <- seq(1,N,by = 1) hashs <- vector(mode="character", length = N) # Download all hash codes (timer and print included, for analysis) VERY LONG start <- proc.time() for (i in 1:N) { url <- paste0("https://api6.tzscan.io//v3/block_hash_level/",i) hashs[i] <- fromJSON(url) print(i) } finish <- proc.time() - start # Remove letters n_hashs <- as.numeric(gsub("\\D+","", hashs, perl = TRUE)) df <- data.frame(value=n_hashs) names(df)[names(df) == "df.value....." ] <- "value" # Plot (definitively not a uniform distribution, for any level of zooming in) ggplot(df, aes(x=value)) + geom_histogram() # Randomness tests (indicating the number sequence is not random) bartels.rank.test(df$value) cox.stuart.test(df$value) difference.sign.test(df$value) rank.test(df$value) runs.test(df$value) turning.point.test(df$value)
Part 1 of my question was answered by Michael. What about the second part? Well, I just had a look at it. What I did is:
- extract the full series of hash codes, from block 1 to the latest (VERY LONG).
- extract the numbers contained in such hash codes (i.e. remove letters).
- analyse the "randomness" of this series of numbers with purposely designed tests.
The tests suggest that the randomness hypothesis cannot be rejected at the 5%. Interestingly, the distribution of numbers is very skewed. If anything, one might expect it to be somewhat resembling a uniform distribution (noticing that the contrary is not true, i.e. uniform distribution does not imply randomness). I'm still pounding on this, but a first look suggest that the series might be random.
The R code to reproduce the above analysis is below:
# Initialise stuff remove(list = ls()) options(timeout = 1000000) # in case request times-out library(jsonlite) library(ggplot2) library(randtests) # Get maximum number of blocks last_block <- fromJSON("https://api6.tzscan.io//v3/head") N <- last_block$level blocks <- seq(1,N,by = 1) hashs <- vector(mode="character", length = N) # Download all hash codes (timer and print included, for analysis) VERY LONG start <- proc.time() for (i in 1:N) { url <- paste0("https://api6.tzscan.io//v3/block_hash_level/",i) hashs[i] <- fromJSON(url) print(i) } finish <- proc.time() - start # Remove letters n_hashs <- as.numeric(gsub("\\D+","", hashs, perl = TRUE)) df <- data.frame(value=n_hashs) names(df)[names(df) == "df.value....." ] <- "value" # Plot (definitively not a uniform distribution, for any level of zooming in) ggplot(df, aes(x=value)) + geom_histogram() # Randomness tests (indicating the number sequence is not random) bartels.rank.test(df$value) cox.stuart.test(df$value) difference.sign.test(df$value) rank.test(df$value) runs.test(df$value) turning.point.test(df$value)
-
人们期望散列统一看起来是随机的.香草面包师将生成伪随机POW随机数,直到POW成功为止.因此,所选的哈希应看起来均匀地随机.我建议生成(虚假的)块哈希,随机地均匀选择每个比特,然后转换为base58,然后将其插入您的分析中.无论如何,请注意,面包师没有理由操纵_today_的哈希,但是如果您给他们一个理由,_could_可以轻松地做到这一点.One expects the hashes to _look_ uniformly random. The vanilla baker will generate pseudorandom POW nonces until the POW succeeds. Thus the chosen hashes should look uniformly random. I suggest generating (bogus) block hashes, choosing each bit uniformly at random and then converting to base58, and plugging them into your analysis. In any case, note that bakers have no reason to manipulate the hash _today_, but _could_ easily do so if you give them a reason.
- 1
- 2019-05-16
- Tom
-
旁注:没有必要向tzscan垃圾邮件.使用带有length和head查询参数的节点RPC/chains/main/blocks/可以一次性获得很多哈希值.Side note: it is not necessary to spam tzscan. You can get lots of hashes in one go using the node RPC /chains/main/blocks/ with the `length` and `head` query parameters.
- 0
- 2019-05-16
- Tom
-
@Tom感谢您的建议.关于最后一个,是否有关于如何使用节点RPC的手册?@Tom Thanks for the suggestions. Regarding the last one, is there a manual on how to use the node RPC?
- 0
- 2019-05-17
- luchonacho
考虑链中的任何给定区块(例如这一个).其哈希码为:
我正在开发一种工具,该工具使用此哈希码并从中产生一个"随机"数字.为了实现我的目标,我需要了解:
任何帮助都非常欢迎.