Skip to content

MBrozhko34/ai-zk-compute

Repository files navigation

AI ZK-Compute

This project implements a decentralized hyper-parameter search where off-chain workers train a tiny neural net, produce a Groth16 proof of their reported accuracy, and the on-chain AiOrchestrator verifies proofs and pays rewards.

How it works

  1. Client opens a job with a grid of hyper-parameters (e.g., 3 learning-rates × steps) and funds a bounty.
  2. Workers each claim exactly one grid slot, train locally, generate a witness + Groth16 proof, and submit their accuracy + proof to a contract on-chain.
  3. Orchestrator contract verifies proofs, records accuracies, and when closed, pays 50% to the best accuracy and splits the rest equally among other proven participants.

Components

The project codebase includes:

  • a Solidity orchestrator,
  • a Circom circuit + verifier,
  • a Python worker,
  • and a simple client scripts to open requests.

How to run the project

Prerequisites

  • Modern Linux or Mac OS X operating system
  • Rust 1.90+
  • Node.js 18+
  • pnpm 8+
  • Python 3.9+ (venv recommended)
  • circom 2.1.x (install via Cargo - see below)
  • snarkjs 0.6.x (see below for installation instructions)
  • ts-node 10.x (see below for installation instructions)
  • ptau file for zk

circom (via cargo -> First Install Rust):

snarkjs:

  • pnpm i -g snarkjs

ts-node:

  • pnpm install -g ts-node

Make sure pnpm and .cargo/bin directories are in your executable PATH.

Execute

  • Open terminal window, navigate to the project directory and execute
    • make clean to reset your environment to the initial state (if necessary)
    • make deps to prepare the environment
    • make startup to compile contracts and launch blockhain nodes locally.
  • Open another terminal window in the project directory and execute make run to compile off-chain workers, deploy contract onto the (local) blockchain, and submit sample ML training request.

Makefile targets

  • make startup # compile blockchain side, start blockchain nodes
  • make run # deploy contract on the node, submit sample request
  • make clean # remove all compiler artefacts and environment configuration
  • make mlp-zk # compile ZK-proofs module
  • make nde # compile contracts and start hardhat node
  • make depl # deploy to localhost
  • make req # open a sample request (grid + bounty)
  • make workers-XX REQ_ID=X # compile and run XX workers, submit requests with ID X (number). Makefile defines 3, 6, 9, 12 worker targets. E.g. make workers-12 REQ_ID=0

Project layout

  • contracts/
    • AiOrchestrator.sol # assigns tasks, verifies proofs, pays rewards
    • AccVerifier.sol # auto-generated by snarkjs (do not edit)
  • circuits/
    • MlpHoldoutAcc_256.circom #
    • MlpHoldoutAcc_256_js/ # wasm + witness generator (generated)
    • MlpHoldoutAcc_256_final.zkey # proving key (generated)
  • client/
    • open_request.ts # opens a request with a hyper-parameter grid
  • node/
    • compute_node.py # worker: claim, train, prove, submit
  • Makefile
  • .env

About

Masters Dissertation Project - Solidity Implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published