Parents hash creating process

Hello,

In Merkle DAGS doc : Merkle DAGs | IPFS Docs
I read “A Merkle DAG is a DAG where each node has an identifier, and this is the result of hashing the node’s contents — any opaque payload carried by the node and the list of identifiers of its children …”

I am trying to fully understand how a parent’s hash is created from its children. From other researches I found that the two hashes are concatenated and the result is hashed. Is it correct and if so in which order are they concatenated ?

Thank you for reading

1 Like

A hash is not created from the children.

You create a new node, which somehow has “links” in it (to children), and you hash that new node. How you do all that is an implementation detail.

i.e. Kubo uses go-merkledag, so the CID will come from serializing protobufs like go-merkledag/merkledag.proto at master · ipfs/go-merkledag · GitHub, which have a field with a list of links. Afaik, order of links matters.

Thank you for your fast response.

Is there any documentations on what are precisely those “links” to the children ?

Is this choice a specific feature of IPFS ? Because when I search for Merkle Dags in general, this is what I found about how hashed are made.

Thanks


This is a schema of IPLD Tutorial | Merkle DAGs: Structuring Data for the Distributed Web (Lesson 4) | ProtoSchool

From what I understand, The hash of a parent node is the hash of all his children’s CID concatenated. Is it correct and if so in which order are this CID concatenated ?

The answer to your question is implementation specific. I just told you that in the go-merkledag implementation of MerkleDags, the hash of the root is the hash of the serialized protobuf that I linked.

It seems that this library chooses to sort links before serializing: go-merkledag/coding.go at c076715ad64cccb1976de3686b0d6304ec3f2839 · ipfs/go-merkledag · GitHub

Here is a 70 lines of code complete implementation of the merkle dag creation process for unixfs (dag-pb).

very well :slight_smile:

I will look into that

Thanks @Jorropo @hector