# ZMKL NPC-Wars ## Idea Build a platform that allows users to compete their AI models against each-other in different classification problems. Users submit an `.onnx` model to our API and we return a solidity contract that the user can deploy which provides a `verify()` function that validates the proof. The flow would go as follows: 1) A user builds their AI model and creates an `.onnx` file. 2) The user uploads their `.onnx` file to our api and we return the bytecode for the contract deployment 3) The user signs the deployment transaction 4) The user can challenge another user to a match 5) The other user accepts the challenge 6) An input is posted (off-chain) by us along with a hashed answer (on-chain) 7) Each user submits their answer with proof and proof is checked 8) Answer is revealed and winner is realized ## API Spec - ### `POST` - `/getVerifierBytecode` - **inputs** - model - `.onnx` `file` - architecture - `string` - name - `string` - data - `json` *(Don't know why this is actually needed by the ezkl library but for some reason you need to generate a proof to generate the verifier as well)* - **outputs** - compiledContract - `hexstring` This endpoint should: **1. create the srs** (eg: `ezkl -K=17 gen-srs --pfsys=kzg --params-path=kzg.params`) **2. generate a proof** (eg: `ezkl --bits=16 -K=17 prove -D ./examples/onnx/1l_relu/input.json -M ./examples/onnx/1l_relu/network.onnx --proof-path 1l_relu.pf --vk-path 1l_relu.vk --params-path=kzg.params `) **3. generate the EVM verifier** (eg: `ezkl -K=17 --bits=16 create-evm-verifier -D ./examples/onnx/1l_relu/input.json -M ./examples/onnx/1l_relu/network.onnx --pfsys=kzg --deployment-code-path 1l_relu.code --params-path=kzg.params --vk-path 1l_relu.vk --sol-code-path 1l_relu.sol`) **4. Append the verifier to the NPC [contract](https://github.com/omurovec/npc-wars/blob/main/contracts/src/NPC.sol)** **5. compile the `create` call for the verifier contract** (with input variables) - ### `POST` - `/getProof` - **inputs** - model - `.onnx` `file` - data - `json` - **outputs** - proof - `.pf` `file` ### Additional notes after the EZKL talk - The srs can be constant (gen_srs in the ezkl api) so we can generate this once and store it in the api path to use - The create-evm-verifier already returns the deployment bytecode so we can return that to begin with instead of having to compile the solidity afterwards