Skip to content

Commit

Permalink
Merge pull request #54 from Sindri-Labs/kp-meta-field
Browse files Browse the repository at this point in the history
Add meta field to compile/prove endpoint methods
  • Loading branch information
KPreisner authored Aug 23, 2024
2 parents 920f986 + baf593a commit ba0200c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
36 changes: 27 additions & 9 deletions src/sindri/sindri.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,11 @@ def _set_json_request_headers(self) -> None:
}

def create_circuit(
self, circuit_upload_path: str, tags: list[str] | None = None, wait: bool = True
self,
circuit_upload_path: str,
tags: list[str] | None = None,
wait: bool = True,
meta: dict | None = None,
) -> str:
"""Create a circuit. For information, refer to the
[API docs](https://sindri.app/docs/reference/api/circuit-create/).
Expand All @@ -359,6 +363,9 @@ def create_circuit(
- `circuit_upload_path`: The path to either
- A directory containing your circuit files
- A compressed file (`.tar.gz` or `.zip`) of your circuit directory
- `meta`: An arbitrary mapping of metadata keys to string values.
This can be used to track additional information about the circuit such as an ID
from an external system.
- `tags`: A list of tags to assign the circuit. Defaults to `["latest"]` if not
sepecified.
- `wait`:
Expand Down Expand Up @@ -401,11 +408,16 @@ def create_circuit(
tar.add(circuit_upload_path, arcname=file_name)
files = {"files": fh.getvalue()} # type: ignore

data = {
"tags": tags,
}
if meta is not None:
data["meta"] = json.dumps(meta) # type: ignore
# Hit circuit/create API endpoint
response_status_code, response_json = self._hit_api(
"POST",
"circuit/create",
data={"tags": tags},
data=data,
files=files,
)
if response_status_code != 201:
Expand Down Expand Up @@ -740,13 +752,16 @@ def prove_circuit(
proof_input: str,
perform_verify: bool = False,
wait: bool = True,
meta: dict | None = None,
**kwargs,
) -> str:
"""Prove a circuit with specified inputs. For information, refer to the
[API docs](https://sindri.app/docs/reference/api/proof-create/).
Args:
- `circuit_id`: The circuit identifier of the circuit.
- `meta`: An arbitrary mapping of metadata keys to string values. This can be used to
track additional information about the proof such as an ID from an external system.
- `proof_input`: A string representing proof input which may be formatted as JSON for any
framework. Noir circuits optionally accept TOML formatted proof input.
- `perform_verify`: A boolean indicating whether to perform an internal verification check
Expand Down Expand Up @@ -775,15 +790,18 @@ def prove_circuit(
# 1. Submit a proof, obtain a proof_id.
if self.verbose_level > 0:
print("Prove circuit")

data = {
"proof_input": proof_input,
"perform_verify": perform_verify,
"prover_implementation": prover_implementation,
}
if meta is not None:
data["meta"] = json.dumps(meta)

# Hit the circuit/<circuit_id>/prove endpoint
response_status_code, response_json = self._hit_api(
"POST",
f"circuit/{circuit_id}/prove",
data={
"proof_input": proof_input,
"perform_verify": perform_verify,
"prover_implementation": prover_implementation,
},
"POST", f"circuit/{circuit_id}/prove", data=data
)
if response_status_code != 201:
raise Sindri.APIError(
Expand Down
6 changes: 4 additions & 2 deletions tests/test_sindri.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ def test_circuit_create_prove_other(self):
1. Test delete proof
1. Test delete circuit
"""
circuit_id = sindri.create_circuit(noir_circuit_dir)
proof_id = sindri.prove_circuit(circuit_id, noir_proof_input)
circuit_id = sindri.create_circuit(
noir_circuit_dir, tags=["latest", "pytest"], meta={"py-sdk": "pytest"}
)
proof_id = sindri.prove_circuit(circuit_id, noir_proof_input, meta={"py-sdk": "pytest"})
sindri.get_all_circuit_proofs(circuit_id)
sindri.get_circuit(circuit_id)
sindri.get_proof(proof_id)
Expand Down

0 comments on commit ba0200c

Please sign in to comment.