I’ve decided to admit defeat. Here is my code. It should build a tree of the execution of the SHA-2 algorithm for a single chunk 512bit input without preprocessing. However, I turned it down from 64 iterations to 4 iterations because traversing the tree never finished for 64 iterations. Even at 4 iterations, it traverses 10,000 nodes- even when only 1000 have been allocated, including a bunch of constants which are leaves and not even counted in the traversal count. In addition, the assertions guarantee acyclical, and if it was cyclical, it would simply never return, not take forever and then return.
What on earth have I done with this code to cause it to take forever to traverse for such a tiny acyclical tree?
Well, that is to be expected. The tree may be stored in a very compact manner, but it has lots and lots of repeated portions. It is massively big.
As an example, consider this sequence:
Now the
s0tree has three of the originallaexpressions below it.… and that tree goes in
t2…… which ends up in
laagain at the end of the loop. So,lahas now (at least) three references to thelatree of the previous iteration. The next iteration will again triplicate this. And over and over. From this we can derive a lower bound of 3^64 instances of the originallain the final tree (even though only one will exist in storage). 3^64 is 3.43368382 × 10^30, i.e., about three gazillions.The generation of the tree takes the easy route and just reuses the subtrees. The traversal function on the other hand, will end up traversing the same subtree many, many times.