Skip to main content
Status: Draft
Type: Standards Track
Category: SDK
Created: 2025-10-20
Requires: CIP-1 (Actor Message Scheduler), CIP-2 (Off-Chain Compute), CIP-3 (Fee Model), CIP-5 (Timers)

1. Abstract

This CIP specifies cowboy_sdk, the Python SDK embedded in the Cowboy PVM and imported by actor code executing on-chain. It is normative for the PVM’s actor model, call primitives, handler permissions, continuation semantics, type system, verification builder, error hierarchy, ownership runtime, and the cowboy CLI surface. There are two Python-facing layers for Cowboy development. This CIP is normative for cowboy_sdk only. The standalone installable package (cowboy-sdk, imported as cowboy) is described in §2 and is non-normative for this CIP. Any Cowboy node that runs Python actors MUST expose the module layout and syscalls defined here. Any CLI that names itself cowboy SHOULD implement the subcommands in §16 with compatible flag semantics. Key properties:
  • Deterministic by construction. Non-deterministic Python primitives (wall-clock time, hardware FPU, unseeded randomness, filesystem, network, set(), pickle) are trapped or replaced by SDK equivalents.
  • Two-dimensional metering. Every syscall is metered in Cycles (compute) or Cells (state IO) per CIP-3.
  • Handler-mode purity. Every actor method declares whether it may issue async side effects (@pure vs @deferred); the runtime enforces this distinction.
  • Deny-by-default access control. Handlers are unreachable from external callers unless explicitly decorated with @public or @callable_by(...).
  • Continuations compiled at decoration time. async methods decorated with @runner.continuation or @actor.continuation are lowered to a finite-state machine at class-load time, not dynamically at runtime.
  • Entitlements gate all external-effect syscalls. Entitlements are declared in a deploy-time manifest and enforced at the Host API boundary.

2. SDK Layers

There are two Python-facing packages for Cowboy development. They are distinct and serve different purposes.

2.1 cowboy_sdk — In-PVM Actor SDK (this CIP)

Actor code that will run on-chain imports from cowboy_sdk. This is the package this CIP specifies.

2.2 cowboy — Standalone Developer SDK

The standalone package provides:
  • Actor authoring helpers@actor, @public, @callable_by, @pure, @deferred, @init_handler, OWNER, SELF, local runtime stubs for unit testing
  • Source generationactor_instance.to_source() emits deployable Python source that imports from cowboy_sdk
  • Chain clientCowboyClient, AsyncCowboyClient for RPC queries and transactions
  • Deploymentclient.deploy_actor(code, salt, init_handler, ...), client.execute_actor(...)
  • Wallets and signingWallet, generate_private_key, sign_payload
  • JobsJobSpec, client.submit_job()
  • CBSS — secrets management helpers
The cowboy local SDK mirrors enough of the cowboy_sdk actor authoring API to write and unit-test actors locally. It does not implement continuations, ActorRef, runner, Verify, CowboyModel, SoftFloat, ordered_set, BlockHeight, or storage raw/guard helpers. Actors that use those features must be tested against a live PVM sandbox.

2.3 Handler Signature Difference

The most important practical difference for actor authors: to_source() generates module-level wrappers with the payload: bytes signature. Actors deployed via to_source() therefore receive raw CBOR bytes on-chain; decoding is the author’s responsibility. CBOR encode/decode is a wire-format concern for call(), send(), and storage — see §9 and §11.5.

2.4 Compatibility Matrix


3. Motivation

Python is the surface that actor authors touch most often. For the protocol to be interoperable across implementations and for actors to remain portable across node versions, the SDK contract must be stable and normatively specified — not left as implementation-defined. A prior revision of this CIP was drafted before significant SDK consolidation landed (handler-mode purity, runtime module, error-code hierarchy, CREATE2 address derivation, entitlement manifest format, permissions system). This revision rebuilds against the shipping code and clarifies the two-package architecture so that the spec tracks implementation reality. Subsequent revisions will extend the SDK for CIP-9 volume mounts (currently runner-side only) and CIP-7 / CIP-17 streaming helpers. Both are noted as gaps in §19.

