Skip to content

Commit

Permalink
Add Cairo verify command
Browse files Browse the repository at this point in the history
  • Loading branch information
franalgaba committed Jan 23, 2024
1 parent 093dcdf commit 171ec1f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 5 deletions.
2 changes: 1 addition & 1 deletion giza/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os

__version__ = "0.7.0"
__version__ = "0.8.0"
# Until DNS is fixed
API_HOST = os.environ.get("GIZA_API_HOST", "https://api.gizatech.xyz")
11 changes: 9 additions & 2 deletions giza/commands/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import typer

from giza.frameworks import ezkl
from giza.frameworks import cairo, ezkl
from giza.options import DEBUG_OPTION
from giza.utils.enums import Framework, JobSize

Expand All @@ -19,7 +19,14 @@ def verify(
debug: Optional[bool] = DEBUG_OPTION,
) -> None:
if framework == Framework.CAIRO:
pass
cairo.verify(
proof_id=proof_id,
model_id=model_id,
version_id=version_id,
size=size,
debug=debug,
proof=proof,
)
elif framework == Framework.EZKL:
ezkl.verify(
proof_id=proof_id,
Expand Down
100 changes: 99 additions & 1 deletion giza/frameworks/cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@
from giza.schemas.proofs import Proof
from giza.schemas.versions import VersionCreate, VersionUpdate
from giza.utils import Echo, echo, get_response_info
from giza.utils.enums import Framework, JobSize, JobStatus, ServiceSize, VersionStatus
from giza.utils.enums import (
Framework,
JobKind,
JobSize,
JobStatus,
ServiceSize,
VersionStatus,
)

app = typer.Typer()

Expand Down Expand Up @@ -328,3 +335,94 @@ def transpile(

zip_file.extractall(output_path)
echo(f"Transpilation saved at: {output_path}")


def verify(
proof_id: Optional[int],
model_id: Optional[int],
version_id: Optional[int],
proof: Optional[str] = None,
debug: Optional[bool] = False,
size: JobSize = JobSize.S,
):
"""
Create a verification job.
This command will create a verification job with the provided proof id.
The job size, model id, and version id can be optionally specified.
"""
echo = Echo()
if not model_id or not version_id:
echo.error("Both model id and version id must be provided.")
sys.exit(1)
if proof_id and proof:
echo.error("You can only use either proof_id or proof, but not both.")
sys.exit(1)
try:
job: Job
client = JobsClient(API_HOST)
if proof_id:
job = client.create(
JobCreate(
size=size,
framework=Framework.CAIRO,
kind=JobKind.VERIFY,
model_id=model_id,
version_id=version_id,
proof_id=proof_id,
),
None,
)
elif proof:
with open(proof) as data:
job = client.create(
JobCreate(
size=size,
framework=Framework.CAIRO,
kind=JobKind.VERIFY,
model_id=model_id,
version_id=version_id,
),
data,
)
echo(
f"Verification job created with name '{job.job_name}' and id -> {job.id} ✅"
)
with Live() as live:
while True:
current_job: Job = client.get(job.id, params={"kind": JobKind.VERIFY})
if current_job.status == JobStatus.COMPLETED:
live.update(echo.format_message("Verification job is successful ✅"))
break
elif current_job.status == JobStatus.FAILED:
live.update(
echo.format_error(
f"Verification Job with name '{current_job.job_name}' and id {current_job.id} failed"
)
)
sys.exit(1)
else:
live.update(
echo.format_message(
f"Job status is '{current_job.status}', elapsed {current_job.elapsed_time}s"
)
)
time.sleep(20)
except ValidationError as e:
echo.error("Job validation error")
echo.error("Review the provided information")
if debug:
raise e
echo.error(str(e))
sys.exit(1)
except HTTPError as e:
info = get_response_info(e.response)
echo.error("⛔️Could not create the job")
echo.error(f"⛔️Detail -> {info.get('detail')}⛔️")
echo.error(f"⛔️Status code -> {info.get('status_code')}⛔️")
echo.error(f"⛔️Error message -> {info.get('content')}⛔️")
echo.error(
f"⛔️Request ID: Give this to an administrator to trace the error -> {info.get('request_id')}⛔️"
) if info.get("request_id") else None
if debug:
raise e
sys.exit(1)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "giza-cli"
version = "0.7.0"
version = "0.8.0"
description = "CLI for interacting with Giza"
authors = ["Gonzalo Mellizo-Soto <gonzalo@gizatech.xyz>"]
readme = "README.md"
Expand Down

0 comments on commit 171ec1f

Please sign in to comment.