[英]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
,我的新树的叶子为向量E
, true
为b
。
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. 如果
m
和n
不相等,我们不会落入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. 但是,我仍然无法弄清楚要使它与偶数一起使用会发生什么变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.