Programs and the VM
A program on Ting, called a contract, is immutable WebAssembly code plus the records it stores. A deployment installs it, and it runs whenever a transaction or another contract calls it. Every node runs every program and must reach exactly the same result and the same resource counters, so Ting's VM is defined more tightly than an ordinary WebAssembly engine: which modules it accepts, what each instruction does, what each step costs and what a failure undoes are all fixed in advance. The exact rules are in sections 16 to 24 of the protocol rules.
What sets the VM apart:
- It accepts a precise integer subset of WebAssembly, which ordinary compilers can target, and rejects everything else at deployment.
- Every instruction has one meaning and a measured price, and every charge is made at a fixed point, so every node runs out of budget at the same instruction.
- Every invocation starts from scratch, with fresh memory and fresh globals. Anything that should last goes into storage through the host interface.
- Programs cannot reach a filesystem, a network, a clock or a source of randomness. Given the same state and input, a program does the same thing on every node.
- The whole machine, from the bytes of a module to the last counter of a receipt, is Ting's own code, so no outside engine decides what is accepted or what it costs.
The pages#
- What a module may contain: the accepted subset, the module's shape, its one encoding and how it is validated.
- Instruction reference: the 115 instructions and what each does.
- How a program runs: values, the stack, branches, instances and how an invocation ends.
- Deploy and invoke: the steps of installing code and of every run, with their charges.
- The host interface: the twelve functions a program uses to talk to the chain.
- Calls, rollback and read-only: nested invocations and what a failure undoes.
- Exact metering: when each charge is made, and why the order matters.
In this section
What a module may containThe integer WebAssembly subset, its one encoding and how a module is validated.Instruction referenceAll 115 accepted instructions with their encodings and what each does.How a program runsValues, the stack, labels, instances, host calls and how an invocation ends.Deploy and invokeWhat happens when code is installed and each time it runs.The host interfaceThe twelve imports a program uses to talk to the chain.Calls, rollback and read-onlyNested invocations, checkpoints and inherited restrictions.Exact meteringHow every instruction is counted the same way on every node.