Back to Browse

Use with your AI agent

  1. Install — run npx skills add Kali-Decoder/Midnight-skills --skill testing for this skill, or npx skills add Kali-Decoder/Midnight-skills for all
  2. Prompt — copy the example prompt and paste it into Cursor, Claude Code, or Codex
  3. Build — the agent loads this skill and scaffolds your Midnight work

Testing

FoundationBeginnerReviewedUpdated 3 days agov1.0.0

Agent picks this when: Debug Compact contracts, read errors, manage versions

Debug Compact contracts and manage toolchain versions. Static vs dynamic errors, version sync, common traps.

Good for

  • Static vs dynamic errors, reading compiler messages, `--skip-zk` dev loop.
  • Version management across 6 components, common debugging patterns.

Preview in agent

Suggested prompts

Debug Compact contracts, read errors, manage versions. Use the "testing" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Loaded skill testing

What the skill guides the agent to do:

  1. Static vs dynamic errors, reading compiler messages, `--skip-zk` dev loop.
  2. Version management across 6 components, common debugging patterns.

Illustrative — based on the skill's description, not recorded agent output.

Try it without installing: npx skills use Kali-Decoder/Midnight-skills@testing

What changed in v1.0.16

All registry changes

Updated since v1.0.14: +2 −0 lines.

Show diff
SKILL.md+2−0
@@ -6,6 +6,8 @@ **Scope** This skill covers the two error layers in Compact (static vs dynamic), how to read compiler messages (especially undeclared disclosure traces), the fast development loop with `--skip-zk`, version management across 6 components, and the most common debugging patterns. Official testing docs are "coming soon" — this is battle-tested from real development. +**Related:** decode an error with `midnight-common-errors/`, check versions with `midnight-doctor/`, and see what to test before a release in `midnight-testing-checklist/`.+ ## 1) Two Error Layers  Compact has two error types, not one:
On this page · 27 sections
SKILL.md

Scope This skill covers the two error layers in Compact (static vs dynamic), how to read compiler messages (especially undeclared disclosure traces), the fast development loop with --skip-zk, version management across 6 components, and the most common debugging patterns. Official testing docs are "coming soon" — this is battle-tested from real development.

Related: decode an error with midnight-common-errors/, check versions with midnight-doctor/, and see what to test before a release in midnight-testing-checklist/.

1) Two Error Layers

Compact has two error types, not one:

Static errors — Caught by the compiler before generating any output. You see these in your terminal while developing. Static errors are your friend — the compiler tells you exactly what's wrong and where.

Dynamic errors — Caught at runtime by the generated JavaScript. You see these when a circuit executes. These are harder to debug because they happen inside generated code you didn't write.

Static Errors (Compile Time)

Error typeWhat it isWhen caught
SyntaxMalformed codeParser
Type mismatchWrong type usedType checker
Undeclared disclosuredisclose() missingWitness protection
Undefined referenceUnknown identifierName resolver
Generic not specializedGeneric entity used at top levelScope checker
Recursive structStruct refers to itselfDeclaration checker
Recursive circuitCircuit calls itselfDeclaration checker
return in forreturn inside loopStatement checker
Sealed ledger writeWrite to sealed field in circuitDeclaration checker

If the compiler produces no output, there's at least one static error. Check the messages.

Dynamic Errors (Runtime)

Error typeWhat it isExample
Type mismatchWrong argument type/numberCalling with wrong args
OverflowCast value too large for target1000 as Uint<8>
UnderflowCounter decremented below zerocounter -= 1 when at 0
Uninitialized nested valueNested ledger state not initializedmap.lookup(k).lookup(k2) before insert
Merkle tree fullInsert into full treetree.insert() when isFull()

Dynamic errors are harder to debug. Read the error message for the line number in your source file.

2) Reading Compiler Error Messages

Type Error

/path/contract.compact line 12 char 5:
  type error: expected Uint<64>, got Field

Read: line:character, expected type, got type. The caret (^) points to the problem token.

Undeclared Disclosure

Exception: /path/contract.compact line 6 char 11:
  potential witness-value disclosure must be declared but is not:
    witness value potentially disclosed:
      the return value of witness getBalance at line 2 char 1
    nature of the disclosure:
      ledger operation might disclose the witness value
    via this path through the program:
      the right-hand side of = at line 6 char 11