4. Definitions

  • Actor: A Python class whose public methods are invocable handlers. Identified by a 20-byte address.
  • Handler: A public method of an Actor. Accepts the payload the host delivers; returns a CBOR-encodable value or raises.
  • Handler mode: A per-method property, either pure (default) or deferred. Pure handlers MUST NOT issue async side effects.
  • Permission: A per-method access control tag (@public, @callable_by, or absent). Absent means deny-by-default from external callers.
  • Syscall: A call from the PVM into the Host API (implemented in Rust) to perform a privileged operation. The SDK wraps syscalls.
  • Continuation: A compiled FSM representation of an async def handler that awaits a runner job or an async actor call. State survives block boundaries.
  • Manifest: A JSON document declaring the entitlements a deployed actor requests. Attached to the deploy transaction.
  • PVM: The Python Virtual Machine executing actor bytecode under determinism constraints (CIP-3 §4).

5. SDK Module Layout

The canonical package is cowboy_sdk, shipped with the PVM at node/pvm/Lib/cowboy_sdk/. Version 0.1.1 targets Python ≥ 3.11. Required actor-facing API — every symbol below MUST be importable from the cowboy_sdk package root. An implementation MUST NOT remove, rename, or change the semantics of any of these: Currently exported helpers and extension surfaces — present in the shipping implementation but not mandated by this CIP. An implementation MAY omit or rename these; actor authors SHOULD prefer the required API above: Private submodules (cowboy_sdk.codec, cowboy_sdk.pvm_sys, cowboy_sdk.pvm_time, cowboy_sdk.pvm_random) are implementation details and SHOULD NOT be imported by actor code. They MAY be imported by SDK extensions that understand the PVM boundary.

6. Actor Model

6.1 Declaration

An Actor is a Python class decorated with @actor. The examples below use cowboy_sdk import style (on-chain). The standalone cowboy package uses the same decorator names but requires (self, payload: bytes) handler signatures — see §2.3.
The @actor decorator:
  1. Injects self.address (read-only Address, the actor’s own 20-byte address). cowboy_sdk only — the standalone cowboy SDK does not inject self.address.
  2. Injects self.storage (a dict-like proxy over actor private state — see §6.5).
  3. Wraps every public method in permission enforcement (deny-by-default; see §7) and handler-mode enforcement (see §8).
  4. Scans for @runner.continuation and @actor.continuation methods and installs the corresponding __resume callbacks. cowboy_sdk only.
  5. Registers the class as the handler entry point for the deployed actor.
The decorator form is canonical. Whether a bare class named Actor is accepted without the decorator depends on the PVM loader’s module-scanning logic, which is non-normative at this layer; actor authors SHOULD always use @actor.

6.2 Address Derivation

Actor addresses are derived via Ethereum-style CREATE2:
  • deployer_address: 20 bytes, the sender of the deploy transaction.
  • salt: caller-supplied bytes, keccak256-reduced to 32 bytes for CREATE2 — derive_actor_address hashes the salt unconditionally; it is not zero-padded (keccak256(salt) ≠ zero_pad(salt) for any non-trivial salt).
  • code_hash: 32-byte hash of the actor source. The CLI’s cowboy actor address is authoritative for the exact hash algorithm used.
  • Output: 20-byte Address.
derive_actor_address(deployer, salt, code_hash) computes this locally. The CLI helper cowboy actor address computes it without submitting a transaction (§16).

6.3 Deployment

Wire fields (DeployActor transaction): CLI defaults (applied by cowboy actor deploy before building the transaction): Atomic initialization:
  • By default the CLI calls "init" atomically in the same transaction as the deploy, with sender set to the deployer’s address.
  • Pass --no-init to deploy without an init call (only safe for actors that do not rely on init for ownership bootstrapping).
  • Pass --init-handler <name> to name a different handler.
  • Pass --init-payload <json-string | @file> to supply a custom payload.
The entire DeployActor transaction reverts if init_handler raises. The deployment receipt carries the derived actor address. Note on __init__: Previous revisions of this CIP described deployment as invoking __init__ with constructor args. This is incorrect. __init__ may be used for local Python class initialization (without args), but the deploy-time initializer is always a handler named via init_handler, not the Python constructor.

6.4 Message Handler Dispatch

A message to an actor carries a method_name (UTF-8 string) and payload (raw bytes). Dispatch:
  1. The PVM loads the actor class and state.
  2. method_name is looked up; unknown methods raise AttributeError — converted to ActorCallError.
  3. The handler runs under its declared permission (§7) and handler mode (§8).
  4. Return value is CBOR-encoded and returned to the caller (for call()) or discarded (for send()).
Actors deployed via to_source() receive payload as raw CBOR bytes in each module-level wrapper. The author is responsible for decoding (e.g. cbor2.loads(payload)). The reserved handler on_timer(msg) receives timer fires (CIP-5). Additional reserved handlers MAY be introduced by future CIPs.

6.5 Storage

