/midnight-verify:verify-by-zkir-checkerfrom midnight-verify
Verifies zero-knowledge proofs for Midnight Compact contracts by running the real PLONK pipeline: compile without --skip-zk, execute via JS runtime, serialize, and check with @midnight-ntwrk/zkir-v2 WASM. Proves ZK validity beyond logic correctness.
Ships in midnight-verify. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are verifying a Compact contract or ZKIR claim by running the full zero-knowledge proof pipeline. This uses the real PLONK verifier — the same verification path the Midnight network uses. Follow these steps in order.
Always compile without --skip-zk. The whole point of this method is using the real PLONK verifier with real proving keys. A checker ACCEPT proves the ZK proof is valid for those specific inputs. It does NOT prove the circuit is correct for all inputs.
What this proves that verify-by-execution doesn't: The execution skill compiles with --skip-zk and runs the JS runtime — it proves the contract logic works. This skill proves the contract's zero-knowledge proof is valid: constraints are satisfied, transcript encoding is correct, proof data serializes properly, and the PLONK verifier accepts.
The workspace lives at ~/.midnight-expert/verify/zkir-workspace/ in your home directory. It is home-based and independent of the project you are working in.
First time (workspace does not exist):
mkdir -p "$HOME/.midnight-expert/verify/zkir-workspace"
cd "$HOME/.midnight-expert/verify/zkir-workspace"
npm init -y
npm install @midnight-ntwrk/zkir-v2 @midnight-ntwrk/compact-runtime
Subsequent times (workspace exists):
cd "$HOME/.midnight-expert/verify/zkir-workspace"
npm ls @midnight-ntwrk/zkir-v2
If npm ls reports errors, run npm install to repair.
Create the job directory:
JOB_ID=$(uuidgen | tr '[:upper:]' '[:lower:]')
mkdir -p "$HOME/.midnight-expert/verify/zkir-workspace/jobs/$JOB_ID"
The user provides a .compact file or path. The contract may have imports and dependencies on other .compact files in its directory — compile it where it lives, directing only the build output to the job directory.
If the contract has already been compiled with keys (a build directory exists containing keys/*.prover and zkir/*.bzkir), copy those build artifacts to the job directory instead of recompiling.
No user contract provided — you're verifying a natural language claim about ZK behavior. Write a minimal .compact contract in the job directory that exercises the claim.
You may load compact-core skills as hints for writing correct Compact code. The compiled output is your evidence, not the skill content.
--skip-zkcompact compile -- <source-path> "$HOME/.midnight-expert/verify/zkir-workspace/jobs/$JOB_ID/build/"
The source path is the .compact file where it lives (contract mode) or in the job directory (claim mode). The build output always goes to jobs/$JOB_ID/build/.
This produces:
build/zkir/<circuit>.zkir — ZKIR JSONbuild/zkir/<circuit>.bzkir — ZKIR binarybuild/keys/<circuit>.prover — PLONK proving keybuild/keys/<circuit>.verifier — PLONK verifying keybuild/contract/index.js — compiled JS contractbuild/compiler/contract-info.json — circuit metadataIf compilation fails, report the error. For claim mode, fix the contract and retry up to 2 times, then report Inconclusive.
Note: Compilation without --skip-zk is slower than with it because it generates PLONK proving keys. This is expected — you are running the real ZK pipeline.
Import the compiled contract and execute the circuit(s) to get proof data:
import * as compactRuntime from '@midnight-ntwrk/compact-runtime';
import { Contract } from '<job-dir>/build/contract/index.js';
// Create contract instance (may need witnesses depending on the contract)
const contract = new Contract(witnesses);
// Create initial state
const initialZswapLocalState = { coinPublicKey: new Uint8Array(32) };
const state = contract.initialState({ initialZswapLocalState, initialPrivateState: {} });
// Create circuit context
const context = compactRuntime.createCircuitContext(
compactRuntime.dummyContractAddress(),
initialZswapLocalState.coinPublicKey,
state.currentContractState.data,
state.currentPrivateState
);
// Execute the circuit via the circuits interface
const circuitResult = contract.circuits.<circuitName>(context);
// circuitResult contains: { result, context, proofData, gasCost }
// proofData contains: { input, output, publicTranscript, privateTranscriptOutputs }
Check build/compiler/contract-info.json for the list of circuits. Each circuit with "proof": true can be verified through the PLONK checker.
In contract mode, verify each provable circuit. In claim mode, only the circuit relevant to the claim.
const serializedPreimage = compactRuntime.proofDataIntoSerializedPreimage(
circuitResult.proofData.input,
circuitResult.proofData.output,
circuitResult.proofData.publicTranscript,
circuitResult.proofData.privateTranscriptOutputs,
'<circuitName>' // keyLocation — matches the circuit name
);
This function takes 5 individual arguments, not an object. The keyLocation parameter is the circuit name (e.g., 'increment') which the key provider uses to look up the correct keys.
import { check } from '@midnight-ntwrk/zkir-v2';
import { readFileSync } from 'fs';
const keyProvider = {
async lookupKey(keyLocation) {
return {
proverKey: readFileSync(`<job-dir>/build/keys/${keyLocation}.prover`),
verifierKey: readFileSync(`<job-dir>/build/keys/${keyLocation}.verifier`),
ir: readFileSync(`<job-dir>/build/zkir/${keyLocation}.bzkir`)
};
},
async getParams(k) {
return readFileSync(`${process.env.HOME}/.compact/params/params_${k}.bin`);
}
};
try {
const result = await check(serializedPreimage, keyProvider);
// ACCEPTED — result is an array of outputs (bigint or undefined for void)
console.log(JSON.stringify({ verdict: 'ACCEPTED', outputs: result.map(v => v?.toString()) }));
} catch (e) {
// REJECTED — error message identifies which constraint failed
console.log(JSON.stringify({ verdict: 'REJECTED', error: e.message }));
}
Checker error message catalog:
"Communications commitment mismatch" — tampered raw bytes or commitment error"Public transcript input mismatch for input N; expected: Some(XX), computed: Some(YY)" — wrong transcript values"Failed direct assertion" — assert input is boolean 0"Expected boolean, found: XX" — non-boolean to assert/cond_select/constrain_to_boolean"Failed equality constraint: XX != YY" — constrain_eq inputs differ"Bit bound failed: XX is not N-bit" — constrain_bits value exceeds range"Ran out of private transcript outputs" — missing witness data"Transcripts not fully consumed" — extra unused witness dataFor claims about rejection behavior (e.g., "tampering with the transcript is detected"), tamper with the proof data before serialization and confirm the checker rejects with the expected error:
// Example: modify a transcript value
const tamperedProofData = {
...circuitResult.proofData,
publicTranscript: circuitResult.proofData.publicTranscript.map(op => {
if ('addi' in op) return { addi: { immediate: 999 } }; // Wrong value
return op;
})
};
const tamperedSerialized = compactRuntime.proofDataIntoSerializedPreimage(
tamperedProofData.input,
tamperedProofData.output,
tamperedProofData.publicTranscript,
tamperedProofData.privateTranscriptOutputs,
'<circuitName>'
);
// This should reject with "Public transcript input mismatch"
const result = await check(tamperedSerialized, keyProvider);
A rejection in a negative test confirms the claim (the constraint is enforced).
### ZKIR Checker Report
**Claim:** [verbatim]
**Contract source:** [user's file path / minimal contract written for claim]
**Compact source:**
\`\`\`compact
[source code]
\`\`\`
**Compilation:** [compiler version, circuit count, compilation time]
**Execution:** [which circuit(s) executed, proof data summary]
**Checker verdict:** ACCEPTED / REJECTED: [error message]
**Interpretation:** [Confirmed / Refuted / Inconclusive] — [explanation]
rm -rf "$HOME/.midnight-expert/verify/zkir-workspace/jobs/$JOB_ID"
Do NOT remove the base workspace — it's shared across jobs.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
midnight, compact, plonk, zero-knowledge, verification, wasm
npx claudepluginhub midnightntwrk/midnight-expert --plugin midnight-verify19 skills in this plugin
/verify-by-cli-executionmidnight-verify:verify-by-cli-executionVerification by running Compact CLI commands and observing output. Checks CLI availability, runs commands, captures stdout/stderr/exit code, inspects filesystem changes, and interprets results. Covers flag existence, flag behavior, output structure, error messages, exit codes, version info, and CLI-vs-compactc comparisons. Loaded by the cli-tester agent./verify-by-devnetmidnight-verify:verify-by-devnetVerification by running E2E scripts against a local Midnight devnet. Writes SDK test scripts (raw or using testkit-js) that exercise the full transaction pipeline: deploy, call circuits, observe state. Checks devnet health before proceeding. Loaded by the sdk-tester agent. Loads the `midnight-tooling:devnet` skill for infrastructure management./verify-by-executionmidnight-verify:verify-by-executionVerification by compilation and execution. Translates a Compact claim into a minimal test contract, compiles it with the Compact CLI, runs the compiled output with @midnight-ntwrk/compact-runtime, and interprets the result. Loaded by the contract-writer agent. Covers workspace setup (lazy init), contract writing, compilation, runner script creation, execution, and result interpretation. References midnight-tooling:compact-cli for compilation details./verify-by-ledger-sourcemidnight-verify:verify-by-ledger-sourceVerification by source code inspection of the Midnight ledger Rust codebase. Searches and reads the actual Rust implementation to verify claims about transaction structure, token mechanics, cost model, on-chain VM, contract execution, and cryptographic primitives. Routes claims to specific crates within the 24-crate workspace. Uses octocode-mcp for quick lookups, falls back to local cloning for deep investigation. Loaded by the source-investigator agent when the claim domain is ledger/protocol./verify-by-sourcemidnight-verify:verify-by-sourceVerification by source code inspection. Searches and reads the actual compiler, ledger, and runtime source code to verify structural or architectural claims about Compact and Midnight that cannot be tested via compilation. Uses octocode-mcp for quick lookups, falls back to local cloning for deep investigation. Loaded by the source-investigator agent./verify-by-type-checkmidnight-verify:verify-by-type-checkVerification by TypeScript compilation. Writes TypeScript test files that exercise SDK type claims, then runs tsc --noEmit to check if types match. Also verifies user .ts files that import @midnight-ntwrk packages. Loaded by the type-checker agent. Covers workspace setup (lazy init), two modes (claim mode and file mode), type assertion patterns, and result interpretation.Other plugins' skills for the same job