Verify fetched IPFS content against its CID via CAR - #202
Open
cyc60 wants to merge 6 commits into
Open
Conversation
cyc60
force-pushed
the
ipfs-hash-verification
branch
from
September 3, 2026 08:20
9f219ac to
dc85f74
Compare
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
IpfsFetchClientpreviously fetched{gateway}/ipfs/{cid}and returned the bytes without checking them against the CID. Consumers treat the CID as an on-chain commitment (Keeper config/rewards IPFS hashes,GENESIS_VALIDATORS_IPFS_HASH), so unverified content is an integrity gap: a malicious or MITM'd gateway could serve arbitrary bytes for a committed CID.Fetched content is now verified against its CID by requesting the trustless-gateway CAR response (
?format=car) and decoding it withipfs-car-decoder, which re-hashes every block against the requested CID. This covers raw and dag-pb codecs, CIDv0/v1, and single- and multi-block DAGs, so it works for config, rewards, and the large genesis-validators lists alike.Behavior with
verify_hash=True(default):Content-Type).cat→ trusted (content-addressed).fetch_jsonnow parses verified bytes.verify_hash=Falsekeeps the previous plain-fetch behavior as an escape hatch.Dependencies: replaced
py-cid/py-multihashwithipfs-car-decoderandmultiformats, pinned exactly because verification relies on the decoder'svalidate=Trueblock-checking.Note for downstream: a custom gateway configured by an operator must support trustless CAR responses (
?format=car); all shipped default gateways (Filebase, Quicknode, Pinata) do.