Hard-fail on provider CID mismatch instead of warn#110
Merged
Conversation
`create_drive` previously logged a `tracing::warn!` and continued when the provider's returned data_root disagreed with the locally-computed CID, defeating content-addressing's only integrity guarantee. Now returns a new `FsClientError::CidMismatch` and refuses to cache or proceed. Adds unit coverage for both the matching and mismatching path via a small `verify_cid` helper.
bkontur
reviewed
Jun 2, 2026
| /// Compare a locally-computed CID against the CID a provider returned for | ||
| /// the same bytes. Returns `CidMismatch` on disagreement so callers can | ||
| /// refuse to trust the provider's response. | ||
| fn verify_cid(expected: Cid, got: Cid) -> Result<()> { |
Collaborator
There was a problem hiding this comment.
@ilchu for this kind of check, we are using ensure_** if you check PolkadotSDK, so I would vote for ensure_cid_matches or better name :)
Suggested change
| fn verify_cid(expected: Cid, got: Cid) -> Result<()> { | |
| fn ensure_cid_matches(expected: Cid, got: Cid) -> Result<()> { |
bkontur
approved these changes
Jun 2, 2026
Collaborator
bkontur
left a comment
There was a problem hiding this comment.
@ilchu please check just: https://github.com/paritytech/web3-storage/pull/110/files#r3341175555
Match FRAME's `ensure!`-style naming convention for predicate helpers that return `Err` on a failed invariant rather than performing verification with side effects. No behavioural change.
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.
The
create_drivefunction previously logged atracing::warn!and continued when the provider's returned data_root disagreed with the locally-computed CID, defeating content-addressing's only integrity guarantee.Now returns a new
FsClientError::CidMismatchand refuses to cache or proceed. Adds unit coverage for both the matching and mismatching path via a smallverify_cidhelper.