> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kynesys.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# ZK Setup Guide

> How to setup and generate ZK keys for the Identity System.

# Setup Instructions

This guide explains how to set up the ZK circuits and keys required for the ZK Identity System.

<Note>
  **Validators**: You must use the verification keys committed in the repository to ensure consensus compatibility.
</Note>

## Prerequisites

* Bun runtime
* Dependencies installed (`bun install`)

## Quick Setup

Run the automated setup script to download the Powers of Tau ceremony file, compile circuits, and generate keys:

```bash theme={null}
bun run zk:setup
```

This process will:

1. Download Powers of Tau file (\~140MB)
2. Compile Circom circuits
3. Generate proving (`.zkey`) and verification keys

## Directory Structure

The ZK files are located in `src/features/zk/`:

```
src/features/zk/
├── circuits/           # Source .circom files
├── keys/               # Generated keys (.zkey, .json)
├── proof/              # Proof generation logic
└── scripts/            # Setup scripts
```

## Git Policy

<Warning>
  **Strict Commit Rules**

  * ✅ **COMMIT**: `circuits/*.circom`, `keys/verification_key.json`
  * ❌ **DO NOT COMMIT**: `keys/*.zkey`, `keys/*.ptau`, `*.r1cs`, `*.wasm`
</Warning>

The `verification_key.json` is the trust anchor. All nodes must use the exact same file to verify proofs correctly.

## Manual Steps

If you need to run steps manually:

### 1. Download Powers of Tau

```bash theme={null}
cd src/features/zk/keys/
curl -L -o powersOfTau28_hez_final_14.ptau \
  https://storage.googleapis.com/zkevm/ptau/powersOfTau28_hez_final_14.ptau
```

### 2. Compile Circuits

```bash theme={null}
bun run zk:compile
```

### 3. Generate Keys

```bash theme={null}
# Generate proving key
npx snarkjs groth16 setup \
  src/features/zk/circuits/identity.r1cs \
  src/features/zk/keys/powersOfTau28_hez_final_14.ptau \
  src/features/zk/keys/identity_0000.zkey

# Export verification key
npx snarkjs zkey export verificationkey \
  src/features/zk/keys/identity_0000.zkey \
  src/features/zk/keys/verification_key.json
```
