Skip to main content
Ton Decompiler is a powerful utility for analyzing and reverse-engineering smart contracts deployed on The Open Network (TON). It transforms compiled TVM bytecode (represented as a Cell) back into human-readable pseudocode resembling Func/Fift, greatly simplifying contract auditing, verification, and comprehension.

Features

  • Decompiles TVM bytecode into structured pseudocode
  • Supports complex constructs: dictionaries, global variables, built-in functions, hashes, signatures, and more
  • Recovers procedures and methods by their hashes (?fun_ref_xxx)
  • Integrates with @ton/core, @ton-community/func-js, and @scaleton/func-debug-symbols
  • End-to-end testing via Vitest with round-trip compilation/decompilation validation
  • Generates code hashes for verification (used in Tact contract tests)

Testing and verification

The tool is extensively tested against a wide range of contracts:
  • Tact contracts: Jetton, NFT, Vesting, Lottery, SkatePassport, and more
  • Func contracts: jetton-minter.fc, nft-collection.fc, wallet v3/v4, stdlib.fc, mathlib.fc
  • Supports contracts compiled via Func, Tact, and Fift
Each test validates:
  • Correctness of decompilation output
  • Re-compilability via Fift
  • Hash stability (exports[...] = "..." in test snapshots)

Architecture

Core modules

  • disasm — TVM instruction disassembler
  • AssemblyWriter — generates readable assembly with configurable options:
    • Instruction aliases (e.g., SWAP instead of s0 s1 XCHG)
    • Inline hex comments (e.g., // 0xD0)
    • Resolution of procedure and method names
  • utils/known-methods — registry of known method IDs and debug symbols
  • e2e/utils — utilities for compilation and result comparison

Supported TVM instructions

  • Arithmetic (DIVMOD, LSHIFT, MULRSHIFTR#, and more)
  • Dictionary operations (DICTGET, DICTSETB, DICTDEL, DICTUREMMIN, and more)
  • Stack manipulation (XCHG, PUXC, BLKSWAP)
  • Control flow (IFELSE, WHILE, CALLREF, INLINECALLDICT)
  • Cell and slice handling (CTOS, STREF, LDREF, STSLICECONST)

Installation and usage

npm install @tact-lang/ton-decompiler
# or clone the repository
git clone https://github.com/tact-lang/ton-decompiler.git

Example usage

import { Cell } from "@ton/core";
import { disassembleRoot } from "./decompiler/disasm";
import { AssemblyWriter } from "./printer/assembly-writer";

const cell: Cell = ...; // your TVM contract bytecode
const program = disassembleRoot(cell);
const writer = new AssemblyWriter();
const code = writer.write(program);
console.log(code);

For developers

  • Tests: Run with vitest; cover hundreds of real-world contracts
  • Specification generation: npm run gen-spec
  • Linting: eslint with modern rules
  • Compatibility: Integrates with @tact-lang/compiler and tact-template

License

This project is licensed under the MIT License — free to use, modify, and distribute.

Why use it?

  • Security auditing: Analyze third-party contracts without source code
  • Reverse engineering: Understand the logic of closed-source contracts
  • Education: Learn TVM internals and low-level TON contract behavior
  • IDE integration: Enable decompilation features in development tools
Note: Decompiled code may not exactly match the original source — variable names and high-level structure can differ — but semantic equivalence is preserved.
I