Skip to content

[WIP] add experimental revive option for reproducible CIDs#6509

Closed
drbh wants to merge 2 commits intoipfs:masterfrom
drbh:reproducible-cids
Closed

[WIP] add experimental revive option for reproducible CIDs#6509
drbh wants to merge 2 commits intoipfs:masterfrom
drbh:reproducible-cids

Conversation

@drbh
Copy link
Copy Markdown

@drbh drbh commented Jul 13, 2019

Draft solution for reviving a CID.

Based on the deep dive specs from IPFS Camp 2019;

This is the case when you have a file - and you know what you expect the CID to be, but you do not know the original params that generated that DAG root.

We implement a --revive flag (also called --expected-cid in the spec) on the ipfs add core command.

In short
We want to automatically loop through known default settings check the CID and return to the user if we find the correct params.

Example CLI use

ipfs add --revive=QmTfwRggLp9mo7fTF5L5cCxk8djbE6reipLpMMNfYgA6ip /tmp/cat.jpg 

Proof of concept work

🐥Add revive flag
🐥Check if flag is called
🐣Loop over default settings
🐣Return useful information on match

Discussion topics

🥚What is returned to the user?
🥚If its the fmtstr what does that look like?

Answerable questions

❓What are the known default settings (when CID versions change)?
❓How to loop over *files.multipartDirectory more than once code?

Comment thread core/commands/add.go
// var added int
addit := special.Entries()

for addit.Next() {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for addit.Next() doesn't initiate a loop on the second default settings. Seems like the entries are removed on each loop. Is there a way we can persist the file as we try different params?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, you could buffer them all into memory. But that's really not something you want to do.

@lanzafame
Copy link
Copy Markdown
Contributor

Can we iterate over the flag name? I am not a fan of expected-cid but revive seems really misleading, maybe reconstruct?

@drbh
Copy link
Copy Markdown
Author

drbh commented Jul 13, 2019

agreed revive and expected-cid are not the most descriptive.

✅I like reconstruct alot

@drbh
Copy link
Copy Markdown
Author

drbh commented Jul 13, 2019

@lanzafame

Just pushed some minor updates (renamed vars for golint)

Also renamed revive to reconstruct!

Use

ipfs add --reconstruct=QmTfwRggLp9mo7fTF5L5cCxk8djbE6reipLpMMNfYgA6ip /Users/drbh2/Desktop/cat.jpg

Comment thread core/commands/add.go
}

if rbset {
myOpts = append(myOpts, options.Unixfs.RawLeaves(rawblks))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caveat: RawLeaves are disabled by default when doing ipfs add --cid-version 0 (current default for CIDv0), but are enabled when user opts-in to CIDv1 (ipfs add --cid-version 0.

--reconstruct should see if CID is v0 or v1 and set proper default

Comment thread core/commands/add.go
}

if trickle {
myOpts = append(myOpts, options.Unixfs.Layout(options.TrickleLayout))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trickle DAG is created by ipfs files write by default, which complicates things: so we should always try enabling/disabling it as a fallback.

@olizilla
Copy link
Copy Markdown
Member

olizilla commented Sep 2, 2019

If we're offering up a CID to ipfs add along with a file, and saying "figure out what parameters to use to get this CID from that file" then I feel like a more idiomatic name for the flag would be --target=<cid>.

ipfs add --target=QmTfwRggLp9mo7fTF5L5cCxk8djbE6reipLpMMNfYgA6ip /path/to/file

Not a blocker, I can totally live with --reconstruct but i felt compelled to comment.

Copy link
Copy Markdown
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this can't be sanely implemented in go-ipfs:

  1. Files will have to be written to a scratch space (on disk) so they can be re-read when trying new parameters. This would be pretty complicated and invasive addition for a small, infrequently used feature.
  2. This is a combinatorial problem involving hashing. Users will have to specify the sets of flags that could reasonably have been used.

Instead of implementing this in go-ipfs, it should probably be implemented as an external script (to avoid problem 1) with some kind of DSL for describing possible/likely flag combinations.


An --expect flag could be implemented in go-ipfs but that seems pretty useless given that a user can just check [[ $(ipfs add -q foobar) == "expected" ]].

Comment thread core/commands/add.go
// var added int
addit := special.Entries()

for addit.Next() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, you could buffer them all into memory. But that's really not something you want to do.

@gammazero gammazero marked this pull request as draft February 4, 2026 07:35
@gammazero
Copy link
Copy Markdown
Contributor

This is such an infrequent activity that it should be done manually, or by an external script. It should not be a feature of the command.

@gammazero gammazero closed this Feb 4, 2026
@lidel
Copy link
Copy Markdown
Member

lidel commented Feb 15, 2026

If anyone finds this when searching for "reproducible CIDs" relevant work happened in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants