WASM Runtime
calimero-runtime
Purpose
Wasmer-based WASM execution engine. The Engine compiles application modules using Cranelift. Module::run builds a VMLogic instance with shared and private Storage, an optional NodeClient, and a ContextHost. It calls the exported method, catches panics, and returns an Outcome containing the return value, logs, events, and storage delta.
crates/runtimeExecution Flow
From SDK-generated WASM to executed outcome in a single synchronous call path.
VMContext & VMLimits
The VMContext carries all input data and identity information needed for a single execution. VMLimits enforces resource boundaries to prevent runaway modules.
VMContext
input: Vec<u8>, // serialized args
context_id: ContextId,
executor_public_key: PublicKey,
governance_epoch: u64,
// group DAG heads for consistency
}
VMLimits
max_memory_pages: u32,
max_stack_size: u32,
max_registers: u64,
max_register_size: u64,
max_logs: u64,
max_log_size: u64,
max_events: u64,
max_event_size: u64,
max_xcalls: u64,
max_storage_key_size: u64,
max_storage_value_size: u64,
max_method_name_len: u32,
max_module_size: u64,
}
Limits are enforced at the host function boundary — each call checks remaining budget before proceeding. Exceeding any limit causes the method to abort with a LimitExceeded error, and all mutations are rolled back.
Host Functions
The runtime imports 50+ host functions into the WASM module. Each function is registered as a Wasmer import under the "env" namespace. Organized by domain:
Identity & I/O
Registers
Registers act as a transfer buffer between host and guest. Host functions write results into numbered registers; the guest reads them out. This avoids complex multi-return calling conventions.
Events & Cross-Context
Events are accumulated in the Outcome and broadcast to WebSocket/SSE subscribers after execution completes. Cross-context calls are queued and executed asynchronously.
KV Storage (shared)
Private Storage
Private storage is scoped to the local node. Use cases include caching, local preferences, and derived data that doesn't need to be replicated.
CRDT / JS Bridge Collections
These host functions back the SDK's CRDT collection types. The js_std_d_* prefix indicates they implement the JavaScript SDK's distributed data structures.
Map operations
Set operations
Vector & RGA operations
User & Frozen storage
Blobs
Merge Registration
Applications can export a custom merge function. When the runtime applies a remote delta and detects a conflict, it invokes the registered merge function instead of using the default strategy. This enables application-specific conflict resolution beyond LWW.
Storage Interface
The runtime uses a simple KV Storage trait that abstracts over the actual storage backend. This allows test isolation via InMemoryStorage.
fn get(&self, key: &[u8]) -> Option<Vec<u8>>;
fn set(&mut self, key: Vec<u8>, value: Vec<u8>);
fn remove(&mut self, key: &[u8]) -> Option<Vec<u8>>;
fn has(&self, key: &[u8]) -> bool;
}
InMemoryStorage
A HashMap<Vec<u8>, Vec<u8>> implementation used in unit tests and the SDK's local test harness. Provides identical semantics to the RocksDB-backed storage without any external dependencies.
RocksDB-backed Storage
In production, the Storage trait is implemented by a thin wrapper over the calimero-store Database, scoped to the executing context's State / PrivateState columns.