简体   繁体   English

我正在尝试实现merkle树一致性证明,但我坚持理解算法

[英]I'm trying to implement a merkle tree consistency proof, but I'm stuck at understanding the algorithm

I'm trying to implement a merkle tree consistency algorithm with this paper: 我正在尝试用本文实现merkle树一致性算法:

https://books.google.de/books?id=CokSDQAAQBAJ&lpg=PA147&dq=merkle%20consistency%20proof&hl=de&pg=PA148#v=onepage&q&f=false https://books.google.de/books?id=CokSDQAAQBAJ&lpg=PA147&dq=merkle%20consistency%20proof&hl=de&pg=PA148#v=onepage&q&f=false

However, I am kinda stuck on the consistency check, because I always land in an infinite loop when I execute the ConsProofSub part. 但是,我有点坚持一致性检查,因为当我执行ConsProofSub部分时,我总是处于无限循环中。

Example: 例:

New tree has 8 , old tree has 7 leaves. 新树有8棵,老树有7片叶子。

Going through the previous function, I am obtaining m = 7 , the leaves of my new tree as vector E and true as b . 通过上一个函数,我得到m = 7 ,我的新树的叶子为向量Etrueb

The function goes through the recursive code flow, until we reach this situation: 该函数通过递归代码流,直到我们达到这种情况:

E now has 2 elements, so n = 2 . E现在有2元素,所以n = 2

m = 1 , due to previous subtractions in the recursive call for m < k , as well as b = false . m = 1 ,由于m < k的递归调用中的先前减法,以及b = false

We don't fall in the m = n && b = false if, as m and n are not equal. 如果mn不相等,我们不会落入m = n && b = false

k is now being calculated as, again, 2 , because the ceiling is correcting the resulting 1/2 from log2(n)/2 to 1 . k现在再次计算为2 ,因为上限正在将log2(n)/2的结果1/2校正为1

We fall into the m <= k case, and once again, we are recursively calling the function with the exact same parameters. 我们落入m <= k情况,再次,我们递归调用具有完全相同参数的函数。 Now we are in an infinite loop. 现在我们处于无限循环中。

However, I can't seem to figure out what i am doing wrong. 但是,我似乎无法弄清楚我做错了什么。 I feel like the ceiling in the k calculation is the problem. 我觉得k计算中的天花板是问题所在。 It basically makes it impossible to get out of the loop, because k will seemingly always be higher than m after some iterations. 它基本上使得不可能离开循环,因为在一些迭代之后k似乎总是高于m

Any advice / hint on my mistake here? 有什么建议/暗示我的错误吗?

EDIT: What's interesting is the fact that the algorithm seems to work perfectly when n is an odd number. 编辑:有趣的是,当n是奇数时,算法似乎工作得很好。 It only seems to fail for even numbers. 它似乎只为偶数而失败。 I just tried it with a new tree of 7 leafs, and it works like a charm, delivering the correct nodes needed to prove consistency. 我只是尝试了一个新的7片叶子树,它就像一个魅力,提供了证明一致性所需的正确节点。

However, I'm still unable to figure out what changes would have to be made to make it work with even numbers. 但是,我仍然无法弄清楚要使它与偶数一起使用会发生什么变化。

There seems to be a mistake in the book. 书中似乎有一个错误。 The case when m = n and b = true needs to be handled separately. m = nb = true需要单独处理。 A bit more detailed description of the algorithm can be found in RFC 6962 . 可以在RFC 6962中找到该算法的更详细描述。

Here is how you can fix it: 以下是如何解决它:

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我被这个 FreeCodeCamp 算法困住了 - I'm stuck with this FreeCodeCamp algorithm 我被这个口头算术算法困住了 - I'm stuck on this verbal arithmetic algorithm 我正在尝试使用python实现strassen的算法,但出现错误 - I'm trying to implement strassen's algorithm using python and I'm getting a error 我正试图找到一个“调酒师算法” - I'm trying to find a “bartender algorithm” 我试图找到以下算法的复杂性: - I'm trying to find the complexity of the following algorithm: 我正在尝试在Python中实现Bubblesort算法,但无法理解为什么它在一种情况下有效而在另一种情况下无效 - I'm trying to implement the bubblesort algorithm in Python and can't understand why it works in one case and not another 我正在编写关于变更的蛮力算法,但有点卡住了 - I'm coding a brute-force algorithm on change making and I'm a little stuck 我正在尝试在 python 中实现树 DS 并且无法理解我做错了什么? - I'm trying to implement trees DS in python and cannot make sense of what i'm doing wrong? 我应该在霍夫曼树的DEFLATE算法中提供一致性检查吗? - Should I provide consistency checks in the Huffman tree building algorithm for DEFLATE? Python代码 - 我卡住了 - 递归 - Python code - I'm stuck - recursion
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM