Skip to content

Any reason to use the Cids.sol library? #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Stebalien opened this issue Apr 17, 2025 · 3 comments
Open

Any reason to use the Cids.sol library? #148

Stebalien opened this issue Apr 17, 2025 · 3 comments

Comments

@Stebalien
Copy link
Collaborator

As far as I can tell, this project could just use raw hashes. I ask because this library:

  1. Does no validation.
  2. Doesn't actually support arbitrary CIDs. It simply assumes that every CID is a prefix followed by a 32 byte digest.

IMO, it would be better to just use raw hashes.

@ZenGround0
Copy link
Contributor

Does no validation.

By this do you mean validate that the prefix is particular mh / codec ? Or that mh length is correct?

@Stebalien
Copy link
Collaborator Author

It validates that the CID is at least 32 bytes long, that's it.

  • It doesn't even look at the codec, length, or multihash-code.
  • It doesn't support or even check if the CID has an unexpected digest length (CIDs support more than 32-byte digests).

From what I can tell, the "CIDs" here are all piece CIDs. I'd just store the digests. Saves space/gas anyways!

If we absolutely need to store them as CIDs, we should change this library to be PieceCid and have it check that the prefix matches a specific prefix and that the CID is of the expected length.

@Stebalien
Copy link
Collaborator Author

Alternatively, if you're worried about changing the state (even though you'd definitely save gas), change it to a generic slice manipulation library for adding/removing prefixes. That way, at the very least, nobody will be confused and think that this library actually handles CIDs in a sane way.

@rjan90 rjan90 moved this to 🐱 Todo in PDP Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🐱 Todo
Development

No branches or pull requests

3 participants