wasm-cloudflare-workers
Family: Wasm host
Stage: Research — target profile and capability map accepted into the registry; no local backend yet.
Related: Wasm family, Capability registry, Shared scenario, RFC 0002.
Summary
Cloudflare Workers is a non-blockchain Wasm-host target. It lets the same portable business core that compiles to blockchain Wasm targets (NEAR, CosmWasm) also run as an off-chain edge worker. The goal is to share verified Lean business logic between on-chain contracts and chain-side services such as oracles, keepers, indexers, simulators, and hybrid dApp backends. Because Workers is not a blockchain, many chain-specific capabilities are reinterpreted or unsupported. The portable core (pure logic, state transitions, types, proofs) stays identical; only the capability adapter changes.Pipeline
@[extern "lean_cf_*"] declarations:
- KV read/write for persistent scalar/map storage.
- Request metadata /
Date.now()for environment reads. fetch()for cross-call invoke.console.logfor events.
Target Profile
Capability Mapping
Not supported by design:
value.native— Workers has no native token transfer semantics.storage.pda,crosscall.cpi— Solana-specific.zk.circuit,zk.proof— not a ZK target.
Runtime Profile
Strategy B from RFC 0003: full Lean runtime plus a Cloudflare-specific host bridge. Constraints:- Single-threaded; no POSIX/libuv assumptions.
- No filesystem; all I/O through host bridge imports.
- Wasm-safe allocator (bump or custom).
- No native GMP; use Zig bigint or restrict arithmetic.
- HTTP request/response is the entry boundary, not a blockchain transaction.
Entrypoint Shape
Exported Wasm function:- Deserializes the incoming request (method, path, headers, body).
- Dispatches to a contract entrypoint based on path or JSON message.
- Runs the portable core with capabilities bound to Workers APIs.
- Serializes the result into an HTTP response.
POST /initialize→initializePOST /increment→incrementGET /count→get
Storage Backend Options
Option A: Workers KV (default for v0)
- Pros: simple, global, cheap.
- Cons: eventual consistency, no transactions, no numeric increment atomicity guarantees across simultaneous edge invocations.
Option B: Durable Objects
- Pros: strong consistency, single-object atomicity, in-memory state.
- Cons: requires object ID routing, more complex binding setup.
storage.scalar.strong capability.
Build Commands (planned)
Example Location
Open Questions
- Should the host bridge be written in Zig (consistent with NEAR/CosmWasm) or in Rust (better Cloudflare ecosystem)?
- Should KV or DO be the default storage backend for the Counter spike?
- How should authentication/caller identity be configured in
wrangler.toml? - Should
crosscall.invokesupport service bindings only, or any HTTP URL? - How do we test atomicity and consistency in the shared scenario when Workers is not transaction-based?
Acceptance Criteria for Spike Exit
-
wasm-cloudflare-workerstarget profile is in the registry. - Counter example compiles to a Workers-compatible
.wasm. -
wrangler devservesPOST /incrementandGET /countcorrectly. - Artifact metadata records
target: wasm-cloudflare-workersand capabilities used.