zkkit witness
Generate a witness file from circuit inputs
Description
The witness command wraps snarkjs to generate a witness file by executing your compiled circuit with provided input values. The witness contains all intermediate wire values needed for proof generation.
Under the hood: This command runs snarkjs wtns calculate [wasm] [input] outputs/[witness]
Usage
bash
zkkit witness [circuit-name] [input-file]Examples
Generate witness from an input JSON file:
bash
zkkit witness multiplier input.jsonExample input.json format:
{
"a": "3",
"b": "5"
}Output
This command generates a witness.wtns file containing all the wire values computed during circuit execution.
Implementation
View how this command works under the hood:
src/commands/witness.js
import { run } from "../utils/exec.js";
export default async function witness(opts = {}) {
const input = opts.input || "inputs/inputs.json";
const name = opts.name || "witness.wtns";
// Use snarkjs to generate witness
await run(
`snarkjs wtns calculate outputs/schema_js/schema.wasm ${input} outputs/${name}`
);
console.log(`✔ Witness generated: outputs/${name}`);
}What it does:
- Accepts input JSON path (defaults to
inputs/inputs.json) - Accepts witness output name (defaults to
witness.wtns) - Uses snarkjs to calculate witness from the compiled WASM binary
- Evaluates the circuit with the provided input values
- Saves the witness file to
outputs/directory