TON ZK Contract Integration
Overview
A verifier proves one relation under one VK; the application binds it to authenticated TON context, current state, and one authorized transition.
Operating Rules
- Use
$groth16-systems for general application binding; this skill adds TON execution and encodings.
- The bundled validator requires Python 3.10+; builds and tests use the target repository's pinned TON toolchain.
- Separate verifier validity, authorization, and state transition.
- Validate the example and schema. The helper separates consistency and artifact identity; it does not verify the circuit or implementation.
- Bind security values through public inputs or authenticated message/state sources; body-supplied addresses are not authentication.
- Bind runtime
global_id, workchain, current address, action, circuit/VK, protocol, and version.
- Persist and atomically consume a nullifier, nonce, seqno, or one-shot marker.
- Reject wrong proof widths, trailing bits/bytes, and refs before TVM BLS operations.
- A getter is read-only; reverify and enforce policy in the state-changing transaction.
- Prefer value-carrying internal messages; never accept an external message unconditionally.
Workflow
- Record proof fields, exact layout, public-input representation, message kind/opcode, wrapper, and value rule.
- Add TON profiles and authenticated sources. Define nonce/seqno bits and range.
- Bind runtime
global_id, workchain, current address, opcode, and TON state.
- Design storage for replay state, roots, VK/version authority, pending operations, and reserves.
- For internal messages: parse, authenticate, range-check, verify, check semantics/state, then atomically consume the application nullifier and transition.
- For signed external messages, authenticate and check envelope replay before
ACCEPT; persist and COMMIT it before expensive ZK work. Consume the application nullifier only with success.
- Define acceptance, payer/value, bounce, duplicates, callbacks, reserves, and in-flight behavior.
- Decode golden wrapper BoCs and compare the complete graph and representation hash with the contract layout.
- Run:
python3 <skills-root>/ton-zk-contract-integration/scripts/validate_proof_context.py \
./proof-context.json --project-root .
Then use $ton-zk-testing for getter, message, state, replay, acceptance, balance, and bounce assertions.
References: architecture, public inputs, executable TON encoding vectors, encoding, replay/domain, and external messages.
Quick Reference
| Layer |
Required invariant |
| Circuit |
Intended relation and context are exposed |
| Verifier |
Fixed VK, canonical inputs, valid proof |
| Policy |
Inputs match authenticated request/current state |
| Replay |
Fresh marker becomes consumed |
| Application |
Exactly one atomic state change |
| Messaging |
Lengths/refs, acceptance, value, bounce, duplicates, and reserves are safe |
Common Mistakes
- Checking proof validity but not application semantics.
- Relying on wrapper-only
queryId for replay protection.
- Reducing an external value modulo the field before business interpretation.
- Trusting an address supplied only in the body.
- Splitting verification and execution without robust correlation state.
- Letting BLS parsing ignore a tail used elsewhere.
- Accepting an external message before cheap authentication/replay checks.
- Treating get-method output as consensus authorization.
Completion Gate
Report manifest, input map, authenticated sources, runtime domain, replay key, message layout, external acceptance/payer, getter role, atomic transition, bounce/value policy, wrapper/BoC fixture, and end-to-end tests. Every application input needs one unambiguous check.
1---2name: ton-zk-contract-integration3description: Use when integrating a TON ZK verifier, proof/public-input cells or BoCs, wrappers, internal/external messages, global_id/state binding, authorization, or nonce/nullifier replay protection.4license: Apache-2.05---67# TON ZK Contract Integration89## Overview1011A verifier proves one relation under one VK; the application binds it to authenticated TON context, current state, and one authorized transition.1213## Operating Rules1415- Use `$groth16-systems` for general application binding; this skill adds TON execution and encodings.16- The bundled validator requires Python 3.10+; builds and tests use the target repository's pinned TON toolchain.17- Separate verifier validity, authorization, and state transition.18- Validate the [example](assets/proof-context.example.json) and [schema](assets/proof-context.schema.json). The helper separates consistency and artifact identity; it does not verify the circuit or implementation.19- Bind security values through public inputs or authenticated message/state sources; body-supplied addresses are not authentication.20- Bind runtime `global_id`, workchain, current address, action, circuit/VK, protocol, and version.21- Persist and atomically consume a nullifier, nonce, seqno, or one-shot marker.22- Reject wrong proof widths, trailing bits/bytes, and refs before TVM BLS operations.23- A getter is read-only; reverify and enforce policy in the state-changing transaction.24- Prefer value-carrying internal messages; never accept an external message unconditionally.2526## Workflow27281. Record proof fields, exact layout, public-input representation, message kind/opcode, wrapper, and value rule.292. Add TON profiles and authenticated sources. Define nonce/seqno bits and range.303. Bind runtime `global_id`, workchain, current address, opcode, and TON state.314. Design storage for replay state, roots, VK/version authority, pending operations, and reserves.325. For internal messages: parse, authenticate, range-check, verify, check semantics/state, then atomically consume the application nullifier and transition.336. For signed external messages, authenticate and check envelope replay before `ACCEPT`; persist and `COMMIT` it before expensive ZK work. Consume the application nullifier only with success.347. Define acceptance, payer/value, bounce, duplicates, callbacks, reserves, and in-flight behavior.358. Decode golden wrapper BoCs and compare the complete graph and representation hash with the contract layout.369. Run:3738```bash39python3 <skills-root>/ton-zk-contract-integration/scripts/validate_proof_context.py \40 ./proof-context.json --project-root .41```4243Then use `$ton-zk-testing` for getter, message, state, replay, acceptance, balance, and bounce assertions.4445References: [architecture](references/architecture-patterns.md), [public inputs](references/public-input-semantics.md), executable [TON encoding vectors](assets/ton-encoding-vectors.json), [encoding](references/message-encoding.md), [replay/domain](references/replay-and-domain-separation.md), and [external messages](references/external-messages.md).4647## Quick Reference4849| Layer | Required invariant |50|---|---|51| Circuit | Intended relation and context are exposed |52| Verifier | Fixed VK, canonical inputs, valid proof |53| Policy | Inputs match authenticated request/current state |54| Replay | Fresh marker becomes consumed |55| Application | Exactly one atomic state change |56| Messaging | Lengths/refs, acceptance, value, bounce, duplicates, and reserves are safe |5758## Common Mistakes5960- Checking proof validity but not application semantics.61- Relying on wrapper-only `queryId` for replay protection.62- Reducing an external value modulo the field before business interpretation.63- Trusting an address supplied only in the body.64- Splitting verification and execution without robust correlation state.65- Letting BLS parsing ignore a tail used elsewhere.66- Accepting an external message before cheap authentication/replay checks.67- Treating get-method output as consensus authorization.6869## Completion Gate7071Report manifest, input map, authenticated sources, runtime domain, replay key, message layout, external acceptance/payer, getter role, atomic transition, bounce/value policy, wrapper/BoC fixture, and end-to-end tests. Every application input needs one unambiguous check.