This project demonstrates verifiable AI inference on-chain using RISC Zero and Boundless. A small neural network trained on MNIST is executed in a zero-knowledge VM (zkVM), and the resulting prediction is verified on the Ethereum blockchain via a smart contract.
The model is run off-chain inside a zkVM, and a zero-knowledge proof (seal) is submitted to an Ethereum smart contract to trustlessly verify the prediction.
- Runs a trained neural network (MNIST digit recognizer) in a zkVM
- Produces a ZK proof of the model's prediction
- Submits the prediction and proof to an Ethereum smart contract (
MNISTPredictor) for on-chain verification - Stores the verified prediction on-chain
Install RISC Zero and Boundless CLI tooling:
curl -L https://risczero.com/install | bash
rzup installInstall Foundry for smart contract development:
curl -L https://foundry.paradigm.xyz | bash
foundryupgit clone https://github.com/your-username/zk-ai-mnist-inference
cd zk-ai-mnist-inferenceMake sure your environment is configured with a valid Ethereum private key and RPC URL (e.g., for Sepolia testnet):
export RPC_URL="https://ethereum-sepolia-rpc.publicnode.com"
export PRIVATE_KEY="your_private_key_here"
export MNIST_PREDICTOR_ADDRESS="deployed_contract_address"If uploading to IPFS via Pinata:
export PINATA_JWT="your_pinata_jwt_token"You can use either a sample MNIST image or provide your own.
RUST_LOG=info cargo run --bin app -- --sampleRUST_LOG=info cargo run --bin app -- --image-file ./input/your_image.txtImage file format must be a list of 784 integers (28x28 pixels), either as a JSON array, CSV, or whitespace-separated.
- The guest binary performs inference using hardcoded weights
- The prediction result is committed to the journal in the zkVM
- A seal (ZK proof) and journal (output) are submitted via Boundless to Ethereum
- The
MNISTPredictorsmart contract verifies the seal and stores the result
forge build
cargo buildforge test -vvv
cargo testDeploy the MNISTPredictor contract to Sepolia:
VERIFIER_ADDRESS="your_verifier_address_here"
forge script contracts/scripts/DeployMNISTPredictor.s.sol --rpc-url ${RPC_URL:?} --broadcast -vv
export MNIST_PREDICTOR_ADDRESS="returned_address_from_deploy"You can upload the guest binary to IPFS or S3. To use Pinata:
export PINATA_JWT="your_pinata_jwt"Run the app without the --program-url flag, and it will automatically upload and use the resulting URL:
cargo run --bin app -- --sampleOr, if you already uploaded your guest:
cargo run --bin app -- --sample --program-url https://your.ipfs.link/to/guestMNISTPredictor.sol: Accepts predictions, verifies ZK proofs, and stores results- Auto-generated interfaces via
alloyare used in the Rust client
- β ZK Inference
- β Seal Generation
- β Ethereum Verification
- β On-Chain Storage
- π Frontend Interface
- π NFT badge for correct predictions
- RISC Zero
- Boundless Market
- Inspired by
boundless-foundry-template
Apache-2.0 Β© 2024 RISC Zero & Contributors