Verify upload CIDs against uploaded content - #207
Merged
Merged
Conversation
# Conflicts: # pyproject.toml # sw_utils/ipfs.py # sw_utils/tests/test_ipfs.py
evgeny-stakewise
approved these changes
Sep 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Every upload client now verifies the CID returned by the provider against a CID computed locally from the uploaded bytes. Fetch-side verification (#202) cannot catch a provider that returns a CID of foreign content: consumers would download that content, it would match the (wrong) CID and be accepted. Until now the only protection was the
IpfsMultiUploadClientquorum, which does nothing for a single client and fails open against a compromised majority.compute_cid(data) -> CIDinsw_utils/vendor/ipfs_unixfs.py. The CAR decoder from Verify fetched IPFS content against its CID via CAR #202 (sw_utils/vendor/ipfs_car.py) is merged into the same module, since both sides describe the dag-pb/UnixFS wire format and now share the codec and protobuf field constants; a round-trip test encodes a multi-block file and decodes it back withdecode_car.compute_cidreproduces Kubo's defaultadd --cid-version 1layout (raw leaves, 256 KiB chunks, balanced dag-pb tree with 174 links per node, sha2-256), which is also what Pinata (cidVersion: 1) and Filebase RPC (cid-version=1) produce. Reference CIDs in the tests were generated with Kubo v0.43.0, including 174 and 175 leaves to cover the depth-2 tree.IpfsUploadClient,PinataUploadClientandFilebaseUploadClientraiseIpfsExceptionwhen the returned CID does not commit to the data.IpfsUploadClientverifies before pinning, so a wrong CID is never pinned.IpfsUploadClient.upload_jsonnow goes throughupload_byteswith_dump_json(byte-identical to the encoderadd_jsonused) so JSON uploads are verified too.IpfsMultiUploadClientneeds no change: a provider that fails verification is logged and excluded from the quorum like any other failed upload.Qm...) response is rejected on purpose: we request CIDv1 and downstream consumers expect it.