Skip to content

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HIVE Neural Network

A privacy-preserving on-chain neural network training application built on Aztec Network. Draw digits, run inference privately, and submit training updates that improve the shared model β€” all with zero-knowledge proofs.

Features

  • 🧠 Three neural network architectures β€” Single Layer (64β†’10), MLP (64β†’16β†’10), CNN+GAP
  • πŸ” Private training β€” gradient updates computed client-side, committed on-chain via hash
  • ✏️ Draw-to-predict β€” canvas input processed through MNIST pipeline, classified by the contract
  • β›½ Sponsored fee payments β€” gasless transactions through SponsoredFPC
  • πŸ”„ Network switching between Testnet and local network

Quick Start

Prerequisites

  • Node.js >= 22.0.0
  • Yarn package manager
  • Foundry (for Anvil, the local L1 chain)

Installation

git clone <repo-url>
cd aztec-hyve-training
yarn install

Start Local Network & Deploy

# Install the Aztec version manager
bash -i <(curl -s https://install.aztec.network)

# Install the matching Aztec version (see package.json config.aztecVersion)
aztec-up install $(node -e "console.log(require('./package.json').config?.aztecVersion ?? 'latest')")

# Terminal 1: Start Anvil (local L1 chain)
anvil --host 0.0.0.0 -p 8545 --block-time 12

# Terminal 2: Start the Aztec local network
aztec start --local-network --l1-rpc-urls http://localhost:8545

# Terminal 3: Build, deploy, and run
yarn build && yarn deploy-contracts:local-network && yarn dev

Note: The aztec-up install step requires Foundry to not be running. If it fails with "anvil is currently running", stop Anvil first, install, then restart it.

The application will be available at http://localhost:3000


Available Commands

Contracts

yarn build-contracts          # Compile all Noir contracts + generate TS bindings
yarn test:nr                  # Run Noir contract tests (aztec test)

Deployment

yarn deploy-contracts                    # Deploy to local network (default)
yarn deploy-contracts:local-network      # Deploy to local network
yarn deploy-contracts:testnet            # Deploy to testnet (needs SPONSOR_FPC_ADDRESS or SPONSOR_FPC_SALT in .env)
yarn deploy-contracts:all                # Deploy to both

Deployed addresses are written to:

  • config/deployed.local.json β€” local network (gitignored)
  • config/deployed.json β€” testnet (committed)

App

yarn dev                      # Start Vite dev server
yarn build                    # Build contracts + app
yarn build-app                # Build app only
yarn build-app:ci             # CI build (reduced memory)
yarn serve                    # Preview production build

Testing & Quality

yarn test:js                  # Run JS unit tests (vitest)
yarn test:nr                  # Run Noir contract tests
yarn test:e2e                 # Run Playwright E2E tests (deploys + builds first)
yarn test:e2e:local-network   # Run E2E tests against a running local network
yarn lint                     # Check formatting (ESLint + Prettier)
yarn lint:fix                 # Auto-fix formatting

Project Structure

aztec-hyve-training/
β”œβ”€β”€ contracts/                     # Noir smart contracts
β”‚   β”œβ”€β”€ zkml/                      # Shared zkml library (forward pass, backprop, packing)
β”‚   β”‚   └── src/
β”‚   β”‚       β”œβ”€β”€ architectures/     # arch_64_10, arch_64_16_10, arch_cnn_gap
β”‚   β”‚       β”œβ”€β”€ test/              # Pure unit tests for all architectures
β”‚   β”‚       └── *.nr               # conv, pooling, relu, softmax, packing, hash
β”‚   β”œβ”€β”€ single_layer_contract/     # On-chain single-layer network (64β†’10)
β”‚   β”œβ”€β”€ multi_layer_perceptron/    # On-chain MLP (64β†’16β†’10)
β”‚   └── cnn_gap_contract/          # On-chain CNN+GAP network
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ deploy.ts                  # Deployment script (local network + testnet)
β”‚   β”œβ”€β”€ build-contracts.ts         # Contract compile + codegen helper
β”‚   β”œβ”€β”€ pretrained-weights.ts      # Pre-trained weight loaders
β”‚   └── weight-packing.ts          # 9-bit weight packing utilities
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ deployed.json              # Testnet deployment addresses (committed)
β”‚   └── deployed.local.json        # Local deployment addresses (gitignored)
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ artifacts/                 # Generated contract TypeScript bindings
β”‚   β”œβ”€β”€ aztec-wallet/              # Modular Aztec wallet library
β”‚   β”‚   β”œβ”€β”€ adapters/              # Browser wallet adapters (Azguard)
β”‚   β”‚   β”œβ”€β”€ components/            # ConnectButton and modals
β”‚   β”‚   β”œβ”€β”€ connectors/            # Wallet connector implementations
β”‚   β”‚   β”œβ”€β”€ hooks/                 # useAztecWallet, useConnectModal, etc.
β”‚   β”‚   β”œβ”€β”€ providers/             # AztecWalletProvider
β”‚   β”‚   β”œβ”€β”€ services/              # PXE client service
β”‚   β”‚   β”œβ”€β”€ signers/               # Account signing implementations
β”‚   β”‚   β”œβ”€β”€ store/                 # Zustand stores
β”‚   β”‚   └── types/                 # Configuration types
β”‚   β”œβ”€β”€ components/                # React UI components
β”‚   β”‚   β”œβ”€β”€ canvas/                # Drawing canvas and controls
β”‚   β”‚   β”œβ”€β”€ home/                  # Prediction panel, architecture selector
β”‚   β”‚   β”œβ”€β”€ settings/              # Config panel
β”‚   β”‚   β”œβ”€β”€ shapley/               # Shapley value visualisation
β”‚   β”‚   └── ui/                    # Primitive components (Button, Card, Dialog, etc.)
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”œβ”€β”€ contracts.ts           # Contract address registry
β”‚   β”‚   β”œβ”€β”€ walletConfig.ts        # Aztec wallet configuration
β”‚   β”‚   └── networks/              # Network constants
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   β”œβ”€β”€ mutations/             # useTrainOnChain (on-chain training mutation)
β”‚   β”‚   β”œβ”€β”€ network/               # useAztecNode, useNetworkStore
β”‚   β”‚   β”œβ”€β”€ useNeural.ts           # Prediction + training orchestration
β”‚   β”‚   β”œβ”€β”€ useNetworkStatus.ts    # Node connection status
β”‚   β”‚   └── useToast.ts            # Toast notifications (Zustand)
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ Home.tsx               # Main draw-predict-train page
β”‚   β”‚   └── DocsPage.tsx           # Documentation page
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ TrainingService.ts     # Aztec node + contract interaction service
β”‚   β”‚   β”œβ”€β”€ aztec/                 # Low-level Aztec client helpers
β”‚   β”‚   └── core/                  # Image processor, neural trainer (JS-side)
β”‚   β”œβ”€β”€ store/                     # Global Zustand stores
β”‚   β”œβ”€β”€ styles/                    # Tailwind CSS + CVA theme
β”‚   └── utils/                     # Utility functions
└── tests/
    β”œβ”€β”€ unit/
    β”‚   β”œβ”€β”€ config/                # contracts.ts tests
    β”‚   └── services/              # TrainingService, ImageProcessor, NeuralTrainer tests
    └── e2e/
        β”œβ”€β”€ app.test.ts            # Unauthenticated smoke tests
        └── local-network/         # Connected-wallet E2E tests

Architecture Overview

On-Chain Training Flow

Training on Aztec uses a hash-commitment pattern to prevent race conditions:

  1. Client computes the forward pass + backward pass (gradient update) entirely off-chain inside the PXE prover
  2. submit_training_input (private) β€” packs current weights, trains, repacks new weights, enqueues a public call with the hash of new weights
  3. apply_training_update (public, only_self) β€” verifies the committed hash and writes the new packed weights to public storage

This means the gradient computation is proven correct by the ZK circuit, and the public state update is atomic and replay-safe.

Neural Network Architectures

Contract Architecture Weights Biases
SingleLayerContract 64β†’10 linear 640 10
MultiLayerPerceptronContract 64β†’16β†’10 (ReLU) 1,184 26
CNNGAPContract Conv(4×4×3)→ReLU→GAP→FC(3→10) 78 13

Weights are stored packed (9-bit, 28 values per Field) to minimise on-chain storage.

Wallet Options

Wallet Description Use Case
Embedded Keys generated and stored in browser Quick testing
Azguard Browser extension wallet Production, user-controlled keys

Using Azguard Wallet

  1. Install the Azguard browser extension
  2. Navigate to Settings β†’ Fee Configuration
  3. Select FPC in the "Pay fee with" dropdown
  4. Click "Create New FPC" and enter the Sponsored FPC address:
    0x1586f476995be97f07ebd415340a14be48dc28c6c661cc6bdddb80ae790caa4e
    

Adding a New Browser Wallet

To add support for a new browser wallet (e.g., Obsidian):

  1. Create src/aztec-wallet/adapters/obsidian/ with ObsidianAdapter.ts, ObsidianWalletService.ts, and index.ts
  2. Implement IBrowserWalletAdapter in the adapter class
  3. Register it in src/aztec-wallet/config/aztecWallets.ts
  4. Add 'obsidian' to the aztecWallets array in src/config/walletConfig.ts

No changes needed to hooks, providers, or BrowserWalletConnector β€” the adapter pattern handles all wallet-specific logic.


Network Information

Network Node URL Usage
Local Network http://localhost:8080 Development
Testnet https://rpc.testnet.aztec-labs.com/ Public testnet

UI Development

This project uses Tailwind CSS v4 and Radix UI Primitives.

All Tailwind classes must be defined in a styles object at the top of the component β€” never inline:

// βœ… Correct
const styles = {
  container: 'flex flex-col gap-4',
  title: 'text-lg font-semibold text-default',
} as const;

// ❌ Wrong
<div className="flex flex-col gap-4">

Resources


License

MIT β€” see LICENSE for details.


Built with Aztec Network

Contributors

Languages