# vio1etus/zkcnn_complete architecture

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

- Interactive diagram: https://gitdiagram.com/vio1etus/zkcnn_complete
- Repository: https://github.com/vio1etus/zkcnn_complete

## Overview

##### Project Type and Purpose
- This is a C++ command‐line tool/library that implements zero‐knowledge proofs (GKR‐based) for convolutional neural network (CNN) inference (LeNet5, VGG11, VGG16, AlexNet).
- It bundles a core library (circuit construction, polynomial commitment, prover, verifier) plus demo executables and bash scripts to run end‐to‐end experiments.

##### File Structure Analysis
- Top level:
- 3rd/ ‐ submodule “hyrax‐bls12‐381” (polynomial commitment on BLS12-381)
- script/ ‐ bash wrappers to build and run demos (Lenet, VGG, AlexNet)
- src/ ‐ CMakeLists & source code:
– main_demo_*.cpp – entry points for each model
– neuralNetwork.* – constructs model layers & parameters
– circuit.* – encodes the CNN computation as an arithmetic circuit
– polynomial.* – low-level field/polynomial ops
– prover.* – “Prover” class uses circuit + commitment scheme
– verifier.* – “Verifier” class checks generated proof
– utils.*, global_var.hpp – I/O, parameter parsing, common definitions
– models.* – hard-coded network architectures (LeNet, VGG, AlexNet)
- Build: CMakeLists.txt files in root and src/

##### Architectural Insights from README
- Core pipeline:
1. Load image data and network weights
2. Build arithmetic circuit representing CNN inference
3. Commit to polynomials (via Hyrax commitment submodule)
4. Run Prover to generate zero‐knowledge proof of correct inference
5. Optionally run Verifier to check proof
- Demo scripts automate (build → run demo → log outputs)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Orchestration"
        Scripts["CLI / Demo Scripts"]:::data
        CMake["CMake Build System"]:::orchestration
    end

    subgraph "Executables"
        ExecLenet["main_demo_lenet"]:::compute
        ExecVgg["main_demo_vgg"]:::compute
        ExecAlex["main_demo_alexnet"]:::compute
    end

    DataDir["Input Data & Weights (data/, weights)"]:::data
    DataLoader["Data Loader"]:::data
    Models["Model Definitions"]:::compute
    NNBuilder["Neural Network Builder"]:::compute
    Circuit["Circuit Generator"]:::compute
    Polynomial["Polynomial Module"]:::crypto
    Hyrax["Hyrax Submodule"]:::crypto
    Prover["Prover Module"]:::crypto
    Verifier["Verifier Module"]:::crypto
    OutputDir["Output (proof & CSV)"]:::data
    README["README"]:::orchestration

    %% Orchestration flow
    Scripts -->|"invoke CMake"| CMake
    CMake -->|"build executables"| ExecLenet
    CMake -->|"build executables"| ExecVgg
    CMake -->|"build executables"| ExecAlex

    %% Execution flow
    ExecLenet -->|"load data & weights"| DataLoader
    DataDir --> DataLoader
    DataLoader -->|"pass to models"| Models
    Models -->|"construct graph"| NNBuilder
    NNBuilder -->|"generate circuit"| Circuit
    Circuit -->|"provide circuit"| Prover
    Polynomial -->|"field ops"| Prover
    Hyrax -->|"commitment ops"| Prover
    Prover -->|"produce proof"| OutputDir
    Prover -->|"send for verification"| Verifier
    Verifier -.->|"optional verification"| OutputDir

    %% README connection
    Scripts -.-> README
    CMake -.-> README

    %% Click Events
    click Scripts "https://github.com/vio1etus/zkcnn_complete/tree/main/script/"
    click CMake "https://github.com/vio1etus/zkcnn_complete/blob/main/CMakeLists.txt"
    click ExecLenet "https://github.com/vio1etus/zkcnn_complete/blob/main/src/main_demo_lenet.cpp"
    click ExecVgg "https://github.com/vio1etus/zkcnn_complete/blob/main/src/main_demo_vgg.cpp"
    click ExecAlex "https://github.com/vio1etus/zkcnn_complete/blob/main/src/main_demo_alexnet.cpp"
    click DataLoader "https://github.com/vio1etus/zkcnn_complete/blob/main/src/utils.cpp"
    click Models "https://github.com/vio1etus/zkcnn_complete/blob/main/src/models.cpp"
    click NNBuilder "https://github.com/vio1etus/zkcnn_complete/blob/main/src/neuralNetwork.cpp"
    click Circuit "https://github.com/vio1etus/zkcnn_complete/blob/main/src/circuit.cpp"
    click Polynomial "https://github.com/vio1etus/zkcnn_complete/blob/main/src/polynomial.cpp"
    click Prover "https://github.com/vio1etus/zkcnn_complete/blob/main/src/prover.cpp"
    click Verifier "https://github.com/vio1etus/zkcnn_complete/blob/main/src/verifier.cpp"
    click Hyrax "https://github.com/vio1etus/zkcnn_complete/tree/main/3rd/hyrax-bls12-381"
    click README "https://github.com/vio1etus/zkcnn_complete/blob/main/README.md"

    %% Styles
    classDef data fill:#ccffcc,stroke:#2d662d
    classDef compute fill:#cce5ff,stroke:#0b3d91
    classDef crypto fill:#ffe0b2,stroke:#994c00
    classDef orchestration fill:#f0f0f0,stroke:#888
```
