Sindri-Labs / sindri-python

Contains SDK code for Sindri APIs
MIT License
4 stars 0 forks source link

Add submit_circuit and submit_proof methods to sindri python sdk #20

Closed KPreisner closed 7 months ago

KPreisner commented 7 months ago

Add submit_circuit and submit_proof methods to sindri python sdk

Reasoning:

Currently, the only way for a user to create a circuit or a proof with the sindri python sdk is to use the create_circuit and create_proof methods. Both of these methods submit the job and then poll until the circuit/proof has a status of either Ready/Failed.

Some applications of the sindri SDK may prefer to submit the circuit or proof job without polling. This PR introduces the submit_circuit and submit_proof methods, which do just that.

Reviewer testing instructions

We want to make sure that the new python sdk methods work and a user can poll for the circuit/proof detail on their own if they choose to do so.

  1. clone the sindri-resources repo somewhere on your system so we have a circuit to upload. The below tests will work as-is if it is cloned to the parent directory of this (sindri-python) repo.
  2. Then, run
    git checkout kp-non-polling-compile-prove-methods
    cd src/sindri
  3. Paste the following python code into a file in your current working directory called test.py. Ensure you are in a python environment with the requests pypi dependency installed.
    
    from sindri import Sindri

circuit_upload_path = "../../../sindri-resources/circuit_database/circom/multiplier2" proof_input_file_path = "../../../sindri-resources/circuit_database/circom/multiplier2/input.json" proof_input = "" with open(proof_input_file_path, "r") as f: proof_input = f.read()

Run Sindri API

API_KEY = "YOUR_API_KEY" API_URL = "https://sindri.app/api/" sindri = Sindri(API_KEY, api_url=API_URL, verbose_level=2)

submit circuit without polling

circuit_id = sindri.submit_circuit(circuit_upload_path)

manually poll circuit detail until status is ready/failed

circuit_status = "" sindri.set_verbose_level(0) while True: circuit_detail = sindri.get_circuit(circuit_id) circuit_status = circuit_detail.get("status", "") if circuit_status in ["Ready", "Failed"]: break

if circuit_status != "Ready": print("Test failed. Circuit not ready. Cannot continue to testing submit_proof method") else:

submit proof without polling

sindri.set_verbose_level(2)
proof_id = sindri.submit_proof(circuit_id, proof_input)
sindri.set_verbose_level(0)

# manually poll proof detail until status is ready/failed
proof_status = ""
while True:
    proof_detail = sindri.get_proof(proof_id)
    proof_status = proof_detail.get("status", "")
    if proof_status in ["Ready", "Failed"]:
        break

if proof_status == "Ready":
    print("Test success!")
else:
    print("Test failed")

1. Change the `API_KEY = "YOUR_API_KEY"` line to include your api key. Optionally change the `API_URL` if you are using a private sindri api instance.
1. Run `python3 test.py`.