Code Monkey home page Code Monkey logo

zkmnist's Introduction

zkMNIST Game

zkMNIST is a proof of concept game that explores the possibility of running a neural network inside a zero knowledge circuit. Game has the following rules:

The goal is to draw a number with the least amount of pixels activated that will be recognized by the model as some number. You can prove that you have such an image without revealing what that image is, to do so you generate a zero-knowledge proof. Later, the only thing you need to expose to is the proof, what digit it is and how many pixels are lit up. The proof is ran through the verifier generated from the circuit and if it passes your score is added to the leader board. Verifier without needing the used input image confirms all the calculations done by the model. Each digit is like a category in speed-running leader board where the proof is like the twitch recording made to confirm that you actually did it.

You can interact with verifiers deployed on Ethereum and zkSync Era.

Using the verifier example:

# Correct public inputs
m@Mateuszs-MacBook-Pro zkmnist % cast call --rpc-url='https://sepolia.gateway.tenderly.co' 0xBB22218723a42eE6B3BfC62D50648c8eA8003e18 "verify(bytes, bytes32[])" `cat proofs/mnist.proof` "[0x0000000000000000000000000000000000000000000000000000000000000002, 0x0000000000000000000000000000000000000000000000000000000000000052]"
0x0000000000000000000000000000000000000000000000000000000000000001

# Invalid public inputs
m@Mateuszs-MacBook-Pro zkmnist % cast call --rpc-url='https://sepolia.gateway.tenderly.co' 0xBB22218723a42eE6B3BfC62D50648c8eA8003e18 "verify(bytes, bytes32[])" `cat proofs/mnist.proof` "[0x0000000000000000000000000000000000000000000000000000000000000004, 0x0000000000000000000000000000000000000000000000000000000000000052]"
Error: 
(code: 3, message: execution reverted, data: Some(String("0xd71fd263")))

Generate a proof

To submit your entry into the game you need to generate a proof that you actually have an image that has a better score than others. Follow the steps below to install noir and prove your input with it.

  • curl -L https://raw.githubusercontent.com/noir-lang/noirup/main/install | bash
  • noirup
  • edit Prover.toml to include your image
  • nargo prove

Deploy the verifier to any evm compliant chain

Since the verifier compiles down to a Solidity contract you can deploy it on any EVM compliant chain. To actually do it, follow these steps:

  • nargo codegen-verifier
  • forge create --rpc-url='<url>' UltraVerifier

Challenges faced

We used zkFloat library, and a surprisingly big issue was understanding it's logic. This implementation was a big help, but confirming that those calculations are valid took us some time.

We were first planning to run the prover in the browser. After fighting with NoirJs compatibility issues, we stumbled upon Unreachable error from WASM. After further investigation, we realized that our model is using over 4GB or RAM (when proving from CLI), so, with WASM overhead, it turned out to be impossible to prove our circuit in the browser client. After confirming with person working in Noir team, they confirmed, that the amount of RAM used can be caused by not optimal approach of the noir compiler, especially regarding matrix multiplication. Noir is still in it's early development state, so it is entirely possible that future versions of the compiler would be able to prove in browser.

Screenshots

image

zkmnist's People

Contributors

michalsidzej avatar mateuszradomski avatar lucadonnoh avatar maciekzygmunt avatar antooni avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.