Score:-1

Merkle Tree Proofs Implementations

pf flag

I'm currently implementing a Merkle Tree in Rust. One of the problems I'm facing is the complexity of generating the proof. Meaning the vector I give to the verifier in order to check if an element is present. Many people say that I should transverse the tree to find the path for the element (if the element is part of the data set), but I don't understand how that would work if the Merkle Tree is not sorted. Am I missing something? From my understanding the best way to do this is find the leaf (if it exists) and find your way up the tree. In that case the complexity will be O(N) to generated.

Thanks in advance!

Score:0
my flag

From my understanding the best way to do this is find the leaf (if it exists) and find your way up the tree. In that case the complexity will be O(N) to generated.

There are two steps here, and it's not clear which you think might take $O(N)$ time.

The first step is finding the leaf; yes, if you take the approach of examining each element individually, this will obviously take $O(N)$ time if there are $O(N)$ elements. On the other hand, this isn't necessarily the only possible algorithm. If we have our $N$ elements, then we can build a data structure (say, a hash table) to look up the elements quickly, if faster lookup is deemed necessary.

The second step is generating the authentication path; yes, generating the entire Merkle tree (and computing the root) will take $O(N)$ time, and there's no way to get around that. On the other hand, once we have constructed the tree, we can often save the values of intermediate nodes. In the most straight-forward approach, we can just save all the intermediate nodes; this requires $O(N)$ memory; on the other hand, constructing the authentication path just involves copying the appropriate node values, and that can be done in $O(\log N)$ time.

Tito avatar
pf flag
How is that it takes O(log N) time to construct the path? From what I understood if you start from the root you have no way to know where the leaf you want is. Or should I build the path from the leaf to the root? In that case I need to change the way I built the tree.
poncho avatar
my flag
@Tito: if you know which leaf it is, you know the path to it from the root (and hence the authentication path, which is the sibling node for every entry on the path). It doesn't matter which direction you build the path; it is easy enough to compute which nodes you need to reveal.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.