Actor state is a private key-value store scoped to the actor’s address. Access is exclusively through self.storage:
Raw-bytes escape hatches (cowboy_sdk only):
Guard-based state snapshot for continuations (cowboy_sdk only):
Keys MUST be UTF-8 strings. Values of self.storage[key] MUST be CBOR-encodable per §11.5. Storage writes and reads are metered in Cells per CIP-3. Cross-actor storage access is prohibited; actor B cannot read actor A’s storage directly — it must call a method on A. A small set of dunder-style keys (__OWNER__, __INITIALIZED__) is reserved by the SDK. All access methods raise ValueError for those keys; use the sanctioned runtime APIs instead (see §12.10).

7. Handler Permissions

Access control is deny-by-default: a non-underscore-prefixed handler with no permission decorator is unreachable from external callers. This applies in both cowboy_sdk and the standalone cowboy package.

7.1 Decorators

7.2 Internal Helpers

Convention: name internal helpers with a leading underscore. The @actor wrap pass skips underscore-prefixed names unless they carry an explicit @public / @callable_by tag, so self._helper(payload) runs without a permission check. A non-underscore method without a permission decorator is still treated as a handler and will raise PermissionDeniedError when reached from an external caller.

7.3 @callable_by(SELF) Semantics

SELF resolves via caller == self.address — i.e., the host has actively set sender to the actor’s own address. This fires for timer self-fires and explicit self-submission flows. It does not fire for ordinary self.method() calls inside a handler, because runtime.get_sender() returns the outermost caller address (the EOA or upstream actor), not the executing actor’s address.

7.4 init Bootstrap Window

A handler named init is implicitly callable by anyone while the actor has not yet recorded successful initialization (the __INITIALIZED__ reserved slot is unset). The SDK sets this flag automatically after init returns without raising. After that, init follows the same deny-by-default rules as every other handler. The deploy machinery runs init in the same transaction as the deploy with sender = deployer, eliminating the front-run window.

8. Handler Modes

Every handler runs under one of two modes, declared via decorator: A pure handler MUST NOT issue any operation that produces an async effect: send(), runtime.schedule_timer(), runtime.submit_job(), emitting callbacks. Synchronous call() and local computation are allowed. Any prohibited operation inside a pure handler raises PurityViolationError. A deferred handler MAY issue any SDK operation subject to entitlement gates.
The split exists because pure handlers are safe targets for read-only RPCs (CIP-14 query path, external introspection tools); the runtime can execute them without the overhead of a deferred effect queue. The enforcement is a runtime check at the Host API boundary, not a static check.

8.1 Read-Only Execution Flag

Independent of the handler-mode distinction in §8 above, the runtime carries a per-call read_only flag on the execution context — a Boolean that the validator sets when a handler is invoked through a non-state-mutating entry point (notably the validator’s POST /actor/read RPC and analogous external query paths). The flag is part of the normative runtime surface and MUST be honored uniformly across implementations. Semantics. When read_only is set:
  • Every state-mutating host syscall MUST return HostError::Forbidden instead of recording the mutation. The mutating syscalls — exhaustive list — are: state_set, state_delete, emit_event, send_message, schedule_timer and cancel_timer (all variants), submit_job, create_deferred_tx, upgrade_self, every token_* mutation, fork (CIP-27), and any future host call that writes durable state.
  • The flag MUST persist across call() sub-calls: a read-only top-level call cannot launder a mutation through a callee. The callee inherits read_only = true for the duration of the cross-call.
  • Read syscalls (state_get, state_scan_prefix, etc.) and pure computation are unaffected.
  • send_message is on the deny list because, although fire-and-forget, it is a durable effect (CIP-1).
Relation to @pure / @deferred. The handler-mode decorator declares the author’s intent for whether a handler issues async effects; read_only is the runtime decision about whether to permit them on a given call. They are independent:
  • @pure + read_only=false: ordinary external view-style call. Async effects would already be rejected by @pure enforcement.
  • @pure + read_only=true: typical RPC query path. Belt-and-braces.
  • @deferred + read_only=false: ordinary mutating call.
  • @deferred + read_only=true: the handler could issue async effects, but the runtime is rejecting them at the host boundary. This is the case other CIPs (e.g. CIP-27 §3.1) need to name when they require their syscalls to be inert under read-only.
Other CIPs that introduce mutating syscalls SHOULD cite this section when stating the syscall’s read-only behavior, rather than redefining the flag locally.

9. Call Primitives

