Skip to content

Verify upload CIDs against uploaded content - #207

Merged
cyc60 merged 5 commits into
masterfrom
verify-upload-cid
Sep 14, 2026
Merged

cyc60 merged 5 commits into
masterfrom
verify-upload-cid

Conversation

@cyc60

@cyc60 cyc60 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

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 IpfsMultiUploadClient quorum, which does nothing for a single client and fails open against a compromised majority.

  • New compute_cid(data) -> CID in sw_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 with decode_car. compute_cid reproduces Kubo's default add --cid-version 1 layout (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, PinataUploadClient and FilebaseUploadClient raise IpfsException when the returned CID does not commit to the data. IpfsUploadClient verifies before pinning, so a wrong CID is never pinned. IpfsUploadClient.upload_json now goes through upload_bytes with _dump_json (byte-identical to the encoder add_json used) so JSON uploads are verified too.
  • IpfsMultiUploadClient needs no change: a provider that fails verification is logged and excluded from the quorum like any other failed upload.
  • A CIDv0 (Qm...) response is rejected on purpose: we request CIDv1 and downstream consumers expect it.
  • Version bumped to v0.14.3.

Base automatically changed from filebase-upload-client to master September 11, 2026 11:26
# Conflicts:
#	pyproject.toml
#	sw_utils/ipfs.py
#	sw_utils/tests/test_ipfs.py
@cyc60
cyc60 merged commit 4e25d5b into master Sep 14, 2026
3 checks passed
@cyc60
cyc60 deleted the verify-upload-cid branch September 14, 2026 06:51
@evgeny-stakewise
evgeny-stakewise restored the verify-upload-cid branch September 15, 2026 15:54
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.

2 participants