TON ZK Testing
Overview
Test proof, verifier, policy, and TON transition separately, then together. A valid proof must work only for its exact VK, inputs, context, message, and state.
Operating Rules
- Use
$groth16-systems for the generic proof, public-input, artifact-mismatch, canonical-field, point-validation, and application-binding negative matrix; add the TON cases below.
- Start from one locally verified valid fixture.
- Change one dimension per negative test.
- Test both getter and state-changing internal message; assert transactions, exit codes, storage, replay state, and outgoing actions.
- Include scalar boundaries, exact BLS lengths, trailing-byte/ref cases, and malformed encodings, not only
+1 mutations.
- Record and review gas/code-size snapshots; never auto-accept regressions.
- Never log private witness, entropy, keys, or production proving material.
- Use the repository-pinned test binaries; do not let
npx install missing tools as an incidental test step.
- Inspect package engines, lockfiles, Acton/Blueprint help, and Sandbox versions before changing Node.js or test dependencies.
Workflow
- Record circuit/VK/generator hashes, versions, lockfile, target, and commands.
- Prove/verify locally; encode through supported helpers; assert getter success and exact state transition.
- Reuse the generic negative baseline, then exercise TON dictionary/list flattening, wrapper/cell/BoC encoding, and runtime domain mapping.
- Compare wrapper/cell/BoC encoding with an independent decoder/encoder and assert canonical decode/re-encode parity.
- For each BLS component, send the same valid 48/96-byte prefix with different tails; reject both before the TVM BLS opcode.
- Test low value, unknown opcode, malformed cell, bounce, duplicates, large payload, reserves, and failed actions. For external receivers, assert acceptance, payer, repeated-invalid balance delta, and pre-accept auth/replay.
- Save verify gas and code size in bits/cells; gate unexpected deltas.
- Run the full repository suite and report exact results.
Use the test matrix, Blueprint/Sandbox, negative fixture design, executable fixture catalog, upgrade matrix, and gas/code size.
Quick Reference
| Layer |
Positive |
Negative |
| Prover |
Local verify true |
Wrong witness/input/VK false |
| Verifier |
Valid getter/message |
Tampered/malformed reject |
| Policy |
Exact context accepted |
Every changed field rejects |
| Replay |
First use succeeds |
Second use fails with no partial state |
| TON |
Expected transaction/state/actions |
Exact lengths, low value, acceptance, balance, bounce, duplicate safe |
| Performance |
Snapshot recorded |
Unreviewed regression fails gate |
npx --no-install blueprint build --all
npx --no-install blueprint test
npx --no-install jest --runInBand
Common Mistakes
- One happy path is treated as evidence for every layer.
- A negative case changes proof and public inputs together, hiding the intended mismatch.
- Field boundaries, exact BLS slice lengths, public-input reordering, runtime domain, and replay storage are untested.
- Tests assert transaction success but not state delta and outgoing messages.
- Huge
.ptau, .zkey, witness, or secret fixtures are checked in without need/provenance.
Completion Gate
Report fresh commands, fixture provenance, local/getter/message results, acceptance/balance/state assertions, negative coverage, counts, gas, code size, snapshot deltas, and blockers. No “tests pass” claim without fresh output.
1---2name: ton-zk-testing3description: Use when testing TON zero-knowledge verifier contracts or integrations, including tampered proofs, malformed encodings, getters/messages, replay/state, gas, code size, or regression gates.4license: Apache-2.05---67# TON ZK Testing89## Overview1011Test proof, verifier, policy, and TON transition separately, then together. A valid proof must work only for its exact VK, inputs, context, message, and state.1213## Operating Rules1415- Use `$groth16-systems` for the generic proof, public-input, artifact-mismatch, canonical-field, point-validation, and application-binding negative matrix; add the TON cases below.16- Start from one locally verified valid fixture.17- Change one dimension per negative test.18- Test both getter and state-changing internal message; assert transactions, exit codes, storage, replay state, and outgoing actions.19- Include scalar boundaries, exact BLS lengths, trailing-byte/ref cases, and malformed encodings, not only `+1` mutations.20- Record and review gas/code-size snapshots; never auto-accept regressions.21- Never log private witness, entropy, keys, or production proving material.22- Use the repository-pinned test binaries; do not let `npx` install missing tools as an incidental test step.23- Inspect package engines, lockfiles, Acton/Blueprint help, and Sandbox versions before changing Node.js or test dependencies.2425## Workflow26271. Record circuit/VK/generator hashes, versions, lockfile, target, and commands.282. Prove/verify locally; encode through supported helpers; assert getter success and exact state transition.293. Reuse the generic negative baseline, then exercise TON dictionary/list flattening, wrapper/cell/BoC encoding, and runtime domain mapping.304. Compare wrapper/cell/BoC encoding with an independent decoder/encoder and assert canonical decode/re-encode parity.315. For each BLS component, send the same valid 48/96-byte prefix with different tails; reject both before the TVM BLS opcode.326. Test low value, unknown opcode, malformed cell, bounce, duplicates, large payload, reserves, and failed actions. For external receivers, assert acceptance, payer, repeated-invalid balance delta, and pre-accept auth/replay.337. Save verify gas and code size in bits/cells; gate unexpected deltas.348. Run the full repository suite and report exact results.3536Use the [test matrix](references/test-matrix.md), [Blueprint/Sandbox](references/blueprint-and-sandbox.md), [negative fixture design](references/negative-fixtures.md), executable [fixture catalog](assets/negative-fixtures.json), [upgrade matrix](references/upgrade-matrix.md), and [gas/code size](references/gas-and-code-size.md).3738## Quick Reference3940| Layer | Positive | Negative |41|---|---|---|42| Prover | Local verify true | Wrong witness/input/VK false |43| Verifier | Valid getter/message | Tampered/malformed reject |44| Policy | Exact context accepted | Every changed field rejects |45| Replay | First use succeeds | Second use fails with no partial state |46| TON | Expected transaction/state/actions | Exact lengths, low value, acceptance, balance, bounce, duplicate safe |47| Performance | Snapshot recorded | Unreviewed regression fails gate |4849```bash50npx --no-install blueprint build --all51npx --no-install blueprint test52npx --no-install jest --runInBand53```5455## Common Mistakes5657- One happy path is treated as evidence for every layer.58- A negative case changes proof and public inputs together, hiding the intended mismatch.59- Field boundaries, exact BLS slice lengths, public-input reordering, runtime domain, and replay storage are untested.60- Tests assert transaction success but not state delta and outgoing messages.61- Huge `.ptau`, `.zkey`, witness, or secret fixtures are checked in without need/provenance.6263## Completion Gate6465Report fresh commands, fixture provenance, local/getter/message results, acceptance/balance/state assertions, negative coverage, counts, gas, code size, snapshot deltas, and blockers. No “tests pass” claim without fresh output.