Skip to content

feat(wasm-sdk): let apps seed the contracts they already hold - #4745

Merged
QuantumExplorer merged 2 commits into
feat/wasm-sdk-persist-contractsfrom
feat/wasm-sdk-known-contracts-unproved-versions
Sep 14, 2026
Merged

QuantumExplorer merged 2 commits into
feat/wasm-sdk-persist-contractsfrom
feat/wasm-sdk-known-contracts-unproved-versions

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

An app knows its contracts at build time, yet the browser SDK offers no way to hand them over: the trusted-context cache fills only through fetches, so every page load pays a contract round trip (0.7 to 1.3 s on Yappr against moutai) before its first document query. #4744 removes that on repeat visits by persisting fetched contracts; this PR removes it on first visits too, by letting the app seed a bundled snapshot.

Stacked on #4744, whose $contractVersion staleness guard also covers seeded contracts, and whose persistence they inherit. Retarget to v4.2-dev once it merges.

What was done?

  • WasmSdk.addKnownContract(contract) seeds the trusted-context cache with a contract the caller holds (a bundled snapshot, a contract it just published). Through cache_contract it is persisted like a fetched one. Returns false when the SDK has no trusted context.
  • evo-sdk: contracts.addKnown(contract), and a README section showing the flow: seed the bundle, then confirm it off the critical path with the proved contracts.getLatestVersions (feat(platform): add getDataContractsLatestVersions query for cheap contract staleness checks #4739) and refetch only what changed. As that proof gets cheaper the flow gets cheaper with it, with no API change.

An unproved variant of the versions check was in an earlier revision of this PR and is gone: with the proved proof being slimmed down it would have been a detour that widened the trust surface for nothing.

How Has This Been Tested?

  • cargo test -p wasm-sdk --lib: 128 passed. New native test: seeding through the JS-facing entry point lands in the cache and the persisted store, and is a no-op without a trusted context.
  • Functional spec added to tests/functional/contracts.spec.ts: addKnownContract accepts a fetched contract.
  • cargo clippy -p wasm-sdk --lib --tests and --target wasm32-unknown-unknown: no findings in wasm-sdk.

Breaking Changes

None. One new method on WasmSdk and one on the evo-sdk contracts facade.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

An app knows its contracts at build time, yet the browser SDK offered no way
to hand them over: the cache filled only through fetches, so every load paid
a contract round trip before its first document query. And the one query that
could confirm a held contract is still current, getDataContractsLatestVersions,
was exposed proved only, whose proof is the full multi-contract proof and
costs as much as fetching the contracts.

Add the two entry points the bundled-contract flow needs:

- `addKnownContract(contract)` seeds the trusted-context cache (and, through
  it, the persisted store) with a contract the caller holds. Returns false
  without a trusted context.
- `getDataContractsLatestVersionsUnproved(query)` answers versions from the
  unproved path rs-sdk already provides: the node's word, checked for
  freshness through the signed metadata, a few bytes per id. Versions only:
  `includeContracts` is refused, because contracts enter the cache through
  proved fetches alone. The trust model is bounded: a node overstating a
  version costs the caller one proved fetch; one understating it leaves the
  caller on its held contract, which the `$contractVersion` guard drops on the
  first document written under the newer version.

evo-sdk exposes both as `contracts.addKnown` and
`contracts.getLatestVersionsUnproved`, and the README shows the flow: seed the
bundle, revalidate unproved off the critical path, fetch only what changed,
proved.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 636141cf-a698-443d-bda2-7a7b53f9b888

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Queued for automated review — 10th in line, estimated start in ~50 min (commit 3eafd55)
Estimated review time once started: ~10 min (two-phase automated review; median of recent runs).

  • Request priority review — tick this box and the review moves to the front of the queue.

…eeding

The proved version proof is being made cheaper, so an unproved primitive
would be a detour that also widened the trust surface. Apps seed the
contracts they hold with `addKnownContract` and confirm them with the proved
`getDataContractsLatestVersions` off the critical path, inheriting the
cheaper proof when it lands.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@QuantumExplorer QuantumExplorer changed the title feat(wasm-sdk): seed known contracts and check their versions unproved feat(wasm-sdk): let apps seed the contracts they already hold Sep 14, 2026
@QuantumExplorer
QuantumExplorer merged commit f6dc8ed into feat/wasm-sdk-persist-contracts Sep 14, 2026
6 of 7 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/wasm-sdk-known-contracts-unproved-versions branch September 14, 2026 16:40
PastaPastaPasta pushed a commit to PastaPastaPasta/yappr that referenced this pull request Sep 14, 2026
…n load (#399)

* perf(sdk): bundle the deployed contracts and seed the SDK from them on load

The app knows its contracts at build time, yet every load fetched all of them
(one batched proved request, 0.7 to 1.3 s on moutai) before the first
document query could run.

Snapshot them instead. `npm run contracts:snapshot` writes the network's
deployed contracts to `lib/contracts/bundled/<network>.json` (version +
serialized bytes; one file per network, loaded on demand so a build ships
only its own). On load the SDK service seeds the SDK with every bundled
contract the deployment configures and fetches only the rest, then, off the
critical path, asks the network unproved which bundled versions are stale and
refetches those proved.

Both SDK entry points (`contracts.addKnown`, `contracts.getLatestVersionsUnproved`,
dashpay/platform#4745) land in a later evo-sdk than the pinned dev.10; until
then the capability checks fall through to the existing preload, so this is
inert today and switches on with the SDK bump.

The snapshot script warms the devnet connection with one DPNS read before the
first v6 contract fetch, the same protocol-version bootstrap the app does.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* refactor(sdk): revalidate bundled contracts through the proved versions check

The proved versions proof is being made cheaper upstream, so the check no
longer routes through an unproved variant. Versions only, off the critical
path; the SDK bump that carries `contracts.getLatestVersions` switches it on.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Quantum Explorer <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
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