Three primitives for inter-actor and off-chain interaction: Standalone cowboy SDK note: Top-level call() and send() are not exported by the standalone package. For local tests use runtime.call_actor(target, method, payload, cycles_limit) and runtime.send_message(target, payload) respectively. Related primitives that move state rather than invoke handlers: runtime.transfer_balance (native CBY, §12.12) and runtime.token_transfer (CIP-20 tokens, §12.4) are ledger-level effects, not handler invocations. They share call()’s same-transaction rollback semantics but invoke no recipient code. Use them when funds need to move and the receiving address is not expected to react.

9.1 call() — Synchronous Cross-Actor Call

Arguments:
  • target: 20-byte address, as Address, hex string, or raw bytes.
  • method: UTF-8 handler name on the target.
  • args: CBOR-encodable dict of keyword arguments, or list of positional arguments.
  • cycles_limit: explicit cycle budget for the callee. Defaults to 100_000 if omitted; passing it explicitly is recommended for precise metering.
Semantics:
  • Executes in the same transaction. Shared read-write set with the caller.
  • Callee exceptions propagate — uncaught, they roll back the entire transaction.
  • Call depth is capped at 32. Exceeding this raises CallDepthExceeded.
  • Return value is CBOR-decoded and returned to the caller.
The ActorRef wrapper provides syntactic sugar:

9.2 send() — Fire-and-Forget Message

Semantics:
  • Enqueues a message for delivery at the start of the next block.
  • No return value; send() returns immediately.
  • Irrevocable: once a transaction commits, its sent messages are delivered even if later logic would want to cancel them.
  • Allowed only from @deferred handlers.
Authors SHOULD structure handlers so that all fallible synchronous calls complete before issuing send(). Raising after a send() does not unsend the message.

9.3 await runner.<op> — Runner Continuation

Decorated async def methods can await off-chain operations. cowboy_sdk (PVM) only — not available in the standalone cowboy package.
The decorator lowers the function into an FSM at class-load time (§10). Available awaitables under runner:

9.4 await ActorRef.async_* — Actor Continuation

Actor-to-actor async calls use the @actor.continuation decorator. cowboy_sdk (PVM) only.
Semantics:
  • Each await ActorRef.async_<method>(...) is lowered to send(target, {...}) plus a state save.
  • The target’s handler is invoked in a future block; when it completes, it delivers a callback message that resumes the caller’s continuation.
  • Requires both caller and callee to be @deferred.

10. Continuations

All continuation features in this section are cowboy_sdk (PVM) only.

10.1 FSM Compilation

Both @runner.continuation and @actor.continuation compile at class-load time into a pair of functions:
  • <name>: the initial handler; starts the FSM, persists state 0, issues the first async effect, returns.
  • <name>__resume: the resume handler; called by the runtime on callback delivery, loads state, advances the FSM, issues the next async effect (or returns final value).
The generated code is never observed by actor authors. Its shape is non-normative.

10.2 capture() — Explicit Local State

Local variables that must survive an await MUST be attached to a capture() object:
Captured values MUST be of CBOR-encodable types (see §11.5). Attempting to capture a closure, generator, file handle, thread, or custom object raises CaptureTypeError at the await point. Continuation state is stored at key __continuation:<correlation_id> within the actor’s own storage. Limits: Exceeding either limit raises ContinuationSizeLimitError or ContinuationCountLimitError.

10.3 Guards

Continuations can assert that specific storage keys were not modified during the async wait: Method A — decorator-level:
Method B — object-level via GuardedValue:
Guard fingerprints are keccak256(cbor(value_at_snapshot)). The fingerprint is stored in the continuation state and re-checked on resume.

10.4 Bounded Loops

await inside a Python loop requires an explicit upper bound:
A bounded_loop with max_iterations = N generates N FSM states at compile time. Exceeding N at runtime raises LoopBoundExceeded. Unbounded iteration with await is rejected at class-load time.

10.5 Sequential Await Limit

A single continuation function MAY contain at most 8 sequential await points (not counting awaits inside bounded_loop). This is a compile-time limit; violations are rejected at class-load. Authors needing more should split into multiple continuations.

10.6 Continuation Persistence Format

The @runner.continuation / @actor.continuation machinery has two orthogonal layers:
  • Authoring layer (compile-time, §10.1–10.5). The decorator rewrites an async def with await points into straight-line code (the FSM transform), and capture() / guards / bounded loops constrain what may cross a suspension. This is developer ergonomics — it shapes the source, not the persisted bytes.
  • Persistence layer (runtime, this section). When a continuation suspends at an await, the runtime serializes the suspended interpreter state and commits it to actor storage; the resuming dispatch restores it. This is the format that is part of the consensus boundary.
