Skip to content

Commit

Permalink
Feat: Add calldata command to CLI (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekkac authored Oct 30, 2024
1 parent c741f55 commit bd82808
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
3 changes: 2 additions & 1 deletion hydra/garaga/starknet/cli/starknet_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from garaga.starknet.cli.declare import declare_project
from garaga.starknet.cli.deploy import deploy_project
from garaga.starknet.cli.gen import gen
from garaga.starknet.cli.verify import verify_onchain
from garaga.starknet.cli.verify import calldata, verify_onchain

app = typer.Typer(
no_args_is_help=True, # Show help when no arguments are provided
Expand All @@ -14,6 +14,7 @@
app.command(no_args_is_help=True)(declare_project)
app.command(no_args_is_help=True)(deploy_project)
app.command(no_args_is_help=True)(verify_onchain)
app.command(no_args_is_help=True)(calldata)


if __name__ == "__main__":
Expand Down
69 changes: 69 additions & 0 deletions hydra/garaga/starknet/cli/verify.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from enum import Enum
from pathlib import Path
from typing import Annotated

Expand Down Expand Up @@ -146,3 +147,71 @@ def verify_onchain(
rich.print(
f"[bold green]Check it out on[/bold green] {voyager_link_tx(network, invoke_result.hash)}"
)


class CalldataFormat(str, Enum):
starkli = "starkli"
array = "array"


def calldata(
system: Annotated[
ProofSystem,
typer.Option(help="Proof system", autocompletion=complete_proof_system),
],
vk: Annotated[
Path,
typer.Option(
help="Path to the verification key JSON file",
file_okay=True,
dir_okay=False,
exists=True,
autocompletion=lambda: [],
),
],
proof: Annotated[
Path,
typer.Option(
help="Path to the proof JSON file",
file_okay=True,
dir_okay=False,
exists=True,
autocompletion=lambda: [],
),
],
public_inputs: Annotated[
Path,
typer.Option(
help="Path to the public inputs JSON file",
file_okay=True,
dir_okay=False,
exists=True,
autocompletion=lambda: [],
),
] = None,
format: Annotated[
CalldataFormat,
typer.Option(
help="Format",
case_sensitive=False,
show_choices=True,
),
] = CalldataFormat.starkli,
):
"""Generate Starknet verifier calldata given a proof and a verification key."""

if system == ProofSystem.Groth16:
vk_obj = Groth16VerifyingKey.from_json(vk)
proof_obj = Groth16Proof.from_json(proof, public_inputs)

calldata = groth16_calldata_from_vk_and_proof(
vk=vk_obj,
proof=proof_obj,
)
else:
raise ValueError(f"Proof system {system} not supported")

if format == CalldataFormat.starkli:
print(" ".join([str(x) for x in calldata]))
elif format == CalldataFormat.array:
print(calldata)

0 comments on commit bd82808

Please sign in to comment.