TVM (TON Virtual Machine)
The stack-based virtual machine that executes smart contracts on TON. Operates on cells and slices, charges gas per instruction, and is fundamentally different from Ethereum's EVM.
Aliases: ton vm, ton virtual machine
TVM — the TON Virtual Machine — is the runtime that executes every smart contract on the TON blockchain. Conceptually it sits in the same role as Ethereum’s EVM, but its design is markedly different.
Stack-based, not register-based
TVM is stack-based: instructions pop operands from a stack and push results back. There is no traditional addressable memory and no general-purpose registers. The machine maintains:
- a working stack for values,
- control registers (
c0–c5,c7) for special data — the current contract code, persistent storage, configuration, and so on, - a separate continuation stack for control flow.
That makes the TVM closer to Forth or Postscript than to a conventional CPU.
Cells and slices
Where the EVM operates on byte arrays in memory, the TVM works with cells — immutable nodes carrying up to 1023 bits of data and up to 4 references to other cells. To read a cell you turn it into a slice (a read cursor); to build one you use a builder (a write cursor). Persistent storage of every contract is itself a cell tree.
This forces a different style of contract design: data is never “in RAM”, it is always in cells, and traversing it costs gas.
Seven data types
The TVM understands a closed set of values:
- Integer (257-bit signed)
- Cell
- Slice
- Builder
- Tuple
- Continuation — a deferred piece of code, used for control flow
- Null
There are no strings, no maps, no arrays in the language sense. Higher-level structures (dictionaries, hashmaps) are encoded as cell trees and parsed by library code.
Gas
Every instruction has a gas cost. If a contract runs out of gas, execution aborts and the message is rolled back. Typical fees on basechain are fractions of a cent — a transfer costs roughly 0.005 TON in 2026.
Languages that target TVM
Source languages are compiled down through Fift (an assembly-like intermediate) into TVM bytecode:
- FunC — the original C-like DSL; now legacy as the official compiler is no longer maintained past v2025.07.
- Tact — a higher-level, statically typed language with a Solidity-like feel.
- Tolk — the new official language replacing FunC, with cleaner syntax and the same compilation pipeline.
Differences from EVM
- Asynchronous, not synchronous: contract calls are messages, not function calls. There is no
callthat returns a value within the same transaction. - No shared global state: every contract owns its own storage, and a “transfer” is two transactions on two contracts.
- Determinism is enforced by the cell model — no opcodes for clock, randomness, or external I/O.