Production runs the persistence layer in checkpoint mode (ContinuationMode::Checkpoint): the persisted artifact is a versioned snapshot of the suspended VM, not an SDK-authored field record.
Note. The SDK also ships continuation.save_cont record helpers (a small typed map of state / ctx / handler / timeout / guards). Those belong to the FSM execution mode, which production does not currently enable, and they exist in two not-yet-reconciled variants. The normative on-chain format is the checkpoint snapshot defined below. Reconciling the record helpers and the fsm-vs-checkpoint terminology is tracked in COW-2340.
Storage location. A suspended continuation is written to the actor-state key __continuation:<cid>, where <cid> is the hex encoding of the resuming message id. The value flows into the state root, so it is consensus-committed. Because a snapshot can legitimately exceed the 64 KiB inline-blob cap (§6.5), __continuation:-prefixed keys are exempt from that cap (capping them would abort actor resumes). Snapshot envelope. The snapshot is encoded as a single canonically-ordered CBOR map with a leading version (current SNAPSHOT_VERSION = 3). The top-level fields are: Encoding & determinism. Maps use length-first key ordering (compare encoded key bytes by length, then bytewise) — the same ordering as §11.5, applied recursively. Integers use shortest-form; strings/bytes are length-prefixed; floats are IEEE-754 big-endian. The serialization performs no hash-ordered iteration and invokes no non-deterministic source, so two validators suspending the same execution produce byte-identical snapshots. (As elsewhere, authors must avoid native float in consensus paths per §11.3; the encoder is deterministic, but IEEE-754 arithmetic across heterogeneous FPUs is not.) Resume validation. On resume the runtime decodes the snapshot, rejects an unknown version or a source_path mismatch, validates that frame lasti values and all object indices are in range, and restores the frame stack before continuing execution at the saved instruction pointer. Versioning. Version 3 is current. The decoder also accepts the legacy single-frame layout (v1/v2 — a flat lasti/code with an implicit single module-level frame) and upgrades it in memory; new snapshots are always written at the current version.

11. Type System

The SDK replaces or constrains Python built-ins whose semantics are non-deterministic or ambiguous across platforms. All types in this section are cowboy_sdk (PVM) only unless otherwise noted. The standalone cowboy package exports Address as two separate forms (a Pydantic hex-string model for chain interactions, and a 20-byte stub for local actor testing) but does not export BlockHeight, SoftFloat, ordered_set, or CowboyModel.

11.1 Address

20-byte Ethereum-compatible address.

11.2 BlockHeight

Semantic int wrapper for block heights. Identity-equal to int at the bytecode level; useful for type annotations.

11.3 SoftFloat, ordered_set

  • SoftFloat is a software-floating-point type. Native Python float depends on the hardware FPU and is non-deterministic across platforms; authors MUST use SoftFloat instead. The SDK may alias SoftFloat = float when running under a PVM that enforces softfloat at the instruction layer; authors SHOULD still annotate with SoftFloat for clarity.
  • ordered_set is a dict-backed set with deterministic insertion-order iteration. Python’s built-in set() is prohibited in actor code.

11.4 CowboyModel

A dataclass-like base class for structured data. Feature set:
  • Deterministic serialization via to_cbor() and from_cbor(bytes).
  • JSON Schema export via schema() (for use with Verify).
  • Field validation on construction.
  • Forbids set / frozenset fields (non-deterministic iteration).
  • Forbids float fields (requires SoftFloat).

11.5 CBOR Codec

The SDK uses Canonical CBOR (RFC 8949 §4.2) everywhere encoding crosses a determinism boundary: storage values, message payloads, continuation state, call arguments, return values. Requirements:
  • Map keys sorted by length-first ordering (RFC 8949 §4.2.3): compare the encoded key bytes by length first, then bytewise (lexicographically) within equal lengths.
  • No duplicate keys.
  • Floats encoded as IEEE 754 double (when unavoidable).
  • Integers encoded in the shortest form.
cowboy_sdk.codec.encode(v) -> bytes and .decode(b) -> value are the canonical entry points.
Ordering note. This is RFC 8949 §4.2.3 (“length-first”) map-key ordering, not the §4.2.1 (“Core Deterministic Encoding”) pure byte-lexicographic ordering. Length-first is what the encoders in this section’s scope actually produce — the pure-Python codec (cowboy_sdk.codec, the encoder used on-chain since there is no host-side cbor_encode) and the VM’s continuation/snapshot encoder (cbor_key_cmp) both sort (len(key), key). The two implementations are byte-for-byte consistent; the choice is fixed by the deployed encoders. (Note: the transaction / PayloadSign envelope is a separate determinism boundary — it is keccak256-signed and serialized with ciborium in struct-field-declaration order, not length-first, so a tx signer must mirror that field order rather than length-first-sort its keys. That envelope is outside §11.5’s scope.) Migrating the boundary to §4.2.1 would change the canonical bytes of all on-chain CBOR (state values, payloads, continuation state) and is therefore a coordinated consensus change, tracked separately — not implied by this section.

12. Runtime Module

cowboy_sdk.runtime exposes the Host API. Actor code SHOULD prefer the higher-level primitives in cowboy_sdk (call, send, storage proxy); runtime is for cases where fine-grained control is needed (e.g., system actors, upgrade flows). The standalone cowboy package provides a partial local stub of runtime. It covers context access (get_sender, get_actor_address, get_block_height, get_timestamp_ms), events, send_message / call_actor, low-level state no-ops, ownership helpers, and test utilities (configure, reset, get_captured_events, get_captured_messages). It does not implement token operations, timers, upgrade_self, submit_job, keccak256, randomness, charge_gas, or scan_state_prefix — those functions exist only in the on-chain cowboy_sdk.runtime.

12.1 Context

These are the ONLY authorized sources of time and identity. time.time(), datetime.now(), and similar are trapped.

12.2 State

Lower-level state access paralleling self.storage:
set_state and delete_state refuse writes to reserved keys (__OWNER__, __INITIALIZED__). See §12.10.

12.3 Events

Emits a log entry visible in the transaction receipt. Metered in Cells per CIP-3.

12.4 Tokens (CIP-20)

The standard CIP-20 interface is exposed as runtime operations:
Each requires the corresponding entitlement (token.create, token.transfer, etc.).

12.5 Timers (CIP-5)

At fire_at_block, the scheduler delivers payload to the actor’s on_timer handler. Requires timer.schedule entitlement. schedule_timer_ex allows overriding fee payer, gas limit, and expiry per CIP-5 §4.1.

12.6 Jobs (CIP-2)

Low-level entry used by @runner.continuation; actor authors SHOULD prefer the continuation form.

12.7 Upgrades

Replaces the running actor’s code and optionally its entitlement manifest. The new manifest MUST be a subset of the current manifest (no privilege escalation); violation raises at the Host boundary. Requires sys.upgrade entitlement.

12.8 Crypto

randomness() produces deterministic per-block VRF output keyed by domain. This is the only authorized source of randomness; random.random() and secrets are trapped.

12.9 Metering

Explicitly consumes Cycles. Useful for implementations that want to front-load gas accounting for complex operations. Most actors do not need this; metering happens automatically at syscall boundaries.
Superseded for application actors (2026-07-28). The paragraph above records the original CIP-6 position and is retained as historical specification text. Current guidance: application actors MUST NOT call runtime.charge_gas(). The function remains implemented and still consumes Cycles, so a manual call charges gas in addition to the automatic syscall-boundary metering described above — it inflates cost rather than front-loading it. Manual calls were removed from the bundled node examples and developer guides in node#921, and from the remaining actors, examples, and guides. This note changes recommended practice only; it does not alter the metering semantics specified in this section.

12.10 Ownership

The ownership model tracks a single privileged address in the reserved __OWNER__ storage slot. User code cannot read or write this slot via self.storage[] — the proxy raises ValueError for reserved keys. Use the runtime APIs:
Canonical bootstrap pattern:
Transfer rules:
  • If no owner is set, any caller may set it (bootstrap window). Safe only when ownership is claimed inside init, because the CLI runs init atomically in the deploy transaction with sender = deployer, closing the window. Deploying with --no-init (or deferring the owner claim to a later transaction) leaves an unguarded front-run window — the protocol enforces no deployer-binding on the first assume_ownership_if_unowned() call, so a third party can claim ownership between deploy and the owner-claim tx. Actors that rely on init for ownership MUST NOT be deployed with --no-init.
  • Once set, only the current owner or an intra-actor call may transfer.
  • Passing the zero address to transfer_ownership raises ValueError; use renounce_ownership() explicitly.
@callable_by(OWNER) handlers become permanently unreachable after renounce_ownership(). Reserved storage keys: The standalone cowboy package provides stub implementations of all ownership functions backed by module-level state. Call runtime.reset() between tests to clear ownership and initialization state.

12.11 State Prefix Scan

Returns up to limit (key, value) pairs whose user-key starts with prefix, in ascending key order. Only verbatim-mode keys (≤ 32 bytes) are visible. limit is clamped to 1000 by the host.

