Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Sec Web3 Ton?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/57blocks-sec-web3-ton-security-plugin)
---
name: "sec-web3-ton"
description: "Security checklist for TON smart contracts (FunC / Tact / Tolk). Triggers when writing or auditing *.fc, *.func, *.tact, *.tolk contracts or Blueprint wrappers: async messages and bounce rollback, sender/workchain checks, external message replay and accept_message, send modes 64/128/+2/+32, gas and storage fees, Jetton/NFT standards, cell parsing, randomness, set_code upgrades, message races."
---
# sec-web3-ton · TON contract security (FunC / Tact / Tolk)
## Scope
Smart contracts on the TON blockchain and their Blueprint test/wrapper code. Languages: **FunC** (`.fc`/`.func`), **Tact** (`.tact`), **Tolk** (`.tolk`); each item's code examples use the most common language for that case, and the concepts apply to all three.
## Read first
- **Read `sec-web3-common` first** ([../sec-web3-common/SKILL.md](../sec-web3-common/SKILL.md)): access control W3-01~06, precision W3-17~21, accounting W3-22~27, signatures W3-28~32, DoS W3-38~42, cross-chain/async messages W3-52~53. This pack covers only what is TON-specific.
- Severity follows [severity.md](../sec-core/severity.md); P0/P1 must include `file:line` + exploit path + impact.
- PoC template: [refs/poc-guide.md](refs/poc-guide.md)
## Attacker model and platform guarantees
**TON's core difference**: contracts can **only send each other asynchronous messages**. After A sends a message to B, A's transaction is finished and its state committed; B processes it in some later block (possibly on another shard). A business flow = a **message chain (trace)** spanning multiple contracts and blocks; there is no cross-contract atomicity on-chain and no automatic rollback.
**Assume the attacker controls**: the body of any internal message sent to the contract, the attached TON amount, the bounce flag (but **cannot forge** an internal message's `src`); arbitrary external messages (carry no funds; the contract pays the gas itself); deploying arbitrary contracts (including impostor jetton wallets and same-name jetton masters); inserting parallel message chains while yours is in progress; observing on-chain and pending messages and front-running.
**Already excluded by the platform — do not report**:
| Do not report | Why | But still check |
|---|---|---|
| Forged internal message sender | `src` is filled in by validators; `sender()` / `in.senderAddress` is trustworthy | "Who" the sender is: anyone can deploy a contract and send messages (TON-01, TON-02) |
| Silent integer overflow | TVM integers are 257-bit; arithmetic overflow throws exit 4; out-of-range `store_uint` throws exit 5 | Negative numbers not rejected (TON-25); FunC constant folding swallows exceptions (TON-26) |
| EVM-style synchronous reentrancy | No synchronous calls; message handling never nests | Async interleaving: two message chains executing alternately (TON-24) |
| Partial writes within one transaction | An exception in the compute phase discards c4/c5 changes | A throw after `commit()` does not roll back the committed part; partial execution across messages (TON-23) |
| Contract A reading contract B's getter | Synchronously reading others' state on-chain is **impossible**; get methods are for off-chain use only | Design uses message request/response and handles response latency and forgery (TON-12) |
| External message replay on standard wallets (v3/v4/v5, highload v3) | Wallet code has built-in seqno / expiry / subwallet ID checks | External message entry points **written by the project** (TON-05, TON-06) |
## Checklist
The 60 items live in `refs/items-*.md`, so a task reads only the part it needs. This index gives each item's ID, title and default level. Items are numbered in the order they were added, so related items can sit in different number ranges; use the file names below.
- Writing or changing code, or `sec-check`: read the files covering what the change touches.
- Full audit: sec-audit assigns item IDs to each perspective (see "Audit perspectives"); read only those items.
- Looking up one item: open the file named here and read from its `### TON-NN` heading to the next `###` heading.
**[refs/items-messages.md](refs/items-messages.md)**
- TON-01 Privileged operation does not verify sender · default P0
- TON-02 Forged Jetton `transfer_notification` · default P0
- TON-03 Unreliable source of the trusted jetton wallet address · default P1
- TON-04 Address workchain or format not verified · default P2
- TON-05 External messages lack replay protection · default P0
- TON-06 `accept_message` before validation · default P1
- TON-07 Signature not bound to recipient and key parameters · default P0
- TON-08 Bounced messages not handled, deducted state not rolled back · default P0
- TON-09 Bounce message parsed incorrectly or treated as a normal message · default P1
- TON-10 Wrong bounce flag choice · default P2
- TON-11 op routing defects: unknown ops silently accepted, text receiver conflicts · default P2
- TON-12 Using an async response as synchronous data · default P1
- TON-40 Generic executor reaches its own / child contracts' privileged entry points under its own identity · default P1
- TON-43 Bounce handler rolls back with relative arithmetic (`nonce -= 1`, `counter -= 1`) · default P1
- TON-46 One order's actions run in sequence: an early action changes the authority that later actions rely on · default P1
- TON-50 Response handlers are not idempotent: `query_id` used as authorization, no pending-operation record · default P1
- TON-57 Default, zero or "renounced" credentials still grant or block authority · default P1 (P0 when an unset or default credential makes the check pass for anyone; P2 when the only effect is a permanently disabled path)
- TON-60 Multi-leg pending contract keyed by a field the attacker can choose · default P1 (P0 when the attacker's leg can redirect the completed operation's output or take the victim's first leg)
**[refs/items-funds-gas.md](refs/items-funds-gas.md)**
- TON-13 Mode 128 (`SEND_MODE_CARRY_ALL_BALANCE` / `SendRemainingBalance`) can be abused · default P0
- TON-14 Wrong combination of mode 64 with multiple messages · default P1
- TON-15 `+2` (IGNORE_ERRORS) swallows send failures · default P1
- TON-16 Race and missing authentication in mode 128+32 self-destruct · default P0
- TON-17 Entry point does not verify that attached TON covers the whole message chain · default P1
- TON-18 Excess refund wrong or usable to drain the contract · default P1
- TON-19 No storage fee reserve: frozen after balance is emptied · default P1
- TON-20 Storage that users can grow without bound · default P1
- TON-21 User-controlled `forward_ton_amount` / forwarding parameters make the contract pay · default P2
- TON-22 Sending messages in a loop, exceeding the action limit · default P2
- TON-41 Balance sufficiency checked with `myBalance()` / `get_balance()`: already includes this message's attached TON · default P1
- TON-42 Child / escrow contract balance unrecoverable in non-success terminal states · default P2
- TON-45 Send-mode or reserve-mode flags combined with `+` instead of `|` (a flag added twice) · default P2 (P3 when no operand involves 128, 64 or `+32`; P1 when an actual overlap yields 128 or `+32` on a user path)
- TON-54 Extra currencies ignored, stuck or mishandled · default P3 (P1 when the contract accepts or custodies extra currencies)
**[refs/items-state-concurrency.md](refs/items-state-concurrency.md)**
- TON-23 Cross-contract flow without compensation/rollback design (partial execution) · default P0
- TON-24 Message race: check result stale by a later hop · default P1
- TON-25 Signed integers: negative amounts transfer in reverse · default P0
- TON-26 Division precision, divide-before-multiply and known FunC compiler issues · default P1
- TON-27 Cell parsing and serialization errors · default P2
- TON-28 Randomness predictable or manipulable by validators · default P1
- TON-29 Sensitive data on-chain · default P2
- TON-30 throw uses reserved exit codes · default P3
- TON-31 Function return values (success flags) ignored · default P2
- TON-32 Unbounded loops and uncatchable out-of-gas · default P1
- TON-44 Assets sent directly to the protocol's jetton wallet or master bypass the guards of a multi-step flow · default P2 (P1 when the direct path changes reserves, prices or credited balances)
- TON-55 Ordering or time-monotonicity assumptions the platform does not give · default P2 (P1 when it gates funds)
- TON-59 Handler that already holds the user's assets throws instead of refunding · default P1 (P2 when the throw needs input the official frontend cannot produce and an admin path can return stranded assets to their owners)
**[refs/items-tolk-func.md](refs/items-tolk-func.md)**
- TON-47 Tolk deserialization: `lazy` fields never validated, permissive `else` in `match`, relaxed `fromSlice` options · default P1 (P0 when the unvalidated field authorizes or prices a transfer)
- TON-48 Tolk typing pitfalls: `!` on nullable state, `any_address`, unchecked casts, narrowing writes · default P2 (P1 when it gates admin or funds)
- TON-49 FunC integer-as-boolean: `true` is `-1`, so flags stored as `1` break `~` and `&` · default P1
**[refs/items-wallets-jettons.md](refs/items-wallets-jettons.md)**
- TON-51 Merkle-proof claims (mintless jettons, compressed NFTs, airdrops) accept forged, replayed or misbound proofs · default P0
- TON-52 Wallet extensions, plugins and owner-signed internal requests (Wallet V5, WalletTg, gasless relays, custom smart accounts) · default P1 (P0 when an unregistered sender or a replayed request can move funds)
- TON-53 Integrating governed or non-standard jettons as if they were plain TEP-74 · default P1 (P2 when only the pool holding that jetton is affected and the issuer is trusted by design)
**[refs/items-upgrades-standards.md](refs/items-upgrades-standards.md)**
- TON-33 `set_code` / `set_data` upgrade without authentication, without delay, or with faulty migration · default P0
- TON-34 Jetton implementation defects · default P0
- TON-35 NFT / SBT implementation defects · default P1
- TON-36 Tact-specific pitfalls · default P1
- TON-37 FunC-specific pitfalls · default P0
- TON-38 Wrappers / frontend and off-chain integration · default P2
- TON-39 Executing third-party code and library cells · default P1
- TON-56 Masterchain contracts and elector interaction (nominator / staking pools, validator controllers) · default P1
- TON-58 Deployment and post-deploy initialisation: front-runnable `init`, re-init, wrong derived addresses · default P1 (P0 when the first initialiser gains custody of funds)
## Protocol pages
Implementation details per protocol type; chain-agnostic principles stay in the matching sec-web3-common page.
- [refs/proto-dex-jetton-vaults.md](refs/proto-dex-jetton-vaults.md)
- [refs/proto-liquid-staking.md](refs/proto-liquid-staking.md)
## PoC guide
See [refs/poc-guide.md](refs/poc-guide.md) for full templates. Key points:
1. Blueprint + `@ton/sandbox`: `Blockchain.create()` → `blockchain.treasury('attacker')` → `blockchain.openContract(...)`; run with `npx blueprint test`.
2. Assert the whole trace: `expect(res.transactions).toHaveTransaction({ from, to, op, success, exitCode, aborted })`; `printTransactionFees(res.transactions)` shows per-hop fees (TON-17).
3. Forged messages: send arbitrary ops directly from the attacker treasury to the target (TON-01/02/34), bypassing the normal jetton wallet.
4. Partial execution/races: control the attached value so hop N fails; use step-by-step processing (e.g. `sendMessageIter`) to interleave two message chains (TON-23/24).
5. External messages: `blockchain.sendMessage(external({ to, body }))` replays the same message twice (TON-05).
6. Assert the **impact**: contract and attacker balances (`getBalance()`), jetton balances, storage fields — not just `success`. P0/P1 reports attach the test name and `npx blueprint test <name>` output.
## Audit perspectives
Run the tools first: `misti --output-format json ...` for Tact, `acton check` for Tolk, TSA on compiled code when installed (see README), plus `npx blueprint test`; map detector names to items in this pack, then judge manually.
**Messages and senders** (TON-01~12, 40, 46, 50, 57, 60)
- For each contract, build an op table: op → allowed sender (owner / specific contract / computed child address / anyone) → bounceable or not → bounce handling.
- Do all "notification" messages (`transfer_notification`, `ownership_assigned`, `take_wallet_address`, custom callbacks) verify their source?
- External message entry points: validation before accept, seqno/valid_until/contract ID, signature coverage; are signed vouchers bound to the claim address (TON-07)?
- Every `sender == this contract / parent` branch: can the contract's own generic execution capability (arbitrary send_message actions) reach it (TON-40)? Developer comments like "only trusts itself / no security issue" are hypotheses to falsify, not reasons to dismiss.
**Funds and gas** (TON-13~22, 41~42, 45, 54)
- List of messages each handler sends: mode, value, bounce, destination; verify `final_value` using the algorithm in modes.mdx.
- Minimum attached value at the entry point vs measured fees of the whole trace; where excess goes; `raw_reserve` and storage fee reserve; whether `myBalance()` includes the inbound value (TON-41).
- Can the balance of each child / escrow contract be recovered in every terminal state (success, expired, voided, bounced) (TON-42)?
- Can users make the contract pay for them (forward_ton_amount, huge payloads, sending in loops)?
**State and concurrency** (TON-23~32, 44, 55, 59)
- Draw the full trace of each business flow, mark the "state committed" point of each hop, and ask for each hop what failure and concurrent insertion would cause.
- Amount types (coins/uint vs int), division and rounding, cell reads and writes consistent in pairs, randomness source.
**Upgrades, languages and standard implementations** (TON-33~39, 47~49, 51~53, 56, 58)
- Upgrade entry authentication, delay, data migration, code source; admin wallet type (multisig?).
- Jetton/NFT: diff against TEP-74/62/89 reference implementations, and check the sender verification and bounce rollback of each modified handler.
- Tact/FunC language pitfalls (TON-36/37); wrappers and off-chain crediting (TON-38).
**Lens 6, message flow and bounce state machine** ([method-message-flow.md](refs/method-message-flow.md)). Runs as its own sub-agent next to the four perspectives above: per-contract op tables, per-flow trace tables (bounce, fee loss, duplicate, reorder, direct entry) and the pending-operation state machine. Items: TON-01, 02, 08~11, 13~19, 21~24, 40~45, 50, 55, 59, 60, plus W3-114 (reviewed by the lens only).
Tools run per [method-tools.md](refs/method-tools.md) (misti for Tact, `acton check` for Tolk, TSA only for P0/P1 claims). After the perspectives return and before Step 4, run [method-sandbox-properties.md](refs/method-sandbox-properties.md) on the value-moving flows (at most 30 minutes).
## Further reading
- TON security best practices: https://docs.ton.org/contracts/techniques/security
- Send modes: https://docs.ton.org/foundations/messages/modes
- On-chain Jetton processing: https://docs.ton.org/contracts/techniques/on-chain-jetton-processing
- Gas estimation: https://docs.ton.org/contracts/techniques/gas
- Contract upgrades: https://docs.ton.org/contracts/techniques/upgrades
- TEPs (74 Jetton, 62 NFT, 85 SBT, 89 Wallet discovery): https://github.com/ton-blockchain/TEPs
- Misti docs and detector list: https://nowarp.io/tools/misti/docs
- Tact security best practices: https://docs.tact-lang.org/book/security-best-practices/
- SlowMist TON security best practices (link only): https://github.com/slowmist/Toncoin-Smart-Contract-Security-Best-Practices
- ton-community/ton-docs (GPL-3.0, archived, link only): https://github.com/ton-community/ton-docs
- TonBit blog: https://www.tonbit.xyz/ ; Zellic blog: https://www.zellic.io/blog ; OtterSec blog: https://osec.io/blog