Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

NMT clarify leaves hashing #109

Closed
liamsi opened this issue Jan 16, 2021 · 1 comment · Fixed by #112
Closed

NMT clarify leaves hashing #109

liamsi opened this issue Jan 16, 2021 · 1 comment · Fixed by #112
Labels
disambiguation documentation Improvements or additions to documentation

Comments

@liamsi
Copy link
Member

liamsi commented Jan 16, 2021

It’s not clear if the namespace is also fed into the hash h as this might or might not be the case depending on what the serialize function looks like. I though I remembered that serialize was narrowed down by specifiying if serialization contains the NID or not but I can't find it currently. In the current form the spec would allow both cases as far as I understand. From a security pov both should be fine as the NID is returned / prefixed in front of the hash anyways (and hence the tree commits to the namespace of each leaf too).

For leaf node node of data d:

node.n_min = d.namespaceID
node.n_max = d.namespaceID
node.v = h(0x00, serialize(d))

https://github.com/lazyledger/lazyledger-specs/blob/master/specs/data_structures.md#namespace-merkle-tree

In the implementation it is not and a leaf hash is computed as:
ns(rawData) || ns(rawData) || hash(leafPrefix || rawData) where rawData does not contain the namespace.
or more precisely:
https://github.com/lazyledger/nmt/blob/4b4c58a9e7c071db650b27a69dccde4821411d07/internal/hasher.go#L63-L67


IMHO, this is a perfect candidate to start putting #108 into practice.

@adlerjohn
Copy link
Member

Yeah, you're right the spec is unclear what specifically the leaf contains. Either would work, but it needs to be unambiguous.

@adlerjohn adlerjohn added bug Something isn't working documentation Improvements or additions to documentation labels Jan 17, 2021
@adlerjohn adlerjohn added disambiguation and removed bug Something isn't working labels Jan 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
disambiguation documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants