Skip to content

Memory (env) ​

The contract exports one linear memory. Host functions read and write it through (ptr, len) pairs; a pointer or length outside the memory makes the host function fail (usually returning -1) rather than trap.

The VM copies the call input to offset 64; see Guest exports → call.

allocate live ​

text
(import "env" "allocate" (func (param i32) (result i32)))
allocate(size: i32) → ptr: i32

Reserves size bytes with a bump allocator and returns the start. The host only advances a cursor — it does not grow the memory, so the contract must make sure the range exists. Negative sizes count as 0; a single request is capped at 1 MiB. For toolchains (AssemblyScript and similar) that expect the host to allocate.

deallocate live ​

text
(import "env" "deallocate" (func (param i32)))

Does nothing — the bump allocator never frees. Present so code written for allocator interfaces links.

abort live ​

text
(import "env" "abort" (func (param i32 i32 i32 i32)))

The AssemblyScript abort hook, accepted so such modules link. It does nothing and does not stop execution — AssemblyScript follows it with unreachable, which is what fails the call. To fail a call deliberately, trap (unreachable), which rolls back the whole call tree, or return an error with set_return when the caller should see a message.