# zkthings/zksdk architecture

> Architecture diagram of the GitHub repository zkthings/zksdk, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zkthings/zksdk
- Repository: https://github.com/zkthings/zksdk

## Overview

##### Main Components

A. Core Components:
- ZkMerkle Engine (Main Interface)
- PowerOfTau Ceremony Manager
- Trusted Setup Manager
- Circuit Components
- Proof Generation/Verification System

B. Supporting Infrastructure:
- File System Interface
- Configuration Management
- WASM Runtime Environment
- External Libraries Integration

**┌─ Application Layer ─────────────────────┐**
- User Applications                       │
- ┬────────────────────┬─┘

**┌─ Public API ─────▼────────────────────▼─┐**
- ZkMerkle Class                          │
- ┬────────────────────┬─┘

**┌─ Core Services ──▼────────────────────▼─┐**
- ┌─────────────┐  ┌──────────┐  ┌─────┐ │
- PowerOfTau   │  │Trusted   │  │Proof│ │
- Ceremony     │  │Setup     │  │Gen  │ │
- ┘  └──────────┘  └─────┘ │
- ┬────────────────────┬─┘

**┌─ Circuit Layer ──▼────────────────────▼─┐**
- ┌─────────────┐  ┌──────────┐          │
- Merkle Tree  │  │MiMC      │          │
- Circuit      │  │Sponge    │          │
- ┘  └──────────┘          │
- ┬────────────────────┬─┘

**┌─ Storage Layer ──▼────────────────────▼─┐**
- ┌─────────────┐  ┌──────────┐  ┌─────┐ │
- Circuit      │  │Ceremony  │  │Proof│ │
- Artifacts    │  │Files     │  │Keys │ │
- ┘  └──────────┘  └─────┘ │
- ┘

##### Key Relationships to Highlight

a. Ceremony Flow:
- Multi-participant nature of the trusted setup
- Phase transitions (Phase 1 → Phase 2)
- Coordinator and participant interactions

b. Proof Generation Flow:
- Data input → Circuit processing
- WASM execution path
- Proof output and verification

c. File System Integration:
- Configuration loading
- Artifact storage
- Circuit file management

##### Implementation Details

**src/**
- ZkMerkle.ts         (Main Interface)
- PowerOfTau.ts       (Ceremony Management)
- TrustedSetup.ts     (Setup Configuration)
- types/              (Type Definitions)

**zkConfig/**
- ceremony/           (Ceremony Artifacts)
- circuits/           (Circuit Components)
- templates/          (Contract Templates)

##### Additional Notes

- Version/compatibility information
- Extension points for custom configurations
- Notes about the maximum supported tree depth (15 levels)

Remember to maintain a balance between detail and clarity, focusing on the core zero-knowledge and Merkle tree functionality while still showing the supporting infrastructure.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles
    classDef api fill:#2196F3,stroke:#1565C0,color:white
    classDef core fill:#4CAF50,stroke:#2E7D32,color:white
    classDef circuit fill:#FFC107,stroke:#FFA000,color:black
    classDef storage fill:#9E9E9E,stroke:#616161,color:white
    classDef security fill:#F44336,stroke:#C62828,color:white
    classDef test fill:#673AB7,stroke:#4527A0,color:white

    %% Application Layer
    subgraph AppLayer["Application Layer"]
        UserApp["User Applications"]
    end

    %% Public API Layer
    subgraph APILayer["Public API"]
        ZkMerkle["ZkMerkle Engine"]:::api
    end

    %% Core Services Layer
    subgraph CoreLayer["Core Services"]
        PowerOfTau["PowerOfTau Ceremony Manager"]:::core
        TrustedSetup["Trusted Setup Manager"]:::core
        ProofGen["Proof Generation System"]:::core
    end

    %% Circuit Layer
    subgraph CircuitLayer["Circuit Layer"]
        MerkleCircuit["Merkle Tree Circuit"]:::circuit
        MiMCSponge["MiMC Sponge Circuit"]:::circuit
    end

    %% Storage Layer
    subgraph StorageLayer["Storage Layer"]
        CircuitArtifacts["Circuit Artifacts"]:::storage
        CeremonyFiles["Ceremony Files"]:::storage
        ProofKeys["Proof Keys"]:::storage
    end

    %% Testing Infrastructure
    subgraph TestLayer["Testing Infrastructure"]
        CircuitCompilation["Circuit Compilation"]:::test
        CeremonySimulation["Ceremony Simulation"]:::test
        ProofVerification["Proof Verification"]:::test
    end

    %% External Libraries
    subgraph ExternalLib["External Libraries"]
        FFJavaScript["FFJavaScript Types"]:::api
        SnarkJS["SnarkJS Types"]:::api
    end

    %% Relationships
    UserApp --> ZkMerkle
    ZkMerkle --> PowerOfTau
    ZkMerkle --> TrustedSetup
    ZkMerkle --> ProofGen
    PowerOfTau --> CeremonyFiles
    TrustedSetup --> CircuitArtifacts
    ProofGen --> ProofKeys
    MerkleCircuit --> ProofGen
    MiMCSponge --> ProofGen
    CircuitCompilation --> CircuitArtifacts
    CeremonySimulation --> CeremonyFiles
    ProofVerification --> ProofKeys

    %% Click Events
    click ZkMerkle "https://github.com/zkThings/zkSDK/blob/main/src/ZkMerkle.ts"
    click PowerOfTau "https://github.com/zkThings/zkSDK/blob/main/src/PowerOfTau.ts"
    click TrustedSetup "https://github.com/zkThings/zkSDK/blob/main/src/TrustedSetup.ts"
    click MerkleCircuit "https://github.com/zkThings/zkSDK/blob/main/zk/MerkleTreeProof.circom"
    click MiMCSponge "https://github.com/zkThings/zkSDK/blob/main/zk/mimcsponge.circom"
    click ProofKeys "https://github.com/zkThings/zkSDK/tree/main/zkConfig/circuits/verification/"
    click CircuitArtifacts "https://github.com/zkThings/zkSDK/tree/main/zkConfig/circuits/wasm/"
    click CeremonyFiles "https://github.com/zkThings/zkSDK/blob/main/zkConfig/ceremony/pot/pot15_final.ptau"
    click FFJavaScript "https://github.com/zkThings/zkSDK/blob/main/src/types/ffjavascript.d.ts"
    click SnarkJS "https://github.com/zkThings/zkSDK/blob/main/src/types/snarkjs.d.ts"
    click CircuitCompilation "https://github.com/zkThings/zkSDK/blob/main/src/test/compileCircuits.js"
    click CeremonySimulation "https://github.com/zkThings/zkSDK/blob/main/src/test/simulate-ceremony.ts"
    click ProofVerification "https://github.com/zkThings/zkSDK/blob/main/src/test/test-proof-verify.ts"

    %% Legend
    subgraph Legend
        API["API Component"]:::api
        Core["Core Component"]:::core
        Circuit["Circuit Component"]:::circuit
        Storage["Storage Component"]:::storage
        Test["Test Component"]:::test
    end
```
