ANTRequest's ANTwasm Specification (Version 0.0.1)

warning! This specification is unfinished. while you MAY implement it as written, the update comes in the form of a version bump.

ANT.wasm is a Brand New way to run wasm safely and securely (or that us the goal).

to use ANT.wasm you can use This Specification to insure interoperability. If you do not Like where this is going please fork.

Table Of Contents

Table Of Contents

Status of this document

this document written on is Semantic version 0.0.1. this document is self-published independently.

i am still Figuring things out. this is not final design and might be vague, impossible, or otherwise not implementable. im still seeking to bring this closer to my vision.

This Specification Depends On

This Specification uses external references

WebAssembly

As a refresher here are some concepts you need to know.

Phases

Your Wasm package is called a game. Your Game has the following phases. in order of appearance

NameDescription
Loading Phase Here is where the Edge loads and verifies the ANT.zip. if it is marked as Untrusted the Edge MUST abort proceeding.
Initialization Phase Here is where you Initialize your game before it runs.
game Phase Here is where you let the player play. this is activated by calling start_game.

Internal Abstract Operation

It is assumed Imports and Exports are called to the invoking Wasm Module unless otherwise stated.

If any of the following Invariants are violated, that is a spec bug.

[[%StringFromBytes%]] (ptr: i32, len: i32): [[String]]

Do the following in order

  1. Go to ptr (inclusive) until (ptr + len) (exclusive) of the current Wasm Module's Linear Memory and take the raw bytes as $string.
  2. Assume: $string is the UTF-8 bytes of the intended string.
  3. If $path contains illegal UTF-8 characters return GENERIC_FAILURE (-1).
  4. Return $string.

[[%BytesFromString%]] (string: [[String]]): i32

Do the following in order

  1. Assert:: $string is encoded in UTF-8 bytes (is a MUST due to the Foundation's Global Rules).
  2. Set $length to the length of $string in UTF-8 bytes.
  3. If host_malloc is not exported return WASM_PORT_MISSING (-7).
  4. Set $pointer to the result of calling host_malloc with $length.
  5. Write the bytes of $string at $pointer (inclusive) until ($pointer + $length) (exclusive) in the current Wasm Module's Linear Memory.
  6. Return $pointer .

[[%LoadModule%]] (path: [[String]], Imports: [[ImportLibrary]])>: i32

Do the following in order

  1. If Game has Started Return GAME_IS_RUNNING_ERROR (-5).
  2. Resolve $path using ANT.zip's Application Behavior to be $resolved.
  3. If the above step fails return the appropriate Error Code.
  4. If $resolved is not a valid Wasm Module, Return RESOLUTION_ERROR (-3).
  5. Initialize and load $resolved as a Wasm Module with Imports as Imports.
  6. If Initializing and loading fails then return RESOLUTION_ERROR (-3).
  7. add 1 to the integer $wasmModulesLoaded.
  8. call $resolved's exported load_module if present with ($wasmModulesLoaded as ModuleId).
  9. Return $wasmModulesLoaded.

Basic Global Library

All Wasm Modules MUST expose or be exposed to the following functions

NameTypesImport/ExportDescription
host_malloc (bytes: i32): i32 Export host_malloc MUST return a positive number indicating a pointer ($pointer) on that Wasm's Linear Memory, $pointer until ($pointer + bytes) MUST be free for the Edge to store whatever is the Edge needs. If that fails or there isnt memory to allocate to the Edge, Return the appropriate Error Code.
on_module_load (ModuleId: i32): void Export called when the Wasm Module is loaded via load_module.

Main

A Main is a wasm file that is called after a Core. it is the main function.

If we are talking about User Generated Content games, A Core is the actual Game where A Main is the core for a sharable package a user has created.

A Main MUST expose or be exposed to the following functions

NameTypesImport/ExportDescription
load_module (ptr: i32, len: i32): i32 Import Do the following in order
  1. If Game has Started Return GAME_IS_RUNNING_ERROR (-5).
  2. Set $path to Calling [[%StringFromBytes%]] giving ptr and len.
  3. If $path starts with /core/ (case-insensitive), Return PATH_RESOLUTION_ERROR (-2).
  4. If $path is /core.wasm (case-insensitive), Return PATH_RESOLUTION_ERROR (-2).
  5. If $path is /main.wasm (case-insensitive), Return PATH_RESOLUTION_ERROR (-2).
  6. Return the result of Calling [[%LoadModule%]] given $path and (Basic Global Library as Imports).
start_game (): void Import Do the following in order
  1. Start the Game.

Cores

A Core is a wasm file that is first called. it is the engine so games can stay self-contained within their ANT.zip. the core MUST live at "/core.wasm" (case-sensitive) ziproot path.

If we are talking about User Generated Content games, A Core is the actual Game where A Main is the core for a sharable package a user has created.

A Core MUST expose or be exposed to the following functions

NameTypesImport/ExportDescription
load_module_core (ptr: i32, len: i32): i32 Import Do the following in order
  1. If Game has Started Return GAME_IS_RUNNING_ERROR (-5).
  2. Set $path to Calling [[%StringFromBytes%]] giving ptr and len.
  3. If $path is /core.wasm (case-insensitive), Return PATH_RESOLUTION_ERROR (-2).
  4. If $path does not start with /core/ (case-insensitive), Return PATH_RESOLUTION_ERROR (-2).
  5. Return the result of Calling [[%LoadModule%]] given $path and (Basic Global Library as Imports).
load_main (): void Import Do the following in order
  1. If Game has Started Return GAME_IS_RUNNING_ERROR (-5).
  2. Return the result of Calling [[%LoadModule%]] given "/main.wasm" and (Basic Global Library and Main as Imports).

Error Codes

the following table will list the error codes as negative numbers, their canonical upper snakecase name, and their description.

CodeUPPER_CASE_NAMEDescription
-1 (Negative One)GENERIC_FAILUREA Generic Failure.
-2 (Negative Two)PATH_RESOLUTION_ERRORA path cant be resolved due to any reason, including bt not limited to
-3 (Negative Three)RESOLUTION_ERRORA Path requiring a Wasm Module, but doesnt point to a valid compilable Wasm Module.
-4 (Negative Four)GAME_HASNT_STARTED_YET_ERRORthe start_game function hasnt been called by the Core when the function requires the game to be started.
-5 (Negative Five)GAME_IS_RUNNING_ERRORthe start_game function has been called by the Corewhen the function requires the game to be in the initialization phase (beforestart_game).
-6 (Negative Six)NO_MORE_MEMORY_ERRORThe Operation requires more memory but it cant be granted
-7 (Negative Seven)WASM_PORT_MISSINGAn Import or Export is missing