12.12 Native CBY Balance

Atomically debits amount wei (CBY has 9 decimals; 1 CBY = 10^9 wei) from this actor’s native CBY balance and credits the same amount to to. Synchronous, no return value, no callback into to. transfer_balance is the only host-level primitive that moves native CBY between addresses. It is the counterpart, for native CBY, of runtime.token_transfer for CIP-20 tokens. The two ledgers are independent: token_transfer does not touch CBY balance and transfer_balance does not touch any token ledger. Arguments:
  • to: 20-byte recipient address. The system-reserved address band (per CIP-1 §5) is rejected with HostError::InvalidInput. The zero address is rejected.
  • amount: non-negative integer in wei.
Semantics:
  • Atomic with the calling transaction. The debit and credit are staged in the transaction’s write-set; if the enclosing transaction reverts, both reverse together. Implementations MUST route the balance writes through the same staged-writeset machinery used by call() and set_state — direct ledger mutations bypassing the writeset are non-conformant and leak balance on revert.
  • Insufficient balance raises HostError::InsufficientFunds and does not mutate either account.
  • amount == 0 is a no-op (no event, no metering beyond the syscall base cost).
  • Self-transfer (to == get_actor_address()) is permitted and is a no-op on net balance, but still consumes the syscall base cost.
  • Allowed from any @deferred handler. @pure and read-only contexts MUST reject transfer_balance with HostError::Forbidden.
  • Requires the econ.transfer entitlement on the calling actor’s manifest. Legacy actors with no manifest MAY transfer freely, consistent with the rest of the runtime.
Compose with fork() (CIP-27 §3.3) by either:
  1. Atomic seed via fork(endowment=N) — birth the child already funded, with a single atomic debit/credit folded into the fork itself. Use when the parent must guarantee the child has CBY before any post-fork code runs (e.g. a child whose on_fork schedules a self-timer at default fee_payer = self).
  2. Post-fork transfer — fork the child, then transfer_balance(child, N) from the parent. Both calls are in the same transaction and share rollback, but the child is briefly zero-balance between the two syscalls. Use when the funding amount depends on state the parent doesn’t know pre-fork.
Why this is a top-level runtime primitive, not a call(): CBY’s balance ledger is part of the chain’s account model, not actor storage. There is no recipient handler to invoke and nothing CBOR-encodable to pass — the operation is a pure debit/credit on two ledger entries. Modeling it as a call() would require every receiving actor to expose a handler whose only behavior is “accept funds,” which forces handler-existence on every actor that might ever be funded (including EOAs, which have no handlers). transfer_balance mirrors EVM’s value field on a plain ether transfer: a runtime-level effect, not a contract method. Standalone cowboy SDK note: The standalone package provides a local in-memory stub recording (to, amount) pairs for test inspection (runtime.get_transfer_log()). No supply checks run.

13. Verification Builder

Verify produces CIP-2 verification configurations using a fluent chain. cowboy_sdk (PVM) only.
VerifyBuilder.mode() validates against the following set and raises ValueError on unknown values: Checks are appended in the order .check() is called and passed to the Rust result-verifier in that order. Built-in checkers: Additional supplemental checkers (not_empty, contains, length_limit, http_status, response_time, signature_valid, tee_attestation, deterministic_output, field_exists, format_check) are exported by the implementation but are not mandated by this CIP.

14. Entitlements

14.1 Manifest Format

A manifest accompanies every deploy and upgrade. JSON shape:
Rules:
  • id values MUST appear in the Entitlement Registry (types/src/registry.rs).
  • The entitlements array MUST be lexicographically sorted by id; a chain MUST reject deploy transactions with an unsorted manifest.
  • params contents are entitlement-specific and validated at deploy time against the registry’s ParamSchema.
  • An upgrade’s manifest MUST be a subset (in both ids and param-bound strength) of the prior manifest.

14.2 Runtime Enforcement

Entitlements are enforced at the Host API boundary, not in SDK Python:
  1. Actor invokes an SDK function.
  2. SDK issues the corresponding syscall.
  3. Host checks the actor’s manifest for the required entitlement.
  4. If absent: Host returns HostError::MissingEntitlement → SDK raises the corresponding error.
  5. If present but quota-exceeded or param-restricted: Host returns the appropriate error.
Actor authors do not check entitlements in Python; they rely on the runtime to enforce.

14.3 Entitlement Registry (Informative Summary)

