ton-vulnerability-scanner
A security auditor for FunC smart contracts on the TON blockchain, focusing on token and gas management vulnerabilities.
Install
mkdir -p .claude/skills/ton-vulnerability-scanner && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2335" && unzip -o skill.zip -d .claude/skills/ton-vulnerability-scanner && rm skill.zipInstalls to .claude/skills/ton-vulnerability-scanner
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Scans TON (The Open Network) smart contracts for 3 critical vulnerabilities including integer-as-boolean misuse, fake Jetton contracts, and forward TON without gas checks. Use when auditing FunC contracts.Key capabilities
- →Detect integer-as-boolean misuse in FunC
- →Identify fake Jetton token implementation risks
- →Scan for missing gas checks in forwarded TON transfers
- →Generate remediation suggestions for vulnerability patterns
- →Validate internal message handler logic
How it works
Parses FunC source files to identify and alert on specific anti-patterns known to cause security issues on the TON blockchain.
Inputs & outputs
When to use ton-vulnerability-scanner
- →Auditing TON smart contracts
- →Reviewing Jetton token implementations
- →Validating token transfer notifications
- →Pre-launch security assessments
About this skill
TON Vulnerability Scanner
1. Purpose
Systematically scan TON blockchain smart contracts written in FunC for platform-specific security vulnerabilities related to boolean logic, Jetton token handling, and gas management. This skill encodes 3 critical vulnerability patterns unique to TON's architecture.
2. When to Use This Skill
- Auditing TON smart contracts (FunC language)
- Reviewing Jetton token implementations
- Validating token transfer notification handlers
- Pre-launch security assessment of TON dApps
- Reviewing gas forwarding logic
- Assessing boolean condition handling
3. Platform Detection
File Extensions & Indicators
- FunC files:
.fc,.func
Language/Framework Markers
;; FunC contract indicators
#include "imports/stdlib.fc";
() recv_internal(int my_balance, int msg_value, cell in_msg_full, slice in_msg_body) impure {
;; Contract logic
}
() recv_external(slice in_msg) impure {
;; External message handler
}
;; Common patterns
send_raw_message()
load_uint(), load_msg_addr(), load_coins()
begin_cell(), end_cell(), store_*()
transfer_notification operation
op::transfer, op::transfer_notification
.store_uint().store_slice().store_coins()
Project Structure
contracts/*.fc- FunC contract sourcewrappers/*.ts- TypeScript wrapperstests/*.spec.ts- Contract testston.config.tsorwasm.config.ts- TON project config
Tool Support
- TON Blueprint: Development framework for TON
- toncli: CLI tool for TON contracts
- ton-compiler: FunC compiler
- Manual review primarily (limited automated tools)
4. How This Skill Works
When invoked, I will:
- Search your codebase for FunC/Tact contracts
- Analyze each contract for the 3 vulnerability patterns
- Report findings with file references and severity, above them a coverage table carrying a verdict for every pattern
- Provide fixes for each identified issue
- Emit the coverage table — all 3 patterns, each with a verdict
5. Example Output
When vulnerabilities are found, you'll get a report like this:
=== TON VULNERABILITY SCAN RESULTS ===
Project: my-ton-contract
Files Scanned: 3 (.fc, .tact)
Vulnerabilities Found: 2
Coverage: 3/3 patterns reported
1 Integer as Boolean .............. found contracts/wallet.fc:45
2 Fake Jetton Contract ............ found contracts/staking.fc:85
3 Forward TON Without Gas Check ... clear forward amounts fixed at 0.05 TON
---
[CRITICAL] Fake Jetton Contract - Missing Sender Validation
File: contracts/staking.fc:85
Pattern: transfer_notification sender not checked against the stored Jetton wallet
6. Vulnerability Patterns (3 Patterns)
I check for 3 critical vulnerability patterns unique to TON. For detailed detection patterns, code examples, mitigations, and testing strategies, see VULNERABILITY_PATTERNS.md.
Pattern Summary:
- Integer as Boolean ⚠️ HIGH - Positive integers used as true; FunC's true is -1
- Fake Jetton Contract ⚠️ CRITICAL -
transfer_notificationsender not validated - Forward TON Without Gas Check ⚠️ HIGH - Forwarding without reserving gas for the rest of execution
For complete vulnerability patterns with code examples, see VULNERABILITY_PATTERNS.md.
7. Scanning Workflow
Step 1: Platform Identification
- Verify FunC language (
.fcor.funcfiles) - Check for TON Blueprint or toncli project structure
- Locate contract source files
- Identify Jetton-related contracts
Step 2: Boolean Logic Review
# Find boolean-like variables
rg "int.*is_|int.*has_|int.*flag|int.*enabled" contracts/
# Check for positive integers used as booleans
rg "= 1;|return 1;" contracts/ | grep -E "is_|has_|flag|enabled|valid"
# Look for NOT operations on boolean-like values
rg "~.*\(|~ " contracts/
For each boolean:
- Uses -1 for true, 0 for false
- NOT using 1 or other positive integers
- Logic operations work correctly
Step 3: Jetton Handler Analysis
# Find transfer_notification handlers
rg "transfer_notification|op::transfer_notification" contracts/
For each Jetton handler:
- Validates sender address
- Sender checked against stored Jetton wallet address
- Cannot trust forward_payload without sender validation
- Has admin function to set Jetton wallet address
Step 4: Gas/Forward Amount Review
# Find forward amount usage
rg "forward_ton_amount|forward_amount" contracts/
rg "load_coins\(\)" contracts/
# Find send_raw_message calls
rg "send_raw_message" contracts/
For each outgoing message:
- Forward amounts are fixed/bounded
- OR user-provided amounts validated against msg_value
- Cannot drain contract balance
- Appropriate send_raw_message flags used
Step 5: Manual Review
TON contracts require thorough manual review:
- Boolean logic with
~,&,|operators - Message parsing and validation
- Gas economics and fee calculations
- Storage operations and data serialization
8. Reporting Format
Coverage Table
Report on every pattern in §6, whether or not it turned anything up. Emit this table above the findings, with all 3 rows present:
| # | Pattern | Verdict | Evidence |
|---|---|---|---|
| 1 | Integer as Boolean | clear | searched is_/has_/flag; all set to -1 |
| 2 | Fake Jetton Contract | ||
| 3 | Forward TON Without Gas Check |
Each verdict is one of:
found— citefile:lineand write the finding up in full below.clear— the pattern applies to this contract and the contract handles it. Name the function, stored address, or check you searched for, so a reader can repeat the search.n/a— the pattern cannot apply here. Give the reason in one clause ("this contract handles no Jetton transfer notifications"). Not having looked is notn/a.
Three patterns is a short list, which makes an incomplete table harder to excuse rather than easier: a report
covering one pattern and silent on the other two reads exactly like a clean contract. Emit all three rows even
when all three are clear. A row whose Verdict cell is empty is incomplete in the same way: row 1 above is filled in to show the shape, and every row is filled in the same way before the report is done.
Finding Template
## [CRITICAL] Fake Jetton Contract - Missing Sender Validation
**Location**: `contracts/staking.fc:85-95` (recv_internal, transfer_notification handler)
**Description**:
The `transfer_notification` operation handler does not validate that the sender is the expected Jetton wallet contract. Any attacker can send a fake `transfer_notification` message claiming to have transferred tokens, crediting themselves without actually depositing any Jettons.
**Vulnerable Code**:
```func
// staking.fc, line 85
if (op == op::transfer_notification) {
int jetton_amount = in_msg_body~load_coins();
slice from_user = in_msg_body~load_msg_addr();
;; WRONG: No validation of sender_address!
;; Attacker can claim any jetton_amount
credit_user(from_user, jetton_amount);
}
```
**Attack Scenario**:
1. Attacker deploys malicious contract
2. Malicious contract sends `transfer_notification` message to staking contract
3. Message claims attacker transferred 1,000,000 Jettons
4. Staking contract credits attacker without checking sender
5. Attacker can now withdraw from contract or gain benefits without depositing
**Proof of Concept**:
```typescript
// Attacker sends fake transfer_notification
const attackerContract = await blockchain.treasury("attacker");
await stakingContract.sendInternalMessage(attackerContract.getSender(), {
op: OP_CODES.TRANSFER_NOTIFICATION,
jettonAmount: toNano("1000000"), // Fake amount
fromUser: attackerContract.address,
});
// Attacker successfully credited without sending real Jettons
const balance = await stakingContract.getUserBalance(attackerContract.address);
expect(balance).toEqual(toNano("1000000")); // Attack succeeded
```
**Recommendation**:
Store expected Jetton wallet address and validate sender:
```func
global slice jetton_wallet_address;
() recv_internal(...) impure {
load_data(); ;; Load jetton_wallet_address from storage
slice cs = in_msg_full.begin_parse();
int flags = cs~load_uint(4);
slice sender_address = cs~load_msg_addr();
int op = in_msg_body~load_uint(32);
if (op == op::transfer_notification) {
;; CRITICAL: Validate sender
throw_unless(error::wrong_jetton_wallet,
equal_slices(sender_address, jetton_wallet_address));
int jetton_amount = in_msg_body~load_coins();
slice from_user = in_msg_body~load_msg_addr();
;; Safe to credit user
credit_user(from_user, jetton_amount);
}
}
```
**References**:
- building-secure-contracts/not-so-smart-contracts/ton/fake_jetton_contract
9. Priority Guidelines
Critical (Immediate Fix Required)
- Fake Jetton contract (unauthorized minting/crediting)
High (Fix Before Launch)
- Integer as boolean (logic errors, broken conditions)
- Forward TON without gas check (balance drainage)
10. Testing Recommendations
Unit Tests
import { Blockchain } from "@ton/sandbox";
import { toNano } from "ton-core";
describe("Security tests", () => {
let blockchain: Blockchain;
let contract: Contract;
beforeEach(async () => {
blockchain = await Blockchain.create();
contract = blockchain.openContract(await Contract.fromInit());
});
it("should use correct boolean values", async () => {
// Test that TRUE = -1, FALSE = 0
const result = await contract.getFlag();
expect(result).toEqual(-1n); // True
expect(result).not.toEqual(1n); // Not 1!
});
it("should reject fake jetton transfer", async () => {
const attacker = await blockchain.treasury("attacker");
---
*Content truncated.*
When not to use it
- →Auditing non-TON smart contracts
- →Static analysis of high-level languages like TypeScript
- →Replacement for manual security review
Prerequisites
Limitations
- →Limited to 3 specific vulnerability patterns
- →No replacement for expert manual audits
- →Only supports FunC language
How it compares
Automates scanning for specific, domain-aware TON vulnerabilities rather than generic syntax analysis.
Compared to similar skills
ton-vulnerability-scanner side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| ton-vulnerability-scanner (this skill) | 4 | 3mo | Review | Advanced |
| solidity-security | 15 | 3mo | No flags | Intermediate |
| supabase-rls-policy-generator | 11 | 10mo | No flags | Advanced |
| backend-security-coder | 24 | 5mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by trailofbits
View all by trailofbits →You might also like
solidity-security
wshobson
Master smart contract security best practices to prevent common vulnerabilities and implement secure Solidity patterns. Use when writing smart contracts, auditing existing contracts, or implementing security measures for blockchain applications.
supabase-rls-policy-generator
hopeoverture
This skill should be used when the user requests to generate, create, or add Row-Level Security (RLS) policies for Supabase databases in multi-tenant or role-based applications. It generates comprehensive RLS policies using auth.uid(), auth.jwt() claims, and role-based access patterns. Trigger terms include RLS, row level security, supabase security, generate policies, auth policies, multi-tenant security, role-based access, database security policies, supabase permissions, tenant isolation.
backend-security-coder
sickn33
Expert in secure backend coding practices specializing in input validation, authentication, and API security. Use PROACTIVELY for backend security implementations or security code reviews.
sqlmap-database-penetration-testing
davila7
This skill should be used when the user asks to "automate SQL injection testing," "enumerate database structure," "extract database credentials using sqlmap," "dump tables and columns from a vulnerable database," or "perform automated database penetration testing." It provides comprehensive guidance for using SQLMap to detect and exploit SQL injection vulnerabilities.
agent-security-manager
ruvnet
Agent skill for security-manager - invoke with $agent-security-manager
secure-workflow-guide
trailofbits
Guides through Trail of Bits' 5-step secure development workflow. Runs Slither scans, checks special features (upgradeability/ERC conformance/token integration), generates visual security diagrams, helps document security properties for fuzzing/verification, and reviews manual security areas.