Does IPFS CID stay constant forever for the same file?

Hello,

This is perhaps very basic question but I couldn’t find in my search. Assuming the file content doesn’t change even single bit, would IPFS CID never change even if it’s being added/pinned by different users?

Would this assumption stay true for foreseeable future? I know it depends on hash algorithm, so just by knowing what hash algorithm was used (SHA-256), the IPFS CID would be reproducable for foreseeable feature right? Or is there other information that needs to be stored as well?

The answer to your question is yes*, the CID for the same file will always be the same no matter who hashes it.

The exception to this is when/if the IPFS devs make a change to the protocol (as we are expecting soonish) that changes the hashing algorithm and results in a different CID. I’m sure they will tell us well in advance of this happening.

Even for >256 KB files right? Because of chunking.

Even if they make a change to the protocol, it is expected to be backwards compatible right?

To my understanding, the chunking algorithm is also deterministic and will result in the same CID every time.

I can only speculate about what future changes will mean, but I assume they would make every attempt to keep backwards compatibility.

Regardless what is the default option set, it should always be possible to add with the same parameters to reproduce the same hash.

I have not heard of any changes to the default coming soon though…

1 Like

There is at least one experimental feature that is stable but not enabled by default due to it changing the hashes, as you can find here:

The footnote for that feature is what I based my answer off of.

Thank you very much for all the replies. So In a nutshell

  1. The CID should stay the same for a file of any size, as long as the same multihash and CID version is used.

  2. The multihash or chunking algorithm may change in future, but will be 100% backward compatible.

So my final question and i would be very grateful for the answer, what parameters should i store to be able to replicate the same CID in case IPFS version changes later? I know hash algorithm number is one thing i need. Anything else i would need?

Bump, please help, would be grateful

To reproduce the same hash in the future you will need to remember:

  • The hashing algorithm used (default now is sha256)
  • The dag-format used (default now is “balanced”)
  • The chunking algorithm used (default now is “fixed-262144” which means “256KiB blocks”).
  • Whether --raw-leaves was used.
  • For very large folders, whether the HAMT directory sharding option was enabled.
2 Likes

Thank you very much hector