CIP-2 §7 is the normative source.
Note — token entitlements are not discrete string IDs (COW-1507). Unlike the other rows, the token.* capabilities are not registered as string IDs in the entitlement registry. The implementation models them with a typed Scope::Token([u8; 32]) (the token id) plus the matching Action variant (TokenTransfer / TokenMint / TokenBurn / TokenFreeze / …) in node/types/src/entitlement.rs — so a grant is naturally scoped to a specific token rather than a global token.transfer string. token.create is the exception: it has no Action variant and is not entitlement-gated — creating a token is gas-metered only, and the creator (tx.from) becomes the token’s owner and mint authority. This row is an informative summary of those capabilities; the typed Scope::Token + Action model is authoritative.

15. Error Hierarchy

All SDK exceptions derive from cowboy_sdk.CowboyError. Each exception exposes:
  • HOST_ERROR_CODE: int — Host API error code (1–8)
  • ERROR_SLUG: str — short identifier, format E1xxx
  • .why: str — human explanation
  • .fix: str — suggested remediation
Categories: Multiple exception classes may share a slug; the slug identifies the error category, not the specific class. Exceptions are CBOR-encoded into the transaction receipt; clients use ERROR_SLUG for programmatic handling. The standalone cowboy package also exports client-side exceptions (TransactionFailed, RpcError, AccountNotFound, NonceMismatch, etc.) that are not part of this CIP.

16. CLI

The canonical CLI is cowboy, implemented in node/cli/. Commands relevant to actor development:

16.1 Project bootstrap

Persists config at .cowboy/config.json (RPC URL, sender key, nonce cache).

16.2 Actor lifecycle

Fund and upgrade are top-level system commands (not subcommands of actor):

16.3 Ecosystem

16.4 Conformance

Any implementation MAY extend the CLI with additional commands. Renaming any command in this section is a breaking change and requires a CIP revision.

17. PVM Determinism Rules

Actor code MUST conform to the following rules. Violations are detected at class-load time where statically decidable; otherwise they raise DeterminismError at runtime.

18. Reference Implementation

Canonical implementation:
  • In-PVM SDK (cowboy_sdk): node/pvm/Lib/cowboy_sdk/ (version 0.1.1)
  • Host API: node/execution/src/pvm_host.rs
  • CLI: node/cli/ (binary cowboy)
  • Standalone developer SDK (cowboy): python-sdk/ (PyPI: cowboy-sdk, version 0.1.0)
  • Examples: cowboy/examples/core/05-tokens-and-balances, cowboy/examples/core/09-runner-llm, cowboy/examples/gallery/audio-transcription, cowboy/examples/gallery/image-generation, cowboy/examples/gallery/dao-copilot, cowboy/examples/gallery/compliance, cowboy/examples/gallery/advanced-messaging-ring

19. Open Questions / Gaps

  1. CIP-9 volume mounts from the SDK. Today, CBFS volumes are a runner-side concern. An actor-side API for mount(volume_id, access_mode) is not yet defined. Needed for first-class storage-attached actor workflows.
  2. CIP-7 / CIP-17 stream helpers. cowboy watchtower exists at the CLI level and as a system-actor pattern, but there is no actor-side @on_stream(stream_id) decorator or stream_publish() helper. Authors currently manage this via raw call() / send().
  3. Checkpoint vs FSM mode. runtime.is_checkpoint_mode() reports the persistence layer. Checkpoint mode (ContinuationMode::Checkpoint) is the current production on-chain format (§9.5); the FSM execution mode is not yet enabled in production. Terminology reconciliation is tracked in COW-2340.
  4. Reentrancy semantics on call() cycles. @reentrancy_guard is defined, but its key derivation (keccak256(method_name ‖ caller_addr)) may over-collide in contract-factory patterns. A CIP-6.1 revision may add an explicit key argument.
  5. Address scheme forward compatibility. Address is fixed at 20 bytes (Ethereum-compatible). A future migration to a larger scheme would break the type; no migration path is specified here.
  6. Static loop-bound detection. The compiler rejects unbounded await-in-loop at class-load, but edge cases (awaits inside comprehensions, awaits in helper functions called from loops) are under-specified. A future revision should enumerate accepted and rejected shapes.
  7. Entitlement manifest upgrade semantics. “Subset” is defined informally; the registry needs an is_tighter_than operator per entitlement, currently implemented ad-hoc.
  8. Standalone cowboy SDK coverage gaps. The standalone package does not yet mirror runner, capture, ActorRef, Verify, CowboyModel, SoftFloat, ordered_set, BlockHeight, or Storage.get_raw() / set_raw() / guard(). Actors that use those features must be tested against a live PVM sandbox.