Skip to content

Register a fetched contract only with the context provider that verified it (DPNS registration, wallet document writes) #6292

Backlog

Description

@Claudius-Maginificent

TL;DR: If an app replaces the SDK's context provider while a DPNS registration or a wallet document write is in progress, the new provider can be handed a data contract it never checked itself.

User story

As a developer embedding the Rust SDK or platform-wallet, I want a contract I did not verify never to be injected into my context provider, to achieve a provider whose cache holds only contracts it authenticated.

Scenario

Base flow

An app starts a DPNS name registration, or a platform-wallet document write, then swaps the SDK's context provider (Sdk::set_context_provider) before the operation registers the contract it fetched.

Actual behavior

The fetched contract is registered with whichever provider is installed when registration runs, not the one that was in place when the contract was fetched and verified. The replacement provider receives a contract it did not authenticate.

Expected behavior

A fetched contract is registered only with the provider that was installed when the fetch started, and only while that provider is still installed. After a swap, neither provider is written to.

Steps to reproduce

Start one of the two operations below, call set_context_provider while its fetch is in flight, then inspect the new provider's registered contracts.

Detailed discussion

Two sites register through self.context_provider() read after the fetch:

  1. packages/rs-sdk/src/platform/dpns_usernames/mod.rs, dpns_registration_documents: fetch_current_dpns_contract() then provider.register_data_contract(..) (from feat(platform)!: dpns contract v3 checks name registration with schema keywords (PV15) #5337).
  2. packages/rs-platform-wallet/src/wallet/identity/network/document.rs, register_contract_for_proof_verification (from fix(platform-wallet): register data contract for returned-proof verification on writes #4035), called after its caller fetched the contract.

Proposed fix, the pattern #5588 applies to Sdk::fetch_system_data_contract (commit 768820c): capture sdk.context_provider_arc() before the fetch, then register through that handle only if Arc::ptr_eq with the currently installed provider. set_context_provider installs a new Arc each time, so pointer equality means no swap happened. No Fetch API change is needed. Add a test that swaps the provider during the operation and asserts neither provider received the contract.

Low likelihood: it needs a provider swap during the operation.

Prior work

Attribution

🤖 Co-authored by Claudius the Magnificent AI Agent

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions