Skip to content

ComposableFi/zk-server

Repository files navigation

ZK HTTP server

Run zk remote api server:

PORT="8000" ADDRESS="0.0.0.0" ED25519CIRCOM_PATH="../ed25519circom" GNARK_JS_PATH="../.nvm/versions/node/v18.19.0/bin/snarkjs" cargo run

How remote API ZK-Prover service works?

  1. Recieved request to generate proof.
  2. Run backgound task to generate proof
  3. Serelized inputs and write input into cicruit root folder : {ed25519_circom_path}/data.json
  4. run npm test. testH2.test.js read the data.json and store batchinput.json into {ed25519_circom_path}/circuits/batchverify_js/batchinput.json
  5. Change directory to {ed25519_circom_path}/circuits/batchverify_js
  6. Execute node generate_witness.js batchverify.wasm batchinput.json witness.wtns -> generated witness.wtns
  7. Change directory {ed25519_circom_path}/circuits
  8. Execute snarkjs groth16 prove batchverify_0001.zkey ./batchverify_js/witness.wtns proof_{h}.json public_{h}.json
  9. Recived request to get the generated proof by block height from relayer. Read proof.json file from {ed25519_circom_path}/circuits/proof_{h}.json and return proof as a string json to the caller.

Note

  1. To run server you need:
    • Install node and npm + gnarkjs
    • Installing dependencies
    • Set env variable : ED25519CIRCOM_PATH - path to ComposableFi/ed25519circom branch zk-service-gnark.
    • Set env variable : GNARK_JS_PATH - path to executable gnarkjs library
    • ED25519CIRCOM_PATH="../ed25519circom" GNARK_JS_PATH="../.nvm/versions/node/v18.19.0/bin/snarkjs" cargo run
  2. Server only handle one proof at a time and DO NOT put/store any request from relayer into the queue to generate proof in future.
  3. Server will ignore any request to generate proof in 2 cases:
    • server busy generating some proof
    • proof for specifed block height already was generated and stored on disk.
  4. Relayer(caller side) need wait and call generate_proof untill remote zk api return back json with a proof_id that means that server started to generate. In other word generate_proof api method will response back with a proof_id to indicate that genration of proof started during this API request.

How to test this

GET http://localhost:8000/status HTTP/1.1



POST http://localhost:8000/create_proof HTTP/1.1
content-type: application/json

{
    "messages": [],
    "pub_keys": [],
    "signatures": [],
    "height: u64,
}



POST http://localhost:8000/get_proof HTTP/1.1
content-type: application/json

{
    "proof_id": "50",
    "height" : 50,
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •