Skip to content

Commit

Permalink
Bind generated Scarb.toml to Garaga git tag version (keep-starknet-st…
Browse files Browse the repository at this point in the history
  • Loading branch information
feltroidprime authored Oct 22, 2024
1 parent 0981867 commit 684d458
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions hydra/garaga/starknet/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import subprocess
from enum import Enum
from importlib.metadata import PackageNotFoundError, version

import rich
from starknet_py.contract import Contract
Expand All @@ -18,6 +19,15 @@
from garaga.hints.io import to_int


def get_package_version():
try:
__version__ = version("garaga")
except PackageNotFoundError:
# package is not installed
__version__ = "dev"
return __version__


class Network(Enum):
SEPOLIA = "sepolia"
MAINNET = "mainnet"
Expand Down
17 changes: 15 additions & 2 deletions hydra/garaga/starknet/groth16_contract_generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from garaga.definitions import CurveID
from garaga.modulo_circuit_structs import G2Line, StructArray
from garaga.precompiled_circuits.multi_miller_loop import precompute_lines
from garaga.starknet.cli.utils import create_directory
from garaga.starknet.cli.utils import create_directory, get_package_version
from garaga.starknet.groth16_contract_generator.parsing_utils import Groth16VerifyingKey

ECIP_OPS_CLASS_HASH = 0x2672F1F079CCBAFE1BE4A20A76421B509FCFB406CBF6818563ED812EDAEB3A3
Expand Down Expand Up @@ -167,6 +167,9 @@ def gen_groth16_verifier(
src_dir = os.path.join(output_folder_path, "src")
create_directory(src_dir)

with open(os.path.join(output_folder_path, ".tools-versions"), "w") as f:
f.write("scarb 2.8.2\n")

with open(os.path.join(src_dir, "groth16_verifier_constants.cairo"), "w") as f:
f.write(constants_code)

Expand All @@ -188,13 +191,23 @@ def gen_groth16_verifier(


def get_scarb_toml_file(package_name: str, cli_mode: bool):
version = get_package_version()
if version == "dev":
suffix = ""
else:
suffix = ', tag = "v' + version + '"'
if cli_mode:
dep = 'git = "https://github.com/keep-starknet-strange/garaga.git"' + suffix
else:
dep = 'path = "../../"'

return f"""[package]
name = "{package_name}"
version = "0.1.0"
edition = "2024_07"
[dependencies]
garaga = {{ {'git = "https://github.com/keep-starknet-strange/garaga.git"' if cli_mode else 'path = "../../"'} }}
garaga = {{ {dep} }}
starknet = "2.8.2"
[cairo]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies = [
"python-dotenv",
"starknet-py-unbroken==0.24.5"
]
description = "State-of-the-art Elliptic Curve operations and SNARKS verification for Cairo & Starknet 🐺."

[project.optional-dependencies]
dev = [
Expand Down
1 change: 1 addition & 0 deletions src/contracts/groth16_example_bls12_381/.tools-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scarb 2.8.2
1 change: 1 addition & 0 deletions src/contracts/groth16_example_bn254/.tools-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scarb 2.8.2

0 comments on commit 684d458

Please sign in to comment.