Skip to content

Integrate Zokrates Proof Generator to Python Backend #18

Description

@silvesterdrago

Objective:

Enhance the Python backend by integrating the Zokrates zk-proof generator for improved security and efficiency.

Requirements:

  1. Configuration Parameters:

    • Add configuration parameters related to the prover:
      • zokrates_executable_location: The location/path where the Zokrates executable is stored.
      • zokrates_work_dir: The working directory for Zokrates operations.
  2. Zokrates Call Integration:

    • Integrate a call to Zokrates within the event handler to initiate the zk-proof generation process.
    • Execute the following Zokrates commands using the subprocess.run method:
      • <zokrates_executable> compute-witness -a <list of params>
      • <zokrates_executable> generate-proof
    • Note: Developers can use the subprocess.run method to execute Zokrates, capturing its stdout and return code.
  3. Zokrates Proof.json File Parser:

    • Develop a parser for the proof.json file generated by Zokrates.
    • Note: You can refer to the existing utility at utils/make_verifier_call.py for guidance and potential code reuse.
  4. Send Encoded Proof and Inputs to Contract:

    • After parsing the proof.json file, encode the proof and its associated inputs.
    • Send the encoded proof and inputs to the contract along with any other results or data.

Development Steps:

  1. Update the backend configuration to include the new Zokrates related parameters.

  2. Modify the event handler to incorporate the Zokrates call for zk-proof generation, utilizing the subprocess.run method to execute the specified commands.

  3. Implement the proof.json file parser, leveraging any relevant code from utils/make_verifier_call.py.

  4. Encode the parsed proof and inputs and integrate the mechanism to send this data to the contract.

  5. Test the entire workflow to ensure the zk-proof generation and transmission processes work seamlessly.

Notes:

Ensure to handle any potential errors or exceptions that might arise during the Zokrates call or the parsing process. Proper logging and error handling will be crucial for debugging and maintenance.

Zokrates code

https://github.com/tommymsz006/zkbattleship-circuit/blob/master/zokrates/code/battleship_sha256.code
https://github.com/tommymsz006/zkbattleship-circuit/blob/master/zokrates/zkprove_sha256

subprocess.run usage

In [1]: import subprocess

In [2]: pr = subprocess.run(["python", "-V"], capture_output=True)

In [3]: pr
Out[3]: CompletedProcess(args=['python', '-V'], returncode=0, stdout=b'Python 3.10.11\n', stderr=b'')

In [4]: pr.returncode
Out[4]: 0

In [5]: pr.stdout
Out[5]: b'Python 3.10.11\n'

In [6]: pr = subprocess.run(["python", "--not-an-argument"], capture_output=True)

In [7]: pr.returncode
Out[7]: 2

In [8]: pr.stdout
Out[8]: b''

In [9]: pr.stderr
Out[9]: b"unknown option --not-an-argument\nusage: /Users/dk/develop/py10playground/venv/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...\nTry `python -h' for more information.\n"

Metadata

Metadata

Assignees

Labels

backendGame Backend Microservice

Type

No type
No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions