TON Graph
A Visual Studio Code extension for visualizing function call graphs in TON smart contracts written in FunC, Tact, and Tolk.
Developed by PositiveWeb3 security researchers.
Features
- Parse and visualize function call relationships in multiple contract types:
- FunC (*.fc, *.func)
- Tact (*.tact)
- Tolk (*.tolk)
- Interactive diagram with cluster-based organization
- Zoom functionality for better navigation
- Filter functions by type (regular, impure, inline, method_id)
- Filter functions by name
- Export diagrams in multiple formats:
- Mermaid (*.mmd)
- SVG
- PNG
- JPG
- Automatic color coding of different function clusters
- Optimized performance with Mermaid library caching
Installation
- Open Visual Studio Code
- Go to Extensions view (Ctrl+Shift+X)
- Search for "TON Graph"
- Click Install
Usage
- Open a contract file (*.fc, *.func, *.tact, or *.tolk)
- You can visualize a contract in multiple ways:
- Press F1 or Ctrl+Shift+P to open the command palette and type "TON Graph: Visualize Contract"
- Right-click on contract code in the editor → TON Graph: Visualize Contract
- Right-click on a contract file in the Explorer panel → TON Graph: Visualize Contract
- The extension will analyze your contract and display a function call graph
Visualizing Projects with Imports
You can also visualize an entire contract including all imports:
- Open a main contract file (*.fc, *.func, *.tact, or *.tolk)
- Visualize the project in one of these ways:
- Press F1 or Ctrl+Shift+P and type "TON Graph: Visualize Contract with Imports"
- Right-click on contract code in the editor → TON Graph: Visualize Contract with Imports
- Right-click on a contract file in the Explorer panel → TON Graph: Visualize Contract with Imports
- The extension will analyze the main contract and all its imports, displaying a complete function call graph
Interactive Features
The visualization provides several interactive features:
- Zoom in/out for better detail view
- Pan and navigate through the diagram
- Filter functions by type
- Filter functions by name using the search bar
Exporting
You can export the diagram in multiple formats:
- Mermaid: Save as a Mermaid markdown file (*.mmd)
- SVG: Vector graphics format for high-quality scaling
- PNG: Raster image format for general use
- JPG: Compressed image format for sharing
How It Works
The extension analyzes your contract code to:
- Identify all function declarations and their types
- Detect function calls between these functions
- Create a directed graph of function relationships
- Generate a visual representation using Mermaid diagrams
- Group related functions into clusters for better readability
- Multiple contracts support (for Tact)
Development
Project Structure
ton-graph/
├── src/
│ ├── extension.ts # Extension entry point
│ ├── parser/ # Contract code parsing
│ │ ├── funcParser.ts # FunC parser
│ │ ├── tactParser.ts # Tact parser
│ │ ├── tolkParser.ts # Tolk parser
│ │ └── parserUtils.ts # Shared parser utilities
│ ├── types/ # Type definitions
│ │ └── graph.ts # Graph data structures
│ ├── visualization/ # Visualization components
│ │ ├── visualizer.ts # Diagram generation
│ │ └── templates.ts # HTML templates
│ └── export/ # Export functionality
│ └── exportHandler.ts # Export handlers
├── out/ # Compiled output
└── cached/ # Cache directory for Mermaid library
Building From Source
# Clone the repository
git clone https://github.com/PositiveSecurity/ton-graph
# Install dependencies
npm install
# Compile the extension
npm run compile
# Package the extension (creates a .vsix file)
chmod +x rebuild.sh && ./rebuild.sh
Requirements
- Visual Studio Code 1.60.0 or newer
Known Issues
- Large contracts with many functions may take longer to process
- Very complex call graphs may become cluttered - use filters to simplify the view
Feedback and Contributions
We welcome your feedback and contributions to improve this extension!
- File issues and suggestions on GitHub
- Fork the repository and submit pull requests
License
MIT