Skip to content

Hard-fail on provider CID mismatch instead of warn#110

Merged
bkontur merged 4 commits into
devfrom
ic/fs-client-cid-verify
Jun 3, 2026
Merged

Hard-fail on provider CID mismatch instead of warn#110
bkontur merged 4 commits into
devfrom
ic/fs-client-cid-verify

Conversation

@ilchu
Copy link
Copy Markdown
Collaborator

@ilchu ilchu commented Jun 1, 2026

The create_drive function 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.

`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.
@ilchu ilchu self-assigned this Jun 1, 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<()> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@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<()> {

Copy link
Copy Markdown
Collaborator

@bkontur bkontur left a comment

Choose a reason for hiding this comment

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

ilchu added 3 commits June 2, 2026 23:51
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.
@bkontur bkontur enabled auto-merge (squash) June 3, 2026 09:08
@bkontur bkontur merged commit 401236a into dev Jun 3, 2026
24 of 27 checks passed
@bkontur bkontur deleted the ic/fs-client-cid-verify branch June 3, 2026 10:42
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