Objective:
Enhance the Python backend by integrating the Zokrates zk-proof generator for improved security and efficiency.
Requirements:
-
Configuration Parameters:
-
Zokrates Call Integration:
-
Zokrates Proof.json File Parser:
-
Send Encoded Proof and Inputs to Contract:
Development Steps:
-
Update the backend configuration to include the new Zokrates related parameters.
-
Modify the event handler to incorporate the Zokrates call for zk-proof generation, utilizing the subprocess.run method to execute the specified commands.
-
Implement the proof.json file parser, leveraging any relevant code from utils/make_verifier_call.py.
-
Encode the parsed proof and inputs and integrate the mechanism to send this data to the contract.
-
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"
Objective:
Enhance the Python backend by integrating the Zokrates zk-proof generator for improved security and efficiency.
Requirements:
Configuration Parameters:
zokrates_executable_location: The location/path where the Zokrates executable is stored.zokrates_work_dir: The working directory for Zokrates operations.Zokrates Call Integration:
subprocess.runmethod:<zokrates_executable> compute-witness -a <list of params><zokrates_executable> generate-proofsubprocess.runmethod to execute Zokrates, capturing its stdout and return code.Zokrates Proof.json File Parser:
proof.jsonfile generated by Zokrates.utils/make_verifier_call.pyfor guidance and potential code reuse.Send Encoded Proof and Inputs to Contract:
proof.jsonfile, encode the proof and its associated inputs.Development Steps:
Update the backend configuration to include the new Zokrates related parameters.
Modify the event handler to incorporate the Zokrates call for zk-proof generation, utilizing the
subprocess.runmethod to execute the specified commands.Implement the
proof.jsonfile parser, leveraging any relevant code fromutils/make_verifier_call.py.Encode the parsed proof and inputs and integrate the mechanism to send this data to the contract.
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.runusage