Read this bottom to top. The path traces how witness data traveled:

  1. Origin: getBalance() at line 2
  2. Path: flows through the right-hand side of the assignment
  3. Destination: the ledger operation at line 6

Fix: Add disclose() somewhere along that path, as close to the disclosure point as possible.

Missing disclose() on Return

Exception: line 5 char 3:
  potential witness-value disclosure must be declared but is not:
    witness value potentially disclosed:
      the return value of witness getBalance at line 2 char 1
    nature of the disclosure:
      the value returned from exported circuit check might disclose
      the result of a comparison involving the witness value

Even a Boolean comparison result counts as disclosure. Wrap the witness call or the return value with disclose().

Version Mismatch

Error: Version mismatch: compiled code expects 0.21.0, runtime is 0.16.0

The contract was compiled by toolchain 0.36.x (which targets runtime 0.21.0), but the project still installs @midnight-ntwrk/[email protected]. This message was reproduced on 21 Nov 2026. Pin the runtime the toolchain expects, or compile with the matching toolchain (compact compile +0.36.1). See version management below. <!-- pin-ok -->

3) The --skip-zk Development Loop

Generating proving keys is slow. During iterative development, skip it:

compact compile --skip-zk contracts/contract.compact contracts/managed/contract

This produces contract/index.js and compiler/contract-info.json, enough to test logic. Re-enable for final builds.

4) Version Management

Midnight has 6 components that must stay in sync. When they're not, you get opaque runtime errors about version mismatches.

The expected version of each one is in references/versions.json, the repo's single source of truth (toolchain for the CLI, compiler, language and Docker images; packages / nodePackages for npm).

ComponentWhat it isHow to check
CLI toolcompact binary (devtools)compact --version
Compilertoolchain / languagecompact compile --version, compact compile --language-version
Runtime@midnight-ntwrk/compact-runtimenpm list
Ledger@midnightntwrk/ledger-v9npm list
JS libraries@midnightntwrk/midnight-js-*npm list
Proof servermidnightntwrk/proof-server Docker imageimage tag

Wallet SDK, indexer and node must also come from the same matrix row. ledger-v8, Midnight.js 4.x and Wallet SDK 1.x cannot transact on Ledger 9 networks.

Check Current Versions

compact --version
compact compile --version
compact compile --language-version
npm list @midnight-ntwrk/compact-runtime @midnightntwrk/ledger-v9
npm ls | grep -E "@midnight-?ntwrk/"   # both scopes: a package in both is a duplicate-WASM bug

Consult the Compatibility Matrix

The official release compatibility matrix is the source of truth. Never mix versions without checking it.

Lock Exact Versions in package.json

{
  "dependencies": {
    "@midnight-ntwrk/compact-runtime": "0.21.0",
    "@midnightntwrk/ledger-v9": "1.0.2"
  }
}

Do not use ^ or ~ — these allow automatic updates that silently break compatibility. Also pin the compiler in your build script ("compact": "compact compile +0.36.1 src/x.compact src/managed/x") so a newer default toolchain cannot silently outrun the runtime.

Use npm ci for Reproducible Installs

rm -rf node_modules
npm ci

npm ci installs exactly what's in package-lock.json. npm install fetches the latest matching version.

After Updating Any Component

  1. Update all related components together
  2. Recompile contracts
  3. Restart the proof server with the new Docker image
  4. Run your test suite

5) Common Mistakes and Fixes

Forgot disclose() on Ledger Write

// wrong — compiler error
balance = getBalance();

// correct
balance = disclose(getBalance());

Forgot disclose() on Return Value

// wrong — compiler error (comparison of witness data)
export circuit check(n: Uint<64>): Boolean {
  return getSecret() > n;
}

// correct — declare the disclosure
export circuit check(n: Uint<64>): Boolean {
  return disclose(getSecret()) > n;
}

return Inside for Loop

// wrong — static error
circuit findFirst(v: Vector<4, Field>, target: Field): Boolean {
  for (const x of v) {
    if (x == target) return true;
  }
  return false;
}

// correct — use fold
circuit findFirst(v: Vector<4, Field>, target: Field): Boolean {
  return fold((found, x) => found || x == target, false, v);
}

Recursive Circuit

// wrong — static error: recursion not allowed
circuit factorial(n: Uint<64>): Uint<64> {
  return n == 0 ? 1 : n * factorial(n - 1);
}

Rewrite using fold or explicit unrolling. Compact requires finite circuits.

Narrowing Cast Overflows at Runtime

const x: Uint<64> = 1000;
const y = x as Uint<8>;  // dynamic error: 1000 doesn't fit

Always verify the value fits before casting. Use assert or bounded types.

Uninitialized Nested Ledger State

ledger fld: Map<Boolean, Map<Field, Counter>>;

// wrong — dynamic error (inner map not initialized)
export circuit increment(b: Boolean, n: Field): [] {
  fld.lookup(b).lookup(n) += 1;
}

// correct — initialize first
export circuit init(b: Boolean): [] {
  fld.insert(disclose(b), default<Map<Field, Counter>>);
}

transientHash Result Used Without disclose()

// wrong — compiler error (witness-tainted)
ledger h: Field;
export circuit store(v: Field): [] {
  h = transientHash<Field>(v);
}

// correct — declare disclosure
h = disclose(transientHash<Field>(v));

// or use transientCommit (nonce provides hiding, no disclose needed)
h = transientCommit<Field>(v, nonce);

6) Common Environment Issues

ErrorCauseFix
compact: command not foundBinary not on PATHexport PATH="$HOME/.compact/bin:$PATH"
ERR_UNSUPPORTED_DIR_IMPORTNode.js tried to import directoryOpen new terminal, clear caches
Docker connection errorsDocker Desktop not runningStart Docker Desktop
Port 6300 in useAnother container on same port-p 6301:6300
Version mismatch: compiled code expects X, runtime is YCompiler and compact-runtime from different toolchainsPin runtime 0.21.0 for toolchain 0.36.x, or compile with +<matching version>
setNetworkId / midnight-js-network-id not foundRemoved in Midnight.js 5Pass networkId via providers.config
Indexer 410 ENDPOINT_DECOMMISSIONEDOld preprod/mainnet indexer hostUse Blockfrost endpoints (see references/volatile.md)

7) Version Check Script

Run this before filing a bug report:

#!/bin/bash
echo "=== Midnight Version Check ==="
echo "CLI:"; compact --version || echo "not found"
echo "Compiler:"; compact compile --version || echo "not found"
echo "Runtime:"
npm list --depth=0 | grep -E "@midnight-?ntwrk/" || echo "none found"
echo "Language:"; compact compile --language-version || echo "not found"
echo "Proof server images:"; docker images midnightntwrk/proof-server --format '{{.Tag}}' 2>/dev/null || echo "docker not running"
echo "Node.js:"; node --version
echo "Compare with: docs.midnight.network/relnotes/support-matrix"

8) Getting Help

If stuck after checking these notes:

  1. Discord #dev-chat — post your error message and version details
  2. FAQ — docs.midnight.network/troubleshoot/faq
  3. Forum — forum.midnight.network

Always include:

  • Output of the version check script
  • The full error message
  • The .compact file (or relevant excerpt)
  • What you expected vs what happened

9) Quick Recap

  • Static errors — compiler catches them before output. Check the messages.
  • Dynamic errors — happen at runtime inside generated code. Read the line numbers.
  • Undeclared disclosure trace — read bottom to top, it traces the path from origin to disclosure.
  • Use --skip-zk during development. Enable for final builds.
  • Lock exact versions in package.json. Use npm ci.
  • Check the compatibility matrix before updating any component.
  • After any update: recompile, restart proof server, run tests.

Start in 2 steps

  1. 1. Install — one skill or the full set
  2. 2. Prompt — paste the example into your agent

Install all skills (recommended)

npx skills add Kali-Decoder/Midnight-skills

One command adds every Midnight skill to Cursor, Claude Code, and similar agents.

Install this skill only

npx skills add Kali-Decoder/Midnight-skills --skill testing

Installs only "testing" into every detected agent (Cursor, Claude Code, Codex, …).

Example agent prompt

Debug Compact contracts, read errors, manage versions. Use the "testing" skill from MIDSKILLS. Follow Compact smart-contract best practices, wire wallet flows where needed, and explain each step as you implement. Target Midnight Preprod unless I specify otherwise.

Paste into Cursor, Claude Code, or Codex after installing.

Author
Tusharpamnani
Category
Foundation
Difficulty
beginner
Version
v1.0.0

Tags

TestingCompilerVersions

Files included

SKILL.md
Create Social CardLive HackathonsGallery
Mock Demo
Testing